:root {
  color-scheme: dark;
  --background: #09131f;
  --surface: #101f2e;
  --sheet: #102131f5;
  --border: #2c4b61;
  --text: #f0f7fb;
  --muted: #a7bbce;
  --blue: #a9ddf7;
  --warm: #f6bf9a;
  --pad: clamp(0.75rem, 2.3vw, 2rem);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 20% 14%, #17314b88, transparent 62%),
    var(--background);
  color: var(--text);
}

button,
input {
  min-width: 0;
  font: inherit;
}

button {
  min-height: 2.6rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid #52738b;
  border-radius: 0.3rem;
  background: #172c40;
  color: var(--text);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 690;
  line-height: 1.25;
}

button:hover {
  background: #223d54;
  border-color: var(--blue);
}

button:active {
  background: #294860;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
.viewport:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #081a27;
}

button.primary:hover {
  background: #d2edff;
}

button.quiet-button {
  min-height: 2.15rem;
  background: transparent;
  color: var(--blue);
}

.masthead,
.shell {
  width: min(100% - var(--pad) * 2, 104rem);
  margin-inline: auto;
}

.masthead {
  display: flex;
  min-height: clamp(3.65rem, 8vw, 4.9rem);
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: clamp(0.78rem, 1.45vw, 1rem);
  font-weight: 850;
  letter-spacing: 0.14em;
  line-height: 1.15;
  text-transform: uppercase;
  white-space: nowrap;
}

.emblem {
  display: grid;
  width: 1.85rem;
  flex: 0 0 auto;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid #6096b7;
  background: #132e433f;
  transform: rotate(45deg);
}

.emblem::after {
  width: 0.53rem;
  flex: 0 0 auto;
  aspect-ratio: 1;
  background: var(--blue);
  content: "";
}

.mode-name {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.68rem, 1.15vw, 0.9rem);
  font-weight: 650;
  letter-spacing: 0.12em;
  text-align: right;
  text-transform: uppercase;
  white-space: nowrap;
}

.stage {
  position: relative;
  min-height: 33rem;
  height: min(68rem, calc(100vh - 9rem));
  height: min(68rem, calc(100svh - 9rem));
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  background: #101e2b;
  box-shadow: 0 1.25rem 4rem #04091288;
}

.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 68% 36%, #3659757f, transparent 67%),
    repeating-linear-gradient(29deg, transparent 0 3.8rem, #41648123 3.8rem 3.9rem),
    repeating-linear-gradient(151deg, transparent 0 4.5rem, #45688326 4.5rem 4.6rem),
    linear-gradient(120deg, #142a3d, #0e1c2b 79%);
  touch-action: none;
}

.viewport:focus-visible {
  outline-offset: -3px;
}

.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#scope-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  display: none;
  width: min(68%, 53svh, 31rem);
  aspect-ratio: 1;
  border: 1px solid #a9ddf777;
  border-radius: 50%;
  box-shadow:
    0 0 0 1px #060d13,
    0 0 0 100vmax #040b13c9,
    inset 0 0 0 0.35rem #040b1338;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.stage.scoped #scope-overlay {
  display: block;
}

#scope-overlay::before,
#scope-overlay::after {
  position: absolute;
  top: 50%;
  left: 50%;
  color: #b9e7fcbd;
  content: "";
  transform: translate(-50%, -50%);
}

#scope-overlay::before {
  width: 38%;
  height: 1px;
  background: linear-gradient(90deg, transparent, currentColor 32% 42%, transparent 42% 58%, currentColor 58% 68%, transparent);
}

#scope-overlay::after {
  width: 1px;
  height: 38%;
  background: linear-gradient(180deg, transparent, currentColor 32% 42%, transparent 42% 58%, currentColor 58% 68%, transparent);
}

.sheet {
  position: absolute;
  z-index: 2;
  inset: 50% auto auto clamp(1.25rem, 5%, 4rem);
  width: min(27.5rem, 100% - 2.5rem);
  max-height: calc(100% - 2.5rem);
  overflow: auto;
  padding: clamp(1.1rem, 2.5vw, 1.8rem);
  border: 1px solid #45677f;
  border-top: 2px solid var(--blue);
  border-radius: 0.32rem;
  background: var(--sheet);
  box-shadow: 0 1.15rem 3rem #040c16ad;
  transform: translateY(-50%);
}

.sheet h1 {
  margin: 0 0 0.55rem;
  color: var(--text);
  font-size: clamp(1.7rem, 3.3vw, 2.6rem);
  font-weight: 820;
  letter-spacing: -0.04em;
  line-height: 1.07;
}

.sheet p {
  margin: 0 0 1.15rem;
  color: var(--muted);
  font-size: 0.89rem;
  line-height: 1.48;
}

.sheet label {
  display: block;
  margin-block: 0.9rem 0.35rem;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 650;
}

.sheet input {
  width: 100%;
  min-height: 2.65rem;
  padding: 0.48rem 0.65rem;
  border: 1px solid #44677f;
  border-radius: 0.25rem;
  background: #0a1928;
  color: var(--text);
}

.sheet input::placeholder {
  color: #91a9be;
}

.sheet .form-note {
  margin-block: 0.62rem 0.95rem;
  font-size: 0.76rem;
}

.button-row,
.join-row,
.account-row {
  display: flex;
  gap: 0.55rem;
}

.button-row > button {
  flex: 1 1 0;
}

.account-row {
  margin-bottom: 1rem;
  align-items: center;
  justify-content: space-between;
}

