:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #000000; /* Black */
  --muted: #606060;
  --accent: #209cbd; /* Primary Teal */
  --good: #209cbd;
  --bad: #f68318; /* Primary Orange */
  --nav-height: 84px;
}

:root.dark {
  --bg: #0e0f12;
  --panel: #141720;
  --ink: #e8eefc;
  --muted: #9aa3b2;
  --accent: #209cbd;
  --good: #3bd671;
  --bad: #f68318;
}

/* Dark mode game page overrides */
:root.dark #app {
  background: var(--bg);
}

:root.dark #app::before {
  opacity: 0.3;
}

:root.dark #board {
  background: var(--panel);
  border-color: rgba(32, 156, 189, 0.2);
  box-shadow: 
    0 20px 40px rgba(0,0,0,0.3),
    0 8px 16px rgba(0,0,0,0.2);
}

:root.dark .valve {
  background: rgba(255,255,255,0.1);
  border-color: rgba(32, 156, 189, 0.3);
  color: var(--ink);
}

/* Dark mode overlay styling */
:root.dark #overlay {
  background:
    radial-gradient(980px 560px at 50% 14%, rgba(32, 156, 189, 0.22) 0%, rgba(246, 131, 24, 0.16) 44%, rgba(14, 15, 18, 0.99) 100%);
}

/* Start section styling */
.start-section {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
}

.overlay-theme-toggle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--bad) 100%);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.overlay-theme-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

:root.dark .card {
  background: var(--panel);
  border-color: rgba(32, 156, 189, 0.2);
  box-shadow: 
    0 20px 40px rgba(0,0,0,0.4),
    0 8px 16px rgba(0,0,0,0.3);
}

:root.dark #title {
  background: linear-gradient(135deg, #dff8ff 0%, #8fd7ea 48%, #ffb165 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

:root.dark .chips {
  border-color: rgba(32, 156, 189, 0.3);
  background: rgba(32, 156, 189, 0.1);
}

:root.dark .difficulty-selector select {
  background: var(--panel);
  border-color: rgba(32, 156, 189, 0.3);
  color: var(--ink);
}

:root.dark .difficulty-selector select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 156, 189, 0.2);
}

/* Brand utility buttons */
.btn-blue {
  background: var(--accent);
  color: #fff;
  border: none;
}
.btn-blue:hover { filter: brightness(0.95); }

.btn-orange {
  background: var(--bad);
  color: #fff;
  border: none;
}
.btn-orange:hover { filter: brightness(0.95); }

/* Brand text colors */
.stat-blue { color: var(--accent); }
.stat-orange { color: var(--bad); }

* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Outfit', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  display: flex;
  flex-direction: column;
}

#app {
  flex: 1 1 auto;
  min-height: 0;
  height: calc(100vh - var(--nav-height));
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: clamp(10px, 2vh, 20px);
  background: linear-gradient(135deg, 
    rgba(32, 156, 189, 0.05) 0%, 
    rgba(246, 131, 24, 0.05) 25%, 
    rgba(32, 156, 189, 0.05) 50%, 
    rgba(246, 131, 24, 0.05) 75%, 
    rgba(32, 156, 189, 0.05) 100%);
  position: relative;
}

#app::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 80%, rgba(32, 156, 189, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(246, 131, 24, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(32, 156, 189, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

#board {
  width: min(94vw, 920px);
  height: auto;
  min-height: 392px;
  max-height: min(92vh, calc(100vh - var(--nav-height) - 12px));
  background: var(--panel);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 20px;
  box-shadow: 0 18px 36px rgba(0,0,0,0.08), inset 0 0 0 1px rgba(0,0,0,0.02);
  display: grid;
  grid-template-rows: auto auto;
  justify-items: center;
  gap: 12px;
  align-content: center;
  position: relative;
  padding: 18px 20px 20px 20px;
}



#board.error {
  border-color: var(--bad);
  box-shadow: 0 10px 30px rgba(0,0,0,0.06), 0 0 0 3px rgba(239, 68, 68, 0.7);
}

#board.correct {
  border-color: #27ae60;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06), 0 0 0 3px rgba(39, 174, 96, 0.7);
}

#vf {
  width: min(100%, 780px);
  margin: 2px auto 0 auto;
  display: flex;
  justify-content: center;
}

#vf svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}

