:root {
  --ink: #12171f;
  --ink-soft: #1c2430;
  --panel: #243042;
  --line: #3a4a60;
  --paper: #dfe7f2;
  --muted: #8fa0b8;
  --text: #e8eef8;
  --accent: #3dd6c6;
  --accent-ink: #062421;
  --warn: #f0b429;
  --danger: #ff6b6b;
  --given: #9eb0c9;
  --cell: #182130;
  --cell-hover: #223147;
  --selected: #2a4a55;
  --conflict: #4a2430;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font: "Outfit", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body.has-platform-topbar {
  padding-top: var(--platform-topbar-h, 3rem);
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #1f3d45 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, #2a3348 0%, transparent 45%),
    var(--ink);
  min-height: 100vh;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(61, 214, 198, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 214, 198, 0.12) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 85%);
}

.hidden {
  display: none !important;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.btn {
  font-family: var(--font);
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn.ghost:hover {
  color: var(--text);
}

/* Auth */
.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  position: relative;
  z-index: 1;
}

.auth-panel {
  width: min(440px, 100%);
  background: linear-gradient(160deg, #243144, #1a2230);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow);
  animation: rise 0.55s ease both;
}

.auth-panel h1 {
  margin: 0.55rem 0 0.65rem;
  font-size: clamp(1.7rem, 4vw, 2.2rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 1.5rem;
  color: var(--muted);
  line-height: 1.5;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
  padding: 0.3rem;
  background: var(--ink);
  border-radius: 10px;
}

.auth-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.55rem;
  border-radius: 8px;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--panel);
  color: var(--text);
}

.auth-form {
  display: grid;
  gap: 0.9rem;
}

.verify-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

#verify-form .btn.ghost {
  width: 100%;
}

.social-auth {
  margin-top: 1.25rem;
}

.auth-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.9rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.social-buttons {
  display: grid;
  gap: 0.5rem;
}

.social-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.social-btn:hover {
  border-color: var(--accent);
  background: var(--ink-soft);
}

.social-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.social-hint {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.social-hint code {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
}

.auth-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-form input {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
}

.auth-form input:focus {
  outline: 2px solid rgba(61, 214, 198, 0.45);
  border-color: var(--accent);
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

/* App shell */
.app-view {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding: 1rem 1.25rem 2rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  animation: rise 0.45s ease both;
}

.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.user-chip {
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar-stats {
  display: flex;
  gap: 1.25rem;
}

.stat {
  display: grid;
  gap: 0.15rem;
}

.stat-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 1.25rem;
  align-items: start;
}

.board-panel,
.standing-card,
.leaderboard-card {
  background: linear-gradient(165deg, rgba(36, 48, 66, 0.95), rgba(24, 33, 48, 0.98));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.board-panel {
  padding: 1rem;
  animation: rise 0.55s ease 0.05s both;
}

.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.9rem;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 36ch;
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#difficulty {
  font: inherit;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0;
  width: min(100%, 520px);
  margin: 0 auto;
  aspect-ratio: 1;
  border: 2px solid var(--accent);
  border-radius: 8px;
  overflow: hidden;
  background: var(--accent);
}

.cell {
  border: 0;
  margin: 0;
  padding: 0;
  font-family: var(--mono);
  font-size: clamp(1rem, 3.5vw, 1.45rem);
  font-weight: 600;
  color: var(--text);
  background: var(--cell);
  cursor: pointer;
  appearance: none;
  transition: background 0.12s ease, color 0.12s ease;
}

.cell:nth-child(9n + 3),
.cell:nth-child(9n + 6) {
  border-right: 2px solid var(--accent);
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--accent);
}

.cell:not(:nth-child(9n)) {
  box-shadow: inset -1px 0 0 rgba(58, 74, 96, 0.7);
}

.cell:nth-child(n + 10) {
  box-shadow: inset 0 1px 0 rgba(58, 74, 96, 0.7),
    inset -1px 0 0 rgba(58, 74, 96, 0.7);
}

.cell:nth-child(9n) {
  box-shadow: inset 0 1px 0 rgba(58, 74, 96, 0.7);
}

.cell:nth-child(-n + 9) {
  box-shadow: inset -1px 0 0 rgba(58, 74, 96, 0.7);
}

.cell:nth-child(9) {
  box-shadow: none;
}

.cell:hover:not(:disabled) {
  background: var(--cell-hover);
}

.cell.selected {
  background: var(--selected);
  color: #fff;
}

.cell.given {
  color: var(--given);
  cursor: pointer;
}

.cell.conflict {
  background: var(--conflict);
  color: #ffc9c9;
}

.cell.wrong {
  background: var(--conflict);
  color: #ffc9c9;
}

.cell.conflict.same-digit,
.cell.wrong.same-digit {
  background: var(--conflict);
  color: #ffc9c9;
}

.cell.same-digit {
  background: #1f3d48;
  color: #b8fff5;
}

.cell.same-digit.selected {
  background: var(--selected);
  color: #fff;
  box-shadow: inset 0 0 0 2px rgba(61, 214, 198, 0.85);
}

.cell.same-digit.given:not(.selected) {
  color: #9ae8de;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
  width: min(100%, 520px);
  margin: 1rem auto 0;
}

.numpad button {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  background: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0;
  cursor: pointer;
}

.numpad button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.numpad .erase {
  grid-column: span 1;
  font-family: var(--font);
  font-size: 0.85rem;
}

.side-panel {
  display: grid;
  gap: 1rem;
  animation: rise 0.55s ease 0.12s both;
}

.standing-card,
.leaderboard-card {
  padding: 1.1rem 1.15rem;
}

.standing-card h2,
.leaderboard-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
}

.standing-copy,
.side-note {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.standing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0;
}

.standing-grid div {
  background: var(--ink);
  border-radius: 10px;
  padding: 0.65rem 0.5rem;
  text-align: center;
}

.standing-grid dt {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.standing-grid dd {
  margin: 0.25rem 0 0;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1rem;
}

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  max-height: 420px;
  overflow: auto;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  background: rgba(18, 23, 31, 0.55);
  font-size: 0.92rem;
}

.leaderboard li.you {
  outline: 1px solid rgba(61, 214, 198, 0.55);
  background: rgba(61, 214, 198, 0.08);
}

.leaderboard .rank {
  font-family: var(--mono);
  color: var(--muted);
}

.leaderboard .time {
  font-family: var(--mono);
  color: var(--accent);
}

.empty-board {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 10, 14, 0.72);
  backdrop-filter: blur(6px);
}

.modal-panel {
  width: min(420px, 100%);
  background: linear-gradient(165deg, #2a3a4f, #1a2433);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.6rem 1.4rem;
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.35s ease both;
}

.modal-kicker {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  font-weight: 700;
}

.modal-panel h2 {
  margin: 0.45rem 0 0.2rem;
}

.result-time {
  margin: 0.35rem 0 0.75rem;
  font-size: 2.4rem;
  font-weight: 600;
  color: var(--warn);
}

.result-copy {
  margin: 0 0 1.2rem;
  color: var(--muted);
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar-stats {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 520px) {
  .app-view {
    padding: 0.85rem;
  }

  .numpad {
    grid-template-columns: repeat(5, 1fr);
  }

  .auth-panel {
    padding: 1.6rem 1.2rem;
  }
}
