/* The Daily Tangle — arcade-noir theme, mobile first */

:root {
  --bg: #08080f;
  --bg2: #0e0e18;
  --panel: #12121e;
  --panel2: #181826;
  --line: #26263a;
  --text: #eceaf6;
  --muted: #8f8ba3;
  --purple: #b26bff;
  --purple-dim: #7a3fd1;
  --teal: #3df5c8;
  --pink: #ff5da2;
  --amber: #ffcf5d;
  --danger: #ff6b6b;
  --radius: 14px;
  --font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #171230 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- header ---------- */
header {
  width: 100%;
  max-width: 560px;
  padding: 14px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.logo {
  font-weight: 800;
  letter-spacing: 0.12em;
  font-size: 15px;
  text-transform: uppercase;
}
.logo .tangle { color: var(--purple); }
.logo .daily { color: var(--text); }

.hdr-right { display: flex; align-items: center; gap: 8px; }

.streak {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--amber);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  white-space: nowrap;
}

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font);
  font-weight: 700;
  font-size: 15px;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  min-height: 52px;
  cursor: pointer;
  color: #0b0614;
  background: linear-gradient(135deg, var(--purple), var(--teal));
  box-shadow: 0 4px 24px rgba(178, 107, 255, 0.35);
  transition: transform 0.08s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

.btn.ghost {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 14px;
}

.btn.small {
  min-height: 40px;
  padding: 9px 14px;
  font-size: 13px;
  border-radius: 10px;
}

.btn.block { width: 100%; }

/* ---------- tabs ---------- */
.tabs {
  width: 100%;
  max-width: 560px;
  display: flex;
  gap: 6px;
  padding: 6px 16px 0;
}
.tab {
  flex: 1;
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  padding: 12px 0;
  min-height: 48px;
  border-radius: 12px 12px 0 0;
  border: 1px solid transparent;
  border-bottom: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.tab.active {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

/* ---------- layout ---------- */
main {
  width: 100%;
  max-width: 560px;
  flex: 1;
  padding: 0 16px 24px;
}
.tabpane { display: none; }
.tabpane.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
}

.puzzle-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 2px 0 12px;
}
.puzzle-date {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}
.next-in {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--teal);
}

/* ---------- puzzle-type switcher ---------- */
.ptype-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 12px;
}
.ptype-tab {
  flex: 1;
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 0;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.ptype-tab.active {
  background: linear-gradient(135deg, var(--purple), var(--teal));
  color: #0b0614;
}

/* ---------- grid ---------- */
#grid[hidden] { display: none; }
#grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  aspect-ratio: 1 / 1;
  border-radius: 7px;
  border: 1px solid #1d1d2e;
  background: #14141f;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.06s ease;
  touch-action: manipulation;
}
.cell:active { transform: scale(0.92); }
.cell.on {
  background: radial-gradient(circle at 50% 40%, #d9b8ff 0%, var(--purple) 45%, var(--purple-dim) 100%);
  border-color: var(--purple);
  box-shadow: 0 0 10px rgba(178, 107, 255, 0.75), inset 0 0 6px rgba(255,255,255,0.25);
}
.cell:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

/* ---------- sudoku ---------- */
#sudoku-wrap { margin-bottom: 4px; }
#sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  user-select: none;
  -webkit-user-select: none;
  border: 2px solid #4a4a6e;
  border-radius: 8px;
  overflow: hidden;
}
.sb-cell {
  aspect-ratio: 1 / 1;
  background: #14141f;
  border: 0;
  border-right: 1px solid #23233a;
  border-bottom: 1px solid #23233a;
  color: var(--text);
  font-family: var(--mono);
  font-size: clamp(15px, 4.8vw, 23px);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}