.sheet .account-row p {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.account-row button {
  flex: 0 0 auto;
}

.account-row strong {
  color: var(--blue);
}

.sheet #shared-room-note {
  margin: 0.85rem 0 0;
  padding: 0.55rem 0.68rem;
  border-left: 2px solid var(--blue);
  background: #0d1d2c;
  color: var(--blue);
  overflow-wrap: anywhere;
}

.join-form {
  margin-top: 1.15rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border);
}

.join-row button {
  flex: 0 0 auto;
}

#room-code {
  flex: 1 1 auto;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.match-panel {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
  --hud-pad: clamp(0.55rem, 2.2vw, 1.2rem);
}

.scoreboard {
  display: grid;
  width: min(46rem, 100% - var(--hud-pad) * 2);
  grid-template-columns: 1.12fr 1.3fr 0.93fr 0.63fr 0.76fr 0.76fr;
  margin: var(--hud-pad) auto 0;
  border: 1px solid #416279;
  border-top: 2px solid var(--blue);
  background: #0c1b2aee;
}

.readout {
  min-width: 0;
  padding: 0.55rem clamp(0.36rem, 1.05vw, 0.78rem);
}

.readout + .readout {
  border-left: 1px solid var(--border);
}

.readout dt {
  color: var(--muted);
  font-size: clamp(0.6rem, 1.1vw, 0.7rem);
  font-weight: 630;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.readout dd {
  margin: 0.12rem 0 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: clamp(0.83rem, 1.95vw, 1.12rem);
  font-variant-numeric: tabular-nums;
  font-weight: 780;
  line-height: 1.17;
}

.readout.player dd {
  color: var(--blue);
}

.readout.opponent dd {
  color: var(--warm);
}

#match-code {
  padding-block: 0.15rem;
  color: var(--blue);
  cursor: text;
  pointer-events: auto;
  user-select: all;
}

.room-invite {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.18rem 0.45rem;
}

#copy-room-code {
  min-height: 1.7rem;
  max-width: 100%;
  padding: 0.2rem 0.35rem;
  font-size: 0.68rem;
  pointer-events: auto;
}

#hit-feedback {
  position: absolute;
  inset: calc(50% + 1.7rem) auto auto 50%;
  width: max-content;
  max-width: calc(100% - var(--hud-pad) * 2);
  margin: 0;
  padding: 0.25rem 0.55rem;
  border: 1px solid #598eac;
  border-radius: 0.23rem;
  background: #0b1928ed;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 740;
  text-align: center;
  text-transform: uppercase;
  transform: translateX(-50%);
}

.result {
  position: absolute;
  inset: 45% auto auto 50%;
  width: min(30rem, 100% - 2rem);
  margin: 0;
  padding: 1rem 1.4rem;
  border: 1px solid var(--border);
  border-top: 2px solid var(--blue);
  background: var(--sheet);
  box-shadow: 0 0.8rem 2.5rem #050c17bd;
  color: var(--text);
  font-size: clamp(1.35rem, 4vw, 2.25rem);
  font-weight: 800;
  text-align: center;
  transform: translate(-50%, -50%);
}

.match-footer {
  position: absolute;
  inset: auto var(--hud-pad) var(--hud-pad);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
}

.match-footer p {
  margin: 0;
  padding: 0.48rem 0.67rem;
  background: #0b1928e8;
  color: var(--text);
  font-size: clamp(0.72rem, 1.3vw, 0.85rem);
  line-height: 1.45;
}

.match-footer .touch-help,
.touch-controls {
  display: none;
}

.match-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
  pointer-events: auto;
}

.touch-controls {
  position: absolute;
  inset: auto var(--hud-pad) 4.3rem;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.touch-controls button {
  min-width: 2.7rem;
  padding: 0.35rem 0.56rem;
  background: #142a3dea;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.touch-controls button.primary {
  background: var(--blue);
}

.touch-controls .movement {
  display: grid;
  grid-template-columns: repeat(3, 2.7rem);
  grid-template-areas: ". forward ." "left back right";
  gap: 0.26rem;
}

.touch-controls .movement button {
  min-height: 2.65rem;
  font-size: 1.35rem;
}

[data-control="forward"] {
  grid-area: forward;
}

[data-control="left"] {
  grid-area: left;
}

[data-control="back"] {
  grid-area: back;
}

[data-control="right"] {
  grid-area: right;
}

.touch-actions {
  display: flex;
  gap: 0.35rem;
}

.status {
  min-height: 1.4rem;
  margin: 0.68rem 0 calc(0.6rem + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

@media (max-width: 680px) {
  .stage {
    min-height: 32rem;
    height: calc(100vh - 7.7rem);
    height: calc(100svh - 7.7rem);
  }

  .sheet {
    inset-inline-start: 50%;
    transform: translate(-50%, -50%);
  }

  .scoreboard {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readout:nth-child(4) {
    border-left: 0;
  }

  .readout:nth-child(n+4) {
    border-top: 1px solid var(--border);
  }

  .match-footer .desktop-help {
    max-width: 12rem;
  }
}

@media (pointer: coarse) {
  .touch-controls {
    display: flex;
  }

  .match-footer .touch-help {
    display: block;
  }

  .match-footer .desktop-help,
  #look-lock {
    display: none;
  }
}

@media (pointer: coarse) and (max-height: 540px) {
  .masthead {
    min-height: 3rem;
  }

  .stage {
    min-height: 19rem;
  }
}

@media (max-width: 380px) {
  .wordmark {
    gap: 0.62rem;
    letter-spacing: 0.08em;
  }

  .emblem {
    width: 1.45rem;
  }

  .sheet {
    width: calc(100% - 1.2rem);
  }

  .touch-controls .movement {
    grid-template-columns: repeat(3, 2.2rem);
  }

  .touch-controls button {
    min-width: 2.2rem;
  }
}
