:root {
  color-scheme: dark;
  --bg: #0e151e;
  --bg-2: #121b27;
  --s1: #151f2b;
  --s2: #1a2633;
  --s3: #213040;
  --ivory: #f3ece0;
  --text-2: #c4c9d0;
  --text-3: #8f99a6;
  --gold: #d6ac5c;
  --gold-hi: #f6e3ae;
  --gold-lo: #8e6621;
  --line-1: rgba(226, 214, 190, 0.1);
  --line-2: rgba(226, 214, 190, 0.2);
  --gold-line: rgba(214, 172, 92, 0.42);
  --ok: #79c48b;
  --warn: #e3a94f;
  --bad: #e2725f;
  --radius: 4px;
  --sans: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ivory);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.ic {
  width: 19px;
  height: 19px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic--sm { width: 16px; height: 16px; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 17, 25, 0.94);
  border-bottom: 1px solid var(--line-1);
  backdrop-filter: blur(12px);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar__inner {
  max-width: 1120px;
  margin: 0 auto;
  min-height: 64px;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.brand img {
  height: 36px;
  width: auto;
  display: block;
}
.brand__tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 3px 8px;
  border: 1px solid var(--gold-line);
  border-radius: 99px;
  color: var(--gold-hi);
  background: rgba(214, 172, 92, 0.12);
}
.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar__link {
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--text-2);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.topbar__link:hover { border-color: var(--gold); color: var(--gold-hi); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); border-color: var(--line-2); color: var(--gold-hi); }
html.theme-light .theme-icon--sun,
body.theme-light .theme-icon--sun { display: none; }
html:not(.theme-light) body:not(.theme-light) .theme-icon--moon { display: none; }

.lang-box { position: relative; }
.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.lang-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--gold-hi); }
.lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 170px;
  padding: 5px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--s2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.lang-menu button {
  border: 0;
  border-radius: 4px;
  background: transparent;
  padding: 8px 10px;
  text-align: left;
  font-size: 13px;
  color: var(--text-2);
}
.lang-menu button:hover,
.lang-menu button[aria-checked="true"] { background: rgba(214, 172, 92, 0.14); color: var(--gold-hi); }

/* Lobby */
.main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 20px calc(48px + env(safe-area-inset-bottom, 0px));
}
.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 44px;
  align-items: start;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.story__title {
  margin: 0;
  font: 600 clamp(28px, 4vw, 44px)/1.14 var(--serif);
}
.story__rule {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 240px;
  margin: 18px 0 20px;
}
.story__rule span { flex: 1; height: 1px; background: var(--gold-line); }
.story__rule i { width: 8px; height: 8px; border: 1px solid var(--gold); transform: rotate(45deg); }
.story__lead {
  margin: 0 0 22px;
  color: var(--text-2);
  font-size: 15px;
}
.info-card {
  padding: 16px 18px;
  border: 1px solid var(--line-1);
  border-left: 2px solid var(--gold);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.025);
  margin-bottom: 18px;
}
.info-card h3 { margin: 0 0 6px; font-size: 13px; letter-spacing: 0.04em; color: var(--gold-hi); }
.info-card p { margin: 0; font-size: 13px; color: var(--text-2); line-height: 1.65; }
.pwa-tip { margin: 0; font-size: 12.5px; color: var(--text-3); line-height: 1.6; }

