:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #000;
  color: #f5f5f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #000;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(320px, 48vh) minmax(0, 1fr);
  background: #000;
  overflow: hidden;
}

.stage-panel {
  min-height: 0;
  border-bottom: 1px solid #282828;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

#tool-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

.hud-panel {
  min-height: 0;
  overflow: auto;
  background: #050505;
  border-top: 1px solid #1c1c1c;
  padding: 12px;
}

.hud-grid {
  width: min(1680px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 0.82fr) minmax(280px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.hud-grid.is-single-seat {
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 0.82fr);
}

.fighter-control,
.center-control {
  min-width: 0;
  border: 1px solid #252525;
  background: #090909;
  padding: 10px;
}

.fighter-control[data-player="p1"] {
  border-color: rgba(255, 70, 70, 0.42);
}

.fighter-control[data-player="p2"] {
  border-color: rgba(70, 140, 255, 0.42);
}

.fighter-control.is-locked {
  border-color: #ededed;
}

.fighter-control.is-remote {
  border-color: #171717;
}

.status-line {
  width: min(720px, 100%);
  margin: 0 auto;
  border: 1px solid #252525;
  background: #090909;
  padding: 14px;
  color: #dcdcdc;
}

.fighter-topline,
.match-line,
.command-row,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.command-row {
  flex-wrap: wrap;
}

.fighter-topline strong,
.match-line strong {
  font-size: 15px;
  letter-spacing: 0;
}

.fighter-topline span,
.match-line span,
.meter span,
.group-label,
.prediction-strip span,
.move-stack span,
.move-stack em {
  color: #a8a8a8;
  font-size: 12px;
  font-style: normal;
}

.field-label {
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  color: #dcdcdc;
  font-size: 13px;
}

select,
button,
.tool-link,
.preset-name,
.phase-row input[type="number"],
.tune-row input[type="number"],
.preset-row select {
  border: 1px solid #383838;
  background: #111;
  color: #f3f3f3;
  border-radius: 4px;
}

select {
  min-width: 0;
  height: 32px;
  padding: 0 8px;
}

button {
  min-height: 32px;
  padding: 6px 10px;
  cursor: pointer;
}

.tool-link {
  min-height: 32px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 13px;
}

button:hover:not(:disabled),
button:focus-visible:not(:disabled),
.tool-link:hover,
.tool-link:focus-visible {
  border-color: #fff;
  outline: none;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.has-tooltip {
  position: relative;
}

.floating-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: min(340px, calc(100vw - 20px));
  border: 1px solid #444;
  background: #050505;
  color: #f4f4f4;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-line;
  text-align: left;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 100ms ease,
    transform 100ms ease,
    visibility 100ms ease;
}

.floating-tooltip.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.floating-tooltip::before {
  content: "";
  position: absolute;
  left: var(--tooltip-arrow-x, 50%);
  width: 8px;
  height: 8px;
  border-right: 1px solid #444;
  border-bottom: 1px solid #444;
  background: #050505;
  transform: translateX(-50%) rotate(45deg);
}

.floating-tooltip[data-placement="top"]::before {
  bottom: -5px;
}

.floating-tooltip[data-placement="bottom"]::before {
  top: -5px;
  transform: translateX(-50%) rotate(225deg);
}

.meter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 8px 0 10px;
}

.meter {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.meter div {
  height: 5px;
  background: #202020;
  overflow: hidden;
}

.meter i {
  display: block;
  height: 100%;
  background: #ededed;
}

.meter b {
  font-size: 11px;
  font-weight: 600;
  color: #f2f2f2;
}

.move-groups {
  display: grid;
  gap: 8px;
}

.move-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.move-button {
  width: 100%;
  min-height: 34px;
  overflow-wrap: anywhere;
  line-height: 1.05;
  font-size: 12px;
}

.move-button.is-selected {
  color: #000;
  background: #fff;
  border-color: #fff;
}

.toggle-row {
  margin: 10px 0;
  justify-content: flex-start;
}

.toggle-row label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: #e9e9e9;
  font-size: 13px;
}

.di-joystick {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px;
  align-items: center;
  margin: 8px 0 10px;
  color: #dcdcdc;
  font-size: 12px;
}

.di-joystick.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.joystick-pad {
  position: relative;
  width: 96px;
  aspect-ratio: 1;
  border: 1px solid #3a3a3a;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.12), transparent 3px),
    #050505;
  touch-action: none;
  cursor: crosshair;
}

.joystick-cross::before,
.joystick-cross::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.18);
}

.joystick-cross::before {
  left: 50%;
  top: 8px;
  bottom: 8px;
  width: 1px;
}

.joystick-cross::after {
  left: 8px;
  right: 8px;
  top: 50%;
  height: 1px;
}

.joystick-vector {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--stick-length);
  height: 2px;
  background: rgba(255, 255, 255, 0.56);
  transform-origin: left center;
  transform: rotate(var(--stick-angle));
}

.joystick-knob {
  position: absolute;
  left: var(--stick-x);
  top: var(--stick-y);
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  background: #000;
  transform: translate(-50%, -50%);
}

.di-joystick output {
  min-width: 64px;
  color: #f0f0f0;
}

input[type="range"] {
  width: 100%;
  accent-color: #fff;
}

.lock-button,
.command-row button,
.debug-toggle {
  width: 100%;
}

.command-row button {
  flex: 1 1 112px;
}

.center-control {
  display: grid;
  grid-template-rows: auto auto auto auto auto 1fr;
  gap: 10px;
}

