:root {
  /* OKLCH tinted neutrals — Saturnus charcoal base with a quiet cool-slate tint */
  --bg: oklch(17.5% 0.007 265);
  --topbar: oklch(14.5% 0.007 265);
  --panel: oklch(12.8% 0.006 265);
  --panel-2: oklch(16.2% 0.007 265);
  --raise: oklch(20.5% 0.009 265);
  --line: oklch(24.5% 0.009 265);
  --line-2: oklch(30% 0.011 265);

  --text: oklch(94.5% 0.004 265);
  --muted: oklch(65% 0.01 265);
  --dim: oklch(46% 0.01 265);

  --blue: #3ba8f6;
  --pink: #f2478f;
  --yellow: #f6c94e;
  --green: #4ae3a2;
  --purple: #8d6ef7;
  --orange: #f5894e;

  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --pixel: 'Silkscreen', monospace;

  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --spring-soft: cubic-bezier(.22, 1.28, .36, 1);
  --out: cubic-bezier(.2, .8, .2, 1);

  --r: 20px;
  --r-sm: 12px;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.top {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  letter-spacing: -.01em;
}
.brand canvas { width: 24px; height: 24px; image-rendering: pixelated; border-radius: 6px; }
.brand .sep { color: var(--dim); }
.top .grow { flex: 1; }

.summary { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.summary b { color: var(--text); font: 500 13px var(--mono); margin-right: 4px; }

.seg {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.seg button {
  position: relative;
  z-index: 1;
  padding: 5px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  transition: color .2s var(--out);
}
.seg button.on { color: var(--text); }
.seg .thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: 8px;
  background: var(--raise);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
  transition: left .42s var(--spring), width .42s var(--spring);
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  transition: transform .35s var(--spring), color .2s, border-color .2s;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); transform: scale(1.06); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.spin svg { animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- main layout ---------- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 16px;
  padding: 16px;
  height: calc(100dvh - 56px);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 0 0 5px rgba(0,0,0,.16), 0 20px 40px -22px rgba(0,0,0,.65);
  min-height: 0;
  min-width: 0;
}

/* ---------- stage / search ---------- */
.stage {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.search-head {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.combo-wrap { position: relative; }
.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 12px 0 14px;
  border-radius: 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  transition: border-color .2s var(--out), box-shadow .28s var(--out), background .2s;
}
.search-box:focus-within {
  border-color: var(--blue);
  background: oklch(17.2% 0.009 265);
  box-shadow: 0 0 0 3px rgba(59,168,246,.16);
}
.search-ic { color: var(--muted); flex: none; transition: color .2s, transform .35s var(--spring); }
.search-box:focus-within .search-ic { color: var(--blue); transform: scale(1.08); }
.search-box input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font: 14.5px/1.2 var(--sans);
  letter-spacing: -.005em;
}
.search-box input::placeholder { color: var(--dim); }
.search-box input::-webkit-search-cancel-button { display: none; }

.parsed-pills { display: flex; align-items: center; gap: 6px; flex: none; }
.tok-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 7px;
  font: 500 11.5px var(--mono);
  background: var(--raise);
  color: var(--text);
  animation: pillPop .32s var(--spring) backwards;
}
.tok-pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--blue)); }
.tok-pill.ctx { color: var(--blue); background: rgba(59,168,246,.12); }
@keyframes pillPop { from { opacity: 0; transform: scale(.82) translateY(3px); } }

.clear-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background .15s, color .15s, transform .25s var(--spring);
}
.clear-btn:hover { background: var(--raise); color: var(--text); }
.clear-btn:active { transform: scale(.88); }

.kbd {
  font: 500 11px var(--mono);
  color: var(--dim);
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.suggest-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  background: oklch(16% 0.008 265 / .97);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 18px 40px rgba(0,0,0,.55);
  transform-origin: top center;
  animation: menuIn .24s var(--out);
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
.suggest-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  text-align: left;
  font-size: 13.5px;
  transition: background .12s;
}
.suggest-item:hover, .suggest-item.active { background: var(--raise); }
.suggest-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); flex: none; }
.suggest-item .kind { margin-left: auto; font: 11px var(--mono); color: var(--dim); text-transform: uppercase; }

