:root,
[data-theme="day"] {
  --bg: #F4F1EA;
  --surface: rgba(250, 248, 244, 0.90);
  --surface-solid: #FAF8F4;
  --surface-hover: rgba(35, 37, 40, 0.06);
  --border: rgba(35, 37, 40, 0.12);
  --text: #232528;
  --text-muted: #6E7278;
  --shadow: 0 8px 28px rgba(20, 24, 30, 0.10);
  --danger: #D9383A;
  --accent: #232528;
  --accent-fg: #FAF8F4;
}

[data-theme="night"] {
  --bg: #181B20;
  --surface: rgba(28, 32, 39, 0.90);
  --surface-solid: #20252E;
  --surface-hover: rgba(236, 234, 228, 0.08);
  --border: rgba(236, 234, 228, 0.14);
  --text: #ECEAE4;
  --text-muted: #949BA6;
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.42);
  --danger: #F25C5C;
  --accent: #ECEAE4;
  --accent-fg: #181B20;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ==================== TOP HUD ==================== */

.hud-top-left {
  position: fixed;
  top: 18px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
}

.hud-top-right {
  position: fixed;
  top: 18px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 20;
}

.pill-btn,
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}

.pill-btn:hover,
.icon-btn:hover {
  background: var(--surface-solid);
  transform: translateY(-1px);
}

.city-pill {
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.city-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text);
}

.icon-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}

.icon-btn.muted {
  opacity: 0.52;
}

.help-q {
  font-size: 15px;
  font-weight: 800;
}

.score-block {
  height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.score-num {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.clock-block {
  height: 52px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.speed-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-hover);
}

.speed-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  height: 28px;
  min-width: 28px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

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

.speed-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.clock-dial {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.clock-ring {
  fill: none;
  stroke: var(--text);
  stroke-width: 2.6;
}

.clock-hand {
  stroke: var(--text);
  stroke-width: 2.6;
  stroke-linecap: round;
  transform-origin: 22px 22px;
}

.clock-center {
  fill: var(--text);
}

.clock-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  min-width: 34px;
}

.day-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.week-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ==================== ONBOARDING HINT ==================== */

.onboarding-hint {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  z-index: 15;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.onboarding-hint.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-8px);
}

/* ==================== BOTTOM DOCK ==================== */

.hud-dock {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  z-index: 20;
  max-width: calc(100vw - 24px);
}

.dock-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dock-divider {
  width: 1px;
  height: 34px;
  background: var(--border);
}

/* Line Swatches */
.line-swatch-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.line-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: transparent;
  cursor: grab;
  transition: transform 0.14s ease, opacity 0.14s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.line-swatch:hover {
  transform: scale(1.12);
}

.line-swatch.locked {
  opacity: 0.2;
  cursor: default;
  pointer-events: none;
}

.line-swatch.unused {
  background: transparent !important;
}

.line-swatch.active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

[data-theme="night"] .line-swatch:not(.locked) {
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.22);
}

.line-delete-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1.5px solid var(--surface-solid);
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.75);
  transition: opacity 0.14s ease, transform 0.14s ease, background 0.14s ease;
}

.line-swatch-wrap:hover .line-delete-btn {
  opacity: 1;
  transform: scale(1);
}

.line-delete-btn:hover {
  background: var(--danger);
  color: #fff;
}

/* Resource Tokens */
.dock-resources {
  gap: 8px;
}

.resource-token {
  position: relative;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 5px 10px;
  border-radius: 12px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: grab;
  min-width: 60px;
  transition: background 0.14s ease, transform 0.14s ease, opacity 0.14s ease;
}

.resource-token:hover:not(.empty):not(.static-token) {
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.resource-token.static-token {
  cursor: default;
}

.resource-token.empty {
  opacity: 0.34;
  cursor: default;
}

.token-icon {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.token-count {
  position: absolute;
  top: 0;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.token-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ==================== MODALS ==================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 22, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  transition: opacity 0.2s ease;
}

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

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface-solid);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  animation: modalPop 0.2s ease-out;
}

.cities-card {
  max-width: 600px;
}

@keyframes modalPop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.modal-eyebrow.danger {
  color: var(--danger);
}

.modal-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.modal-subtitle {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
}

/* Upgrade Choices */
.upgrade-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 22px;
}

.upgrade-option {
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 16px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.upgrade-option:hover {
  transform: translateY(-3px);
  border-color: var(--text);
  background: var(--surface-hover);
}

.upgrade-icon-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
}

.upgrade-option-title {
  font-size: 16px;
  font-weight: 800;
}

.upgrade-option-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

/* City Selector Grid */
.city-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.city-card {
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.city-card:hover {
  transform: translateY(-2px);
  border-color: var(--text);
  background: var(--surface-hover);
}

.city-card.current {
  border-color: var(--text);
}

.city-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.city-card-name {
  font-size: 17px;
  font-weight: 800;
}

.city-card-best {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.city-card-sub {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.city-card-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.city-swatches {
  display: flex;
  gap: 5px;
  margin-top: 4px;
}

.city-swatches span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

/* Game Over Stats */
.gameover-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 22px 0;
}

.stat-box {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.primary-btn,
.secondary-btn {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease;
}

.primary-btn {
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
}

.secondary-btn {
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
}

.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}

/* Help list */
.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13.5px;
  line-height: 1.48;
  color: var(--text-muted);
}

.help-list strong {
  color: var(--text);
}

.help-list code {
  background: var(--surface-hover);
  color: var(--text);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 700px) {
  .city-grid,
  .upgrade-choices {
    grid-template-columns: 1fr;
  }
  .hud-dock {
    padding: 8px 12px;
    gap: 8px;
  }
  .token-label {
    display: none;
  }
  .resource-token {
    min-width: 44px;
    padding: 4px 6px;
  }
}