.learning-hint {
  position: absolute;
  top: 26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  min-height: 42px;
  margin: 0;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(32, 156, 189, 0.24);
  background: linear-gradient(120deg, rgba(32, 156, 189, 0.1), rgba(246, 131, 24, 0.08));
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  white-space: nowrap;
  pointer-events: none;
  max-width: calc(100% - 150px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.learning-hint .note-token { color: var(--accent); }
.learning-hint .finger-token { color: var(--bad); }
.learning-hint .divider {
  color: var(--muted);
  opacity: 0.7;
  font-weight: 600;
}

:root.dark .learning-hint {
  border-color: rgba(32, 156, 189, 0.36);
  background: linear-gradient(120deg, rgba(32, 156, 189, 0.2), rgba(255, 255, 255, 0.06));
}

.board-reset {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 6;
  border: none;
  border-radius: 10px;
  padding: 9px 13px;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.2px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--bad) 100%);
  box-shadow: 0 8px 18px rgba(32, 156, 189, 0.28), 0 3px 8px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.board-reset:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(32, 156, 189, 0.34), 0 5px 10px rgba(0, 0, 0, 0.16);
  filter: saturate(1.08);
}

.board-reset:active {
  transform: translateY(0);
}

#hud {
  width: min(100%, 780px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  gap: 12px;
  align-items: center;
}

#stats { 
  color: var(--ink); 
  opacity: 0.95; 
  font-weight: 600; 
  font-size: 12px;
  font-variant-numeric: tabular-nums; 
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  text-align: left;
  max-width: 100%;
  margin-left: 0;
}
.stat-row {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 9px;
  border-radius: 999px;
  border: 1px solid rgba(32, 156, 189, 0.24);
  background: rgba(32, 156, 189, 0.07);
  line-height: 1;
}

:root.dark .stat-row {
  border-color: rgba(32, 156, 189, 0.36);
  background: rgba(255, 255, 255, 0.06);
}

#valves { display: flex; gap: 10px; align-items: center; justify-self: start; }
.valve {
  width: 50px; height: 50px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #ffffff 0%, rgba(255,255,255,0.9) 100%);
  color: var(--ink); 
  font-weight: 700;
  font-size: 18px;
  border: 2px solid rgba(32, 156, 189, 0.2);
  transition: all 0.3s ease;
  box-shadow: 
    0 4px 12px rgba(32, 156, 189, 0.1),
    0 2px 4px rgba(0,0,0,0.05);
}
/* No pre-highlight of correct answer; only show what user presses */
.valve.active { 
  background: linear-gradient(135deg, var(--accent) 0%, var(--bad) 100%); 
  color: white; 
  border-color: var(--accent);
  box-shadow: 
    0 8px 20px rgba(32, 156, 189, 0.3),
    0 4px 8px rgba(0,0,0,0.1);
}

@media (max-width: 860px) {
  #board {
    min-height: 0;
    max-height: calc(100vh - var(--nav-height) - 10px);
    padding: 14px 10px 14px 10px;
    gap: 12px;
  }

  #hud {
    grid-template-columns: 1fr;
    gap: 12px;
    justify-items: center;
  }

  #stats {
    justify-content: center;
  }

  #valves {
    justify-self: center;
  }

  .valve {
    width: 46px;
    height: 46px;
    font-size: 17px;
  }

  .stat-row {
    font-size: 12px;
    padding: 6px 9px;
  }

  .learning-hint {
    top: 20px;
    max-width: calc(100% - 130px);
    min-height: 34px;
    padding: 7px 12px;
    font-size: 16px;
    gap: 8px;
  }

  .board-reset {
    top: 10px;
    right: 10px;
    padding: 7px 10px;
    font-size: 12px;
    border-radius: 9px;
  }
}

#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(980px 520px at 50% 14%, rgba(32, 156, 189, 0.13) 0%, rgba(246, 131, 24, 0.1) 42%, rgba(255, 255, 255, 0.985) 100%);
  text-align: center;
  padding: 18px;
  backdrop-filter: blur(2px);
  overflow: hidden;
}

.card {
  width: min(540px, 90vw);
  padding: 24px 20px 20px 20px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.96) 0%, rgba(246, 250, 251, 0.92) 100%);
  border: 1px solid rgba(32, 156, 189, 0.2);
  border-radius: 24px;
  box-shadow:
    0 26px 42px rgba(16, 24, 40, 0.12),
    0 8px 18px rgba(32, 156, 189, 0.14);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  height: min(500px, calc(100vh - var(--nav-height) - 14px));
  max-height: min(500px, calc(100vh - var(--nav-height) - 14px));
  min-height: 0;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(220px, 62%);
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--bad), var(--accent));
}

.brand-logo {
  width: 98px;
  height: auto;
  display: block;
  margin: 0 auto 10px auto;
}

.eyebrow {
  margin: 0 0 7px 0;
  text-transform: uppercase;
  letter-spacing: 1.8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin: 9px 0 12px 0; }
.chip {
  padding: 5px 9px; border-radius: 999px; border: 1px solid rgba(0,0,0,0.12);
  color: var(--ink); background: rgba(0,0,0,0.04);
  font-weight: 600; font-size: 12px;
}

.difficulty-selector {
  margin: 10px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  flex-wrap: wrap;
}

.difficulty-selector > div {
  min-width: 165px;
  text-align: left;
}

.difficulty-selector label {
  font-weight: 600;
  color: var(--ink);
  font-size: 13px;
}

