:root {
  --ink: #f5e9d8; --gold: #ffcf87; --coral: #ff7a59; --teal: #5fe0c8;
  --panel: rgba(24, 18, 46, 0.82); --edge: rgba(255, 207, 135, 0.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #1a1440; }
body { font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif; color: var(--ink); }
#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud-top {
  position: absolute; top: 10px; left: 12px; right: 12px;
  display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap;
}
.stat {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 12px;
  padding: 6px 14px; display: flex; flex-direction: column; align-items: center;
  font-size: 20px; font-weight: 700; min-width: 74px; line-height: 1.15;
}
.stat-label { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); opacity: 0.85; }
.stat.lv { font-size: 14px; }
#goal-wrap { background: var(--panel); border: 1px solid var(--edge); border-radius: 12px; padding: 8px 14px; flex: 1; min-width: 150px; max-width: 330px; }
#goal-bar { margin-top: 6px; height: 9px; border-radius: 6px; background: rgba(255,255,255,0.12); overflow: hidden; }
#goal-fill { height: 100%; width: 0%; border-radius: 6px; background: linear-gradient(90deg, var(--teal), var(--gold)); transition: width 0.35s; }
#hud-time.low { color: var(--coral); }

#flash { position: absolute; top: 86px; left: 50%; transform: translateX(-50%);
  font-size: 17px; font-weight: 700; padding: 8px 18px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--edge); opacity: 0; white-space: nowrap;
  max-width: 92vw; text-align: center; }
.flash.good { color: #c9ffe9; animation: flashfade 2.4s forwards; }
.flash.bad { color: #ffb9a3; animation: flashfade 2.4s forwards; }
@keyframes flashfade { 0% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; } 100% { opacity: 0; } }

#prompt { position: absolute; bottom: 112px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--edge); border-radius: 14px;
  padding: 8px 16px; font-size: 14px; max-width: 92vw; text-align: center; }

#tension { display: none; position: absolute; top: 120px; left: 50%; transform: translateX(-50%);
  width: min(420px, 84vw); background: var(--panel); border: 1px solid var(--edge);
  border-radius: 14px; padding: 12px 16px; text-align: center; }
.tbar { position: relative; height: 20px; border-radius: 10px; background: rgba(255,255,255,0.12); overflow: hidden; }
#zone { position: absolute; top: 0; bottom: 0; background: rgba(95, 224, 200, 0.55); border-left: 2px solid var(--teal); border-right: 2px solid var(--teal); }
#marker { position: absolute; top: -3px; bottom: -3px; width: 5px; margin-left: -2px; background: var(--gold); box-shadow: 0 0 10px var(--gold); border-radius: 3px; }
.thint { font-size: 12px; margin-top: 8px; color: var(--gold); letter-spacing: 0.08em; }

#touch-controls { position: absolute; bottom: 14px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; pointer-events: auto; }
#btn-action { pointer-events: auto; background: linear-gradient(135deg, #3f8f5f, #2f6f4f); color: #eafff2;
  border: 1px solid var(--edge); border-radius: 14px; padding: 12px 22px; font-size: 15px; font-weight: 800;
  letter-spacing: 0.06em; cursor: pointer; }
#touch-row { display: flex; gap: 12px; }
.tbtn { pointer-events: auto; width: 64px; height: 58px; border-radius: 16px; font-size: 22px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--edge); cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; }
.tbtn.accel { background: rgba(64, 44, 96, 0.85); }
.tbtn.cast { width: 84px; font-size: 15px; font-weight: 800; color: var(--gold); background: rgba(88, 46, 36, 0.85); }
.tbtn:active { transform: translateY(2px); filter: brightness(1.3); }

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(74, 42, 76, 0.88), rgba(12, 8, 30, 0.95));
  pointer-events: auto; padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--edge); border-radius: 22px;
  padding: 26px 30px; max-width: 620px; width: min(620px, 94vw); max-height: 92vh; overflow: auto;
  box-shadow: 0 18px 60px rgba(0,0,0,0.5); }
.panel h1 { font-size: clamp(26px, 6vw, 40px); color: var(--gold); letter-spacing: 0.02em; }
.tag { color: var(--teal); margin: 6px 0 14px; font-size: 15px; }
.howto { list-style: none; display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }
.howto li { font-size: 13.5px; line-height: 1.45; padding-left: 14px; border-left: 3px solid var(--teal); }
.howto b { color: var(--gold); }
.fineprint { margin-top: 12px; font-size: 11px; opacity: 0.7; text-align: center; }
.big-btn { display: block; margin: 4px auto 0; padding: 14px 34px; font-size: 18px; font-weight: 800;
  color: #1c1230; background: linear-gradient(135deg, var(--gold), var(--coral));
  border: none; border-radius: 30px; cursor: pointer; letter-spacing: 0.04em;
  box-shadow: 0 6px 24px rgba(255, 150, 80, 0.4); }
.big-btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
#end-overlay.won .panel { border-color: rgba(95, 224, 200, 0.6); }
#end-overlay #end-sub { margin: 12px 0 18px; font-size: 15px; line-height: 1.5; }

@media (max-width: 640px) {
  .stat { min-width: 58px; padding: 4px 8px; font-size: 16px; }
  .stat.lv { display: none; }
  #goal-wrap { min-width: 120px; padding: 6px 10px; }
  #prompt { bottom: 128px; font-size: 12px; }
  .tbtn { width: 56px; height: 52px; }
  .tbtn.cast { width: 72px; }
}
