:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #153945;
  background: #edf1df;
  --ink: #153945;
  --muted: #486068;
  --cream: #fff8df;
  --field: #fffdf3;
  --line: #c9d3bd;
  --mark: #ffcd55;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .65; }
:focus-visible { outline: 3px solid #157094; outline-offset: 3px; }
h1, p { margin: 0; }

.app {
  margin-inline: auto;
  width: min(100%, 1260px);
  padding: max(12px, env(safe-area-inset-top)) max(clamp(12px, 3vw, 34px), env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom)) max(clamp(12px, 3vw, 34px), env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0 18px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-size: clamp(18px, 3.7vw, 26px); font-weight: 900; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  color: var(--mark); background: var(--ink);
  border-radius: 9px; box-shadow: 0 3px 0 #34595a;
}
.tabs { display: flex; flex-wrap: wrap; gap: 5px; }
.tabs button, .quiet-button {
  min-height: 40px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  font-weight: 700;
  font-size: 13px;
}
.tabs [aria-pressed="true"] { background: var(--ink); color: #fff7d9; border-color: var(--ink); }
.tabs button:hover:not(:disabled), .quiet-button:hover { border-color: #416f71; }

.game-view, .workshop { display: grid; grid-template-columns: minmax(0, 1fr) minmax(268px, 318px); gap: clamp(12px, 2.4vw, 24px); align-items: start; }
.stage-column { min-width: 0; }
.stage-toolbar { display: flex; min-height: 40px; margin-bottom: 9px; justify-content: space-between; gap: 10px; align-items: center; }
.stage-toolbar p { font-size: 13px; font-weight: 750; min-width: 0; }
.stage-buttons { display: flex; flex: 0 0 auto; gap: 5px; }
.quiet-button { min-height: 36px; padding-inline: 9px; }
.stage { position: relative; border: 4px solid var(--ink); border-radius: 14px; background: #244d55; box-shadow: 0 6px 0 #c5d0bc; overflow: hidden; }
.arena-surface { position: relative; aspect-ratio: 16 / 9; }
#game { display: block; width: 100%; height: 100%; }
.hud { position: absolute; inset: 5% 4% auto; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); column-gap: 3%; pointer-events: none; }
.fighter-label { display: flex; gap: 4px; align-items: center; margin-bottom: 4px; font-size: clamp(9px, 1.5vw, 15px); }
.fighter-label strong, .fighter-label span { padding: 3px 5px; border-radius: 4px; background: var(--ink); color: #fff9de; }
.fighter-label span { color: #ffdd71; font-size: .8em; white-space: nowrap; }
.second-hud .fighter-label { justify-content: flex-end; }
.second-hud .fighter-label span { color: #92e0ff; }
.health { position: relative; height: clamp(15px, 2.7vw, 24px); border: 2px solid var(--ink); border-radius: 5px; background: #522b29; overflow: hidden; }
.health i, .meter i { position: absolute; inset: 0; background: #ffcf53; transform-origin: left; }
.second-hud i { transform-origin: right; }
.second-hud .health i { background: #ff8c77; }
.health b { position: absolute; inset: 0; display: grid; place-items: center; color: white; text-shadow: 0 1px 2px #201600, 0 -1px 2px #201600; font: 800 clamp(8px, 1.3vw, 12px)/1 Inter, sans-serif; }
.meter { position: relative; height: clamp(5px, .8vw, 8px); margin-top: 5px; border: 1px solid var(--ink); border-radius: 4px; background: #273c41; overflow: hidden; }
.meter i { background: #78dafe; }
.round-clock {
  min-width: clamp(37px, 6.3vw, 64px);
  display: grid; place-items: center; align-self: start;
  border: 2px solid var(--ink); border-radius: 7px; color: #fff9de; background: var(--ink);
}
.round-clock span { font-size: clamp(7px, 1vw, 10px); padding: 1px 2px; }
.round-clock b {
  display: block; width: 100%; text-align: center; border-radius: 4px;
  background: #fff4cc; color: var(--ink); padding: 1px 3px;
  font: 900 clamp(16px, 3.2vw, 34px)/1.12 Inter, sans-serif;
}
.fight-message {
  position: absolute; inset: 32% 7% auto; width: max-content; max-width: 86%; margin-inline: auto;
  padding: .2em .55em; border: 3px solid var(--ink); border-radius: 10px;
  text-align: center; font-weight: 950; font-size: clamp(18px, 4vw, 45px);
  color: var(--ink); background: #ffe385; box-shadow: 0 4px 0 #1539459c;
  pointer-events: none;
}
.keyboard-tip { margin-top: 15px; color: var(--muted); font-size: 12px; line-height: 1.65; }
kbd { padding: 2px 4px; border: 1px solid #b6c8b4; border-bottom-width: 2px; border-radius: 4px; background: #fffdf3; font-size: 10px; }

.side-panel {
  min-width: 0; padding: 16px; background: var(--cream); border: 2px solid var(--ink);
  border-radius: 12px; box-shadow: 0 4px 0 #c5d0bc;
}
.panel-heading { display: flex; align-items: center; gap: 8px; justify-content: space-between; margin-bottom: 13px; }
.panel-heading h1 { font-size: clamp(17px, 2.4vw, 23px); letter-spacing: -.015em; }
.network-state { font-size: 11px; font-weight: 700; color: var(--muted); text-align: right; }
.network-state[data-online="true"] { color: #286345; }
.public-lobby { padding: clamp(13px, 3vw, 25px); }
.lobby-heading, .lobby-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.lobby-heading h1 { font-size: clamp(19px, 3vw, 27px); }
.lobby-heading .network-state { margin-top: 5px; text-align: left; }
.lobby-actions .primary-button { width: auto; min-width: 62px; }
.lobby-actions button { white-space: nowrap; }
#lobby-retry { margin-top: 10px; }
.room-empty {
  margin-top: 16px;
  padding: 18px 12px;
  border: 1px dashed #a8b7a0;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}
.room-directory {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 218px), 1fr));
  gap: 12px;
  padding: 0;
  margin: 16px 0 0;
  list-style: none;
}
.room-directory:empty { display: none; }
.room-card {
  width: 100%;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--field);
  box-shadow: 0 2px 0 #bfcdb5;
  text-align: left;
}
.room-card:hover:not(:disabled) { background: #f3f5e6; }
.room-card-heading, .room-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
.room-card-heading [data-phase], .room-card-footer [data-action] {
  padding: 3px 7px;
  border-radius: 5px;
  background: #e4efdc;
  color: #244c35;
  font-weight: 800;
  white-space: nowrap;
}
.room-card[data-full="true"] [data-phase] { background: #f9e6bd; color: #604820; }
.room-card-footer [data-action] { background: var(--ink); color: var(--field); }
.room-card-number { display: grid; gap: 3px; }
.room-card-number > span { font-size: 11px; color: var(--muted); }
.room-card-number strong { font-size: 26px; letter-spacing: .11em; font-variant-numeric: tabular-nums; }
label, legend { font-size: 13px; font-weight: 750; }
input[type="text"], select {
  min-width: 0; width: 100%; min-height: 44px;
  border: 1px solid #9aaea5; border-radius: 8px; padding: 7px 10px;
  background: var(--field); font-size: 16px;
}
.inline-controls { display: flex; align-items: stretch; gap: 7px; margin-top: 6px; }
.inline-controls button { flex: 0 0 auto; }
.primary-button, .secondary-button, .leave-button {
  min-height: 44px; padding: 8px 12px; border: 1.5px solid var(--ink);
  border-radius: 8px; font-weight: 800; font-size: 14px;
}
.primary-button { width: 100%; background: var(--mark); box-shadow: 0 2px 0 var(--ink); }
.primary-button:hover:not(:disabled) { background: #ffdf84; }
.secondary-button { background: var(--field); }
.secondary-button:hover:not(:disabled) { background: #ebf4df; }
.compact { font-size: 12px; padding-inline: 9px; }
.hint, .feedback { font-size: 12px; line-height: 1.55; margin-top: 10px; color: var(--muted); }
.feedback:empty { display: none; }
.feedback[data-error="true"], .asset-error { color: #8d271f; }
#retry-network { margin-top: 8px; }
.join-form, .match-button, .invite, .seats { margin-top: 13px; }
.match-button { width: 100%; }
.room-number { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 10px; background: #e4efdc; border-radius: 8px; }
.room-number span { display: block; font-size: 11px; font-weight: 750; }
.room-number strong { font-size: clamp(23px, 5vw, 30px); font-variant-numeric: tabular-nums; letter-spacing: .1em; }
#invite-url { font-size: 16px; }
.seats { list-style: none; margin-bottom: 12px; padding: 0; display: grid; gap: 5px; }
.seats li { display: flex; gap: 9px; align-items: center; padding: 5px 1px; }
.seats strong, .seats small { display: block; }
.seats strong { font-size: 13px; }
.seats small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.seat-marker { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 8px; background: #ffde78; font-weight: 800; }
.seat-marker.second { background: #b6e8fa; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
.characters { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.characters label { display: flex; min-height: 42px; align-items: center; justify-content: center; gap: 3px; white-space: nowrap; background: var(--field); border: 1px solid var(--line); border-radius: 6px; }
.characters label:has(input:checked) { background: #ffe6a1; border-color: #705113; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--ink); }
.leave-button { width: 100%; background: transparent; border-color: transparent; margin-top: 5px; }
.leave-button:hover { background: #f5eace; }
.match-result { margin-bottom: 10px; background: #e4efdc; border-radius: 6px; padding: 8px; font-size: 13px; font-weight: 750; }
#local-panel select, #local-panel #start-local, .viewer-settings select { margin: 6px 0 11px; }
.training-options label { display: block; padding: 5px 0; }
.asset-error { grid-column: 1 / -1; font-size: 13px; }

html.battle-expanded { overflow: hidden; overscroll-behavior: none; }
.battle-expanded .topbar,
.battle-expanded .game-view > .side-panel,
.battle-expanded .asset-error { display: none; }

.stage-expanded {
  --left-gutter: max(clamp(10px, 3vw, 30px), calc(env(safe-area-inset-left) + 8px));
  --right-gutter: max(clamp(10px, 3vw, 30px), calc(env(safe-area-inset-right) + 8px));
  --top-gutter: max(8px, env(safe-area-inset-top));
  --bottom-gutter: max(12px, calc(env(safe-area-inset-bottom) + 8px));
  position: fixed;
  z-index: 10;
  top: var(--view-top, 0px);
  left: var(--view-left, 0px);
  width: var(--view-width, 100%);
  height: 100vh;
  height: var(--view-height, 100dvh);
  background: #244d55;
  overflow: hidden;
  touch-action: none;
}
.stage-expanded:fullscreen { inset: 0; width: 100%; height: 100%; }
.stage-expanded .stage { position: absolute; inset: 0; border: 0; border-radius: 0; box-shadow: none; }
.stage-expanded .arena-surface { position: absolute; inset: 0; aspect-ratio: auto; }
.stage-expanded .stage-toolbar {
  position: absolute;
  z-index: 3;
  inset: var(--top-gutter) var(--right-gutter) auto var(--left-gutter);
  margin: 0;
  color: #fff7dd;
  pointer-events: none;
}
.stage-expanded .stage-toolbar p {
  background: #153945eb;
  border-radius: 7px;
  padding: 6px 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-expanded .quiet-button {
  min-width: 44px;
  min-height: 44px;
  color: #fff7dd;
  border-color: #dbe9cab3;
  background: #153945ed;
  pointer-events: auto;
}
.stage-expanded .hud {
  inset: calc(var(--top-gutter) + 50px) var(--right-gutter) auto var(--left-gutter);
  max-width: 1240px;
  margin-inline: auto;
}
.stage-expanded .fighter-label { font-size: clamp(11px, 1.5vw, 16px); }
.stage-expanded .fight-message { inset-block-start: 37%; }
.stage-expanded .keyboard-tip {
  position: absolute;
  z-index: 2;
  inset: auto 10px var(--bottom-gutter);
  width: max-content;
  max-width: calc(100% - 20px);
  margin: 0 auto;
  padding: 5px 9px;
  background: #153945ed;
  border-radius: 7px;
  color: #fff7dd;
  text-align: center;
  pointer-events: none;
}
.stage-expanded .keyboard-tip kbd { color: var(--ink); }

.touch-controls {
  --button-size: clamp(50px, 15.8vw, 82px);
  --slap-size: calc(var(--button-size) + 12px);
  --pad-gap: clamp(6px, 1.7vw, 12px);
  position: absolute;
  z-index: 2;
  inset: auto var(--right-gutter) var(--bottom-gutter) var(--left-gutter);
  display: none;
  justify-content: space-between;
  align-items: end;
  pointer-events: none;
}
.touch-controls button {
  display: grid;
  place-items: center;
  width: var(--button-size);
  height: var(--button-size);
  padding: 0;
  border: 2px solid #153945;
  border-radius: 50%;
  color: #152f37;
  background-color: #dbeed6;
  background-image: linear-gradient(#ffffff40, transparent 54%);
  box-shadow: inset 0 0 0 2px #ffffff85, 0 4px 0 #142d37bb;
  font-weight: 900;
  font-size: clamp(16px, calc(var(--button-size) * .33), 25px);
  line-height: 1;
  touch-action: none; pointer-events: auto; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-controls button:focus-visible { outline-color: #fff4ab; }
.touch-controls button.pressed { transform: translateY(3px); box-shadow: inset 0 0 0 3px #fff4ab; filter: brightness(1.15); }
.touch-controls .guard { background-color: #a9e9ff; }
.touch-controls .ultimate { background-color: #fff0a1; font-size: clamp(13px, calc(var(--button-size) * .28), 19px); }
.touch-controls .slap {
  width: var(--slap-size);
  height: var(--slap-size);
  background-color: #ffcd55;
  font-size: clamp(19px, calc(var(--slap-size) * .35), 30px);
}
.touch-controls .pounce { background-color: #ff9b82; }
.move-pad, .action-pad { display: grid; place-items: center; gap: var(--pad-gap); }
.move-pad { grid-template-columns: repeat(2, var(--button-size)); }
.move-pad [data-control="jump"] { grid-area: 1 / 1 / 2 / 3; }
.move-pad [data-control="left"], .move-pad [data-control="right"] {
  font-size: clamp(24px, calc(var(--button-size) * .49), 40px);
}
.action-pad { grid-template-columns: var(--button-size) var(--slap-size); }
.workshop-preview {
  display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 12px;
  background: repeating-conic-gradient(#f2ecd9 0% 25%, #fffaf0 0% 50%) 50% / 28px 28px;
}
.workshop-preview canvas { display: block; width: min(100%, 500px); aspect-ratio: 1; }
.viewer-playback, .viewer-extra { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-block: 8px; }
.viewer-playback output { font: 750 12px Inter, sans-serif; }
#frame-slider { width: 100%; }
.viewer-extra select { margin: 0 0 0 4px; min-height: 34px; width: auto; font-size: 14px; }
.viewer-settings a { color: #245b6b; font-size: 13px; text-underline-offset: 3px; }

@media (max-width: 820px) {
  .game-view, .workshop { grid-template-columns: minmax(0, 1fr); }
  .game-view:not(.round-active) .side-panel { grid-row: 1; }
  .stage-toolbar { margin-bottom: 5px; }
}
@media (max-width: 425px) {
  .topbar { align-items: flex-start; flex-direction: column; padding-bottom: 11px; margin-bottom: 10px; }
  .tabs { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tabs button { min-height: 44px; padding-inline: 5px; white-space: nowrap; font-size: clamp(11px, 3.2vw, 13px); }
  .brand-mark { width: 32px; height: 32px; }
  .side-panel { padding: 12px; }
  .stage-toolbar { gap: 5px; }
  .stage-toolbar p { font-size: 11px; }
  .quiet-button { padding-inline: 7px; font-size: 12px; }
}
@media (any-pointer: coarse) {
  .stage-expanded .touch-controls { display: flex; }
  .keyboard-tip { display: none; }
}
@media (orientation: landscape) {
  .touch-controls {
    --button-size: clamp(48px, 17vh, 86px);
    --button-size: clamp(48px, calc(var(--view-height, 100dvh) * .17), 86px);
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::after, *::before { animation-duration: 0s !important; scroll-behavior: auto !important; }
}

.copy-buffer { position: fixed; inset: 0 auto auto 0; opacity: 0; pointer-events: none; }