.difficulty-selector select {
  padding: 7px 9px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.difficulty-selector select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 156, 189, 0.1);
}
.cta {
  appearance: none; border: none; outline: none; cursor: pointer;
  padding: 14px 26px; border-radius: 12px; 
  background: linear-gradient(135deg, var(--accent) 0%, var(--bad) 100%); 
  color: #fff; font-weight: 700;
  transition: all 0.3s ease;
  box-shadow: 
    0 8px 20px rgba(32, 156, 189, 0.3),
    0 4px 8px rgba(0,0,0,0.1);
  position: relative;
  overflow: hidden;
}

.cta::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
}

.cta:hover::before {
  left: 100%;
}

.cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(32, 156, 189, 0.4);
}

.cta:active {
  transform: translateY(0);
  box-shadow: 0 4px 10px rgba(32, 156, 189, 0.3);
}

.cta:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.hint { color: var(--muted); margin-top: 10px; }

#title {
  margin: 0 0 8px 0;
  font-family: 'Space Grotesk', 'Outfit', sans-serif;
  font-size: clamp(1.8rem, 4.2vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.03;
  background: linear-gradient(140deg, #133a46 0%, #1f8fae 48%, #f68318 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#subtitle {
  margin: 0 auto 14px auto;
  max-width: 520px;
  color: var(--muted);
  font-size: clamp(0.92rem, 1.9vw, 1.02rem);
  font-weight: 500;
}
#help { color: var(--muted); max-width: 720px; }
#cta {
  margin-top: 16px;
  color: var(--accent);
  font-weight: 600;
}

.results-panel {
  width: min(520px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 10px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 6px;
}

.result-item {
  border-radius: 10px;
  border: 1px solid rgba(32, 156, 189, 0.28);
  background: linear-gradient(150deg, rgba(32, 156, 189, 0.12), rgba(246, 131, 24, 0.08));
  padding: 6px 8px;
  text-align: center;
}

.result-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
  margin-bottom: 3px;
}

.result-value {
  display: block;
  font-size: 17px;
  line-height: 1.1;
}

.result-value.teal { color: var(--accent); }
.result-value.orange { color: var(--bad); }

.results-panel .cta {
  justify-self: center;
  min-width: 170px;
  padding: 11px 18px;
}

:root.dark .result-item {
  border-color: rgba(32, 156, 189, 0.34);
  background: linear-gradient(150deg, rgba(32, 156, 189, 0.16), rgba(255, 255, 255, 0.06));
}

.card.results-mode .chips,
.card.results-mode .start-section {
  display: none !important;
}

.card.results-mode .eyebrow,
.card.results-mode #subtitle {
  display: none !important;
}

.card.results-mode #cta {
  margin-top: 10px;
}

.card.results-mode {
  height: min(500px, calc(100vh - var(--nav-height) - 14px));
  max-height: min(500px, calc(100vh - var(--nav-height) - 14px));
  padding-top: 20px;
}

.card.results-mode #title {
  margin-bottom: 8px;
  font-size: clamp(1.7rem, 3.6vw, 2.1rem);
}

.card.results-mode .results-panel {
  gap: 8px;
}

.card.results-mode .results-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.card.results-mode .result-item {
  padding: 6px 6px;
}

.card.results-mode .result-value {
  font-size: 15px;
}

.card.results-mode .results-panel .cta {
  min-width: 155px;
  padding: 10px 16px;
}

@media (max-width: 860px) {
  .card {
    min-height: 0;
  }

  .card.results-mode .results-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-height: 760px) {
  #overlay {
    padding: 10px;
  }

  .card {
    width: min(500px, 92vw);
    height: min(460px, calc(100vh - var(--nav-height) - 10px));
    max-height: calc(100vh - var(--nav-height) - 10px);
    overflow: hidden;
    padding: 16px 14px 14px 14px;
  }

  .card.results-mode {
    overflow: hidden;
  }
}

.hidden { display: none !important; }

#themeToggle {
  position: fixed;
  top: 20px;
  right: 20px;
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, var(--bad) 100%);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(32, 156, 189, 0.3);
}

#board #themeToggle {
  position: absolute;
  top: 20px;
  right: 20px;
}

#themeToggle:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 8px 20px rgba(32, 156, 189, 0.4),
    0 4px 8px rgba(0,0,0,0.15);
}

/* Bottom navigation buttons styling */
.nav-button {
  appearance: none;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 12px 20px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--bad) 100%);
  color: white;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.3s ease;
  box-shadow: 
    0 8px 20px rgba(32, 156, 189, 0.3),
    0 4px 8px rgba(0,0,0,0.1);
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.nav-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(32, 156, 189, 0.4);
}

.nav-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 10px rgba(32, 156, 189, 0.3);
}

#brandMark { position: absolute; left: 12px; top: 10px; height: 26px; width: auto; }
