:root {
  color-scheme: dark;
  --bg: #101114;
  --ink: #f2f1ea;
  --muted: #a9adb6;
  --line: #313640;
  --accent: #e2c15f;
  --danger: #cf4b45;
  --ok: #5ebd73;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.controls-open {
  overflow: hidden;
}

button {
  border: 1px solid var(--line);
  background: #1e2229;
  color: var(--ink);
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mobile-menu-toggle {
  display: none;
}

button:hover {
  border-color: var(--accent);
}

button[aria-pressed="true"] {
  border-color: var(--ok);
  color: #dff7e5;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  width: min(1400px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.stage-wrap {
  position: relative;
  display: grid;
  align-items: center;
  min-height: calc(100vh - 36px);
  overflow: hidden;
  border: 1px solid #242832;
  border-radius: 8px;
  background: #050609;
}

canvas {
  width: 100%;
  aspect-ratio: 16 / 10;
  image-rendering: pixelated;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(5, 6, 9, 0.72);
}

.title-overlay {
  place-content: start end;
  padding: 12px;
  background: transparent;
  pointer-events: none;
}

.title-overlay button {
  pointer-events: auto;
}

.virtual-pad {
  display: none;
}

.overlay.hidden {
  display: none;
}

.title {
  font-size: clamp(42px, 9vw, 108px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: 0;
}

.subtitle {
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
}

.panel {
  border: 1px solid #242832;
  border-radius: 8px;
  padding: 18px;
  background: #151820;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 14px;
  color: var(--accent);
  text-transform: uppercase;
}

p {
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status-grid > div,
.select-control {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #11141b;
}

.status-grid span,
.select-control span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin-top: 4px;
}

.select-control select {
  width: 100%;
  margin-top: 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.control-block {
  display: grid;
  gap: 10px;
}

dl {
  margin: 0;
  display: grid;
  gap: 8px;
}

dl div {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
  align-items: center;
}

dt {
  font-weight: 800;
  color: #fff;
}

dd {
  margin: 0;
  color: var(--muted);
}

.actions {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.doc-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.doc-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 6, 9, 0.78);
}

.doc-modal[hidden] {
  display: none;
}

.doc-dialog {
  width: min(900px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151820;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #11141b;
}

.doc-header h2 {
  color: var(--ink);
  font-size: 18px;
  text-transform: none;
}

.doc-content {
  max-height: calc(min(760px, 100vh - 36px) - 66px);
  overflow: auto;
  padding: 18px;
  color: var(--ink);
  line-height: 1.65;
}

.doc-content h1,
.doc-content h2,
.doc-content h3 {
  margin: 18px 0 10px;
  color: var(--accent);
  text-transform: none;
}

.doc-content h1:first-child,
.doc-content h2:first-child,
.doc-content h3:first-child {
  margin-top: 0;
}

.doc-content h1 {
  font-size: 24px;
}

.doc-content h2 {
  font-size: 18px;
}

.doc-content h3 {
  font-size: 15px;
}

.doc-content p,
.doc-content ul {
  margin: 0 0 12px;
}

.doc-content ul {
  padding-left: 20px;
}

.doc-content code {
  padding: 1px 4px;
  border-radius: 4px;
  background: #0d1016;
  color: #fff;
}

.doc-table-wrap {
  overflow-x: auto;
  margin: 0 0 16px;
}

.doc-content table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
}

.doc-content th,
.doc-content td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  vertical-align: top;
}

.doc-content th {
  background: #20242d;
  color: #fff;
  text-align: left;
}

.doc-content td {
  background: #11141b;
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .stage-wrap {
    min-height: auto;
  }

  .panel {
    min-height: 0;
  }
}

@media (max-width: 760px), (pointer: coarse) and (max-width: 920px), (orientation: landscape) and (max-width: 1024px) and (max-height: 520px) {
  body {
    overflow: hidden;
  }

  .mobile-menu-toggle {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 16;
    display: inline-grid;
    place-items: center;
    min-width: 70px;
    min-height: 42px;
    background: rgba(17, 20, 27, 0.9);
    backdrop-filter: blur(8px);
  }

  .shell {
    display: block;
    width: 100%;
    min-height: 100svh;
    padding: 0;
  }

  .stage-wrap {
    place-items: center;
    min-height: 100svh;
    border: 0;
    border-radius: 0;
  }

  canvas {
    width: min(100vw, calc(100svh * 16 / 10));
    height: auto;
    max-height: none;
  }

  .title-overlay {
    padding: 58px 10px 10px;
  }

  .virtual-pad {
    position: absolute;
    inset: auto 0 16px;
    z-index: 12;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    padding: 0 16px;
    pointer-events: none;
  }

  .virtual-pad button {
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    border-color: rgba(242, 241, 234, 0.16);
    background: rgba(17, 20, 27, 0.28);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(4px);
  }

  .virtual-pad button:active,
  .virtual-pad button.is-active {
    border-color: var(--ok);
    color: #dff7e5;
    background: rgba(28, 45, 35, 0.48);
  }

  .virtual-dpad {
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 7px;
  }

  .virtual-dpad button {
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    font-size: 20px;
  }

  .virtual-dpad button[data-virtual-key="KeyW"] {
    grid-column: 2;
    grid-row: 1;
  }

  .virtual-dpad button[data-virtual-key="KeyA"] {
    grid-column: 1;
    grid-row: 2;
  }

  .virtual-dpad button[data-virtual-key="KeyS"] {
    grid-column: 2;
    grid-row: 3;
  }

  .virtual-dpad button[data-virtual-key="KeyD"] {
    grid-column: 3;
    grid-row: 2;
  }

  .virtual-attacks {
    display: flex;
    gap: 12px;
    align-items: center;
    padding-bottom: 16px;
  }

  .virtual-attacks button {
    min-width: 58px;
    min-height: 58px;
    padding: 0;
    border-radius: 50%;
    font-size: 18px;
  }

  .panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 15;
    width: min(340px, 88vw);
    height: 100svh;
    overflow: auto;
    border-width: 0 0 0 1px;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 160ms ease;
  }

  body.controls-open .panel {
    transform: translateX(0);
  }

  body.controls-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 14;
    background: rgba(5, 6, 9, 0.58);
  }

  .doc-modal {
    z-index: 30;
    padding: 10px;
  }

  .doc-dialog {
    max-height: calc(100svh - 20px);
  }

  .doc-content {
    max-height: calc(100svh - 88px);
    padding: 14px;
  }
}

@media (max-width: 420px) {
  .virtual-dpad {
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
    gap: 6px;
  }

  .virtual-dpad button {
    min-width: 42px;
    min-height: 42px;
  }

  .virtual-attacks button {
    min-width: 52px;
    min-height: 52px;
  }
}
