* { box-sizing: border-box; margin: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { font-family: system-ui, "Segoe UI", sans-serif; background: #2c3a68; color: #fff7ea; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#hud { position: fixed; top: 0; left: 0; right: 0; padding: 8px; pointer-events: none; z-index: 5; }
.hud-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hud-row.right { margin-top: 4px; margin-left: auto; width: auto; justify-content: flex-end; }
.chip {
  background: rgba(20, 16, 40, 0.72); border: 1px solid rgba(255, 210, 150, 0.35);
  border-radius: 10px; padding: 5px 10px; font-size: 14px; display: inline-flex; gap: 6px; align-items: center;
}
.chip.neg b { color: #ff8859; }
.chip.btn-chip { pointer-events: auto; cursor: pointer; font-size: 15px; }
#hud-powerbar-wrap { width: 52px; height: 7px; background: rgba(255,255,255,0.18); border-radius: 4px; overflow: hidden; }
#hud-powerbar { display: block; height: 100%; width: 0%; background: #35d0ba; transition: width 0.3s; }
#hud-powerbar.over { background: #ff5964; }

#toolbar {
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: flex; gap: 6px; z-index: 6; flex-wrap: wrap; justify-content: center;
  max-width: 96vw;
}
.tool {
  pointer-events: auto; cursor: pointer; border-radius: 12px; font-size: 12px;
  border: 1px solid rgba(255, 210, 150, 0.35); background: rgba(20, 16, 40, 0.78);
  color: #fff7ea; padding: 6px 9px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tool .icon { font-size: 19px; line-height: 1; }
.tool .cost { color: #ffd166; }
.tool.sel { outline: 2px solid #ffd166; background: rgba(70, 46, 20, 0.85); }
.tool:hover { background: rgba(60, 46, 30, 0.85); }
#touch-controls {
  position: fixed; right: 8px; bottom: 10px; z-index: 7;
  display: grid; grid-template-columns: repeat(3, 46px); gap: 5px;
}
.tbtn {
  pointer-events: auto; cursor: pointer; height: 42px; border-radius: 10px; font-size: 14px;
  border: 1px solid rgba(255, 210, 150, 0.35); background: rgba(20, 16, 40, 0.78); color: #fff7ea;
}
.tbtn.big { background: rgba(160, 70, 30, 0.85); font-weight: 700; grid-column: span 3; }
.tbtn:active { background: rgba(255, 160, 80, 0.8); }

#toasts { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 8; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast {
  background: rgba(20, 16, 40, 0.9); border: 1px solid rgba(255, 210, 150, 0.45);
  padding: 6px 14px; border-radius: 20px; font-size: 14px; animation: pop 0.18s ease-out;
}
.toast.out { opacity: 0; transition: opacity 0.5s; }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#start-screen, #end-screen {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(44, 58, 104, 0.55), rgba(12, 10, 30, 0.88));
}
.panel {
  max-width: 620px; width: calc(100% - 32px); max-height: calc(100vh - 24px); overflow: auto;
  background: rgba(18, 14, 38, 0.88); border: 1px solid rgba(255, 210, 150, 0.4);
  border-radius: 18px; padding: 26px 28px; text-align: center;
}
.panel h1 { font-size: 34px; letter-spacing: 1px; background: linear-gradient(90deg, #ffd166, #ff8859); -webkit-background-clip: text; background-clip: text; color: transparent; }
.panel #end-title.won { background: linear-gradient(90deg, #7fffd0, #35d0ba); -webkit-background-clip: text; background-clip: text; }
.tag { margin: 8px 0 14px; color: #ffe6c9; }
.how { text-align: left; display: inline-block; margin: 0 0 16px; color: #f3e9d8; font-size: 14px; line-height: 1.65; }
.how li { margin-bottom: 4px; list-style: none; }
.big-cta {
  cursor: pointer; border: 0; border-radius: 14px; padding: 13px 34px; font-size: 18px; font-weight: 700;
  background: linear-gradient(135deg, #ff9c4a, #ff5964); color: #221026; box-shadow: 0 6px 24px rgba(255, 120, 70, 0.4);
}
.score { margin: 10px 0 18px; font-size: 20px; color: #ffd166; }
@media (max-width: 720px) {
  #toolbar { bottom: 8px; gap: 4px; max-width: 100vw; padding: 0 4px; }
  .tool { flex-direction: row; gap: 4px; padding: 4px 7px; font-size: 10px; border-radius: 9px; }
  .tool .nm { display: none; }
  .tool .icon { font-size: 14px; }
  #touch-controls { bottom: 64px; right: 6px; grid-template-columns: repeat(3, 40px); gap: 4px; }
  .tbtn { height: 34px; font-size: 12px; border-radius: 8px; }
  .tbtn.big { height: 38px; font-size: 13px; }
  .chip { font-size: 12px; padding: 4px 7px; }
  #hud { padding: 5px; }
  #toasts { top: 64px; }
  .panel { padding: 18px 16px; }
  .panel h1 { font-size: 26px; }
  .how { font-size: 12.5px; }
}
