/* ==========================================================================
   MacIndex — styles.css
   Raycast / Linear / macOS-style dark UI.
   ========================================================================== */

:root {
  --bg: #0B0D10;
  --surface: #13161C;
  --surface-2: #1A1E26;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #F3F4F6;
  --text-2: #9CA3AF;
  --text-3: #6B7280;
  --accent: #3B82F6;
  --accent-2: #60A5FA;
  --accent-glow: rgba(59, 130, 246, 0.08);
  --ok: #34D399;
  --err: #F87171;
  --warn: #FBBF24;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* ambient glow behind hero search */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(760px 380px at 50% 24vh, rgba(59, 130, 246, 0.09), transparent 70%);
  opacity: 1;
  transition: opacity .5s var(--ease);
  z-index: 0;
}
body.has-results::before { opacity: .35; background-position: top; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 200;
  background: var(--surface-2); padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { left: 8px; }

.muted { color: var(--text-3); }
.mono { font-family: var(--mono); }

kbd {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 3px 6px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background .3s var(--ease), border-color .3s var(--ease);
  border-bottom: 1px solid transparent;
}

.topbar-inner {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
  justify-items: center;
  grid-template-areas: "brand" "seg" "search" "chips" "suggest";
  padding: clamp(84px, 21vh, 210px) 20px 6px;
  transition: padding .45s var(--ease), gap .3s var(--ease);
}

.brand { grid-area: brand; display: inline-flex; align-items: center; gap: 12px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-name { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; transition: font-size .3s var(--ease); }
.brand-name b { font-weight: 600; color: var(--accent-2); }
.brand-logo { transition: width .3s var(--ease), height .3s var(--ease); }

/* segmented pill */
.seg {
  grid-area: seg;
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.seg button {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 112px;
  padding: 7px 16px;
  background: none; border: 0; border-radius: 999px;
  color: var(--text-2);
  font-weight: 500; font-size: 14px;
  cursor: pointer;
  transition: color .2s;
}
.seg button kbd { opacity: 0; transition: opacity .2s; padding: 2px 5px; font-size: 10px; }
.seg button:hover kbd, .seg button:focus-visible kbd { opacity: .9; }
.seg button[aria-selected="true"] { color: var(--text); }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px;
  width: calc(50% - 3px);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
  transition: transform .3s var(--ease);
}
.seg[data-active="games"] .seg-thumb { transform: translateX(100%); }

/* search input */
.searchbar {
  grid-area: search;
  display: flex; align-items: center; gap: 10px;
  width: 100%; max-width: 680px; height: 54px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, .38);
  transition: border-color .2s, box-shadow .2s, height .3s var(--ease), border-radius .3s var(--ease);
}
.searchbar:focus-within {
  border-color: rgba(96, 165, 250, .6);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, .16), 0 10px 34px rgba(0, 0, 0, .38);
}
.search-icon { color: var(--text-3); flex: none; }
.searchbar input {
  flex: 1; min-width: 0; height: 100%;
  background: none; border: 0; outline: 0;
  color: var(--text); font: inherit; font-size: 17px;
}
.searchbar input::placeholder { color: var(--text-3); }
.kbd-group { display: inline-flex; gap: 6px; flex: none; }
.searchbar:focus-within .kbd-group, .searchbar.has-text .kbd-group { display: none; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; flex: none;
  background: rgba(255, 255, 255, .06); border: 0; border-radius: 8px;
  color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); color: var(--text); }

/* chips */
.chips { grid-area: chips; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip, .suggest button {
  height: 32px; padding: 0 13px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2); font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .15s;
  white-space: nowrap;
}
.chip:hover, .suggest button:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.chip:active, .suggest button:active { transform: scale(.97); }
.chip.is-active {
  background: rgba(59, 130, 246, .14);
  border-color: rgba(96, 165, 250, .45);
  color: var(--accent-2);
}

.suggest { grid-area: suggest; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin-top: 4px; }
.suggest::before { content: "Try"; color: var(--text-3); font-size: 13px; margin-right: 2px; }
.suggest button { border-style: dashed; font-size: 12.5px; height: 28px; }

/* top-right actions */
.top-actions { position: fixed; top: 14px; right: 16px; z-index: 60; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text); font-size: 13.5px; font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--border-strong); background: #20252f; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-primary:hover { background: #2f74e6; border-color: transparent; }
.btn-danger { color: var(--err); }
.btn-small { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }

/* ---------- Results state: compact sticky bar ---------- */

