:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --ink: #1d1a16;
  --muted: #695f54;
  --border: #e5dccf;
  --shopee: #ee4d2d;
  --shopee-dark: #c93b1e;
  --shopee-soft: #fff0eb;
  --grab: #00a859;
  --grab-soft: #e6f7ee;
  --gold: #d97706;
  --gold-soft: #fef3c7;
  --blue: #0284c7;
  --blue-soft: #e0f2fe;
  --shadow: 0 12px 30px rgba(29, 26, 22, 0.09);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at top right, #fff3e0 0%, var(--bg) 55%);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
}

button {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  max-width: 960px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Top HUD */
.top-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: 0 6px 18px rgba(29, 26, 22, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.home-link {
  text-decoration: none;
  color: var(--ink);
  background: #f3ede3;
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.home-link:hover {
  background: #eae1d2;
}

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

.game-title {
  font-size: clamp(0.95rem, 2.2vw, 1.18rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.level-badge.is-normal {
  background: var(--grab-soft);
  color: #047857;
  border: 1px solid #a7f3d0;
}

.level-badge.is-express {
  background: var(--gold-soft);
  color: #b45309;
  border: 1px solid #fcd34d;
}

.level-badge.is-supersale {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  animation: salePulse 1.1s ease-in-out infinite alternate;
}

@keyframes salePulse {
  from {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.25);
  }
  to {
    box-shadow: 0 0 0 6px rgba(220, 38, 38, 0);
  }
}

.top-stats {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-pill {
  background: #faf7f2;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 9px;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 66px;
}

.stat-pill.stat-money {
  background: var(--shopee-soft);
  border-color: #ffd3c7;
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

.stat-pill strong {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat-pill.stat-money strong {
  color: var(--shopee-dark);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #faf7f2;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: #efe8dc;
}

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

.icon-btn.is-active {
  background: var(--shopee-soft);
  border-color: #ffb8a4;
}

/* Action Callout Banner */
.callout-strip {
  background: linear-gradient(90deg, #fff7ed, #ffffff, #fef3c7);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #7c2d12;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: transform 0.15s ease, background 0.2s ease;
}

.callout-strip.is-flash {
  background: linear-gradient(90deg, #dcfce7, #fef08a, #fed7aa);
  color: #14532d;
  border-color: #86efac;
  transform: scale(1.01);
}

/* Main Layout */
.play-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 216px;
  gap: 12px;
  align-items: stretch;
}

.stage-wrap {
  position: relative;
  background: #1d2430;
  border: 2px solid #d7cbb8;
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 440px;
  padding: 6px;
}

#boardCanvas {
  display: block;
  touch-action: none;
  border-radius: 14px;
  max-width: 100%;
  max-height: 100%;
}

/* Side Panel */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: 0 6px 18px rgba(29, 26, 22, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.mini-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.mini-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink);
}

.mini-tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--grab-soft);
  color: #047857;
}

.mini-tag.is-locked {
  background: #f1f5f9;
  color: #64748b;
}

.mini-tag.tag-next {
  background: var(--blue-soft);
  color: #0369a1;
}

.mini-canvas {
  width: 112px;
  height: 76px;
  background: #f8f5ef;
  border: 1px dashed #d8cebe;
  border-radius: 12px;
  touch-action: none;
}

.mini-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.record-card {
  align-items: stretch;
  gap: 8px;
  margin-top: auto;
}

.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--muted);
}

.mini-row strong {
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.desktop-keys {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

kbd {
  display: inline-block;
  background: #f3ede3;
  border: 1px solid #d5cab8;
  border-radius: 5px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink);
  margin-right: 2px;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 33, 0.74);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 20;
}

.overlay[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px 18px 16px;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.35);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 11px;
  max-height: 100%;
  overflow-y: auto;
}

.modal-compact {
  max-width: 320px;
}

.modal-badge {
  align-self: center;
  background: var(--shopee-soft);
  color: var(--shopee-dark);
  border: 1px solid #ffd3c7;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 11px;
  border-radius: 999px;
}

.modal-badge.badge-alert {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

.modal-card h2 {
  font-size: 1.3rem;
  line-height: 1.2;
  font-weight: 800;
}

.modal-desc {
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--muted);
}

.cargo-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
}

