:root,
body[data-theme="Teal"] {
  --primary: #006A60;
  --on-primary: #FFFFFF;
  --primary-container: #BEECE6;
  --on-primary-container: #00201C;
  --surface: #F4FBFA;
  --surface-container: #E6F0EE;
  --surface-container-high: #D8E6E3;
  --on-surface: #191C1B;
  --on-surface-variant: #3F4947;
  --error: #BA1A1A;
  --success: #006D3B;
  --cell-alt: rgba(230, 240, 238, 0.55);
  --cell-related: rgba(0, 106, 96, 0.10);
  --cell-same: rgba(0, 106, 96, 0.24);
  --cell-selected: rgba(0, 106, 96, 0.35);
  --cell-flash: rgba(0, 106, 96, 0.45);
  --cell-conflict: rgba(186, 26, 26, 0.28);
  --border-subtle: rgba(63, 73, 71, 0.18);
  --subgrid-line: rgba(0, 106, 96, 0.58);
}

body[data-theme="Navy"] {
  --primary: #1A237E;
  --on-primary: #FFFFFF;
  --primary-container: #DCE1FF;
  --on-primary-container: #00105C;
  --surface: #F8F9FF;
  --surface-container: #ECEEF8;
  --surface-container-high: #E0E3F3;
  --on-surface: #191B23;
  --on-surface-variant: #444654;
  --error: #BA1A1A;
  --success: #1B6D3E;
  --cell-alt: rgba(236, 238, 248, 0.55);
  --cell-related: rgba(26, 35, 126, 0.10);
  --cell-same: rgba(26, 35, 126, 0.24);
  --cell-selected: rgba(26, 35, 126, 0.35);
  --cell-flash: rgba(26, 35, 126, 0.45);
  --cell-conflict: rgba(186, 26, 26, 0.28);
  --border-subtle: rgba(68, 70, 84, 0.18);
  --subgrid-line: rgba(26, 35, 126, 0.58);
}

body[data-theme="WarmPaper"] {
  --primary: #6D4C2F;
  --on-primary: #FFFFFF;
  --primary-container: #F5DEC9;
  --on-primary-container: #281706;
  --surface: #FDF8F2;
  --surface-container: #F2EAE0;
  --surface-container-high: #E6DDD1;
  --on-surface: #201B16;
  --on-surface-variant: #51453A;
  --error: #B3261E;
  --success: #2E6B3E;
  --cell-alt: rgba(242, 234, 224, 0.55);
  --cell-related: rgba(109, 76, 47, 0.10);
  --cell-same: rgba(109, 76, 47, 0.24);
  --cell-selected: rgba(109, 76, 47, 0.35);
  --cell-flash: rgba(109, 76, 47, 0.45);
  --cell-conflict: rgba(179, 38, 30, 0.28);
  --border-subtle: rgba(81, 69, 58, 0.18);
  --subgrid-line: rgba(109, 76, 47, 0.58);
}

body[data-theme="Midnight"] {
  --primary: #5CD5C6;
  --on-primary: #003731;
  --primary-container: #005048;
  --on-primary-container: #7BF2E2;
  --surface: #0F1514;
  --surface-container: #1B2322;
  --surface-container-high: #26302E;
  --on-surface: #E0E6E4;
  --on-surface-variant: #99A6A3;
  --error: #FF897D;
  --success: #6DDB99;
  --cell-alt: rgba(27, 35, 34, 0.65);
  --cell-related: rgba(92, 213, 198, 0.10);
  --cell-same: rgba(92, 213, 198, 0.24);
  --cell-selected: rgba(92, 213, 198, 0.35);
  --cell-flash: rgba(92, 213, 198, 0.45);
  --cell-conflict: rgba(255, 137, 125, 0.28);
  --border-subtle: rgba(153, 166, 163, 0.16);
  --subgrid-line: rgba(92, 213, 198, 0.55);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--surface);
  color: var(--on-surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background-color 0.2s ease, color 0.2s ease;
}

#ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
}

.glow-top {
  width: 380px;
  height: 380px;
  top: -80px;
  right: -60px;
  background: var(--primary-container);
  opacity: 0.32;
}

.glow-bottom {
  width: 340px;
  height: 340px;
  bottom: -80px;
  left: -60px;
  background: var(--primary);
  opacity: 0.10;
}

