:root {
  --bg: #090b10;
  --stone: #121621;
  --stone-light: #181e2d;
  --stone-elevated: #1e2638;
  --border: #273046;
  --gold: #d4a64a;
  --gold-bright: #f2cc78;
  --gold-dim: rgba(212, 166, 74, 0.35);
  --gold-soft: rgba(212, 166, 74, 0.12);
  --arcane: #38bdf8;
  --arcane-soft: rgba(56, 189, 248, 0.14);
  --fel: #34d399;
  --crimson: #f87171;
  --crimson-soft: rgba(248, 113, 113, 0.14);
  --text: #eef1f7;
  --text-muted: #98a2b8;
  --text-dim: #667085;
  --font-display: "Cinzel", Georgia, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  position: relative;
}

.bg-artwork {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(ellipse at 50% 48%, rgba(9, 11, 16, 0.88) 0%, rgba(9, 11, 16, 0.62) 55%, rgba(9, 11, 16, 0.25) 100%),
    url("/assets/sudoku-bg.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.72;
  pointer-events: none;
  z-index: 0;
}

.bg-runes {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(212, 166, 74, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(212, 166, 74, 0.03) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 25%, black 15%, transparent 80%);
  pointer-events: none;
  z-index: 0;
}

.bg-aura {
  position: fixed;
  top: -160px;
  left: 50%;
  transform: translateX(-50%);
  width: 780px;
  height: 440px;
  background: radial-gradient(
    ellipse at center,
    rgba(212, 166, 74, 0.11) 0%,
    rgba(56, 189, 248, 0.08) 48%,
    transparent 75%
  );
  filter: blur(50px);
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 20px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

.back-link,
.sync-link {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  width: fit-content;
  transition: color 0.15s ease;
}

.back-link:hover,
.sync-link:hover {
  color: var(--gold-bright);
}

.sync-link {
  color: var(--arcane);
}

.title-group {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.game-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #fceabb 0%, #d4a64a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.game-subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.adventurer-card {
  background: linear-gradient(180deg, var(--stone-light), var(--stone));
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 10px 14px;
  min-width: 230px;
}

.adv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.adv-level {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold-bright);
}

.adv-rank {
  color: var(--text);
  font-weight: 600;
}

.adv-cleared {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.76rem;
}

.xp-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--fel));
  transition: width 0.35s ease;
}

.adv-xp-text {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
}

.quest-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 14px 0;
}

.control-group {
  display: inline-flex;
  background: var(--stone);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.pill-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

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

.pill-btn.is-active {
  background: var(--stone-elevated);
  color: var(--gold-bright);
  border-color: var(--gold-dim);
}

.quest-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#glyph-toggle {
  background: var(--stone);
  border-color: var(--border);
  font-family: var(--font-display);
}

.timer-pill {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--stone);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

.btn-gold {
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, rgba(212, 166, 74, 0.25), rgba(212, 166, 74, 0.12));
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-gold:hover {
  background: linear-gradient(180deg, rgba(212, 166, 74, 0.36), rgba(212, 166, 74, 0.18));
}

.btn-gold:active {
  transform: scale(0.98);
}

.play-area {
  display: grid;
  grid-template-columns: auto minmax(260px, 310px);
  align-items: start;
  justify-content: center;
  gap: 28px;
  margin-top: 4px;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toast-slot {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.rpg-toast {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gold-bright);
  background: var(--gold-soft);
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  padding: 3px 14px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.rpg-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.sudoku-board {
  width: min(92vw, 486px);
  height: min(92vw, 486px);
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--stone);
  border: 2px solid var(--gold-dim);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  user-select: none;
}

.cell {
  position: relative;
  border: none;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--stone);
  color: var(--arcane);
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 3.2vw, 1.48rem);
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.cell:nth-child(9n) {
  border-right: none;
}

.cell:nth-child(n + 73) {
  border-bottom: none;
}

.cell.box-right {
  border-right: 2px solid var(--gold-dim);
}

.cell.box-bottom {
  border-bottom: 2px solid var(--gold-dim);
}

.cell.is-given {
  color: var(--text);
  background: rgba(255, 255, 255, 0.02);
}

.cell.is-peer {
  background: rgba(255, 255, 255, 0.035);
}

.cell.is-same-num {
  background: var(--arcane-soft);
}

.cell.is-selected {
  background: rgba(212, 166, 74, 0.18);
  box-shadow: inset 0 0 0 2px var(--gold);
}

.cell.is-error {
  color: var(--crimson);
  background: var(--crimson-soft);
}

.cell.is-flash {
  animation: wardFlash 0.7s ease;
}

@keyframes wardFlash {
  0% {
    background: rgba(212, 166, 74, 0.42);
  }
  100% {
    background: var(--stone);
  }
}

.notes-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 2px;
  pointer-events: none;
}

.note-num {
  display: grid;
  place-items: center;
  font-family: var(--font-sans);
  font-size: clamp(0.54rem, 1.4vw, 0.68rem);
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1;
}

.command-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 38px;
}

.boon-box {
  background: linear-gradient(180deg, var(--stone-light), var(--stone));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.boon-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.boon-name {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--gold-bright);
}

.boon-charges {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--arcane);
}

.boon-desc {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-arcane {
  width: 100%;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.14);
  color: #bae6fd;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn-arcane:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.24);
}

.btn-arcane:disabled {
  opacity: 0.45;
  cursor: default;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--stone);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 6px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.action-btn:hover {
  border-color: var(--gold-dim);
  color: var(--text);
}

.action-btn.is-active {
  background: var(--arcane-soft);
  border-color: var(--arcane);
  color: #bae6fd;
}

.action-icon {
  font-size: 1rem;
  line-height: 1.1;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.num-btn {
  position: relative;
  height: 54px;
  background: linear-gradient(180deg, var(--stone-light), var(--stone));
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.num-btn:hover:not(:disabled) {
  border-color: var(--gold);
}

.num-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.num-btn.is-complete {
  opacity: 0.4;
  border-color: rgba(52, 211, 153, 0.35);
  color: var(--fel);
}

.num-rem {
  position: absolute;
  top: 4px;
  right: 7px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-dim);
}

.shortcut-hint {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-dim);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.78);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.modal-backdrop[hidden] {
  display: none;
}

.victory-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--stone-light), var(--stone));
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.victory-crest {
  font-size: 1.8rem;
  color: var(--gold-bright);
  margin-bottom: 6px;
}

.victory-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.65rem;
  color: var(--gold-bright);
}

.victory-sub {
  margin: 0 0 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.victory-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.stat-val--gold {
  color: var(--gold-bright);
}

.victory-breakdown {
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
}

.levelup-banner {
  margin: 0 0 18px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(52, 211, 153, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: var(--fel);
  font-size: 0.86rem;
  font-weight: 600;
}

.victory-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

@media (max-width: 820px) {
  .play-area {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .command-panel {
    margin-top: 0;
    max-width: 486px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

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

  .num-btn {
    height: 46px;
    font-size: 1.05rem;
  }

  .num-rem {
    display: none;
  }
}
