:root {
  color-scheme: dark;
  --bg: #08090d;
  --bg-soft: #0e1118;
  --surface: #141821;
  --surface-2: #1c2230;
  --line: #262d3b;
  --text: #f3f5f9;
  --muted: #97a0b3;
  --red: #e5484d;
  --red-bright: #ff5a5f;
  --red-dark: #cb2f35;
  --green: #3ddc84;
  --pad-size: clamp(46px, 13.5vw, 62px);
  --action-size: clamp(58px, 17vw, 76px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
}

/* ---------- Landing ---------- */

.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(229, 72, 77, 0.2), transparent 60%),
    radial-gradient(80% 60% at 50% 110%, rgba(79, 140, 255, 0.12), transparent 60%),
    var(--bg);
  overflow: auto;
}

.landing::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at 50% 40%, black, transparent 72%);
  pointer-events: none;
}

.landing-inner {
  position: relative;
  width: min(100%, 430px);
  text-align: center;
}

.logo-mark {
  width: 76px;
  height: 76px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: linear-gradient(145deg, var(--red-bright), var(--red-dark));
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow:
    0 18px 40px rgba(229, 72, 77, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  color: #fff;
  font-size: 2.4rem;
  font-weight: 900;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
}

h1 {
  margin: 0;
  font-size: clamp(2.05rem, 8.5vw, 2.8rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.tagline {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.feature-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 22px 0 30px;
  flex-wrap: wrap;
}

.feature-row span {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20, 24, 33, 0.7);
  color: #c4cbd8;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

.loader {
  display: flex;
  justify-content: center;
  margin: 22px 0 6px;
}

.loader span {
  width: 30px;
  height: 30px;
  border: 3px solid #2a3242;
  border-top-color: var(--red-bright);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.landing-status {
  min-height: 2.6em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

#btn-landing-reload {
  margin-top: 8px;
}

.landing-status.error {
  color: #ff8b8f;
}

.legal {
  margin: 26px 0 0;
  color: #646d7e;
  font-size: 0.72rem;
  line-height: 1.55;
}

/* ---------- Game ---------- */

.game-screen {
  display: flex;
  flex-direction: column;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  outline: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.stage-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 26px calc(10px + var(--safe-left));
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.68), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.stage-topbar > * {
  pointer-events: auto;
}

.topbar-spacer {
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(14, 17, 24, 0.74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #e9edf4;
  font-size: 0.78rem;
  font-weight: 600;
}

.chip:disabled {
  opacity: 0.45;
  cursor: default;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7486;
}

.chip.waiting .chip-dot {
  background: #f5b544;
  box-shadow: 0 0 0 4px rgba(245, 181, 68, 0.16);
}

.chip.live .chip-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(61, 220, 132, 0.18);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 7px rgba(61, 220, 132, 0.04);
  }
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 11px;
  background: rgba(14, 17, 24, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #e9edf4;
  font-size: 0.95rem;
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover {
  background: rgba(28, 34, 48, 0.9);
}

.stage-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.start-card {
  width: min(330px, 100%);
  padding: 26px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(20, 24, 33, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.overline {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

.error-text {
  margin: 0 0 18px;
  color: #ff9a9e;
  font-size: 0.88rem;
  line-height: 1.6;
  word-break: break-word;
}

/* ---------- Virtual controls ---------- */

.controls {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
  padding: 8px calc(14px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(14px + var(--safe-left));
  background: linear-gradient(to top, #0b0d12 30%, #0d1017);
  border-top: 1px solid #171b24;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.controls button {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, var(--pad-size));
  grid-template-rows: repeat(3, var(--pad-size));
  justify-self: start;
  gap: 3px;
}

.pad {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #2d3546;
  border-radius: 12px;
  background: linear-gradient(180deg, #222938, #171c26);
  box-shadow:
    0 3px 0 #0a0c11,
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: #cbd3e1;
  font-size: calc(var(--pad-size) * 0.3);
  line-height: 1;
  transition: transform 0.05s ease, background 0.05s ease;
}

.pad.up { grid-area: 1 / 2; }
.pad.left { grid-area: 2 / 1; }
.pad.right { grid-area: 2 / 3; }
.pad.down { grid-area: 3 / 2; }

.pad-center {
  grid-area: 2 / 2;
  position: relative;
}

.pad-center::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: #11151d;
  border: 1px solid #232a38;
}

.pad.pressed {
  transform: translateY(2px);
  background: linear-gradient(180deg, var(--red-bright), var(--red-dark));
  border-color: #ff8b8f;
  color: #fff;
  box-shadow:
    0 1px 0 #0a0c11,
    0 0 20px rgba(229, 72, 77, 0.35);
}

.system-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding-bottom: 4px;
}

.pill {
  min-width: 76px;
  padding: 7px 10px;
  border: 1px solid #2d3546;
  border-radius: 999px;
  background: linear-gradient(180deg, #1d2431, #141923);
  box-shadow: 0 2px 0 #0a0c11;
  color: #aeb8c9;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  transition: transform 0.05s ease, background 0.05s ease;
}

.pill.pressed {
  transform: translateY(2px);
  background: #3a2a18;
  border-color: #8d6530;
  color: #ffd18a;
  box-shadow: 0 0 16px rgba(245, 181, 68, 0.18);
}

.action-buttons {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: clamp(10px, 3.5vw, 18px);
  padding-bottom: 2px;
}

.round {
  display: grid;
  place-items: center;
  width: var(--action-size);
  height: var(--action-size);
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(180deg, #2a3243, #1a202c);
  box-shadow:
    0 4px 0 #090b0f,
    inset 0 2px 0 rgba(255, 255, 255, 0.1);
  color: #eef1f6;
  font-size: calc(var(--action-size) * 0.32);
  font-weight: 800;
  transition: transform 0.05s ease, filter 0.05s ease;
}

.round.a {
  background: linear-gradient(180deg, var(--red-bright), var(--red-dark));
  border-color: #ff9a9e;
  box-shadow:
    0 4px 0 #651417,
    inset 0 2px 0 rgba(255, 255, 255, 0.26),
    0 0 26px rgba(229, 72, 77, 0.24);
}

.round.b {
  width: calc(var(--action-size) * 0.86);
  height: calc(var(--action-size) * 0.86);
  margin-top: calc(var(--action-size) * 0.2);
}

.round.pressed {
  transform: translateY(3px) scale(0.98);
  filter: brightness(1.18);
  box-shadow:
    0 1px 0 #090b0f,
    inset 0 2px 0 rgba(255, 255, 255, 0.2);
}

/* Landscape: keep the canvas full-screen and float the controls over the
   side letterboxing, which is where thumbs naturally rest. */
@media (orientation: landscape) and (max-height: 620px) {
  .game-screen {
    display: block;
  }

  .stage {
    position: absolute;
    inset: 0;
  }

  .controls {
    position: absolute;
    inset: 0;
    display: block;
    padding: 0;
    border: 0;
    background: none;
    pointer-events: none;
  }

  .dpad {
    position: absolute;
    left: calc(18px + var(--safe-left));
    bottom: calc(16px + var(--safe-bottom));
    pointer-events: auto;
  }

  .action-buttons {
    position: absolute;
    right: calc(22px + var(--safe-right));
    bottom: calc(20px + var(--safe-bottom));
    pointer-events: auto;
  }

  .system-buttons {
    position: absolute;
    right: calc(22px + var(--safe-right));
    bottom: calc(20px + var(--action-size) + 16px);
    left: auto;
    transform: none;
    flex-direction: row;
    gap: 8px;
    padding-bottom: 0;
    pointer-events: auto;
  }

  .stage-topbar {
    padding-bottom: 36px;
  }
}

/* ---------- Sheets ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in 0.18s ease-out;
}

.sheet-panel {
  position: relative;
  width: min(100%, 480px);
  max-height: 88dvh;
  overflow: auto;
  padding: 8px 20px calc(22px + var(--safe-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
  animation: slide-up 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (min-width: 700px) {
  .sheet {
    align-items: center;
  }

  .sheet-panel {
    border-bottom: 1px solid var(--line);
    border-radius: 24px;
    padding-bottom: 22px;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes slide-up {
  from { transform: translateY(24px); opacity: 0; }
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 6px auto 12px;
  border-radius: 999px;
  background: #333b4c;
}

@media (min-width: 700px) {
  .sheet-handle {
    display: none;
  }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: -0.01em;
}

.share-view {
  padding-bottom: 2px;
}

.share-copy {
  margin: 0 0 12px;
  color: #c8cfdb;
  font-size: 0.9rem;
  line-height: 1.65;
}

.share-note {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.6;
}

.primary,
.secondary,
.danger {
  min-height: 46px;
  padding: 11px 18px;
  border-radius: 13px;
  font-weight: 700;
  font-size: 0.92rem;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.primary {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(180deg, var(--red-bright), var(--red-dark));
  box-shadow: 0 10px 24px rgba(229, 72, 77, 0.24);
  color: #fff;
}

.secondary {
  border: 1px solid #30394b;
  background: var(--surface-2);
  color: #d7deea;
}

.danger {
  border: 1px solid #5b2327;
  background: #2a1416;
  color: #ff8b8f;
}

.primary:active,
.secondary:active,
.danger:active {
  transform: scale(0.985);
  filter: brightness(0.94);
}

.primary.full,
.danger.full {
  width: 100%;
}

.primary.big {
  min-height: 52px;
  padding: 14px 30px;
  font-size: 1.02rem;
}

.room-code {
  padding: 14px 10px 12px;
  border: 1px solid #2c3444;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
    #0b0e14;
  color: #fff;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: clamp(1.9rem, 9vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-align: center;
  text-indent: 0.2em;
  user-select: all;
}

.share-link-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.share-link-row input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #2c3444;
  border-radius: 11px;
  background: #0b0e14;
  color: #9fa9bb;
  font-size: 0.76rem;
  outline: none;
}

.share-link-row .secondary {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 16px;
}

.share-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f5b544;
  box-shadow: 0 0 0 4px rgba(245, 181, 68, 0.14);
}

.status-dot.live {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(61, 220, 132, 0.16);
  animation: pulse 1.8s ease-in-out infinite;
}

.status-dot.error {
  background: #ff6b70;
  box-shadow: 0 0 0 4px rgba(255, 107, 112, 0.14);
}

.menu-list {
  display: flex;
  flex-direction: column;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 52px;
  padding: 12px 4px;
  border: 0;
  border-bottom: 1px solid #202635;
  background: none;
  color: #e3e8f0;
  font-size: 0.94rem;
  text-align: left;
}

.menu-item:last-child {
  border-bottom: 0;
}

.menu-item.danger {
  background: none;
  border-bottom: 0;
  color: #ff8b8f;
}

.menu-item kbd {
  padding: 3px 7px;
  border: 1px solid #30394b;
  border-radius: 6px;
  background: #0e1118;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.68rem;
}

.menu-divider {
  height: 1px;
  margin: 6px 0;
  background: #202635;
}

.menu-hint {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.6;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 100;
  max-width: min(90vw, 420px);
  padding: 11px 18px;
  border: 1px solid #30394b;
  border-radius: 999px;
  background: rgba(28, 34, 48, 0.96);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.4);
  color: #e9edf4;
  font-size: 0.82rem;
  text-align: center;
  transform: translateX(-50%);
  animation: toast-in 0.2s ease-out;
  pointer-events: none;
}

@keyframes toast-in {
  from {
    transform: translate(-50%, 8px);
    opacity: 0;
  }
}

/* ---------- Viewer ---------- */

.viewer-body {
  background: #050608;
}

.viewer-app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.viewer-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) calc(14px + var(--safe-right)) 10px calc(14px + var(--safe-left));
  border-bottom: 1px solid #171b24;
  background: #0b0d12;
}

.viewer-brand {
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
}

.viewer-brand span {
  color: var(--red-bright);
}

.viewer-header .spacer {
  flex: 1;
}

.room-pill {
  padding: 5px 10px;
  border: 1px solid #2c3444;
  border-radius: 999px;
  background: #0e1118;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
}

.viewer-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
}

#viewer-video {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.viewer-stage.has-video #viewer-video {
  display: block;
}

.viewer-status {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(229, 72, 77, 0.1), transparent 60%),
    #050608;
  text-align: center;
}

.viewer-status.hidden {
  display: none !important;
}

.join-card,
.status-card {
  width: min(360px, 100%);
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(20, 24, 33, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.join-card h1 {
  margin: 0 0 8px;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.join-card p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

#room-input {
  width: 100%;
  margin: 20px 0 12px;
  padding: 15px 12px;
  border: 1px solid #2f3849;
  border-radius: 14px;
  background: #0b0e14;
  color: #fff;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-align: center;
  text-indent: 0.24em;
  text-transform: uppercase;
  outline: none;
}

#room-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.16);
}

#btn-join {
  width: 100%;
}

.status-card h2 {
  margin: 16px 0 0;
  font-size: 1.06rem;
}

.status-card p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.6;
  word-break: break-word;
}

.status-card .primary,
.status-card .secondary {
  width: 100%;
  margin-top: 20px;
}

.status-card .secondary {
  margin-top: 10px;
}

.join-error {
  min-height: 1.3em;
  margin-top: 12px !important;
  color: #ff8b8f !important;
  font-size: 0.76rem !important;
}

.spinner {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border: 3px solid #2a3242;
  border-top-color: var(--red-bright);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.status-card.error .spinner {
  display: none;
}

.status-card.ok .spinner {
  display: none;
}

.status-card.ok h2 {
  color: var(--green);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.viewer-stats {
  position: absolute;
  left: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 3;
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(10, 12, 17, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #aab4c5;
  font-size: 0.66rem;
  pointer-events: none;
}

@media (max-width: 420px) {
  .viewer-brand {
    font-size: 0.84rem;
  }

  .room-pill {
    font-size: 0.66rem;
  }
}

/* ---------- Admin room dashboard ---------- */

.admin-body {
  min-height: 100dvh;
  overflow: auto;
  background:
    radial-gradient(100% 60% at 50% -10%, rgba(229, 72, 77, 0.12), transparent 60%),
    var(--bg);
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-top)) calc(18px + var(--safe-right)) 12px calc(18px + var(--safe-left));
  border-bottom: 1px solid #171b24;
  background: #0b0d12;
}

.admin-main {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 20px calc(16px + var(--safe-right)) calc(30px + var(--safe-bottom)) calc(16px + var(--safe-left));
  display: grid;
  gap: 16px;
}

.admin-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(20, 24, 33, 0.9);
}

.admin-card > label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-token-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.admin-token-row input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid #2c3444;
  border-radius: 11px;
  background: #0b0e14;
  color: #e9edf4;
  outline: none;
}

.admin-token-row input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.15);
}

.admin-token-row .primary {
  flex: 0 0 auto;
  min-height: 42px;
}

.admin-rooms-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-rooms-head h1 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}

.admin-rooms-head .secondary {
  min-height: 36px;
  padding: 7px 14px;
  font-size: 0.78rem;
}

.admin-count {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: #2a1416;
  color: #ff9a9e;
  font-size: 0.72rem;
  font-weight: 700;
}

.admin-status {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.admin-status.error {
  color: #ff8b8f;
}

.admin-empty {
  margin: 18px 0 2px;
  padding: 22px;
  border: 1px dashed #2c3444;
  border-radius: 13px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.room-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.room-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid #242b39;
  border-radius: 13px;
  background: #0e1118;
}

.room-row-code {
  min-width: 108px;
  color: #fff;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.room-row-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 0.74rem;
}

.room-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.room-state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.room-state.free {
  color: var(--green);
}

.room-state.busy {
  color: #f5b544;
}

.admin-watch {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 16px;
  border: 1px solid #30394b;
  border-radius: 10px;
  background: var(--surface-2);
  color: #e9edf4;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
}

.admin-watch:hover {
  border-color: #46536b;
  background: #242c3b;
}

@media (max-width: 520px) {
  .room-row {
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .room-row-code {
    min-width: 0;
    flex: 1 1 auto;
  }

  .room-row-meta {
    order: 3;
    flex-basis: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
