:root {
  color-scheme: dark;
  --page: #11150f;
  --panel: #20271b;
  --line: #4a5540;
  --text: #f0ead8;
  --muted: #c5cbb6;
  --accent: #f2c56c;
  --red: #902c33;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: radial-gradient(ellipse at 58% 0%, #303729, var(--page) 50rem); color: var(--text); font: 1rem/1.5 system-ui, sans-serif; }
button, a { -webkit-tap-highlight-color: transparent; }
button, .topbar a { border: 1px solid var(--line); border-radius: .4rem; background: #272e22; color: var(--text); padding: .6rem .85rem; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; }
button:enabled:hover, .topbar a:hover { border-color: var(--accent); }
button:disabled { opacity: .42; cursor: default; }
button:focus-visible, a:focus-visible, canvas:focus-visible, input:focus-visible + .character { outline: 3px solid var(--accent); outline-offset: 3px; }
.primary { background: var(--red); border-color: #dc7071; }
.primary:enabled:hover { background: #a43a41; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: .8rem; max-width: 1080px; padding: .9rem 1.15rem; margin: auto; }
.topbar nav { display: flex; align-items: center; gap: .5rem; }
.wordmark { color: var(--accent); font: 900 1.42rem/1 Impact, 'Arial Narrow', sans-serif; letter-spacing: .045em; }
.subtitle { display: inline-block; margin-left: .85rem; color: var(--muted); font-size: .9rem; }
main { max-width: 1040px; margin: 0 auto; padding: .25rem 1rem 1rem; }
.briefing { display: grid; align-items: center; min-height: 30rem; border: 1px solid var(--line); border-radius: .65rem; overflow: hidden; background: linear-gradient(90deg, #131810 6%, #131810f4 45%, #13181055 75%, #13181025), url('cover.webp') 84% 41% / cover; }
.briefing-content { width: min(100%, 39rem); padding: clamp(1.4rem, 5vw, 3.25rem); }
h1, h2 { margin: 0; font-family: Georgia, serif; line-height: 1.05; }
h1 { font-size: clamp(2.6rem, 6.5vw, 5rem); letter-spacing: -.045em; }
.briefing p { max-width: 34ch; color: var(--muted); }
.characters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; border: 0; padding: 0; margin: 1.5rem 0 1rem; }
.characters legend { margin-bottom: .5rem; font-weight: 700; }
.characters label { position: relative; cursor: pointer; }
.characters input { position: absolute; opacity: 0; }
.character { display: flex; align-items: center; min-height: 4.5rem; gap: .55rem; border: 1px solid var(--line); border-radius: .45rem; background: #22281ef0; padding: .4rem; }
.character img { width: 3.35rem; height: 3.5rem; border-radius: .24rem; object-fit: cover; object-position: 50% 22%; }
.character strong, .character small { display: block; }
.character small { color: var(--muted); font-size: .77rem; }
.characters input:checked + .character { border-color: var(--accent); background: #383322; }
.hud { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .5rem; margin-bottom: .5rem; }
.hud-item { display: flex; align-items: baseline; justify-content: space-between; gap: .4rem; padding: .48rem .8rem; border: 1px solid var(--line); border-radius: .4rem; background: var(--panel); }
.hud-item span { color: var(--muted); font-size: .85rem; }
.hud-item strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.game-frame { position: relative; border: 1px solid var(--line); border-radius: .55rem; overflow: hidden; background: var(--panel); }
canvas { display: block; width: 100%; height: auto; touch-action: none; }
.notice { position: absolute; inset: auto .5rem .65rem; text-align: center; color: #fff0b7; font-size: .92rem; font-weight: 750; text-shadow: 0 2px 4px #000; pointer-events: none; }
.notice:empty { display: none; }
.game-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: .5rem; background: #11150fcd; overflow: auto; }
.overlay-panel { background: var(--panel); border: 1px solid var(--line); padding: clamp(.85rem,3vw,1.8rem); border-radius: .5rem; width: min(100%, 26rem); }
.overlay-panel h2 { font-size: clamp(1.35rem,4vw,2.1rem); }
.overlay-panel p { margin: .65rem 0; }
.equipment { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .55rem; }
.equipment button[aria-pressed=true] { border-color: var(--accent); color: var(--accent); }
.touch, .touch-guide { display: none; }
.controls { margin-top: 1.15rem; padding: .9rem 1rem; background: #20271bc2; border: 1px solid var(--line); border-radius: .5rem; }
.controls h2 { font-size: 1.05rem; }
.controls dl { margin: .65rem 0 0; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: .5rem; }
.controls dt { font-size: .8rem; font-weight: 800; color: var(--accent); }
.controls dd { margin: 0; font-size: .85rem; color: var(--muted); }
@media (pointer: coarse), (max-width: 730px) {
  .touch {
    display: grid;
    grid-template-columns: minmax(7rem, 1fr) minmax(7rem, 1fr);
    gap: .65rem;
    align-items: stretch;
    margin-top: .55rem;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  .steer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    min-height: 5.2rem;
    padding: .35rem;
    border: 1px solid var(--line);
    border-radius: .5rem;
    background: var(--panel);
    color: var(--muted);
    font-size: .78rem;
    font-weight: 750;
    cursor: grab;
  }
  .steer-ring {
    position: relative;
    flex: 0 0 auto;
    width: 3.45rem;
    height: 3.45rem;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #171e15;
  }
  .steer-thumb {
    position: absolute;
    inset: calc(50% - .62rem) auto auto calc(50% - .62rem);
    width: 1.24rem;
    height: 1.24rem;
    border-radius: 50%;
    background: var(--accent);
  }
  #touch-attack { min-height: 5.2rem; font-size: 1.15rem; touch-action: none; }
  #touch-attack[data-held] { background: #ad4149; }
  .touch-guide { display: block; color: var(--muted); margin: .55rem 0 0; font-size: .88rem; }
  .controls .keyboard-guide { display: none; }
  .equipment { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .equipment button { min-height: 44px; }
}
@media (max-width: 550px) {
  .subtitle { display: none; }
  main { padding-inline: .5rem; }
  .topbar { padding-inline: .6rem; }
  .briefing { min-height: 27rem; background-position: 72% center; }
  .character img { width: 2.35rem; height: 3.1rem; }
  .hud-item { display: grid; gap: 0; padding: .3rem .5rem; }
  .hud-item span { font-size: .72rem; }
  .notice { font-size: .76rem; }
  .equipment button { font-size: .8rem; padding: .4rem .55rem; }
  .controls dl { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  #play { display: grid; grid-template-columns: minmax(0, 1fr) 9.5rem; column-gap: .6rem; }
  .hud { grid-column: 1 / -1; }
  .game-frame { grid-column: 1; grid-row: 2 / span 2; place-self: start center; width: min(100%, max(14rem, calc((100svh - 7rem) * 1.63))); }
  .touch { grid-column: 2; grid-row: 2; grid-template-columns: 1fr; align-self: start; margin-top: 0; }
  .steer, #touch-attack { min-height: 3.35rem; }
  .steer-ring { width: 2.6rem; height: 2.6rem; }
  .equipment { grid-column: 2; grid-row: 3; grid-template-columns: 1fr; gap: .2rem; margin-top: .25rem; }
  .equipment button { min-height: 2.25rem; padding: .15rem .35rem; font-size: .8rem; }
}

/* Touch layout: controls overlay the playfield, with space for both thumbs. */
.game-overlay { z-index: 10; }
.game-frame > .equipment { padding: .45rem; }
@media (pointer: coarse), (max-width: 730px) {
  .game-frame { isolation: isolate; border-radius: .65rem; }
  .game-frame .touch { position: absolute; inset: auto 0 0; margin: 0; display: flex; justify-content: space-between; align-items: end; padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); pointer-events: none; z-index: 3; }
  .steer { pointer-events: auto; width: 118px; height: 118px; min-height: 0; flex: none; display: grid; place-items: center; gap: 0; padding: 10px; border-radius: 50%; border: 1px solid #d9dfbc66; background: #111b10a8; backdrop-filter: blur(3px); font-size: 10px; letter-spacing: .1em; touch-action: none; }
  .steer-ring { width: 78px; height: 78px; background: #a7b57620; border: 2px solid #cbd8ad77; }
  .steer-thumb { width: 34px; height: 34px; inset: calc(50% - 17px) auto auto calc(50% - 17px); background: #e1c27add; box-shadow: 0 2px 8px #0008; border: 1px solid #ffedbd; }
  #touch-attack { pointer-events: auto; flex: none; width: 96px; height: 96px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid #ef9992aa; background: #992e35dd; box-shadow: 0 4px 18px #0007; font-size: 15px; letter-spacing: .04em; }
  #touch-attack[data-held] { background: #c64a48; transform: scale(.96); }
  .game-frame > .equipment { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: calc(122px + env(safe-area-inset-bottom)); z-index: 4; display: flex; gap: 6px; padding: 0; margin: 0; }
  .equipment button { min-height: 44px; padding: 8px 9px; font-size: 12px; background: #152011df; border-color: #b4c68a80; backdrop-filter: blur(3px); }
  .equipment button[aria-pressed=true] { background: #5a4e2add; border-color: #f2c56c; }
  .equipment button:disabled { opacity: .6; }
  .notice { inset: 8px 10px auto; font-size: 13px; z-index: 2; background: #0e170dd9; border-radius: 5px; padding: 5px 8px; }
  .controls { margin-top: .6rem; }
}
@media (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  #play { display: block; }
  .game-frame { width: 100%; }
  .topbar { padding-block: .3rem; }
  .hud { margin-bottom: .25rem; }
  .hud-item { padding-block: .2rem; }
  .steer { width: 100px; height: 100px; padding: 5px; }
  .steer-ring { width: 68px; height: 68px; }
  #touch-attack { width: 80px; height: 80px; }
  .game-frame > .equipment { bottom: calc(105px + env(safe-area-inset-bottom)); }
  body:has(#play:not([hidden])) .controls { display: none; }
}
