:root {
  --bg: #080a10;
  --panel: #0e1119;
  --panel-2: #12161f;
  --line: rgba(255,255,255,.14);
  --text: #eef0f4;
  --muted: #b6bbc7;
  --mint: #72e2bd;
  --cell: 34px;
}
body[data-theme="ember"]      { --accent:#ff7a1a; --accent-2:#ffb347; --accent-deep:#96460e; }
body[data-theme="verdigris"]  { --accent:#2ee6a8; --accent-2:#9df5d9; --accent-deep:#0e7a56; }
body[data-theme="ultraviolet"]{ --accent:#a989ff; --accent-2:#d3c3ff; --accent-deep:#5636b4; }
body[data-theme="glacier"]    { --accent:#6cc8ff; --accent-2:#c1e8ff; --accent-deep:#1f6ea3; }
body[data-theme="meltdown"]   { --accent:#ff4d6d; --accent-2:#ff9fb1; --accent-deep:#9c1f38; }
body[data-theme="goldleaf"]   { --accent:#ffd34d; --accent-2:#ffe9a8; --accent-deep:#a3791a; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}
.noise {
  position: fixed; inset: 0; pointer-events: none; opacity: .05; z-index: 40;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}
button { font: inherit; color: inherit; cursor: pointer; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
  background: rgba(8,10,16,.86); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; flex: 0 0 30px;
  background:
    linear-gradient(45deg, var(--accent) 0 50%, transparent 50%) 0 0 / 15px 15px no-repeat,
    linear-gradient(45deg, #262b38 0 100%) 15px 0 / 15px 15px no-repeat,
    linear-gradient(45deg, #262b38 0 100%) 0 15px / 15px 15px no-repeat,
    linear-gradient(45deg, var(--accent) 0 100%) 15px 15px / 15px 15px no-repeat;
}
.brand-text b { display: block; font: 900 15px/1 "Arial Black", Impact, sans-serif; letter-spacing: .04em; }
.brand-text small { font: 700 9px ui-monospace, monospace; letter-spacing: .22em; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.shard-pill {
  font: 700 12px ui-monospace, monospace; letter-spacing: .08em;
  color: var(--accent-2); border: 1px solid var(--line); padding: 8px 11px; background: var(--panel);
}
.chip-button {
  background: var(--panel); border: 1px solid var(--line);
  font: 700 10px ui-monospace, monospace; letter-spacing: .14em; padding: 9px 12px;
}
.chip-button:hover { border-color: var(--accent); color: var(--accent-2); }
.chip-button.account.signed-in { border-color: var(--accent); color: var(--accent-2); }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px; padding: clamp(14px, 3vw, 34px); max-width: 1280px; margin: 0 auto;
}
.eyebrow {
  font: 700 10px ui-monospace, monospace; letter-spacing: .24em; color: var(--muted); margin: 0 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.eyebrow .dot { width: 7px; height: 7px; background: var(--accent); box-shadow: 0 0 10px var(--accent); display: inline-block; }

.board-shell { background: var(--panel); border: 1px solid var(--line); padding: clamp(14px, 2.4vw, 26px); }
.board-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.board-head h1 { margin: 0; font: 900 clamp(24px, 3.4vw, 40px)/1 "Arial Black", Impact, sans-serif; letter-spacing: -.03em; text-transform: uppercase; }
.board-stats { display: flex; gap: 18px; }
.board-stats small, .side-stats small, .done-stats small { display: block; font: 700 9px ui-monospace, monospace; letter-spacing: .18em; color: var(--muted); }
.board-stats b { font: 800 20px ui-monospace, monospace; color: var(--accent-2); }

#boardWrap {
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto;
  justify-content: center; outline: none; user-select: none; touch-action: none; width: max-content; margin: 0 auto;
  max-width: 100%; overflow: auto; padding-bottom: 4px;
}
#boardWrap:focus-visible { box-shadow: 0 0 0 2px var(--accent-deep); }
#corner { border-right: 2px solid var(--line); border-bottom: 2px solid var(--line); }
#colClues { display: grid; grid-auto-flow: column; border-bottom: 2px solid var(--line); }
#colClues .clue { width: var(--cell); display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 5px 0 4px; gap: 1px; }
#rowClues { display: grid; grid-auto-flow: row; border-right: 2px solid var(--line); }
#rowClues .clue { height: var(--cell); display: flex; justify-content: flex-end; align-items: center; gap: 7px; padding: 0 8px 0 6px; }
.clue span { font: 700 calc(var(--cell) * .38) ui-monospace, monospace; color: var(--text); line-height: 1.05; }
.clue.done span { color: rgba(182,187,199,.38); }
#cells { display: grid; background: var(--panel-2); }
.cell {
  width: var(--cell); height: var(--cell);
  border-right: 1px solid rgba(255,255,255,.07); border-bottom: 1px solid rgba(255,255,255,.07);
  position: relative;
}
.cell.g5r { border-right: 1px solid rgba(255,255,255,.28); }
.cell.g5b { border-bottom: 1px solid rgba(255,255,255,.28); }
.cell.filled { background: var(--accent); box-shadow: inset -3px -4px 0 rgba(0,0,0,.28), inset 2px 2px 0 rgba(255,255,255,.22); }
.cell.marked::after {
  content: "✕"; position: absolute; inset: 0; display: grid; place-items: center;
  font: 700 calc(var(--cell) * .5) ui-monospace, monospace; color: rgba(182,187,199,.55);
}
.cell.marked.auto::after { color: rgba(182,187,199,.3); }
.cell.miss { animation: missflash .45s ease; }
@keyframes missflash { 0%, 60% { background: #d92b45; } 100% { background: transparent; } }
.cell.cursor::before { content: ""; position: absolute; inset: 0; border: 2px solid var(--accent-2); z-index: 2; pointer-events: none; }

.board-foot { display: flex; align-items: center; gap: 18px; margin-top: 16px; flex-wrap: wrap; }
.mode-toggle { display: flex; border: 1px solid var(--line); }
.mode-toggle button { background: transparent; border: 0; padding: 10px 16px; font: 700 11px ui-monospace, monospace; letter-spacing: .12em; color: var(--muted); }
.mode-toggle button.active { background: var(--accent); color: #10131a; }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; }

.side { display: flex; flex-direction: column; gap: 18px; }
.panel { background: var(--panel); border: 1px solid var(--line); padding: 20px; }
.panel h2 { margin: 0 0 8px; font: 900 22px/1.05 "Arial Black", Impact, sans-serif; text-transform: uppercase; letter-spacing: -.02em; }
.panel-copy { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.side-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.side-stats b { font: 800 19px ui-monospace, monospace; color: var(--accent-2); }
.side-actions { display: flex; flex-direction: column; gap: 9px; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border: 1px solid var(--line); background: transparent;
  font: 700 11px ui-monospace, monospace; letter-spacing: .14em; text-decoration: none; color: var(--text);
}
.button.primary { background: var(--accent); border-color: var(--accent); color: #10131a; }
.button.primary:hover { background: var(--accent-2); }
.button.ghost:hover { border-color: var(--accent); color: var(--accent-2); }
.button:disabled { opacity: .45; cursor: default; }

.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(5,6,10,.82); backdrop-filter: blur(6px); padding: 18px; overflow: auto;
}
.overlay[hidden] { display: none; }
.overlay-card {
  width: min(560px, 100%); background: var(--panel); border: 1px solid var(--line);
  padding: clamp(20px, 4vw, 34px); box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.overlay-card.wide { width: min(680px, 100%); }
.overlay-card h2 { margin: 0 0 12px; font: 900 clamp(24px, 4vw, 34px)/1.02 "Arial Black", Impact, sans-serif; text-transform: uppercase; letter-spacing: -.03em; }
.overlay-card > p { color: var(--muted); }
.overlay-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.fine { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
#reveal { width: 100%; height: auto; background: var(--panel-2); border: 1px solid var(--line); margin: 6px 0 14px; }
.done-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.done-stats b { font: 800 20px ui-monospace, monospace; color: var(--accent-2); }
.how-copy p { color: var(--muted); font-size: 14px; }
.how-copy b { color: var(--text); }

.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.theme-card { border: 1px solid var(--line); background: var(--panel-2); padding: 13px; text-align: left; }
.theme-card .swatch { display: flex; gap: 4px; margin-bottom: 9px; }
.theme-card .swatch i { width: 18px; height: 18px; display: block; }
.theme-card b { display: block; font: 800 12px ui-monospace, monospace; letter-spacing: .1em; }
.theme-card small { font: 700 10px ui-monospace, monospace; color: var(--muted); letter-spacing: .1em; }
.theme-card.active { border-color: var(--accent); }
.theme-card.locked { opacity: .8; }

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--panel); border: 1px solid var(--accent); color: var(--accent-2);
  font: 700 11px ui-monospace, monospace; letter-spacing: .12em; padding: 12px 18px;
  opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease; z-index: 60;
  max-width: min(480px, 90vw); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; }
  .panel { flex: 1 1 280px; }
}
@media (max-width: 480px) {
  .board-stats { gap: 12px; }
  .board-stats b { font-size: 16px; }
  .done-stats { grid-template-columns: repeat(2, 1fr); }
  .topbar-right .chip-button { padding: 8px 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .cell.miss { animation: none; }
  #toast { transition: none; }
}