.sb-cell.shade { background: #171724; }
.sb-cell.bl { border-left: 2px solid #4a4a6e; }
.sb-cell.bt { border-top: 2px solid #4a4a6e; }
.sb-cell.given { color: var(--purple); }
.sb-cell.user { color: var(--teal); }
.sb-cell.wrong { color: var(--danger); }
.sb-cell.selected { background: rgba(178, 107, 255, 0.38) !important; }
.sb-cell.related { background: rgba(178, 107, 255, 0.14); }
.sb-cell.shade.related { background: rgba(178, 107, 255, 0.18); }
.sb-cell:focus-visible { outline: 2px solid var(--teal); outline-offset: -2px; }
.sb-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 3px;
  pointer-events: none;
}
.sb-notes span {
  font-size: clamp(6px, 1.9vw, 10px);
  font-weight: 400;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.numkey {
  min-height: 54px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, background 0.12s ease;
}
.numkey:active { transform: scale(0.93); }
.numkey.wide { grid-column: span 4; font-size: 14px; font-family: var(--font); }
.numkey.notes-on {
  border-color: var(--teal);
  color: var(--teal);
  box-shadow: 0 0 10px rgba(61, 245, 200, 0.35);
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.hud .stat {
  flex: 1;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.hud .stat .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.hud .stat .value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  margin-top: 2px;
}

.controls {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.controls .btn, .controls .ghost { flex: 1; }

.rules-link {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-family: var(--font);
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
  padding: 10px;
  min-height: 44px;
}

/* ---------- leaderboard ---------- */
.lb-row {
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.lb-row:last-child { border-bottom: 0; }
.lb-row.me {
  background: rgba(178, 107, 255, 0.12);
  border-radius: 10px;
  border-bottom: 0;
}
.lb-rank { font-family: var(--mono); color: var(--muted); font-weight: 700; }
.lb-row:nth-child(1) .lb-rank { color: var(--amber); }
.lb-row:nth-child(2) .lb-rank { color: #cfd6e4; }
.lb-row:nth-child(3) .lb-rank { color: #e09a5a; }
.lb-handle { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-time { font-family: var(--mono); color: var(--teal); }
.lb-moves { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.lb-note { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 8px; }
.lb-own {
  margin-top: 10px;
  text-align: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--amber);
}

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 4px; }
.stat-card {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
}
.stat-card .big { font-family: var(--mono); font-size: 24px; font-weight: 700; color: var(--purple); }
.stat-card .cap { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 4px; }
.recent { margin-top: 14px; }
.recent-row {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 13px;
  padding: 9px 4px; border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.recent-row span:last-child { color: var(--text); }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 4, 10, 0.78);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 20px 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal h2 { margin: 0 0 8px; font-size: 20px; letter-spacing: 0.02em; }
.modal p { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 8px 0; }
.modal .field { margin: 14px 0; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.modal input[type="email"], .modal input[type="text"] {
  width: 100%;
  font-family: var(--mono);
  font-size: 16px;
  color: var(--text);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  min-height: 52px;
}
.modal input:focus { outline: 2px solid var(--purple); border-color: var(--purple); }
.modal .err { color: var(--danger); font-size: 13px; min-height: 20px; margin: 8px 0 0; }
.modal .row { display: flex; gap: 10px; margin-top: 14px; }
.modal .row .btn, .modal .row .ghost { flex: 1; }
.win-stats { display: flex; gap: 10px; margin: 16px 0; }
.win-stats div { flex: 1; text-align: center; background: var(--panel2); border-radius: 12px; padding: 12px 6px; }
.win-stats .v { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--teal); }
.win-stats .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px; }
.newbest {
  text-align: center; font-weight: 800; letter-spacing: 0.06em;
  color: var(--amber); margin: 4px 0 0; font-size: 15px;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel2);
  border: 1px solid var(--purple-dim);
  color: var(--text);
  font-size: 14px;
  padding: 13px 18px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: calc(100vw - 40px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- confetti ---------- */
.confetti {
  position: fixed;
  top: -12px;
  width: 9px; height: 14px;
  border-radius: 2px;
  z-index: 90;
  pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: 0.7; }
}

footer {
  width: 100%;
  max-width: 560px;
  padding: 8px 16px 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-family: var(--mono);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

@media (min-width: 600px) {
  .logo { font-size: 17px; }
  #grid { gap: 6px; }
}
