:root {
  --ink: #e8eef2;
  --muted: #c8d0d8;
  --cream: #f0e2c4;
  --cream-dim: #c2a06a;
  --iron0: #2b2723;
  --iron1: #1c1916;
  --iron2: #141210;
  --brass: #c99f52;
  --brass-dk: #7a5c2e;
  --brass-edge: #4a3d26;
  --accent: #e07030;
  --signal: #3cbc2a;
  --danger: #d94a3d;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
  background:
    radial-gradient(1100px 640px at 50% -8%, #33302a 0%, transparent 55%),
    linear-gradient(180deg, #211e1a, #141210);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html.is-splash body {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ——— Shared brass panel + buttons (splash, overlays) ——— */

.panel-face {
  background:
    linear-gradient(180deg, rgba(255, 226, 158, 0.06), rgba(0, 0, 0, 0.25)),
    linear-gradient(180deg, #33302a 0%, #211e1a 60%, #1a1714 100%);
  border: 2px solid var(--brass-dk);
  border-radius: 12px;
  box-shadow:
    inset 0 1px 0 rgba(230, 190, 120, 0.28),
    inset 0 0 0 1px rgba(0, 0, 0, 0.55),
    0 8px 24px rgba(0, 0, 0, 0.55);
}

.btn {
  appearance: none;
  border: 2px solid var(--brass-dk);
  border-radius: 8px;
  background: linear-gradient(180deg, #3a352c 0%, #241f19 100%);
  color: var(--cream);
  font: inherit;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(230, 190, 120, 0.25), 0 2px 3px rgba(0, 0, 0, 0.5);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}

.btn:hover {
  border-color: var(--brass);
  color: #fff2d6;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-accent {
  background: linear-gradient(180deg, #e88a48 0%, #c85a20 100%);
  border-color: #8a3a14;
  color: #fff8f0;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 220, 180, 0.5), 0 2px 3px rgba(0, 0, 0, 0.5);
}

.btn-accent:hover {
  border-color: #ffb070;
}

/* ——— Splash ——— */

.splash {
  position: fixed;
  inset: 0;
  top: var(--fg-ad-h, 0px);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 520px at 50% 6%, rgba(224, 148, 64, 0.16), transparent 60%),
    linear-gradient(180deg, #2e2a24 0%, #141210 100%);
}

html.is-playing .splash {
  display: none;
}

.splash-box {
  width: min(100%, 380px);
  padding: 26px 24px 22px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255, 226, 158, 0.06), rgba(0, 0, 0, 0.25)),
    linear-gradient(180deg, #33302a 0%, #211e1a 60%, #1a1714 100%);
  border: 2px solid var(--brass-dk);
  border-radius: 12px;
  box-shadow:
    inset 0 1px 0 rgba(230, 190, 120, 0.28),
    inset 0 0 0 1px rgba(0, 0, 0, 0.55),
    0 8px 24px rgba(0, 0, 0, 0.55);
}

.splash-title {
  font-family: "Bebas Neue", sans-serif;
  font-size: clamp(2.8rem, 10vw, 3.6rem);
  letter-spacing: 0.04em;
  line-height: 0.9;
  color: var(--cream);
  text-shadow: 0 2px 0 #0e0b08, 0 0 24px rgba(224, 148, 64, 0.25);
}

.splash-tag {
  margin: 8px 0 4px;
  color: var(--cream-dim);
  font-size: 0.92rem;
  letter-spacing: 0.04em;
}

.splash-tag::after {
  content: "";
  display: block;
  margin: 14px auto 16px;
  width: 72%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--brass-dk) 20%, var(--brass) 50%, var(--brass-dk) 80%, transparent);
}

.splash-actions {
  display: grid;
  gap: 10px;
}

.splash-btn {
  width: 100%;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  font-family: "Bebas Neue", sans-serif;
  font-size: 1.15rem;
  letter-spacing: 0.1em;
}

.splash-depot {
  color: var(--muted);
  border-color: rgba(122, 92, 46, 0.6);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 0.82rem;
}

.dev-unlock-btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 41;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid var(--brass-dk);
  border-radius: 10px;
  background: linear-gradient(180deg, #33302a 0%, #211e1a 100%);
  color: var(--cream);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(230, 190, 120, 0.25), 0 2px 3px rgba(0, 0, 0, 0.5);
}

.dev-unlock-btn.on {
  border-color: #e0b84a;
  color: #ffe28a;
}

.train-row {
  display: grid;
  gap: 8px;
  justify-items: center;
  margin: 0 0 16px;
}

.train-label {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream-dim);
}

.train-select {
  width: 100%;
  appearance: none;
  padding: 10px 12px;
  border: 2px solid var(--brass-dk);
  border-radius: 8px;
  background: #17140f;
  color: var(--cream);
  font: inherit;
  text-align: center;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

#trainPreview {
  display: block;
  width: 128px;
  height: 40px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ——— Pin pad / debug ——— */

.pin-display {
  font-size: 22px;
  letter-spacing: 0.35em;
  text-align: center;
  color: var(--cream);
  margin: 2px 0 10px;
  padding: 10px 8px;
  background: rgba(10, 8, 6, 0.65);
  border: 2px solid rgba(224, 184, 74, 0.35);
  border-radius: 8px;
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.pin-grid button {
  appearance: none;
  border: 2px solid var(--brass-dk);
  border-radius: 10px;
  padding: 12px 0;
  font: inherit;
  font-size: 1.1rem;
  color: var(--cream);
  background: linear-gradient(180deg, #3a352c 0%, #241f19 100%);
  box-shadow: inset 0 1px 0 rgba(230, 190, 120, 0.25), 0 2px 3px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.pin-grid button:active {
  transform: translateY(1px);
}

.pin-msg {
  min-height: 16px;
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-align: center;
  color: #f3c4bf;
  text-transform: uppercase;
}

.debug-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.debug-row .btn {
  width: auto;
  min-width: 92px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.debug-row .btn.on {
  background: #e0b84a;
  border-color: #8a6a18;
  color: #2a1608;
}

/* ——— Game shell: one compact top bar + board, nothing below ——— */

.app {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 8px 10px 14px;
  display: grid;
  gap: 8px;
}

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px;
  background:
    linear-gradient(180deg, rgba(255, 226, 158, 0.05), rgba(0, 0, 0, 0.28)),
    linear-gradient(180deg, #2e2a24 0%, #1c1916 100%);
  border: 2px solid var(--brass-edge);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(230, 190, 120, 0.18), 0 2px 6px rgba(0, 0, 0, 0.45);
}

.brand-plate {
  flex: 0 0 auto;
  height: clamp(30px, 5vw, 42px);
  width: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

.hud-stats {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-evenly;
  gap: 2px;
}

.stat {
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 clamp(4px, 1.2vw, 12px);
}

.stat + .stat {
  border-left: 1px solid rgba(0, 0, 0, 0.55);
  box-shadow: inset 1px 0 0 rgba(214, 178, 116, 0.14);
}

.stat .label {
  font-size: clamp(0.48rem, 1.15vw, 0.6rem);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--cream-dim);
  white-space: nowrap;
}

.stat .value {
  font-family: "Bebas Neue", sans-serif;
  font-size: clamp(0.95rem, 2.2vw, 1.3rem);
  letter-spacing: 0.04em;
  line-height: 1.05;
  color: var(--cream);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.counter-bridge .label { color: #d8c290; }
.counter-junction .label { color: #a8c25e; }

.stat.empty .value {
  color: rgba(240, 226, 196, 0.38);
}

.btn-action {
  flex: 0 0 auto;
  appearance: none;
  border: 2px solid var(--brass-dk);
  border-radius: 8px;
  background: linear-gradient(180deg, #3a352c 0%, #241f19 100%);
  color: var(--cream);
  font-family: "Bebas Neue", sans-serif;
  font-size: clamp(0.9rem, 1.8vw, 1.1rem);
  letter-spacing: 0.1em;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(230, 190, 120, 0.25), 0 2px 3px rgba(0, 0, 0, 0.5);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.btn-action:hover {
  border-color: var(--brass);
  color: #fff2d6;
}

.btn-action:active {
  transform: translateY(1px);
}

.btn-pause {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  padding: 0;
  width: clamp(38px, 5.6vw, 48px);
  aspect-ratio: 1001 / 1074;
  background: url("images/ui/trim/Pause.png") 50% 50% / 100% 100% no-repeat;
  cursor: pointer;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
  transition: filter 120ms ease, transform 120ms ease;
}

.btn-pause:hover {
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)) brightness(1.15);
}

.btn-pause:active {
  transform: translateY(2px);
  filter: brightness(0.92);
}

/* ——— Board + floating banner ——— */

.board {
  position: relative;
  justify-self: center;
  /* Hole in the artwork is 90% wide; slight vertical stretch keeps the
     canvas perfectly square while the ornamental frame absorbs the skew. */
  width: min(100%, 806px);
  aspect-ratio: 901 / 900;
}

.board-frame {
  position: absolute;
  inset: 0;
  background: url("images/ui/trim/GameBoard.png") 50% 50% / 100% 100% no-repeat;
  pointer-events: none;
  z-index: 2;
}

#game {
  position: absolute;
  left: 5%;
  top: 4.9%;
  width: 90%;
  aspect-ratio: 1;
  display: block;
  background: #2b2b2b;
  touch-action: none;
  cursor: crosshair;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.banner {
  position: absolute;
  left: 50%;
  top: 7.5%;
  transform: translateX(-50%);
  z-index: 3;
  max-width: 86%;
  padding: 10px 18px;
  text-align: center;
  font-weight: 600;
  font-size: clamp(0.78rem, 2vw, 1rem);
  line-height: 1.3;
  color: #e9c76a;
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(255, 226, 158, 0.07), rgba(0, 0, 0, 0.3)),
    linear-gradient(180deg, rgba(46, 42, 36, 0.96) 0%, rgba(24, 21, 18, 0.96) 100%);
  border: 2px solid var(--brass-dk);
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(230, 190, 120, 0.25),
    0 6px 18px rgba(0, 0, 0, 0.6);
}

.banner.win {
  color: #b5d178;
  border-color: #5c7a2e;
}

.banner.lose {
  color: #e9c76a;
}

.banner.hidden {
  display: none;
}

/* ——— Overlays ——— */

.overlay {
  position: fixed;
  inset: 0;
  top: var(--fg-ad-h, 0px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 6, 4, 0.74);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(100%, 420px);
  max-height: min(86vh, 640px);
  overflow: auto;
  padding: 22px 18px 16px;
  background:
    linear-gradient(180deg, rgba(255, 226, 158, 0.06), rgba(0, 0, 0, 0.25)),
    linear-gradient(180deg, #33302a 0%, #211e1a 60%, #1a1714 100%);
  border: 2px solid var(--brass-dk);
  border-radius: 12px;
  box-shadow:
    inset 0 1px 0 rgba(230, 190, 120, 0.28),
    inset 0 0 0 1px rgba(0, 0, 0, 0.55),
    0 8px 24px rgba(0, 0, 0, 0.55);
}

.overlay-card-narrow {
  width: min(100%, 320px);
}

.overlay-card-levels {
  width: min(100%, 320px);
  max-height: min(86vh, 520px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}

.overlay-title {
  font-family: "Bebas Neue", sans-serif;
  font-size: 2rem;
  letter-spacing: 0.06em;
  text-align: center;
  margin-bottom: 6px;
  flex: 0 0 auto;
  color: var(--cream);
  text-shadow: 0 2px 0 #0e0b08;
}

.overlay-sub {
  text-align: center;
  color: var(--cream-dim);
  font-size: 0.9rem;
  margin-bottom: 14px;
  flex: 0 0 auto;
}

.overlay-actions {
  display: grid;
  gap: 10px;
}

.overlay-actions .btn,
.btn-wide {
  width: 100%;
  text-align: center;
}

.btn-wide {
  margin-top: 14px;
  flex: 0 0 auto;
}

/* Save Pinky 2-style: 4-col scrollable milestone grid */
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  max-height: 260px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(201, 159, 82, 0.25);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.35);
  scrollbar-width: thin;
  scrollbar-color: var(--brass) #1a1612;
}

.level-grid::-webkit-scrollbar {
  width: 10px;
}

.level-grid::-webkit-scrollbar-track {
  background: #1a1612;
  border-radius: 8px;
  margin: 3px;
}

.level-grid::-webkit-scrollbar-thumb {
  background: var(--brass);
  border: 2px solid var(--brass-edge);
  border-radius: 8px;
}

.level-btn {
  appearance: none;
  min-width: 0;
  padding: 10px 0;
  border: 2px solid #1a3010;
  border-radius: 8px;
  background: linear-gradient(180deg, #4cc63a 0%, #2f9a20 100%);
  color: #f4f7fa;
  font-family: "Bebas Neue", sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(220, 255, 190, 0.4), 0 2px 0 #0e2010;
  text-shadow: 0 1px 0 #1a3010;
}

.level-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #0e2010;
}

.level-btn:disabled {
  cursor: default;
  color: rgba(243, 230, 212, 0.4);
  background: #2c251d;
  border-color: #1c1610;
  box-shadow: 0 2px 0 #100c08;
  text-shadow: none;
}

/* ——— Mobile ——— */

@media (max-width: 640px) {
  .app {
    padding: 6px 6px 12px;
    gap: 6px;
  }

  .top {
    flex-wrap: wrap;
    padding: 4px 6px;
    row-gap: 2px;
  }

  .brand-plate {
    height: 26px;
    order: 1;
  }

  .btn-action {
    order: 2;
    margin-left: auto;
    padding: 5px 10px;
  }

  .btn-pause {
    order: 3;
    width: 34px;
  }

  .hud-stats {
    order: 4;
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .stat {
    padding: 0 4px;
  }
}