/* quick filter chips */
.quick-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 1px;
}
.quick-bar::-webkit-scrollbar { display: none; }
.qchip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid transparent;
  transition: color .18s, background .18s, border-color .18s, transform .3s var(--spring);
}
.qchip i { width: 6px; height: 6px; border-radius: 50%; background: var(--dot, var(--blue)); }
.qchip:hover { color: var(--text); background: var(--raise); transform: translateY(-1px); }
.qchip:active { transform: scale(.95); }
.qchip.on { color: var(--text); background: var(--raise); border-color: var(--line-2); }

/* ---------- zero-CLS masonry grid ---------- */
.grid-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.masonry {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}
.mcol {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.gcard {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel-2);
  cursor: pointer;
  transform: translateZ(0);
  transition: transform .36s var(--spring-soft), box-shadow .28s var(--out);
  animation: cardIn .42s var(--out) backwards;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.gcard:hover {
  transform: translateY(-3px) scale(1.012);
  box-shadow: 0 14px 28px -12px rgba(0,0,0,.7), 0 0 0 1px var(--line-2);
  z-index: 2;
}
.gcard:active { transform: scale(.985); }
.gcard.sel {
  box-shadow: 0 0 0 2px var(--blue), 0 16px 32px -14px rgba(59,168,246,.42);
}

.gframe {
  position: relative;
  width: 100%;
  background: var(--raise);
  overflow: hidden;
}
.gframe::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,.04) 50%, transparent 80%);
  background-size: 200% 100%;
  animation: skelSweep 1.3s ease-in-out infinite;
}
.gframe.loaded::before { display: none; }
@keyframes skelSweep { to { background-position: -200% 0; } }

.gframe img, .gframe video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .24s var(--out);
}
.gframe.loaded img, .gframe.loaded video { opacity: 1; }

/* progressive disclosure overlay */
.gover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px;
  background: linear-gradient(180deg, rgba(10,10,13,.45) 0%, transparent 32%, transparent 56%, rgba(10,10,13,.86) 100%);
  opacity: 0;
  transition: opacity .18s var(--out);
  pointer-events: none;
}
.gcard:hover .gover, .gcard:focus-within .gover, .gcard.copied .gover { opacity: 1; }

