:root {
  color-scheme: dark;
  --bg: #070914;
  --panel: rgba(12, 18, 34, 0.88);
  --line: rgba(131, 232, 255, 0.26);
  --text: #effbff;
  --muted: rgba(239, 251, 255, 0.68);
  --cyan: #76f0ff;
  --gold: #f8d46a;
  --red: #ff6c7e;
  --green: #8df7b1;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #050611; color: var(--text); font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif; }
button, select { font: inherit; }
button { border: 1px solid var(--line); border-radius: 8px; background: rgba(118, 240, 255, 0.12); color: var(--text); min-height: 36px; padding: 0 12px; }
button:disabled { opacity: .42; }
select { border: 1px solid var(--line); border-radius: 8px; background: rgba(10, 15, 27, .95); color: var(--text); min-height: 36px; padding: 0 8px; }

.battle-screen {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(245px, 1fr) auto;
  height: 100dvh;
  min-height: 560px;
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
  padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom);
  background: radial-gradient(circle at 20% 0%, rgba(118, 240, 255, .14), transparent 28%), linear-gradient(180deg, #080b19 0%, #080a12 54%, #050611 100%);
}

.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 7px; padding: 7px 0; font-size: 12px; }
.vital { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; min-width: 0; }
.enemy-vital { justify-content: end; }
.vital span, .vital strong, .round-pill { border: 1px solid var(--line); border-radius: 999px; background: rgba(4, 9, 20, .72); padding: 4px 7px; white-space: nowrap; }
.round-pill { display: grid; place-items: center; min-width: 76px; color: var(--cyan); }
.round-pill span { font-size: 10px; color: var(--muted); }
.icon-btn { min-height: 26px; padding: 0 8px; font-size: 11px; }

.machine-strip { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(145px, 1fr); gap: 8px; overflow-x: auto; padding: 2px 1px 7px; scrollbar-width: none; }
.machine-card { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 8px; align-items: center; border: 1px solid rgba(255,255,255,.14); border-radius: 8px; background: rgba(255,255,255,.055); padding: 7px; text-align: left; }
.machine-card.active { border-color: var(--cyan); background: rgba(118, 240, 255, .12); }
.portrait { width: 42px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, rgba(118,240,255,.22), rgba(248,212,106,.16)); color: var(--cyan); font-weight: 800; }
.machine-card strong, .machine-card span { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.machine-card span { color: var(--muted); font-size: 11px; }

.stage { min-height: 0; border: 1px solid rgba(118,240,255,.22); border-radius: 10px; background: linear-gradient(180deg, rgba(10, 17, 32, .86), rgba(6, 9, 18, .96)); padding: 10px; overflow: hidden; }
.stage-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px; font-size: 12px; }
.name, .trait { display: block; min-width: 0; overflow-wrap: break-word; }
.trait { color: var(--muted); font-size: 10px; line-height: 1.3; }
.right-name { text-align: right; }
.distance-readout { display: grid; place-items: center; border: 1px solid rgba(248,212,106,.34); border-radius: 8px; background: rgba(248,212,106,.1); padding: 6px 9px; min-width: 112px; }
.distance-readout span { color: var(--gold); font-size: 11px; letter-spacing: .06em; }
.distance-readout strong { font-size: 18px; line-height: 1.1; }

