:root {
  --card: #e2bd8a;
  --card-light: #f0d6ad;
  --card-dark: #b98a56;
  --ink: #3a2a22;
  --accent: #e05a4e;
  --good: #4fae62;
  --shadow: rgba(58, 42, 34, 0.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e9d9bd; }
body { font-family: 'Pixelify Sans', 'Courier New', monospace; color: var(--ink); user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; image-rendering: pixelated; cursor: grab; touch-action: none; }
#game.building { cursor: crosshair; }
canvas[data-icon], .tool-icon { image-rendering: pixelated; }
[hidden] { display: none !important; }

/* cardboard panels: flat colour, hard offset shadow, dashed "cut" inner line */
.panel {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 4px 4px 0 var(--shadow), inset 0 0 0 3px var(--card-light);
  position: relative;
}
.panel::after {
  content: ''; position: absolute; inset: 5px; border: 1px dashed rgba(58, 42, 34, 0.25); border-radius: 3px; pointer-events: none;
}
.panel.small { padding: 8px 10px; font-size: 15px; line-height: 1.35; max-width: 280px; position: fixed; z-index: 30; pointer-events: none; }
.warn { color: #b8322a; }
.price { color: #7a4d14; }

button {
  font: inherit; color: var(--ink); background: var(--card-light); border: 2px solid var(--ink); border-radius: 4px;
  padding: 4px 9px; cursor: pointer; box-shadow: 2px 2px 0 var(--shadow); font-size: 15px;
}
button:hover { background: #fbe7c4; }
button:active { transform: translate(2px, 2px); box-shadow: none; }
button.active { background: #fff3c4; box-shadow: inset 0 0 0 2px #e3a33a; }
button.off { opacity: 0.5; text-decoration: line-through; }

#hud { position: fixed; top: 12px; left: 12px; display: flex; gap: 14px; padding: 9px 14px; z-index: 10; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 600; }
.stat canvas { width: 21px; height: 21px; }
.stat small { font-size: 13px; font-weight: 400; color: #6b4c2e; margin-left: 2px; }

#goal { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); padding: 8px 14px 10px; min-width: 300px; z-index: 10; text-align: center; font-size: 16px; }
.goal-label { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: #7a5a3a; }
.goal-track { height: 8px; background: var(--card-dark); border: 2px solid var(--ink); border-radius: 3px; margin-top: 6px; overflow: hidden; }
#goal-bar { height: 100%; width: 0; background: var(--good); transition: width 0.4s; }

#controls { position: fixed; top: 12px; right: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 10; }
#controls .row { display: flex; gap: 5px; }
#controls .row button { flex: 1; }

#toolbar {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 8px; z-index: 10; max-width: calc(100vw - 24px); overflow-x: auto;
}
.tool { position: relative; width: 84px; padding: 4px 2px 5px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tool-icon { width: 64px; height: 64px; }
.tool-name { font-size: 14px; font-weight: 600; }
.tool-price { font-size: 13px; color: #7a4d14; }
.tool-price::after { content: ' ¢'; }
.tool[data-tool="bulldoze"] .tool-price::after { content: ''; }
.tool-key { position: absolute; top: 2px; left: 4px; font-size: 11px; color: #8a6a4a; }
.tool.poor .tool-price { color: #b8322a; }
.tool.locked { filter: grayscale(0.9); opacity: 0.55; }
.tool-lock { font-size: 11px; color: #b8322a; position: absolute; top: 2px; right: 4px; }
.tool.active { background: #fff3c4; transform: translateY(-4px); box-shadow: 2px 6px 0 var(--shadow), inset 0 0 0 2px #e3a33a; }

#overlay { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.float, .warn-icon { position: absolute; left: 0; top: 0; font-weight: 600; white-space: nowrap; }
.float { font-size: 18px; text-shadow: 2px 0 var(--ink), -2px 0 var(--ink), 0 2px var(--ink), 0 -2px var(--ink), 2px 2px var(--ink); }
.float.gain { color: #ffe28a; }
.float.gain::after { content: ' ¢'; }
.float.cost { color: #ffb3a3; }
.warn-icon { width: 22px; height: 26px; background: var(--accent); color: #fff; border: 2px solid var(--ink); border-radius: 4px; text-align: center; font-size: 18px; line-height: 22px; box-shadow: 2px 2px 0 var(--shadow); }

#toast {
  position: fixed; left: 50%; top: 92px; transform: translate(-50%, -10px); background: var(--ink); color: #fff3d6;
  padding: 8px 16px; border-radius: 4px; font-size: 17px; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; z-index: 40;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#saved { position: fixed; right: 16px; bottom: 16px; color: var(--ink); font-size: 15px; opacity: 0; transition: opacity 0.3s; z-index: 40; }
#saved.show { opacity: 0.85; }

#menu { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(233, 217, 189, 0.35); z-index: 50; }
.menu-card { padding: 26px 34px 22px; width: min(480px, calc(100vw - 32px)); text-align: center; }
.menu-card h1 { margin: 0; font-size: clamp(34px, 10vw, 54px); overflow-wrap: anywhere; letter-spacing: 1px; color: #fff3d6; text-shadow: 3px 0 var(--ink), -3px 0 var(--ink), 0 3px var(--ink), 0 -3px var(--ink), 3px 3px var(--ink), 5px 5px 0 var(--shadow); }
.subtitle { margin: 4px 0 18px; color: #6b4c2e; }
button.big { display: block; width: 100%; font-size: 22px; padding: 9px; margin: 8px 0; }
#btn-continue { background: #fff3c4; }
#save-info { font-size: 13px; color: #6b4c2e; min-height: 4px; }
.help { text-align: left; font-size: 14px; margin-top: 14px; background: var(--card-light); border: 2px solid var(--card-dark); border-radius: 4px; padding: 10px 12px; }
.help ul { margin: 4px 0 8px; padding-left: 18px; }
kbd { font: inherit; background: #fff8e6; border: 1px solid var(--ink); border-radius: 3px; padding: 0 4px; font-size: 12px; }

@media (max-width: 900px) {
  #goal { top: auto; bottom: 128px; min-width: 0; width: calc(100vw - 24px); }
  #hud { gap: 8px; flex-wrap: wrap; right: 12px; }
  .stat { font-size: 16px; }
  #controls { top: auto; bottom: 190px; }
  .tool { width: 70px; }
  .tool-icon { width: 48px; height: 48px; }
}
