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

/* Display face for titles and the big buttons (the art page's pairing). */
h1, h2, h3, .lobby-h2, .map-name, .btn.big {
  font-family: "Bricolage Grotesque", "Outfit", "Trebuchet MS", sans-serif;
  letter-spacing: -.01em;
}

:root {
  --gold: #f2b544;
  --panel: #2c3b26;
  --panel-edge: #4a5c3f;
  --ink: #f0ead8;
}

body {
  font-family: "Outfit", "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  background: radial-gradient(1200px 700px at 50% -10%, #33482c, #141c12 75%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  user-select: none;
}

#app { width: 100%; max-width: 1000px; padding: 10px; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 15px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 2px solid var(--panel-edge);
  background: #3b4d31;
  color: var(--ink);
  cursor: pointer;
  transition: transform .06s, filter .12s;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: #2e7d3a; border-color: #59a75f; font-weight: bold; }
.btn.danger { background: #7d2e2e; border-color: #a75959; }
.btn.big { font-size: 20px; padding: 14px 34px; }
.btn.small { font-size: 13px; padding: 6px 10px; }

/* ---------- Screens ---------- */
.screen { display: flex; flex-direction: column; align-items: center; }

/* ---------- Lobby ---------- */
.lobby-card {
  margin-top: 24px;
  background: var(--panel);
  border: 3px solid var(--panel-edge);
  border-radius: 18px;
  padding: 26px 30px;
  width: min(96vw, 760px);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  text-align: center;
}
.lobby-card h1 { font-size: 32px; color: var(--gold); text-shadow: 0 2px 0 #00000066; margin-bottom: 6px; }
.subtitle { opacity: .85; margin-bottom: 14px; }
.gems-row { font-size: 17px; margin-bottom: 16px; color: #ffd977; }

#upgradeGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.up-card {
  background: #243020;
  border: 2px solid #3d4f33;
  border-radius: 12px;
  padding: 12px;
  text-align: left;
}
.up-card .up-head { display: flex; align-items: center; gap: 8px; font-weight: bold; }
.up-card .up-icon { font-size: 20px; }
.up-card .up-desc { font-size: 12px; opacity: .75; margin: 4px 0 8px; min-height: 28px; }
.up-pips { display: flex; gap: 5px; margin-bottom: 8px; }
.pip { width: 14px; height: 14px; border-radius: 50%; background: #3a4632; border: 1px solid #55684a; }
.pip.on { background: var(--gold); border-color: #fff2c0; box-shadow: 0 0 6px #f2c14e88; }
.up-card button { width: 100%; font-size: 14px; padding: 6px; }

.lobby-actions { display: flex; gap: 12px; justify-content: center; margin-bottom: 12px; }

/* ---------- Lobby map picker ---------- */
.lobby-h2 { font-size: 18px; color: var(--gold); margin: 4px 0 10px; }
#mapPicker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.map-card {
  font-family: inherit;
  color: var(--ink);
  background: #243020;
  border: 2px solid #3d4f33;
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  text-align: center;
  transition: filter .12s, transform .06s;
  min-width: 0;
}
.map-card:hover { filter: brightness(1.15); }
.map-card:active { transform: scale(.98); }
.map-card.selected { border-color: var(--gold); box-shadow: 0 0 0 3px #f2c14e55, 0 0 18px #f2c14e44; }
.map-card .map-prev { display: block; border-radius: 8px; margin-bottom: 6px; background: #7ab55c; max-width: 100%; height: auto; }
.map-card .map-name { font-weight: 700; font-size: 13.5px; }
.map-card .map-desc { font-size: 11px; opacity: .72; margin: 3px 0 5px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.map-card .map-meta { font-size: 10.5px; color: #ffd977; }
@media (max-width: 640px) { #mapPicker { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Lobby cursor picker ----------
   Four styles, each showing a PREVIEW of the very cursor it selects (a
   data: URL drawn by js/cursor.js at boot — no image files). */
#cursorPicker {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.cursor-card {
  font-family: inherit;
  color: var(--ink);
  background: #243020;
  border: 2px solid #3d4f33;
  border-radius: 12px;
  padding: 8px 10px;
  width: 168px;
  cursor: pointer;
  text-align: center;
  transition: filter .12s, transform .06s;
}
.cursor-card:hover { filter: brightness(1.15); }
.cursor-card:active { transform: scale(.98); }
.cursor-card.selected { border-color: var(--gold); box-shadow: 0 0 0 3px #f2c14e55, 0 0 18px #f2c14e44; }
.cursor-card .cursor-prev {
  display: block;
  height: 40px;
  margin: 0 auto 6px;
  image-rendering: -webkit-optimize-contrast;
}
.cursor-card .cursor-name { font-weight: bold; font-size: 14px; }
.cursor-card .cursor-desc { font-size: 11px; opacity: .72; margin-top: 3px; line-height: 1.3; min-height: 42px; }

/* Turret artwork in the DOM (the lobby cards and the help legend): the same
   renderer the park uses, handed over as a data: URL (js/turret-art.js). */
img.turret-art { vertical-align: middle; }
.help-cols li img.turret-art { width: 26px; height: 37px; margin-right: 2px; }
.help-art-note { font-size: 12px; opacity: .7; margin-top: 6px; }
.up-card .up-icon-img { width: 30px; height: 43px; }

/* ---------- Game screen ----------
   The run interface lives inside the canvas, so the canvas gets the whole
   window: no DOM bars steal height, and the logical 1600x900 board is
   scaled up (or down) to fit whatever space is available. */
#game {
  width: 100%;
  min-height: 100vh;
  justify-content: center;
}

body.playing #app { max-width: none; padding: 0; }
body.playing #canvasWrap {
  width: min(100vw, calc(100vh * var(--canvas-ratio, 1.7778)));
  border: none;
  border-radius: 0;
  box-shadow: 0 0 40px rgba(0, 0, 0, .6);
}

/* ---------- Multiplayer panel ---------- */
.mp-panel { width: min(94vw, 760px); text-align: left; }
.mp-panel h2 { text-align: center; }
.mp-note { font-size: 13.5px; opacity: .9; text-align: center; margin-bottom: 8px; line-height: 1.4; }
.mp-note.small { font-size: 12px; opacity: .7; }
.mp-note code, .mp-hint code { background: #1a2416; padding: 1px 5px; border-radius: 5px; }
/* The one-link flow is the first thing a player sees: one box, one button.
   (.panel sets text-align: center and wins the cascade over .mp-panel, so
   the prose blocks ask for left alignment themselves.) */
.mp-simple { background: #243020; border: 2px solid #59a75f; border-radius: 12px; padding: 12px; margin: 10px 0; text-align: left; }
.mp-steps { font-size: 13px; line-height: 1.5; opacity: .95; padding-left: 20px; margin-bottom: 10px; }
.mp-steps li { margin-bottom: 3px; }
.mp-simple .btn.primary.big { width: 100%; margin-bottom: 10px; }
.mp-label { display: block; font-size: 13px; color: #ffd977; margin: 6px 0 2px; }
.mp-label.warn, .mp-hint.warn { color: #ffc46b; }
.mp-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mp-row .btn { flex: 1 1 auto; }
/* small buttons stay their own size so the primary action keeps the row */
.mp-row .btn.small { flex: 0 0 auto; }
.mp-code-in { height: 68px; }
.mp-simple textarea {
  width: 100%;
  margin: 4px 0 8px;
  background: #16200f;
  color: #cfe8c8;
  border: 1px solid #3d4f33;
  border-radius: 8px;
  font-family: Consolas, monospace;
  font-size: 11px;
  padding: 6px;
  resize: none;
  word-break: break-all;
}
.mp-hint { font-size: 12px; opacity: .75; line-height: 1.35; }
.mp-share { margin-top: 10px; padding-top: 8px; border-top: 1px dashed #3d4f33; }
.mp-session { margin-top: 10px; font-size: 13px; color: #a8e6a3; }
.mp-session b { font-family: Consolas, monospace; font-size: 15px; letter-spacing: 2px; color: #ffd977; }
.mp-advanced { margin: 10px 0; }
.mp-advanced summary { cursor: pointer; font-size: 13px; color: #ffd977; padding: 4px 0; }
.mp-legacy { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; opacity: .85; line-height: 1.35; margin-top: 6px; text-align: left; }
.mp-legacy input { margin-top: 2px; }
.mp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 10px 0; }
@media (max-width: 620px) { .mp-cols { grid-template-columns: 1fr; } }
.mp-col { background: #243020; border: 2px solid #3d4f33; border-radius: 12px; padding: 12px; }
.mp-col h3 { margin-bottom: 8px; font-size: 15px; color: #ffd977; }
.mp-col textarea {
  width: 100%;
  height: 62px;
  margin: 8px 0;
  background: #16200f;
  color: #cfe8c8;
  border: 1px solid #3d4f33;
  border-radius: 8px;
  font-family: Consolas, monospace;
  font-size: 10px;
  padding: 6px;
  resize: none;
  word-break: break-all;
}
.mp-col .btn { width: 100%; }
.mp-col .btn.small { margin-bottom: 2px; }
.mp-status {
  text-align: center;
  font-weight: bold;
  padding: 8px;
  border-radius: 8px;
  background: #16200f;
  margin-bottom: 10px;
  color: #cfd8c5;
}
/* The status line carries the real state, so it is colour-coded:
   info = idle, wait = waiting for the other player, ok = connected,
   err = needs the player's attention (never a silent failure). */
.mp-status.info { color: #cfd8c5; }
.mp-status.wait { color: #ffd977; }
.mp-status.ok { color: #a8e6a3; border: 1px solid #59a75f; }
.mp-status.err { color: #ffb3b3; border: 1px solid #8c4a4a; }
.spacer { flex: 1; }

#canvasWrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 34px rgba(0,0,0,.55);
  border: 3px solid #56422a;
}
/* The pointer over the park is owned by the GAME (js/cursor.js sets an inline
   cursor for every context: arrow, hand, crosshair, grab, merge, swap, the
   "not allowed" mark), so the stylesheet only says what to show before the
   first frame. */
#canvas { display: block; width: 100%; aspect-ratio: var(--canvas-ratio, 1.7778); cursor: default; }

/* ---------- Toasts (MENU screens only — in a run they are drawn into
     the canvas, see js/hud.js) ---------- */
#toastWrap {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 70;
  pointer-events: none;
}
.toast {
  background: #10160de6;
  border: 2px solid #f2c14e88;
  color: #ffe9b0;
  font-size: 15px;
  font-weight: bold;
  padding: 8px 18px;
  border-radius: 999px;
  animation: toastIn .25s ease-out;
  text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 6, .68);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  backdrop-filter: blur(2px);
}
.panel {
  background: var(--panel);
  border: 3px solid var(--panel-edge);
  border-radius: 16px;
  padding: 26px 30px;
  width: min(92vw, 480px);
  text-align: center;
  box-shadow: 0 14px 50px rgba(0,0,0,.6);
  max-height: 88vh;
  overflow: auto;
}
.panel h2 { color: var(--gold); margin-bottom: 14px; }
.col-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.help-panel { width: min(94vw, 860px); text-align: left; }
.help-panel h2 { text-align: center; }
.help-panel .help-cols { margin-bottom: 10px; }
.help-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; margin-bottom: 16px; }
.help-cols h3 { font-size: 15px; color: #ffd977; margin: 10px 0 4px; }
.help-cols p, .help-cols li { font-size: 13.5px; line-height: 1.45; opacity: .92; }
.help-cols ul, .help-cols ol { padding-left: 18px; }
.help-cols li { margin-bottom: 3px; }
/* The panel scrolls on short screens: keep the close button in reach. */
.help-panel .close-overlay { display: block; margin: 0 auto; position: sticky; bottom: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
  font-size: 15px;
}
.stats-grid .stat {
  background: #243020;
  border: 1px solid #3d4f33;
  border-radius: 10px;
  padding: 10px;
}
.stats-grid .stat b { display: block; font-size: 20px; color: #ffd977; }
.gems-earned { font-size: 18px; color: #9fd0ff; margin: 8px 0 14px; }