body.has-results .topbar {
  background: rgba(11, 13, 16, .82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom-color: var(--border);
}
body.has-results .topbar-inner {
  padding: 12px 24px 10px;
  gap: 10px 16px;
  justify-items: stretch;
  align-items: center;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "brand seg search actions" "chips chips chips chips";
}
body.has-results .brand-name { font-size: 19px; }
body.has-results .brand-logo { width: 26px; height: 26px; }
body.has-results .brand { gap: 9px; }
body.has-results .searchbar { height: 42px; max-width: 720px; border-radius: 12px; box-shadow: none; }
body.has-results .searchbar input { font-size: 15px; }
body.has-results .seg button { min-width: 0; padding: 5px 13px; font-size: 13px; }
body.has-results .seg button kbd { display: none; }
body.has-results .top-actions { position: static; grid-area: actions; justify-self: end; }
body.has-results .chips {
  justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto;
  scrollbar-width: none; padding-bottom: 2px;
}
body.has-results .chips::-webkit-scrollbar { display: none; }
body.has-results .chip { height: 28px; font-size: 12.5px; }
body.has-results .suggest { display: none; }

/* ---------- Main ---------- */

main { position: relative; z-index: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 8px 24px 40px; flex: 1; }
body.is-hero main { padding-top: 22px; }

.section-title { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }

/* Direct search card */
.direct {
  margin: 14px 0 22px;
  padding: 16px 18px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: rise .35s var(--ease);
}
body.is-hero .direct { max-width: 760px; margin-left: auto; margin-right: auto; }
.direct-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.direct-head h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.direct-head p { font-size: 13px; color: var(--text-2); margin-top: 2px; word-break: break-word; }
.direct-head p em { font-style: normal; color: var(--text); }
.count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  background: rgba(255, 255, 255, .22); border-radius: 999px; font-size: 11px; font-weight: 600;
}
.pills { display: flex; flex-wrap: wrap; gap: 10px; }
.pill-src {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 12px 8px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  transition: background .15s, border-color .15s, transform .15s;
}
.pill-src:hover { background: var(--surface-2); border-color: var(--border-strong); text-decoration: none; transform: translateY(-1px); }
.pill-avatar {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: #fff;
}
.pill-text { display: grid; line-height: 1.25; }
.pill-name { font-size: 13.5px; font-weight: 550; }
.pill-host { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.badge {
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 999px; border: 1px solid transparent;
}
.badge-direct { color: var(--ok); background: rgba(52, 211, 153, .1); border-color: rgba(52, 211, 153, .25); }
.badge-login { color: var(--warn); background: rgba(251, 191, 36, .1); border-color: rgba(251, 191, 36, .28); }

/* tooltip */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 230px; padding: 8px 10px;
  background: #0f1217; border: 1px solid var(--border-strong); border-radius: 8px;
  color: var(--text-2); font-size: 12px; font-weight: 400; line-height: 1.4; text-align: left;
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity .15s, transform .15s; z-index: 30;
}
.tip:hover::after, .tip:focus-visible::after { opacity: 1; transform: none; }

/* CSE wrapper */
.cse-wrap { animation: rise .35s var(--ease) .05s both; }
.cse-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 4px 2px 12px; }
.cse-meta .mono { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }

.empty-card {
  padding: 22px; text-align: center;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--text-2); font-size: 14px;
}
.empty-card strong { color: var(--text); display: block; margin-bottom: 4px; font-size: 15px; }

.loading { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13px; padding: 8px 2px 14px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .15); border-top-color: var(--accent-2); animation: spin .7s linear infinite; }

.footer { position: relative; z-index: 1; padding: 22px 20px 28px; text-align: center; color: var(--text-3); font-size: 12px; }
.noscript { padding: 20px; text-align: center; color: var(--text-2); }

/* ---------- Dialogs ---------- */

dialog {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(5, 6, 8, .62); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .22s var(--ease); }
dialog[open]::backdrop { animation: fade .22s ease; }

.modal { width: min(680px, calc(100vw - 24px)); max-height: min(82vh, 760px); }
.modal-inner, .drawer-inner { display: flex; flex-direction: column; max-height: inherit; height: 100%; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.modal-body { padding: 18px 20px 22px; overflow-y: auto; max-height: calc(min(82vh, 760px) - 60px); }

.src-section + .src-section { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--border); }
.src-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.src-section-head h3 { font-size: 15px; font-weight: 600; }
.src-group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin: 14px 0 8px; font-weight: 600; }
.src-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.src-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; font-size: 13.5px;
}
.src-list .mono { font-size: 12px; color: var(--text-3); }
.dom-list { display: flex; flex-wrap: wrap; gap: 6px; }
.dom { font-family: var(--mono); font-size: 12px; padding: 4px 9px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text-2); }
.note { font-size: 13px; color: var(--text-2); margin-bottom: 18px; }
.note code, .hint code { font-family: var(--mono); font-size: 12px; background: rgba(255, 255, 255, .06); padding: 1px 5px; border-radius: 5px; }