.prediction-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.prediction-card {
  border: 1px solid #242424;
  padding: 8px;
  min-width: 0;
}

.prediction-card:focus-visible {
  border-color: #fff;
  outline: none;
}

.prediction-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.winner-line {
  min-height: 22px;
  color: #fff;
  font-weight: 700;
}

.room-panel,
.debug-panel {
  display: grid;
  gap: 8px;
  border: 1px solid #242424;
  padding: 8px;
}

.room-topline {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.room-topline strong {
  font-size: 13px;
}

.room-topline span,
.room-panel label,
.debug-panel span {
  color: #a8a8a8;
  font-size: 12px;
}

.room-panel label {
  display: grid;
  gap: 4px;
}

.room-panel input {
  min-width: 0;
  min-height: 30px;
  border: 1px solid #383838;
  background: #111;
  color: #f3f3f3;
  border-radius: 4px;
  padding: 4px 6px;
}

.checkbox-line {
  display: inline-flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px !important;
  color: #dcdcdc !important;
}

.replay-db {
  display: grid;
  gap: 8px;
  border-top: 1px solid #1d1d1d;
  padding-top: 8px;
}

.debug-panel div {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 8px;
  border-bottom: 1px solid #1d1d1d;
  padding-bottom: 5px;
}

.debug-panel b {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #f2f2f2;
  font-size: 12px;
}

.stack-header {
  border-top: 1px solid #222;
  padding-top: 8px;
  color: #dcdcdc;
  font-size: 13px;
  font-weight: 700;
}

.move-stack {
  min-height: 150px;
  max-height: 290px;
  overflow: auto;
  padding: 0;
  margin: 0;
  list-style: none;
  display: grid;
  align-content: start;
  gap: 6px;
}

.move-stack li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid #1d1d1d;
  padding: 5px 0;
  min-width: 0;
}

.move-stack b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.tool-shell {
  grid-template-rows: minmax(300px, 44vh) minmax(0, 1fr);
}

.tool-grid {
  width: min(1680px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(320px, 1fr);
  gap: 12px;
}

.render-control {
  align-content: start;
}

.tool-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.preset-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(120px, 1fr) minmax(100px, 0.8fr);
  gap: 8px;
}

.preset-name {
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
}

.preset-row select {
  min-width: 0;
  height: 32px;
  padding: 0 8px;
}

.timeline-scrub {
  display: grid;
  grid-template-columns: 100px 1fr 64px;
  gap: 8px;
  align-items: center;
  color: #dcdcdc;
  font-size: 12px;
}

.timeline-scrub output {
  text-align: right;
}

.render-timeline {
  position: relative;
  display: grid;
  gap: 6px;
  border: 1px solid #242424;
  padding: 10px;
  overflow: hidden;
}

.timeline-row {
  position: relative;
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 8px;
  min-height: 21px;
  align-items: center;
}

.timeline-row span {
  color: #a8a8a8;
  font-size: 12px;
}

.timeline-row b {
  position: absolute;
  left: var(--start-left);
  top: 4px;
  width: var(--bar-width);
  height: 13px;
  background: #f2f2f2;
  border: 1px solid #fff;
}

.timeline-row::after {
  content: "";
  grid-column: 2;
  height: 1px;
  background: #242424;
}

.timeline-cursor {
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: #fff;
  z-index: 2;
}

.phase-editor {
  display: grid;
  gap: 8px;
  align-content: start;
}

.character-tool-grid {
  grid-template-columns: minmax(300px, 0.62fr) minmax(360px, 1fr);
}

.character-editor-panel {
  overflow: auto;
}

.tune-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  border: 1px solid #242424;
  padding: 8px;
}

.tune-section {
  display: grid;
  gap: 8px;
  border-top: 1px solid #1d1d1d;
  padding-top: 8px;
}

.tune-row {
  display: grid;
  grid-template-columns: 92px minmax(120px, 1fr) 82px 54px;
  gap: 8px;
  align-items: center;
  color: #a8a8a8;
  font-size: 12px;
}

.tune-row input[type="number"] {
  min-width: 0;
  min-height: 30px;
  padding: 4px 6px;
}

.tune-row output {
  text-align: right;
  color: #f0f0f0;
}

.phase-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  border-top: 1px solid #1d1d1d;
  padding-top: 8px;
}

.phase-row-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.phase-row-head strong {
  font-size: 13px;
}

.phase-row-head span,
.phase-row label {
  color: #a8a8a8;
  font-size: 12px;
}

.phase-row label {
  display: grid;
  gap: 4px;
}

.phase-row input[type="number"] {
  min-width: 0;
  min-height: 30px;
  padding: 4px 6px;
}

@media (max-width: 980px) {
  .hud-grid {
    grid-template-columns: 1fr;
  }

  .tool-grid {
    grid-template-columns: 1fr;
  }

  .center-control {
    grid-row: 1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-rows: minmax(280px, 42vh) minmax(0, 1fr);
  }

  .meter-grid,
  .prediction-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .di-joystick,
  .move-stack li,
  .tool-actions,
  .preset-row,
  .timeline-scrub,
  .phase-row,
  .tune-summary,
  .tune-row {
    grid-template-columns: 1fr;
  }

  .di-joystick output,
  .tune-row output {
    text-align: left;
  }

  .joystick-pad {
    width: min(120px, 100%);
  }

  .floating-tooltip {
    max-width: min(300px, calc(100vw - 20px));
  }
}