.gtop { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.gtag-char {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(14,14,18,.78);
  backdrop-filter: blur(8px);
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gtag-char i { width: 6px; height: 6px; border-radius: 50%; flex: none; }

.gbot { display: flex; align-items: center; justify-content: space-between; gap: 6px; pointer-events: auto; }
.gtitle {
  font-size: 11.5px;
  color: rgba(255,255,255,.88);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.copy-mini {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  background: #f3f3f5;
  color: #111114;
  transition: transform .3s var(--spring), background .2s, color .2s;
}
.copy-mini:hover { transform: scale(1.06); }
.copy-mini:active { transform: scale(.92); }
.copy-mini.ok { background: var(--green); color: #091c14; }

.gcard.skeleton { pointer-events: none; animation: none; }

/* empty state */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.empty-state[hidden] { display: none; }
.empty-title { font-size: 16px; font-weight: 500; }
.empty-sub { color: var(--muted); font-size: 13px; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 6px; }

/* ---------- side detail panel ---------- */
.side { display: flex; flex-direction: column; overflow: hidden; }
.side-backdrop { display: none; }
.side-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ph {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.tile {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  display: grid;
  place-items: center;
  flex: none;
}
.tile canvas { width: 18px; height: 18px; image-rendering: pixelated; }
.crumb-wrap { min-width: 0; flex: 1; }
.ph h2 { font-size: 14.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph .sub { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.close-sheet { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  white-space: nowrap;
  background: var(--raise);
  color: var(--muted);
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--blue); background: rgba(59,168,246,.12); }

.side-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.swap { animation: swapIn .38s var(--spring-soft) backwards; }
@keyframes swapIn { from { opacity: 0; transform: translateX(18px) scale(.98); } }

.detail-placeholder {
  margin: auto;
  text-align: center;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}
.ph-ring {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px dashed var(--line-2);
  background: var(--panel-2);
}

.detail-stage {
  border-radius: 14px;
  overflow: hidden;
  background: #0a0a0c;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  max-height: 290px;
}
.detail-stage img {
  width: 100%;
  max-height: 288px;
  object-fit: contain;
  display: block;
}

.action-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: transform .32s var(--spring), background .2s, color .2s, border-color .2s;
}
.btn:hover { transform: scale(1.03); }
.btn:active { transform: scale(.95); }
.btn.light { background: #f2f2f4; color: #101014; font-weight: 600; }
.btn.light.ok { background: var(--green); color: #081c13; }
.btn.dark { background: var(--raise); border: 1px solid var(--line-2); color: var(--text); }

.box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.box h3 {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 7px;
  background: var(--raise);
  border: 1px solid var(--line);
  font: 11.5px var(--mono);
  color: var(--muted);
  transition: color .15s, border-color .15s, transform .25s var(--spring);
}
.tag-btn:hover { color: var(--text); border-color: var(--line-2); transform: translateY(-1px); }
.tag-btn.char { color: var(--text); }
.tag-btn i { width: 6px; height: 6px; border-radius: 50%; }

.sim-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.sim-card {
  border-radius: 10px;
  overflow: hidden;
  background: var(--raise);
  aspect-ratio: 16 / 10;
  cursor: pointer;
  transition: transform .3s var(--spring), box-shadow .2s;
}
.sim-card:hover { transform: scale(1.03); box-shadow: 0 0 0 1px var(--line-2); }
.sim-card img { width: 100%; height: 100%; object-fit: cover; display: block; }

.strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
}
.strip > div { padding: 10px 12px 12px; border-left: 1px solid var(--line); min-width: 0; }
.strip > div:first-child { border-left: 0; }
.strip .k { color: var(--muted); font-size: 11px; }
.strip .v { font: 500 13px var(--mono); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* toast & version */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px) scale(.95);
  z-index: 90;
  padding: 9px 15px;
  border-radius: 11px;
  background: oklch(20% 0.01 265 / .96);
  border: 1px solid var(--line-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 14px 36px rgba(0,0,0,.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--out), transform .34s var(--spring);
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }

.ver {
  position: fixed;
  right: 12px;
  bottom: calc(6px + env(safe-area-inset-bottom));
  font: 10px var(--pixel);
  color: var(--dim);
  letter-spacing: .06em;
  z-index: 5;
  pointer-events: none;
}

/* ?still flag for deterministic screenshots */
.still *, .still *::before { animation: none !important; transition: none !important; }

/* ---------- responsive (laptop & iPhone) ---------- */
@media (max-width: 1400px) {
  .masonry { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .app { grid-template-columns: minmax(0, 1fr) 360px; }
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
    height: calc(100dvh - 56px);
  }
  .masonry { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .top { padding: 0 12px; gap: 10px; }
  .hide-sm { display: none; }
  .seg button { padding: 5px 9px; font-size: 12px; }
  .search-box { height: 46px; }
  .btn, .qchip { min-height: 36px; }

  /* Mobile bottom sheet for detail panel */
  .side {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    pointer-events: none;
    opacity: 0;
    transition: opacity .22s var(--out);
  }
  .side.open { pointer-events: auto; opacity: 1; }
  .side-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.62);
    backdrop-filter: blur(4px);
  }
  .side-inner {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    max-height: 86dvh;
    background: var(--panel);
    border-top: 1px solid var(--line-2);
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(100%);
    transition: transform .36s var(--spring-soft);
  }
  .side.open .side-inner { transform: translateY(0); }
  .close-sheet { display: grid; min-width: 40px; min-height: 40px; }
  .gover { opacity: 1; justify-content: flex-end; background: linear-gradient(180deg, transparent 52%, rgba(10,10,13,.86) 100%); }
  .gtop { display: none; }
  .copy-mini { min-height: 32px; padding: 6px 11px; }
}

@media (max-width: 640px) {
  .top { gap: 6px; padding: 0 10px; overflow: hidden; }
  .brand .sep, .brand .muted, .summary { display: none; }
  .parsed-pills { display: none; }
  .seg button { padding: 4px 7px; font-size: 11px; }
  .icon-btn { width: 32px; height: 32px; flex: none; }
  .grid-scroll { padding: 10px 10px 20px; }
  .search-head { padding: 10px; }
}