.card {
  padding: 28px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--s1);
  box-shadow: 0 20px 54px rgba(0, 0, 0, 0.35);
}
.card__title {
  margin: 0 0 10px;
  font: 600 26px/1.2 var(--serif);
}
.card__intro {
  margin: 0 0 22px;
  color: var(--text-2);
  font-size: 14px;
}
.notice {
  margin-bottom: 18px;
  padding: 11px 14px;
  border: 1px solid rgba(226, 114, 95, 0.45);
  border-left: 3px solid var(--bad);
  border-radius: var(--radius);
  background: rgba(226, 114, 95, 0.12);
  color: var(--ivory);
  font-size: 13.5px;
}

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field__label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field__input, .field__select {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ivory);
  font-size: 15px;
}
.field__input:focus, .field__select:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}
.field__input--code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 22px;
  letter-spacing: 0.16em;
  text-align: center;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--s3);
  color: var(--ivory);
  font-size: 14px;
  font-weight: 700;
  width: 100%;
  transition: filter 0.18s, background 0.18s, border-color 0.18s;
}
.btn:disabled { opacity: 0.48; cursor: not-allowed; }
.btn--gold {
  border-color: #d6ac5c;
  background: linear-gradient(180deg, #f6e3ae 0%, #d9b25f 44%, #8e6621 100%);
  color: #211707;
}
.btn--gold:hover:not(:disabled) { filter: brightness(1.06); }
.btn--secondary { background: var(--s2); }
.btn--secondary:hover:not(:disabled) { border-color: var(--gold); color: var(--gold-hi); }
.btn--quiet { background: transparent; border-color: transparent; color: var(--text-3); font-weight: 600; min-height: 38px; }
.btn--quiet:hover:not(:disabled) { color: var(--bad); }

.confirm-box {
  margin: 18px 0 22px;
  padding: 20px;
  text-align: center;
  border: 1px solid var(--gold-line);
  border-radius: var(--radius);
  background: rgba(214, 172, 92, 0.08);
}
.confirm-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--gold-hi);
}
.confirm-host { margin: 8px 0 4px; font-weight: 600; }
.confirm-wait { margin: 0; font-size: 13px; color: var(--text-2); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border: 1px solid var(--line-2);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 13px;
  margin-bottom: 10px;
}
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}
.status-pill--online .status-dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-pill--busy .status-dot { background: var(--warn); }
.window-meta { margin: 0 0 16px; font-size: 13px; color: var(--text-3); }

.preset-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
  margin: 16px 0 20px;
}
.card__actions { display: grid; gap: 10px; }
.privacy-note {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line-1);
  font-size: 12px;
  color: var(--text-3);
}

/* Light theme (matches MA / SUPPORT / SITE / Launcher) */
html.theme-light,
body.theme-light {
  color-scheme: light;
  --bg: #ece8de;
  --bg-2: #e5dfd2;
  --s1: #ffffff;
  --s2: #f8f6f0;
  --s3: #ebe5d8;
  --ivory: #18222f;
  --text-2: #394656;
  --text-3: #637182;
  --gold: #9b6f1e;
  --gold-hi: #75500e;
  --gold-lo: #6e4b0e;
  --line-1: rgba(24, 34, 47, 0.1);
  --line-2: rgba(24, 34, 47, 0.18);
  --gold-line: rgba(155, 111, 30, 0.38);
  --ok: #247a4d;
  --warn: #a86812;
  --bad: #c23b2a;
}
html.theme-light .topbar,
body.theme-light .topbar {
  background: rgba(252, 250, 246, 0.96);
  border-bottom-color: rgba(24, 34, 47, 0.14);
  box-shadow: 0 2px 12px rgba(24, 34, 47, 0.06);
}
html.theme-light .brand img,
body.theme-light .brand img {
  filter: drop-shadow(0 1px 1.5px rgba(24, 34, 47, 0.28));
}
html.theme-light .topbar__link,
body.theme-light .topbar__link {
  background: #f3efe6;
  color: #18222f;
}
html.theme-light .icon-btn:hover,
body.theme-light .icon-btn:hover,
html.theme-light .lang-btn:hover,
body.theme-light .lang-btn:hover {
  background: rgba(24, 34, 47, 0.06);
}
html.theme-light .lang-menu,
body.theme-light .lang-menu {
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(24, 34, 47, 0.16);
}
html.theme-light .card,
body.theme-light .card {
  box-shadow: 0 12px 36px rgba(24, 34, 47, 0.08);
}
html.theme-light .info-card,
body.theme-light .info-card {
  background: rgba(255, 255, 255, 0.78);
}
html.theme-light .field__input,
body.theme-light .field__input,
html.theme-light .field__select,
body.theme-light .field__select {
  background: #ffffff;
  color: #18222f;
}
html.theme-light .notice,
body.theme-light .notice {
  background: rgba(194, 59, 42, 0.09);
  color: #7c1c12;
}

