.game-body { overflow: hidden; height: 100vh; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; display: flex; gap: 10px;
  padding: 8px 12px; align-items: center; pointer-events: none;
  background: linear-gradient(180deg, rgba(23,32,28,0.92), rgba(23,32,28,0.35) 80%, transparent);
  z-index: 5;
}
.stat {
  display: flex; flex-direction: column; gap: 2px; min-width: 64px;
  background: rgba(16,22,19,0.72); border: 1px solid #3b4b42; border-radius: 10px;
  padding: 6px 10px;
}
.stat.wide { flex: 1; max-width: 340px; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: #9fb3a6; }
.stat b { font-size: 17px; color: var(--cream); }
.bar { height: 8px; background: #2c3a33; border-radius: 4px; overflow: hidden; margin-top: 4px; }
#popfill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal), var(--mint)); transition: width 0.4s; }
.net.pos { color: #9ad88a; } .net.neg { color: #ef8a7a; }

#palette {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 6; flex-wrap: wrap; justify-content: center;
}
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 72px; padding: 7px 10px 6px; cursor: pointer;
  background: rgba(23,32,28,0.85); color: var(--cream);
  border: 1px solid #3b4b42; border-radius: 12px;
}
.tool b { font-size: 13px; }
.tool span { font-size: 12px; color: var(--amber); }
.tool kbd { font-size: 10px; }
.tool.active { border-color: var(--amber); background: rgba(60,48,20,0.9); box-shadow: 0 0 14px rgba(232,176,74,0.35); }
.tool.poor span { color: #ef8a7a; }
.tool.poor { opacity: 0.55; }

#touch-controls {
  position: fixed; bottom: 12px; right: 12px; z-index: 7;
  display: flex; gap: 14px; align-items: flex-end;
}
.dpad { display: grid; grid-template-columns: 46px 46px; grid-template-rows: 46px 46px; gap: 4px; }
.dpad button:nth-child(1) { grid-column: 1; grid-row: 1; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 2; grid-row: 1; }
.acts { display: grid; grid-template-columns: repeat(2, 58px); gap: 5px; }
#touch-controls button {
  background: rgba(23,32,28,0.8); color: var(--cream);
  border: 1px solid #3b4b42; border-radius: 12px; font-size: 16px;
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
#touch-controls button:active { background: rgba(62,143,166,0.6); }
#t-place { font-size: 14px; font-weight: 700; border-color: var(--amber); }
#t-wipe { font-size: 12px; }

#toast {
  position: fixed; top: 66px; left: 50%; transform: translateX(-50%);
  background: rgba(23,32,28,0.92); border: 1px solid #56685d; color: var(--cream);
  padding: 8px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; transition: opacity 0.35s; pointer-events: none; z-index: 9;
  max-width: 92vw; text-align: center;
}
#toast.show { opacity: 1; }

.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(24,38,33,0.9), rgba(10,14,12,0.96));
}
.overlay.hidden { display: none; }
.panel {
  max-width: 560px; width: min(92vw, 560px); padding: 26px 30px;
  background: rgba(23,32,28,0.94); border: 1px solid #46584e; border-radius: 18px;
  text-align: center;
}
.panel h1 { margin: 0; font-size: clamp(30px, 8vw, 48px); color: var(--amber); letter-spacing: 0.18em; }
.panel .tag { margin: 4px 0 14px; color: var(--mint); }
.howto { text-align: left; margin: 0 0 18px; padding-left: 20px; font-size: 14px; line-height: 1.6; }
.howto li { margin: 4px 0; }
.big-btn {
  font-size: 18px; font-weight: 700; padding: 12px 34px; border-radius: 999px;
  border: none; cursor: pointer; color: #23200f;
  background: linear-gradient(180deg, #f2c46a, #e8b04a);
  box-shadow: 0 4px 18px rgba(232,176,74,0.45);
}
.overlay.won #end-title { color: var(--mint); }
#end-text { color: #cfe0d4; line-height: 1.5; }

@media (max-width: 640px) {
  #palette { bottom: 118px; gap: 5px; }
  .tool { min-width: 58px; padding: 5px 6px; }
  .tool kbd { display: none; }
  #touch-controls { bottom: 10px; gap: 8px; }
  #topbar { flex-wrap: wrap; gap: 6px; }
  .stat { min-width: 0; padding: 4px 8px; }
  .stat b { font-size: 14px; }
}

#paused-banner {
  position: fixed; top: 44%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(23,32,28,0.92); border: 1px solid var(--amber); color: var(--cream);
  font-size: clamp(18px, 4.5vw, 28px); letter-spacing: 0.22em; text-transform: uppercase;
  padding: 14px 32px; border-radius: 999px; z-index: 15; pointer-events: none;
  box-shadow: 0 6px 24px rgba(0,0,0,0.45);
}
#paused-banner.hidden { display: none; }