.cargo-chip {
  font-size: 0.71rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
}

.c-i { background: #0284c7; }
.c-o { background: #d97706; }
.c-t { background: #db2777; }
.c-l { background: #ea580c; }
.c-j { background: #2563eb; }
.c-s { background: #059669; }
.c-z { background: #7c3aed; }

.start-records,
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.start-records > div,
.summary-box {
  background: #faf7f2;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.start-records span,
.summary-box span {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.start-records strong,
.summary-box strong {
  font-size: 0.96rem;
  font-weight: 800;
  color: var(--ink);
}

.summary-box.summary-highlight {
  background: var(--shopee-soft);
  border-color: #ffd3c7;
}

.summary-box.summary-highlight strong {
  color: var(--shopee-dark);
}

.new-record-pill {
  align-self: center;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 999px;
}

.total-career-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.primary-btn {
  border: none;
  border-radius: 13px;
  padding: 12px 16px;
  font-size: 0.96rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--shopee), #ff6b35);
  box-shadow: 0 8px 18px rgba(238, 77, 45, 0.28);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.primary-btn:hover {
  filter: brightness(1.05);
}

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

.secondary-btn {
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  background: #f6f1e7;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.secondary-btn:hover {
  background: #ece3d3;
}

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

.controls-hint {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Touch Controls */
.touch-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.ctrl-btn {
  border: 1px solid #d5cab8;
  border-radius: 13px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 800;
  padding: 11px 8px;
  box-shadow: 0 4px 10px rgba(29, 26, 22, 0.08);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.1s ease;
}

.ctrl-btn:active,
.ctrl-btn.is-pressed {
  transform: translateY(1px) scale(0.97);
  background: #efe7da;
}

.ctrl-btn.ctrl-accent {
  background: #fff7ed;
  border-color: #fdba74;
  color: #c2410c;
}

.ctrl-btn.ctrl-drop {
  background: var(--shopee-soft);
  border-color: #fca5a5;
  color: var(--shopee-dark);
}

.ctrl-btn.ctrl-hold {
  background: var(--blue-soft);
  border-color: #7dd3fc;
  color: #0369a1;
}

/* Responsive Mobile Layout */
@media (max-width: 760px) {
  .app-shell {
    padding: 6px 8px 8px;
    gap: 6px;
    height: 100dvh;
  }

  .top-bar {
    padding: 6px 8px;
    border-radius: 13px;
  }

  .title-group {
    gap: 5px;
  }

  .game-title {
    font-size: 0.92rem;
  }

  .stat-sub-hide {
    display: none;
  }

  .stat-pill {
    padding: 3px 7px;
    min-width: 56px;
  }

  .stat-pill strong {
    font-size: 0.82rem;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.92rem;
  }

  .callout-strip {
    font-size: 0.74rem;
    padding: 4px 8px;
  }

  .play-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px;
  }

  .side-panel {
    order: -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .record-card {
    display: none;
  }

  .mini-card {
    flex-direction: row;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: 12px;
    gap: 6px;
  }

  .mini-header {
    width: auto;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
  }

  .mini-title {
    font-size: 0.74rem;
  }

  .mini-tag {
    font-size: 0.62rem;
    padding: 1px 6px;
  }

  .mini-canvas {
    width: 68px;
    height: 44px;
    border-radius: 8px;
  }

  .mini-name {
    display: none;
  }

  .stage-wrap {
    min-height: 0;
    border-radius: 16px;
    padding: 4px;
  }

  .ctrl-btn {
    padding: 10px 6px;
    font-size: 0.88rem;
    border-radius: 11px;
  }
}

@media (min-width: 761px) {
  .stage-wrap {
    min-height: 540px;
  }
}

@media (min-width: 761px) and (hover: hover) and (pointer: fine) {
  .touch-controls {
    display: none;
  }
}
