:root {
  --bg: #16140f;
  --panel: #221f18;
  --line: #3a352a;
  --text: #e8e0cc;
  --muted: #a59c86;
  --accent: #d08a2e;
  --hp: #b8432f;
  --st: #c9a94a;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: none;
}

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; color: inherit; touch-action: manipulation; }

.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(14, 12, 9, 0.92); z-index: 20; padding: 16px;
}
.screen[hidden] { display: none; }
.panel { max-width: 460px; width: 100%; text-align: center; }
.panel h1 { margin: 0; font-size: 34px; letter-spacing: 0.04em; color: var(--accent); }
.panel .sub { margin: 4px 0 18px; color: var(--muted); }
.panel .hint { margin-top: 22px; color: var(--muted); font-size: 13px; }

#progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
#progressFill { height: 100%; width: 0; background: var(--accent); transition: width 0.15s linear; }
#status { min-height: 1.4em; color: var(--muted); }

.big {
  min-width: 200px; min-height: 52px; margin-top: 10px; border: 1px solid var(--accent); border-radius: 8px;
  background: #3a2a14; color: var(--text); font-size: 18px;
}
#errorText { text-align: left; white-space: pre-wrap; font-size: 12px; color: #e7a08f; max-height: 40vh; overflow: auto; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud[hidden] { display: none; }
.bars { position: absolute; left: calc(12px + var(--safe-l)); top: calc(10px + var(--safe-t)); width: min(260px, 42vw); }
.bar { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.bar .label { width: 22px; font-size: 12px; color: var(--muted); }
.track { flex: 1; height: 10px; background: rgba(0, 0, 0, 0.5); border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.fill { height: 100%; width: 100%; }
.fill.hp { background: var(--hp); }
.fill.st { background: var(--st); }
.num { width: 54px; font-size: 12px; font-variant-numeric: tabular-nums; }
.top-right { position: absolute; right: calc(12px + var(--safe-r)); top: calc(10px + var(--safe-t)); pointer-events: auto; }

.chip {
  min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text);
}
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip.strong { border-color: var(--accent); }

#labels { position: absolute; inset: 0; }
.label3d {
  position: absolute; transform: translate(-50%, -100%); font-size: 12px; text-align: center; white-space: nowrap;
  text-shadow: 0 1px 2px #000;
}
.label3d .mini { width: 56px; height: 5px; margin: 2px auto 0; background: rgba(0, 0, 0, 0.6); border: 1px solid #000; }
.label3d .mini div { height: 100%; background: var(--hp); }
.float {
  position: absolute; transform: translate(-50%, -100%); font-weight: 700; font-size: 18px; text-shadow: 0 1px 3px #000;
  animation: rise 0.7s ease-out forwards;
}
.float.hurt { color: #ff8a6b; }
.float.deal { color: #f3e3b3; }
.float.miss { color: #9fb8c9; font-size: 14px; }
@keyframes rise { to { opacity: 0; transform: translate(-50%, -190%); } }
@media (prefers-reduced-motion: reduce) { .float { animation: fade 0.7s linear forwards; } @keyframes fade { to { opacity: 0; } } }

#toast {
  position: absolute; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%);
  font-size: 13px; color: var(--muted);
}

#touch { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#touch[hidden] { display: none; }
#stickBase {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 2px solid rgba(232, 224, 204, 0.35); background: rgba(0, 0, 0, 0.18); display: none;
}
#stickKnob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(232, 224, 204, 0.55);
}
.act {
  position: absolute; pointer-events: auto; border-radius: 50%; border: 2px solid rgba(232, 224, 204, 0.55);
  background: rgba(30, 26, 18, 0.55); color: var(--text); font-size: 14px; touch-action: none;
}
.act.attack { width: 92px; height: 92px; right: calc(28px + var(--safe-r)); bottom: calc(28px + var(--safe-b)); border-color: var(--accent); }
.act.dodge { width: 70px; height: 70px; right: calc(136px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); }
.act.pressed { background: rgba(208, 138, 46, 0.45); }

.sheet {
  position: fixed; z-index: 15; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t));
  width: min(440px, calc(100vw - 20px)); max-height: calc(100% - 20px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.sheet[hidden] { display: none; }
.sheet h2 { margin: 0 0 8px; font-size: 18px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.row > span:first-child { width: 84px; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); font-size: 13px; }
#resultsText {
  white-space: pre-wrap; word-break: break-word; font-size: 11px; line-height: 1.35; background: #15130e;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px; max-height: 50vh; overflow: auto; user-select: text; -webkit-user-select: text;
}

#timer {
  position: absolute; left: 50%; bottom: calc(8px + var(--safe-b)); transform: translateX(-50%);
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
}