/* Fullscreen Play Stage (always dark cinema canvas for game contrast) */
.play-stage {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000000;
  color: #f3ece0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#play-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000000;
  pointer-events: none;
}
#play-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.play-banner,
.play-minimized {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 20px;
  border-radius: 8px;
  background: rgba(10, 15, 22, 0.88);
  border: 1px solid rgba(214, 172, 92, 0.42);
  color: #f3ece0;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(460px, 88vw);
  text-align: center;
  font-size: 14px;
  pointer-events: none;
  z-index: 210;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(214, 172, 92, 0.3);
  border-top-color: #f6e3ae;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sound-cta {
  position: absolute;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 215;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid #d6ac5c;
  border-radius: 99px;
  background: rgba(14, 21, 30, 0.88);
  color: #f6e3ae;
  font-size: 13px;
  font-weight: 700;
  backdrop-filter: blur(8px);
}

.play-hud {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 220;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid rgba(226, 214, 190, 0.22);
  border-radius: 99px;
  background: rgba(10, 15, 22, 0.78);
  backdrop-filter: blur(10px);
  max-width: calc(100vw - 16px);
  overflow-x: auto;
}
.hud-controls { display: flex; align-items: center; gap: 5px; }
.play-hud.is-collapsed .hud-controls { display: none; }
.hud-btn, .hud-select {
  height: 30px;
  padding: 0 9px;
  border: 1px solid rgba(226, 214, 190, 0.2);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  color: #f3ece0;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.hud-btn:hover, .hud-btn.is-active {
  border-color: #d6ac5c;
  background: rgba(214, 172, 92, 0.2);
  color: #f6e3ae;
}
.hud-btn--danger { border-color: rgba(226, 114, 95, 0.45); color: #ffb3a6; }
.hud-btn--danger:hover { background: rgba(226, 114, 95, 0.28); border-color: #e2725f; color: #fff; }
.hud-select { background: rgba(16, 24, 34, 0.92); }
.hud-stats { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: #c4c9d0; }

.hotbar {
  position: absolute;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 215;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  max-width: min(680px, calc(100vw - 20px));
  padding: 6px;
  border: 1px solid rgba(226, 214, 190, 0.2);
  border-radius: 8px;
  background: rgba(10, 15, 22, 0.76);
  backdrop-filter: blur(8px);
}
.hotbar button {
  min-width: 42px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid rgba(214, 172, 92, 0.34);
  border-radius: 4px;
  background: rgba(26, 38, 51, 0.86);
  color: #f3ece0;
  font-size: 12px;
  font-weight: 700;
}
.hotbar button:active { background: rgba(214, 172, 92, 0.36); color: #fff; }

.chat-dialog {
  width: min(420px, calc(100vw - 28px));
  padding: 20px;
  border: 1px solid var(--gold-line);
  border-radius: 6px;
  background: #151f2b;
  color: #f3ece0;
}
.chat-dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
.chat-form { display: grid; gap: 14px; }
.chat-form h3 { margin: 0; font-size: 16px; }
.chat-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #c4c9d0; }
.chat-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 860px) {
  .lobby-grid { grid-template-columns: 1fr; gap: 24px; }
  .main { padding-top: 22px; }
  .card { padding: 20px; }
}
@media (max-width: 480px) {
  .preset-row { grid-template-columns: 1fr; }
  .topbar__link { display: none; }
}