/* Drawer */
.drawer {
  margin: 0 0 0 auto;
  width: min(660px, 100vw);
  height: 100vh; height: 100dvh;
  max-height: none;
  border-radius: 18px 0 0 18px;
  border-right: 0;
}
.drawer[open] { animation: slide .3s var(--ease); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 24px; display: grid; gap: 16px; align-content: start; }
.drawer-foot {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.drawer-foot .btn-danger { margin-left: auto; }

.card { background: var(--bg); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin: 16px 0 8px; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--text-3); margin-top: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 8px; }

.field {
  width: 100%; height: 36px; padding: 0 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font: inherit; font-size: 13.5px; outline: 0;
  transition: border-color .15s, box-shadow .15s;
}
textarea.field { height: auto; min-height: 96px; padding: 9px 11px; resize: vertical; line-height: 1.5; }
.field:focus { border-color: rgba(96, 165, 250, .6); box-shadow: 0 0 0 3px rgba(59, 130, 246, .15); }
.field.mono { font-family: var(--mono); font-size: 12.5px; }
select.field { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, #9CA3AF 50%), linear-gradient(135deg, #9CA3AF 50%, transparent 50%); background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }

.src-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; }
.src-row-top { display: grid; grid-template-columns: minmax(90px, 160px) 1fr; gap: 6px; }
.src-row-bot { display: flex; align-items: center; gap: 6px; }
.src-row-bot .spacer { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.mini {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text-2); cursor: pointer;
}
.mini:hover { color: var(--text); border-color: var(--border-strong); }
.mini:disabled { opacity: .35; cursor: default; }
.mini.del:hover { color: var(--err); }

.conv-result {
  font-family: var(--mono); font-size: 12px; word-break: break-all;
  padding: 10px 11px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: 9px; color: var(--accent-2);
}
.conv-result.err { color: var(--err); }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 1000; display: grid; gap: 8px; justify-items: center; width: min(520px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  display: inline-flex; align-items: center; gap: 10px; max-width: 100%;
  padding: 10px 14px;
  background: rgba(26, 30, 38, .96);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  color: var(--text); font-size: 13.5px;
  opacity: 0; transform: translateY(10px) scale(.98);
  transition: opacity .22s var(--ease), transform .22s var(--ease);
}
.toast.in { opacity: 1; transform: none; }
.toast-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 211, 153, .15); flex: none; }
.toast.err .toast-dot { background: var(--err); box-shadow: 0 0 0 4px rgba(248, 113, 113, .15); }
.toast span:last-child { overflow-wrap: anywhere; }

/* ---------- Animations ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  body.has-results .topbar-inner {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand seg actions" "search search search" "chips chips chips";
  }
  body.has-results .seg { justify-self: start; }
  body.has-results .searchbar { max-width: none; }
}

@media (max-width: 600px) {
  body { font-size: 14.5px; }
  .topbar-inner { padding-left: 14px; padding-right: 14px; }
  .brand-name { font-size: 26px; }
  .searchbar { height: 50px; }
  .searchbar input { font-size: 16px; } /* avoids iOS zoom */
  .kbd-group { display: none; }
  .seg button { min-width: 96px; }
  .seg button kbd { display: none; }
  body.has-results .topbar-inner { padding: 10px 14px 8px; }
  body.has-results .brand-name { display: none; }
  body.has-results .topbar-inner { grid-template-columns: auto 1fr auto; }
  main { padding-left: 14px; padding-right: 14px; }
  .direct { padding: 14px; }
  .direct-head { flex-direction: column; }
  .pills { display: grid; grid-template-columns: 1fr 1fr; }
  .pill-src { padding-right: 8px; min-width: 0; }
  .pill-text { min-width: 0; }
  .pill-host { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pill-src .badge { display: none; }
  .tip::after { right: auto; left: 0; }
  .drawer { border-radius: 0; }
  .src-row-top { grid-template-columns: 1fr; }
  .top-actions .btn span { display: none; }
  .top-actions .btn { padding: 0 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