#app-root {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen {
  width: 100%;
  max-width: 500px;
  height: 100%;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
  animation: fadeIn 0.18s ease-out;
}

.screen.scrollable {
  justify-content: flex-start;
  gap: 14px;
}

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

/* Rank & XP Header Card */
.rank-card {
  background: var(--surface-container);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.rank-card:active {
  transform: scale(0.98);
}

.rank-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.level-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 900;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rank-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--on-surface);
}

.rank-xp {
  font-size: 11px;
  color: var(--on-surface-variant);
}

.streak-pill {
  background: var(--primary-container);
  color: var(--on-primary-container);
  padding: 6px 10px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Hero Section */
.hero-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: 8px 0;
}

.brand-pill {
  background: var(--primary-container);
  color: var(--primary);
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 5px 14px;
  border-radius: 50px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
}

.hero-icon-box {
  width: 74px;
  height: 74px;
  margin: 14px 0;
  border-radius: 22px;
  background: var(--surface-container);
  border: 1.5px solid var(--subgrid-line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.hero-title {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--primary);
  margin: 0;
}

.hero-subtitle {
  font-size: 13px;
  color: var(--on-surface-variant);
  letter-spacing: 1px;
  margin-top: 4px;
}

/* Buttons & Cards */
.action-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.daily-card {
  background: var(--primary-container);
  border: 1px solid var(--subgrid-line);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.daily-card:active {
  transform: scale(0.98);
}

.daily-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge-tag {
  background: var(--primary);
  color: var(--on-primary);
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 6px;
}

.btn {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s ease, filter 0.15s ease;
}

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

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

.btn-tonal {
  background: var(--surface-container-high);
  color: var(--primary);
}

.btn-outline {
  background: transparent;
  color: var(--on-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  font-weight: 600;
  font-size: 14px;
}

.btn-outline.highlight {
  background: var(--cell-related);
  border-color: var(--subgrid-line);
}

.btn-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.btn-row > .btn {
  flex: 1;
}

/* Top Nav Bar */
.top-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--cell-related);
}

.screen-title {
  font-size: 24px;
  font-weight: 800;
  margin: 0;
}

/* Difficulty Cards */
.diff-card {
  background: var(--surface-container);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.12s ease;
}

.diff-card.expert {
  background: var(--primary-container);
  border-color: var(--subgrid-line);
}

.diff-card:active {
  transform: scale(0.98);
}

.diff-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--primary-container);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.diff-card.expert .diff-icon {
  background: var(--primary);
  color: var(--on-primary);
}

/* Game Screen Layout (Portrait & Landscape) */
.game-layout {
  width: 100%;
  max-width: 500px;
  height: 100%;
  padding: 8px 14px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.game-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.game-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-header-center {
  text-align: center;
  cursor: pointer;
}

.game-header-title {
  font-weight: 900;
  letter-spacing: 3px;
  font-size: 17px;
  color: var(--primary);
}

.game-header-sub {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--on-surface-variant);
}

.game-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.game-meta {
  text-align: right;
}

.mistakes-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--on-surface-variant);
}

.mistakes-label.has-err {
  color: var(--error);
}

.timer-label {
  font-size: 15px;
  font-weight: 800;
  color: var(--on-surface);
}

