:root {
  --bg: #0b0b10;
  --panel: #13131b;
  --panel-2: #1a1a25;
  --line: #2a2a3a;
  --text: #e9e7f2;
  --dim: #9895ab;
  --accent: #7cf0b0;
  --accent-2: #c38cff;
  --bad: #ff6b8b;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(1200px 600px at 80% -10%, #1d1430 0%, transparent 60%),
                    radial-gradient(900px 500px at -10% 10%, #0f2620 0%, transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--mono); letter-spacing: -0.02em; margin: 0; }
h1 { font-size: clamp(26px, 4vw, 36px); font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
a { color: inherit; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--mono); font-weight: 800; text-decoration: none; font-size: 16px; white-space: nowrap; }
.caret { color: var(--accent); }
nav { display: flex; gap: clamp(10px, 2.5vw, 22px); font-size: 14px; flex-wrap: wrap; justify-content: flex-end; }
nav a, .linkish { color: var(--dim); text-decoration: none; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
nav a:hover, .linkish:hover { color: var(--text); }

main { max-width: 1240px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px); }
section { padding-top: 36px; }

/* ---------- cards / buttons ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.btn {
  font: 600 14px var(--mono);
  background: var(--accent); color: #06140d;
  border: 0; border-radius: 10px; padding: 0 16px; height: 42px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn.ghost { background: transparent; color: var(--dim); border: 1px solid var(--line); }
.btn.ghost:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---------- daily ---------- */
.daily-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.daily-head p { margin: 0; font-family: var(--mono); font-size: 13px; }
.puzzles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 20px; }
.puzzle { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.puzzle > p { margin: 0; }
.puzzle-head { display: flex; justify-content: space-between; align-items: center; }
.tries { display: flex; gap: 5px; }
.tries i { width: 10px; height: 10px; border-radius: 3px; background: var(--line); display: block; }
.tries i.bad { background: var(--bad); }
.tries i.good { background: var(--accent); }

.crop-frame { border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #000; aspect-ratio: 16 / 9; }
.crop {
  width: 100%; height: 100%;
  background-repeat: no-repeat;
  transition: background-size .6s cubic-bezier(.2,.7,.2,1), background-position .6s cubic-bezier(.2,.7,.2,1);
  image-rendering: auto;
}

.guess { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; min-width: 0; }
.combo input, #filter {
  width: 100%; height: 42px; padding: 0 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font: 14px var(--mono);
}
.combo input:focus, #filter:focus { outline: none; border-color: var(--accent-2); }
.suggest {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px);
  list-style: none; margin: 0; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  max-height: 240px; overflow: auto; z-index: 5;
  box-shadow: 0 -12px 30px rgba(0,0,0,.4);
}
.suggest li { padding: 7px 10px; border-radius: 6px; cursor: pointer; font: 14px var(--mono); }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--line); }

.guesses { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.guesses li { font: 13px var(--mono); padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); }
.guesses li.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); text-decoration: line-through; }
.guesses li.skip { color: var(--dim); }
.guesses li.good { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }

.reveal { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: 10px; background: var(--panel-2); }
.reveal img { width: 120px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; flex: none; }
.reveal b { font-family: var(--mono); }
.reveal p { margin: 2px 0 0; font-size: 13px; }
.reveal button { margin-top: 6px; }

/* palette */
.term {
  border-radius: 10px; padding: 16px 18px;
  font: 13px/1.7 var(--mono);
  border: 1px solid var(--line);
  overflow-x: auto; white-space: pre;
  min-height: 210px;
}
.term .cur { display: inline-block; width: .6em; height: 1.1em; vertical-align: -0.2em; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.swatches span { aspect-ratio: 2 / 1; border-radius: 4px; border: 1px solid rgba(255,255,255,.06); }
.swatches.big { gap: 6px; grid-template-columns: repeat(9, 1fr); }
.swatches.big button {
  aspect-ratio: 1.6 / 1; border-radius: 6px; border: 1px solid rgba(255,255,255,.08); cursor: pointer;
  display: flex; align-items: flex-end; justify-content: flex-start; padding: 4px; font: 10px var(--mono);
}
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choices button {
  height: 46px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: 600 14px var(--mono); cursor: pointer;
}
.choices button:hover:not(:disabled) { border-color: var(--accent-2); }
.choices button.bad { color: var(--bad); border-color: var(--bad); text-decoration: line-through; opacity: .7; }
.choices button.good { color: #06140d; background: var(--accent); border-color: var(--accent); }
.choices button:disabled { cursor: default; }

.done { margin-top: 20px; display: flex; gap: 20px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.done p { margin: 4px 0 0; font-family: var(--mono); font-size: 13px; }
.share-preview { margin: 0; font: 13px/1.5 var(--mono); color: var(--dim); }

/* ---------- gallery ---------- */
.gallery { padding-bottom: 40px; }
.gallery-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
#filter { max-width: 280px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 18px; }
.tile {
  text-align: left; padding: 0; overflow: hidden; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: inherit;
  transition: transform .2s, border-color .2s;
}
.tile:hover { transform: translateY(-2px); border-color: #3c3c52; }
.tile .media { position: relative; aspect-ratio: 16/9; background: #000; }
.tile img, .tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .body { padding: 12px 14px 14px; }
.tile h3 { margin: 0 0 8px; font: 700 15px var(--mono); }
.strip { display: flex; height: 8px; border-radius: 4px; overflow: hidden; }
.strip span { flex: 1; }

/* ---------- dialogs ---------- */
dialog.sheet {
  width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); color: var(--text); overflow: auto;
}
dialog.sheet.narrow { width: min(460px, calc(100vw - 32px)); padding: 24px; }
dialog.sheet.narrow h2 { margin-bottom: 14px; }
dialog::backdrop { background: rgba(4,4,8,.72); backdrop-filter: blur(3px); }
.close {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.55); color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
}
.detail-media { aspect-ratio: 16/9; background: #000; }
.detail-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-body { padding: 20px 24px 24px; }
.detail-body p { margin: 6px 0 14px; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin: 8px 0 18px; }
.stat-row b { display: block; font: 800 24px var(--mono); }
.stat-row span { font-size: 12px; color: var(--dim); }
.dist { display: grid; gap: 4px; margin-bottom: 22px; }
.dist div { display: grid; grid-template-columns: 16px 1fr; gap: 8px; align-items: center; font: 12px var(--mono); }
.dist i { display: block; height: 18px; background: var(--line); border-radius: 3px; text-align: right; padding-right: 6px; font-style: normal; line-height: 18px; min-width: 22px; }
.dist i.hi { background: var(--accent); color: #06140d; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); font: 600 13px var(--mono);
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { text-align: center; padding: 30px 16px 40px; border-top: 1px solid var(--line); }

@media (max-width: 560px) {
  .guess { flex-wrap: wrap; }
  .combo { flex-basis: 100%; }
  .guess .btn { flex: 1; }
  .swatches.big { grid-template-columns: repeat(6, 1fr); }
  .reveal img { width: 88px; }
  .term { font-size: 11.5px; padding: 12px 14px; }
  nav #open-help { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .crop, .tile, .toast { transition: none; }
  .term .cur { animation: none; }
}