.lane-wrap { position: relative; height: clamp(150px, 28dvh, 250px); margin: 10px 0 8px; overflow: hidden; }
.lane { position: absolute; left: 54px; right: 54px; top: 50%; height: 76px; transform: translateY(-50%); }
.lane-line { position: absolute; left: 0; right: 0; top: 50%; height: 4px; border-radius: 999px; background: linear-gradient(90deg, var(--cyan), rgba(248,212,106,.9), var(--red)); box-shadow: 0 0 22px rgba(118,240,255,.38); }
.range-nodes { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.node { display: grid; place-items: center; width: 32px; height: 32px; justify-self: center; border: 1px solid rgba(255,255,255,.22); border-radius: 50%; background: rgba(5, 8, 18, .88); color: var(--muted); font-size: 12px; }
.node.active { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 18px rgba(248,212,106,.55); }
.fighter { position: absolute; top: 50%; width: 50px; height: 50px; transform: translateY(-50%); display: grid; place-items: center; transition: transform .28s ease, left .28s ease, right .28s ease, filter .18s ease; }
.fighter.player { left: 3px; }
.fighter.enemy { right: 3px; }
.fighter .core { width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--cyan); background: radial-gradient(circle, rgba(255,255,255,.96), rgba(118,240,255,.36) 45%, rgba(14,23,42,.9) 72%); box-shadow: 0 0 24px rgba(118,240,255,.48); }
.fighter.enemy .core { border-color: var(--red); background: radial-gradient(circle, rgba(255,255,255,.96), rgba(255,108,126,.42) 45%, rgba(38,11,22,.9) 72%); box-shadow: 0 0 24px rgba(255,108,126,.44); }
.fighter.active { filter: brightness(1.35); }
.fighter.active .core { animation: pulse .55s ease-in-out infinite alternate; }
.float { position: absolute; top: -19px; min-width: 64px; text-align: center; font-weight: 800; font-size: 12px; color: var(--gold); opacity: 0; pointer-events: none; }
.float.show { animation: floatLabel .65s ease forwards; }
.lane-effects { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.effect { position: absolute; top: 50%; transform: translateY(-50%); }
.projectile { height: 6px; border-radius: 999px; background: var(--cyan); box-shadow: 0 0 16px var(--cyan); animation: shoot .42s ease forwards; }
.projectile.enemy { background: var(--red); box-shadow: 0 0 16px var(--red); }
.melee { width: 58px; height: 58px; border: 3px solid transparent; border-top-color: var(--gold); border-right-color: var(--gold); border-radius: 50%; animation: slash .32s ease forwards; }
.shield { width: 60px; height: 70px; border: 2px solid var(--green); border-radius: 50%; background: rgba(141,247,177,.14); box-shadow: 0 0 22px rgba(141,247,177,.45); animation: flash .55s ease forwards; }
.counter { width: 58px; height: 58px; border: 2px dashed var(--gold); border-radius: 50%; animation: flash .55s ease forwards; }
.evade { width: 72px; height: 48px; border-radius: 50%; background: repeating-linear-gradient(90deg, rgba(255,255,255,.04), rgba(255,255,255,.04) 5px, rgba(118,240,255,.35) 7px); animation: flash .5s ease forwards; }
.charge { width: 70px; height: 70px; border-radius: 50%; border: 2px solid var(--gold); box-shadow: 0 0 24px rgba(248,212,106,.6) inset, 0 0 18px rgba(248,212,106,.5); animation: flash .55s ease forwards; }

.step-banner, .last-log { min-height: 26px; display: grid; place-items: center; text-align: center; border-radius: 8px; background: rgba(255,255,255,.055); color: var(--muted); font-size: 12px; padding: 5px 8px; overflow-wrap: anywhere; }
.step-banner { color: var(--text); font-weight: 800; margin-bottom: 6px; }

.command-panel { display: grid; gap: 6px; padding: 8px 0 2px; }
.queue-line { display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 6px; font-size: 12px; }
.queue { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.slot { min-width: 0; min-height: 38px; border: 1px solid rgba(255,255,255,.16); border-radius: 7px; background: rgba(255,255,255,.055); display: grid; place-items: center; text-align: center; padding: 3px; font-size: 10px; line-height: 1.15; overflow: hidden; }
.slot.current { border-color: var(--gold); box-shadow: 0 0 14px rgba(248,212,106,.5); }
.slot.done { opacity: .46; }
.slot.failed { border-color: var(--red); }
.enemy-queue .slot { color: var(--muted); }
.analysis, .round-summary { border: 1px solid rgba(248,212,106,.24); border-radius: 8px; background: rgba(248,212,106,.08); color: var(--gold); padding: 6px 8px; font-size: 12px; }
.controls { display: grid; grid-template-columns: 1.15fr 1.15fr .8fr .7fr .8fr; gap: 5px; }
.controls button, .controls select { padding: 0 5px; font-size: 12px; }

.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 64dvh; z-index: 20; display: grid; grid-template-rows: auto auto auto auto minmax(0, 1fr); gap: 8px; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; background: rgba(5, 9, 18, .98); box-shadow: 0 -18px 44px rgba(0,0,0,.5); }
.sheet.hidden, .hidden { display: none !important; }
.sheet-handle { width: 48px; height: 4px; border-radius: 999px; background: rgba(255,255,255,.26); justify-self: center; }
.sheet-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.sheet-head span { display: block; color: var(--muted); font-size: 11px; }
.sheet-queue { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.hand { min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; padding-right: 2px; }
.card { display: grid; gap: 3px; min-width: 0; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; background: rgba(255,255,255,.06); padding: 8px; text-align: left; line-height: 1.2; }
.card.selected { opacity: .45; }
.card.core-card { border-color: rgba(248,212,106,.48); background: rgba(248,212,106,.11); }
.card strong { font-size: 13px; overflow-wrap: break-word; }
.card span { color: var(--muted); font-size: 11px; }
.card .tagline { color: var(--cyan); }
.card.attack { border-left: 4px solid var(--red); }
.card.defense, .card.evade, .card.counter { border-left: 4px solid var(--green); }
.card.movement, .card.movementAttack { border-left: 4px solid var(--cyan); }
.card.charge { border-left: 4px solid var(--gold); }

.detail-pop, .result-panel, .log-drawer, .tutorial { position: absolute; z-index: 30; border: 1px solid var(--line); border-radius: 12px; background: rgba(5, 8, 18, .98); box-shadow: 0 18px 50px rgba(0,0,0,.55); }
.detail-pop { left: 12px; right: 12px; bottom: 12px; padding: 14px; max-height: 70dvh; overflow: auto; }
.detail-pop > button { float: right; }
.detail-pop h3 { margin: 6px 0 8px; }
.detail-pop p { color: var(--muted); line-height: 1.55; }
.log-drawer { inset: auto 10px 10px 10px; max-height: 48dvh; padding: 10px; overflow: auto; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.log-drawer ol { padding-left: 22px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.tutorial { left: 10px; right: 10px; bottom: 10px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 12px; }
.tutorial p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.result-panel { inset: 12px; padding: 18px; display: grid; place-items: center; text-align: center; }
#resultGrid { display: grid; gap: 8px; width: 100%; margin: 8px 0; color: var(--muted); }

@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
@keyframes floatLabel { 0% { opacity: 0; transform: translateY(5px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }
@keyframes shoot { from { opacity: 0; transform: translateY(-50%) scaleX(.2); } 20% { opacity: 1; } to { opacity: 0; transform: translateY(-50%) scaleX(1); } }
@keyframes slash { from { opacity: 0; transform: translateY(-50%) rotate(-35deg) scale(.7); } 35% { opacity: 1; } to { opacity: 0; transform: translateY(-50%) rotate(45deg) scale(1.1); } }
@keyframes flash { 0% { opacity: 0; transform: translateY(-50%) scale(.72); } 35% { opacity: 1; } 100% { opacity: 0; transform: translateY(-50%) scale(1.12); } }

@media (min-width: 520px) { .hand { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 370px) {
  .battle-screen { padding-left: 7px; padding-right: 7px; }
  .machine-strip { grid-auto-columns: 132px; }
  .controls { grid-template-columns: 1fr 1fr .72fr .62fr .72fr; gap: 4px; }
  button, select { min-height: 34px; }
  .distance-readout { min-width: 96px; padding: 5px; }
  .distance-readout strong { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }
