:root {
  --ink: #1d2433;
  --paper: #f6f0e3;
  --card: #ffffff;
  --line: #d9cfba;
  --bar: #1f2b45;
  --go: #2fa84f;
  --go-dark: #1f7a37;
  --warn: #e0433a;
  --muted: #5f636d;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #26324f; }
body { overflow: hidden; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 700; font-size: 15px;
  border: 0; border-radius: 10px; padding: 8px 12px;
  background: #e9e3d4; color: var(--ink); cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
  transition: transform 0.05s;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.go { background: var(--go); color: white; }
.btn.danger { background: var(--warn); color: white; }
.btn.on { background: #ffb347; }
.btn.small { font-size: 14px; padding: 6px 10px; }
.btn.big { font-size: 20px; padding: 12px 22px; border-radius: 14px; }
.btn.icon { padding: 8px 9px; }

/* ---------- Setup ---------- */
#setup { overflow-y: auto; background: radial-gradient(circle at 30% 20%, #3c5a8f, #1c2640 70%); padding: 24px 16px; }
.setup-card {
  max-width: 760px; margin: 0 auto; background: var(--paper); border-radius: 20px;
  padding: 24px 28px; box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.setup-card h1 { margin: 0; font-size: 40px; text-align: center; }
.tagline { text-align: center; color: var(--muted); margin: 6px 0 10px; font-size: 18px; }
.setup-card h2 { font-size: 20px; margin: 22px 0 10px; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.level {
  border: 3px solid var(--line); border-radius: 14px; background: var(--card);
  padding: 12px; cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.level b { font-size: 18px; display: block; margin-bottom: 4px; }
.level span { font-size: 14px; color: var(--muted); }
.level.selected { border-color: var(--go); box-shadow: 0 0 0 3px rgba(47,168,79,0.25); }
.player-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.player-row .dot { font-size: 24px; }
.player-row input, .player-row select, .row input {
  font: inherit; font-size: 16px; padding: 7px 10px; border-radius: 8px; border: 2px solid var(--line); background: white;
}
.player-row input { width: 180px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row input { width: 140px; }
.start-row { justify-content: flex-end; margin-top: 26px; }

@media (max-width: 640px) {
  .levels { grid-template-columns: 1fr; }
  .setup-card h1 { font-size: 30px; }
}

/* ---------- Game ---------- */
#game { display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--bar); color: white; flex-wrap: wrap;
}
#turn-info { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; }
#turn-info .swatch { width: 18px; height: 18px; border-radius: 50%; border: 2px solid white; }
#money { font-size: 16px; display: flex; gap: 14px; margin-left: 10px; }
#money b { font-size: 18px; }
#topbar .spacer { flex: 1; }

main { flex: 1; display: flex; min-height: 0; }
#mapwrap { flex: 1; position: relative; min-width: 0; overflow: hidden; background: #1b1f2a; }
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
#side {
  width: 330px; background: var(--paper); display: flex; flex-direction: column;
  border-left: 3px solid #1b2236; min-height: 0;
}
#minimap { display: block; margin: 10px auto 6px; border-radius: 8px; border: 2px solid #1b2236; cursor: crosshair; image-rendering: pixelated; }
#info { padding: 0 10px; overflow-y: auto; flex: 1; min-height: 0; }
#log {
  height: 150px; overflow-y: auto; font-size: 13px; padding: 6px 10px;
  border-top: 2px solid var(--line); background: #efe7d4;
}
#log div { margin: 2px 0; }
#log .t { color: var(--muted); font-size: 11px; margin-right: 4px; }

@media (max-width: 860px) {
  main { flex-direction: column; }
  #side { width: auto; height: 42%; border-left: 0; border-top: 3px solid #1b2236; }
  #minimap { display: none; }
  #log { height: 80px; }
}

.card { background: var(--card); border-radius: 12px; padding: 10px 12px; margin: 8px 0; box-shadow: 0 2px 0 var(--line); }
.card h3 { margin: 0 0 6px; font-size: 17px; display: flex; align-items: center; gap: 6px; }
.card p { margin: 4px 0; font-size: 14px; }
.card .muted { color: var(--muted); }
.stats { display: flex; gap: 10px; font-size: 15px; flex-wrap: wrap; margin: 4px 0; }
.stats span { background: #f1ece0; border-radius: 8px; padding: 2px 7px; }
.hearts { letter-spacing: -2px; }
.buy-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.buy {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px;
  text-align: left; font: inherit; border: 2px solid var(--line); background: #fffdf8;
  border-radius: 10px; padding: 6px 8px; cursor: pointer; color: inherit;
}
.buy:hover:not(:disabled) { border-color: var(--go); }
.buy:disabled { opacity: 0.45; cursor: not-allowed; }
.buy .ico { font-size: 24px; text-align: center; }
.buy .ico canvas { width: 30px; height: 30px; }
.buy .nm { font-weight: 700; font-size: 15px; }
.buy .sub { font-size: 12px; color: var(--muted); }
.buy .price { font-weight: 800; font-size: 15px; }
.preview { border: 3px solid var(--warn); }
.preview .big { font-size: 18px; font-weight: 800; margin: 6px 0; }
.preview .math { font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-top: 8px; }

#tooltip {
  position: absolute; pointer-events: none; background: rgba(20,24,36,0.92); color: white;
  font-size: 14px; padding: 6px 9px; border-radius: 8px; max-width: 260px; z-index: 5;
}
#banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: rgba(20,24,36,0.88); color: white; font-weight: 800; font-size: 18px;
  padding: 10px 18px; border-radius: 12px; pointer-events: none; z-index: 6; text-align: center;
}

/* ---------- Overlays ---------- */
#overlay {
  position: fixed; inset: 0; background: rgba(15,20,35,0.97); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#overlay-card {
  background: var(--paper); border-radius: 18px; padding: 22px 26px; max-width: 720px; width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
#overlay-card h2 { margin-top: 0; font-size: 28px; }
#overlay-card table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0 14px; }
#overlay-card th, #overlay-card td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; }
#overlay-card .center { text-align: center; }
#overlay-card pre { background: #fff; padding: 10px; border-radius: 8px; font-size: 14px; white-space: pre-wrap; }
