:root {
  --bg: #101214; --panel: #1b1f24; --panel2: #262c33; --fg: #e9edf1; --muted: #9aa4af;
  --damage: #d64545; --nodamage: #2f9e5f; --unsure: #d9a441; --accent: #4c8dff;
  --sab: env(safe-area-inset-bottom, 0px); --sat: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
body { display: flex; flex-direction: column; height: 100dvh; }
button { font: inherit; color: var(--fg); background: var(--panel2); border: 0; border-radius: 12px;
  padding: 12px 16px; min-height: 48px; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; }
button.ghost { background: transparent; color: var(--muted); }
button.icon { min-width: 48px; min-height: 48px; font-size: 24px; padding: 0; background: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > button { flex: 1 1 auto; }

#top { position: relative; display: flex; align-items: center; gap: 8px; padding: calc(var(--sat) + 4px) 8px 6px;
  background: var(--panel); z-index: 5; }
#title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: #2a3038; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

#stage-wrap { position: relative; flex: 1; min-height: 140px; background: #000; }
#controls { position: absolute; top: 8px; left: 8px; right: 8px; z-index: 6; }
#controls .panel { padding: 8px 10px; background: rgba(27,31,36,.94); border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 8px; }
#chips { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; align-items: flex-start; }
body.busy #chips { display: none; }
#controls .q, #controls label { font-weight: 600; }
#controls textarea { width: 100%; font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 10px; border: 1px solid #3a424c; background: #0d0f11; color: var(--fg); resize: none; }
#controls .row > button { min-height: 44px; padding: 8px 12px; }
#stage { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }

.chip { height: 36px; min-height: 0; padding: 0 12px; border-radius: 18px; background: rgba(27,31,36,.85); font-size: 14px; line-height: 36px; }

#verdict-bar { display: flex; gap: 8px; padding: 8px 8px calc(var(--sab) + 8px); background: var(--panel); }
#verdict-bar.dim { opacity: .35; pointer-events: none; }
.verdict { flex: 1; min-height: 60px; font-size: 17px; font-weight: 700; color: #fff; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.verdict small { font-weight: 400; font-size: 11px; opacity: .7; }
.verdict.damage { background: var(--damage); }
.verdict.nodamage { background: var(--nodamage); }
.verdict.unsure { background: var(--unsure); color: #1a1a1a; }
.verdict.selected { outline: 3px solid #fff; outline-offset: -3px; }
@media (hover: none) { .verdict small { display: none; } }


body.locked > *:not(#signin) { display: none !important; }
#signin { background: var(--bg); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 30; }
.card { width: min(420px, 100%); background: var(--panel); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.card h1, .card h2 { margin: 0 0 4px; }
.card p { margin: 0; }
#dev-form { display: flex; gap: 8px; }
#dev-form input { flex: 1; font: inherit; padding: 10px; border-radius: 10px; border: 1px solid #3a424c; background: #0d0f11; color: var(--fg); }
#help-text { white-space: pre-line; }

#toast { position: fixed; left: 50%; top: calc(var(--sat) + 60px); transform: translateX(-50%); background: #333a43; color: #fff;
  padding: 10px 14px; border-radius: 10px; z-index: 40; max-width: 90vw; }

@media (min-width: 900px) {
  body { max-width: 1100px; margin: 0 auto; }
  .verdict { min-height: 56px; }
}