.progress-track {
  width: 100%;
  height: 4px;
  background: var(--surface-container-high);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

/* Smart Hint Banner */
.smart-hint-banner {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border: 1px solid var(--subgrid-line);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  line-height: 1.35;
  cursor: pointer;
}

.smart-hint-title {
  font-weight: 800;
  font-size: 12px;
  color: var(--primary);
}

/* Sudoku 9x9 Board */
.board-wrapper {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(62vh, 460px);
  margin: 0 auto;
  background: var(--surface-container);
  border: 2px solid var(--primary);
  border-radius: 14px;
  padding: 4px;
  position: relative;
  display: flex;
}

.sudoku-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.sudoku-cell {
  border: 0.5px solid var(--border-subtle);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

/* Bold 3x3 subgrid lines */
.sudoku-cell[data-col="2"],
.sudoku-cell[data-col="5"] {
  border-right: 2.2px solid var(--subgrid-line);
}

.sudoku-cell[data-row="2"],
.sudoku-cell[data-row="5"] {
  border-bottom: 2.2px solid var(--subgrid-line);
}

.sudoku-cell.alt-box {
  background: var(--cell-alt);
}

.sudoku-cell.related {
  background: var(--cell-related);
}

.sudoku-cell.same-num {
  background: var(--cell-same);
}

.sudoku-cell.selected {
  background: var(--cell-selected);
}

.sudoku-cell.flashed {
  background: var(--cell-flash);
}

.sudoku-cell.conflict {
  background: var(--cell-conflict);
  border: 1.5px solid var(--error);
}

.sudoku-cell.tutorial-target {
  background: var(--cell-selected);
  box-shadow: inset 0 0 0 2px var(--primary);
  animation: pulseTarget 1.2s infinite alternate;
}

@keyframes pulseTarget {
  from { background: var(--cell-related); }
  to { background: var(--cell-selected); }
}

.cell-digit {
  font-size: clamp(18px, 4.8vw, 24px);
  font-weight: 600;
  color: var(--on-surface);
  line-height: 1;
}

.cell-digit.user-digit {
  color: var(--primary);
  font-weight: 800;
}

.cell-digit.error-digit {
  color: var(--error);
  font-weight: 800;
  animation: shakeError 0.35s ease;
}

.cell-digit.pop-anim {
  animation: popScale 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popScale {
  0% { transform: scale(0.7); }
  65% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

@keyframes shakeError {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

/* 3x3 Positional Pencil Notes */
.cell-notes {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 1px;
}

.note-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(7px, 1.9vw, 10px);
  font-weight: 700;
  color: var(--on-surface-variant);
  line-height: 1;
}

.note-item.highlight {
  color: var(--primary);
  font-weight: 900;
}

/* Pause Overlay */
.pause-overlay {
  position: absolute;
  inset: 4px;
  border-radius: 10px;
  background: var(--surface-container);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
}

/* Control Toolbar */
.controls-row {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  width: 100%;
  padding: 2px 0;
}

.ctrl-btn-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.ctrl-btn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface-container-high);
  border: 1px solid var(--border-subtle);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.ctrl-btn.toggled {
  background: var(--primary);
  color: var(--on-primary);
}

.ctrl-btn:active {
  transform: scale(0.94);
}

.ctrl-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 9px;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 99px;
}

.ctrl-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--on-surface-variant);
}

/* Number Pad */
.numpad {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
}

.numpad-row {
  display: flex;
  gap: 7px;
  justify-content: center;
}

.num-key {
  flex: 1;
  max-width: 86px;
  height: 54px;
  border-radius: 14px;
  background: var(--surface-container-high);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.num-key.note-mode {
  background: var(--primary-container);
}

.num-key.locked {
  background: var(--primary);
  border: 2px solid var(--on-primary);
}

.num-key.completed {
  opacity: 0.32;
  pointer-events: none;
  border-color: transparent;
}

.num-key:active {
  transform: scale(0.95);
}

.num-key-digit {
  font-size: 21px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--primary);
}

.num-key.locked .num-key-digit {
  color: var(--on-primary);
}

.num-key-sub {
  font-size: 9px;
  font-weight: 600;
  color: var(--on-surface-variant);
}

.num-key.locked .num-key-sub {
  color: var(--on-primary);
  font-weight: 900;
}

/* Stats & Settings Cards */
.stat-grid-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.stat-card {
  flex: 1;
  background: var(--surface-container);
  border-radius: 16px;
  padding: 14px 16px;
}

.stat-card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--on-surface-variant);
}

.stat-card-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin-top: 4px;
}

.theme-selector-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.theme-swatch-card {
  flex: 1;
  border-radius: 14px;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border: 1.5px solid var(--border-subtle);
}

.theme-swatch-card.active {
  border: 2.5px solid var(--primary);
}

.swatch-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

/* Landscape Layout (16:9 YouTube Desktop & Mobile Landscape) */
@media (min-aspect-ratio: 11/10) and (min-height: 420px) {
  .game-layout {
    max-width: 920px;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 28px;
    padding: 16px 28px;
  }

  .board-wrapper {
    height: min(86vh, 480px);
    width: min(86vh, 480px);
    max-height: none;
    margin: 0;
    flex-shrink: 0;
  }

  .game-side-panel {
    flex: 1;
    max-width: 380px;
    height: min(86vh, 480px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
}
