@font-face {
  font-family: Outfit;
  src: url('./assets/fonts/outfit-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: 'Plex Thai';
  src: url('./assets/fonts/thai-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Plex Thai';
  src: url('./assets/fonts/thai-500.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: 'Plex Thai';
  src: url('./assets/fonts/thai-600.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --page: #0a1322;
  --panel: #111f32;
  --raised: #182b43;
  --line: #263c55;
  --ink: #ecf5ff;
  --muted: #a7bbd0;
  --accent: #75d6f5;
  --primary: #3476df;
  --amber: #f6c58b;
  --mint: #8ee1b9;
  font-family: Outfit, 'Plex Thai', sans-serif;
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  color: var(--ink);
  background: radial-gradient(ellipse 780px 500px at 15% -20%, #1d3655 0%, transparent 85%), var(--page);
}

button, a, canvas { -webkit-tap-highlight-color: transparent; }
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color .16s, border-color .16s, transform .13s;
}

button:disabled { cursor: default; }
button:not(:disabled):active { transform: translateY(2px); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

svg {
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app { width: min(1180px, calc(100% - 48px)); margin: auto; padding: 21px 0 22px; }
.masthead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 15px; }
.wordmark { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.wordmark strong, .wordmark small { display: block; }
.wordmark strong { font-size: 24px; font-weight: 650; line-height: 1.05; letter-spacing: -.55px; }
.wordmark small { margin-top: 3px; font-size: 11px; color: var(--muted); }
.logo-c1 {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: contain;
  border: 1px solid #34567c;
  border-radius: 11px;
  background: #223b5d;
}

.header-actions { display: flex; gap: 8px; }
.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-color: var(--line);
  border-radius: 11px;
  background: var(--raised);
  color: var(--muted);
}
.icon-button svg { width: 19px; height: 19px; }
.icon-button:hover { background: #24415e; border-color: #4e7397; color: var(--ink); }
.icon-button[aria-pressed=true] { color: var(--accent); border-color: #396887; }

.game-shell {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 24px 55px -28px #000b;
}

.scoreboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 14px 0;
}

.fighter {
  --team: var(--accent);
  --team-dark: #3889ea;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid #2c4560;
  border-radius: 12px;
  background: linear-gradient(115deg, #1b314b, var(--raised) 70%);
}

.fighter-dog {
  --team: var(--amber);
  --team-dark: #d48745;
  flex-direction: row-reverse;
  border-color: #4c4141;
  background: linear-gradient(245deg, #302c37, #20293a 70%);
}

.portrait {
  flex: none;
  width: 45px;
  height: 45px;
  overflow: hidden;
  border: 1px solid #3a5d84;
  border-radius: 9px;
  background: #223b5d;
}

.portrait img { display: block; width: 100%; height: 100%; object-fit: contain; }
.orange-portrait { border-color: #735446; background: #493730; }
.orange-portrait img { transform: scaleX(-1); }
.fighter-info { flex: 1; min-width: 0; }

.fighter-meta, .fighter-details {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
}

.fighter-meta { margin-bottom: 5px; line-height: 1.1; }
.fighter-meta strong { font-size: 16px; font-weight: 650; }
.fighter-meta > span { color: var(--team); font-size: 17px; font-weight: 650; }

.health-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #091321;
}

.health-fill {
  width: 100%;
  height: 100%;
  transform-origin: left;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--team-dark), var(--team));
  transition: transform .45s cubic-bezier(.22, 1, .36, 1);
}

.fighter-dog .health-fill { transform-origin: right; }
.health-fill.is-low { background: linear-gradient(90deg, #d85463, #ff9a99); }
.fighter-details { align-items: center; margin-top: 5px; color: var(--muted); font-size: 11px; }

.item-stock {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 5px;
  border-radius: 4px;
  background: #1c3c3c;
  color: var(--mint);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.item-stock svg { width: 9px; height: 9px; stroke-width: 2.3; }
.item-stock.is-empty { color: var(--muted); background: #263344; }

.match-timer {
  display: grid;
  place-content: center;
  gap: 3px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0c1728;
}

.match-timer > span { font-size: 11px; color: var(--muted); line-height: 1; }
.match-timer strong { font-size: 28px; font-weight: 650; line-height: 1; }
.match-timer.is-urgent { border-color: #764550; background: #342032; color: #ffb8b2; }

.scene-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
}

.turn-label, .stage-pill, .wind-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 25px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.25;
  white-space: nowrap;
}

.turn-label { justify-self: start; color: var(--accent); background: #183449; }
.turn-label i, .arena-status::before {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.turn-label.ai, .turn-label.is-replay { color: var(--amber); background: #362d30; }
.stage-pill { color: var(--muted); }
.stage-pill[data-stage='cover'] { color: var(--amber); }
.stage-pill[data-stage='rush'] { color: #ffb8b2; }
.wind-pill { justify-self: end; color: var(--muted); background: var(--raised); }
.wind-pill svg { width: 15px; height: 15px; }
.wind-pill strong { color: var(--ink); font-weight: 600; }

.arena-wrap { position: relative; isolation: isolate; background: #233348; }
.arena-wrap canvas { display: block; width: 100%; height: clamp(350px, calc(100svh - 305px), 570px); touch-action: none; }
.arena-wrap canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.can-throw { cursor: crosshair; }

.character-power {
  position: absolute;
  z-index: 1;
  width: 138px;
  padding: 8px 9px;
  transform: translateX(-50%);
  border: 1px solid #5e879e;
  border-radius: 10px;
  background: #0b192bef;
  box-shadow: 0 4px 14px #07101a68;
  pointer-events: none;
}

.character-power::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: calc(50% - 4px);
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  border-right: 1px solid #5e879e;
  border-bottom: 1px solid #5e879e;
  background: #0b192b;
}

.meter-heading, .damage-estimate { display: flex; align-items: center; justify-content: space-between; gap: 5px; }
.meter-heading { margin-bottom: 5px; }
.meter-heading b, .damage-estimate { font-size: 11px; font-weight: 500; color: var(--muted); }
.meter-heading output { font-size: 20px; font-weight: 650; line-height: 1; color: var(--ink); }
.damage-estimate { margin-top: 4px; }
.damage-estimate output { color: var(--amber); font-size: 14px; font-weight: 650; line-height: 1; }
.timing-meter { position: relative; height: 9px; overflow: hidden; border-radius: 3px; background: #263b56; }
.meter-fill, .meter-marker { position: absolute; inset: 0; will-change: transform; }
.meter-fill { transform-origin: left; background: linear-gradient(90deg, #3476df, #75d6f5); }
.meter-perfect-zone {
  position: absolute;
  inset: 0 var(--perfect-end) 0 var(--perfect-start);
  border-radius: 2px;
  background: #ffd176;
}

.meter-marker::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 -1px;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 0 1px #172739;
}

.character-power.is-perfect, .character-power.is-perfect::after { border-color: #ffd176; }
.character-power.is-perfect .meter-heading b { color: #ffd176; }

.action-dock {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 46%);
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.arena-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding-inline: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.arena-status::before { content: ''; color: var(--accent); }
.action-buttons { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 8px; }
.throw-action { min-width: 0; }
.heal-button, .fire-button, .primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 51px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
}

.fire-button, .primary-button {
  width: 100%;
  border-color: #578ff0;
  background: var(--primary);
  color: #fff;
  box-shadow: inset 0 1px #ffffff20;
}

.fire-button svg, .heal-button svg { width: 20px; height: 20px; }
.fire-button { position: relative; padding-inline: 46px; }
.fire-button:hover:not(:disabled), .primary-button:hover { background: #285fbd; }
.fire-button:disabled {
  pointer-events: none;
  border-color: var(--line);
  background: var(--raised);
  color: var(--muted);
  box-shadow: none;
}

.game-shell:has(#arena[data-stage='power']) .fire-button:not(:disabled) {
  color: #092039;
  background: var(--accent);
  border-color: #a1e5fb;
}

.game-shell:has(#arena[data-stage='power']) .fire-button:hover:not(:disabled) { background: #a1e5fb; }
.game-shell:has(#arena[data-stage='power']) .arena-status::before { color: var(--amber); }
.fire-button kbd {
  position: absolute;
  right: 12px;
  padding: 3px 6px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font: 500 10px/1 Outfit, sans-serif;
  opacity: .82;
}
.fire-button:disabled kbd { visibility: hidden; }

.heal-button { border-color: #356058; background: #17363b; color: var(--mint); }
.heal-button:hover:not(:disabled) { background: #235047; border-color: #599582; }
.heal-button:disabled { border-color: var(--line); background: #142337; color: var(--muted); }
.heal-button span { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.heal-button b { font-size: 13px; font-weight: 600; white-space: nowrap; }
.heal-button small { font-size: 10px; font-weight: 400; }

.result-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #081323a0;
  backdrop-filter: blur(4px);
}

.result-card {
  width: min(100%, 325px);
  padding: 22px 24px 24px;
  border: 1px solid #3a5675;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 16px 42px #07101a80;
  text-align: center;
  animation: result-in .3s ease-out;
}

.result-emoji { display: block; color: var(--amber); font-size: 34px; line-height: 1; }
.result-card h2 { font-size: 24px; margin: 8px 0; }
.result-card > p { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
.primary-button span { margin-left: 4px; }
@keyframes result-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 760px) {
  .app { width: calc(100% - 16px); padding: 10px 0 12px; }
  .masthead { margin-inline: 3px; margin-bottom: 10px; }
  .wordmark strong { font-size: 21px; }
  .logo-c1 { width: 42px; height: 42px; }
  .game-shell { border-radius: 15px; }
  .scoreboard { grid-template-columns: minmax(0, 1fr) 56px minmax(0, 1fr); gap: 7px; padding: 8px 8px 0; }
  .fighter { gap: 6px; padding: 7px; border-radius: 9px; }
  .portrait { width: 29px; height: 32px; border-radius: 6px; }
  .fighter-meta { margin-bottom: 4px; }
  .fighter-meta strong, .fighter-meta > span { font-size: 12px; }
  .fighter-details { margin-top: 4px; font-size: 10px; }
  .health-track { height: 6px; }
  .match-timer { border-radius: 9px; }
  .match-timer strong { font-size: 21px; }
  .match-timer > span { font-size: 10px; }
  .scene-top { padding: 5px 8px; }
  .turn-label, .stage-pill, .wind-pill { gap: 4px; padding-inline: 6px; font-size: 11px; }
  .arena-wrap canvas { height: clamp(360px, calc(100svh - 270px), 560px); }
  .character-power { width: 126px; }
  .action-dock { grid-template-columns: minmax(0, 1fr); gap: 5px; padding: 6px 8px max(9px, env(safe-area-inset-bottom)); }
  .arena-status { min-height: 24px; padding-inline: 2px; font-size: 11px; }
  .action-buttons { grid-template-columns: 104px minmax(0, 1fr); }
  .heal-button, .fire-button { min-height: 48px; }
}

@media (max-width: 365px) {
  .app { width: calc(100% - 8px); }
  .scoreboard { grid-template-columns: minmax(0, 1fr) 49px minmax(0, 1fr); gap: 5px; }
  .fighter { gap: 4px; padding: 6px; }
  .portrait { width: 24px; height: 29px; }
  .fighter-meta strong, .fighter-meta > span { font-size: 11.5px; }
  .item-stock { padding-inline: 3px; }
  .wind-pill svg { width: 13px; height: 13px; }
}

@media (hover: none), (max-width: 600px) {
  .fire-button kbd { display: none; }
  .fire-button { padding-inline: 10px; }
}

@media (max-height: 550px) and (min-width: 650px) {
  .app { padding-block: 8px; }
  .masthead { margin-bottom: 8px; }
  .scoreboard { padding-top: 7px; }
  .fighter { padding-block: 5px; }
  .portrait { width: 34px; height: 34px; }
  .scene-top { padding-block: 4px; }
  .arena-wrap canvas { height: max(250px, calc(100svh - 224px)); }
  .action-dock { padding-block: 6px; }
  .heal-button, .fire-button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  button, .health-fill { transition: none; }
  .result-card { animation: none; }
}

.c1-game-controls { display: flex; align-items: center; flex-wrap: wrap; gap: .7rem; padding: .5rem 0; }
.c1-game-link { color: #d6ebff; }
