:root {
  color-scheme: dark;
  --bg: #080d18;
  --panel: rgba(17, 25, 42, 0.82);
  --panel-strong: rgba(22, 32, 52, 0.96);
  --line: rgba(166, 187, 222, 0.16);
  --muted: #93a4bf;
  --text: #f6f3e9;
  --gold: #e6bd69;
  --gold-bright: #f5d895;
  --blue: #72a7ff;
  --green: #52d6a0;
  --red: #f06c78;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 0%, rgba(54, 91, 150, 0.22), transparent 34rem),
    radial-gradient(circle at 88% 24%, rgba(122, 69, 113, 0.16), transparent 28rem),
    linear-gradient(160deg, #0d1423 0%, #080d18 56%, #0d111c 100%);
  color: var(--text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.ambient {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(1px);
  opacity: 0.45;
  pointer-events: none;
}

.ambient-one {
  top: 22vh;
  left: -13rem;
  width: 28rem;
  height: 28rem;
  border: 1px solid rgba(230, 189, 105, 0.18);
  box-shadow: inset 0 0 80px rgba(230, 189, 105, 0.06);
}

.ambient-two {
  right: -8rem;
  bottom: -10rem;
  width: 30rem;
  height: 30rem;
  background: rgba(36, 69, 119, 0.08);
}

.site-header {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(230, 189, 105, 0.58);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: Georgia, serif;
  font-size: 23px;
  box-shadow: inset 0 0 20px rgba(230, 189, 105, 0.1);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: Georgia, serif;
  letter-spacing: 0.22em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.connection-pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 12, 22, 0.55);
  color: var(--muted);
  font-size: 13px;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #657187;
}

.connection-pill[data-state="connecting"] .connection-dot {
  background: var(--gold);
  box-shadow: 0 0 12px rgba(230, 189, 105, 0.8);
}

.connection-pill[data-state="online"] {
  color: #bdf5dc;
}

.connection-pill[data-state="online"] .connection-dot {
  background: var(--green);
  box-shadow: 0 0 12px rgba(82, 214, 160, 0.8);
}

.connection-pill[data-state="error"] {
  color: #ffc2c8;
}

.connection-pill[data-state="error"] .connection-dot {
  background: var(--red);
}

.shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 50px 0 80px;
}

.screen-lobby {
  min-height: calc(100vh - 180px);
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.72fr);
  gap: clamp(40px, 8vw, 110px);
  align-items: center;
}

.hero-copy {
  max-width: 690px;
}

.eyebrow {
  display: block;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero-copy h1,
.room-topbar h1,
.game-topbar h1 {
  margin: 14px 0 18px;
  font-family: Georgia, "Times New Roman", "Microsoft JhengHei", serif;
  font-weight: 500;
  line-height: 1.1;
}

.hero-copy h1 {
  font-size: clamp(42px, 6.2vw, 78px);
}

.hero-copy h1 span {
  color: var(--gold-bright);
}

.hero-copy > p {
  max-width: 630px;
  margin: 0;
  color: #aab7cc;
  font-size: clamp(16px, 2vw, 19px);
  line-height: 1.9;
}

.feature-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 30px;
}

.feature-row span {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #c1cbe0;
  font-size: 13px;
}

.glass-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.lobby-card {
  padding: clamp(24px, 4vw, 36px);
}

.card-heading {
  display: flex;
  gap: 15px;
  align-items: flex-start;
  margin-bottom: 28px;
}

.card-heading.compact {
  margin-bottom: 22px;
}

.card-heading h2,
.section-title-row h2 {
  margin: 0;
  font-size: 20px;
}

.card-heading p,
.section-title-row p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.step-number {
  flex: 0 0 auto;
  color: var(--gold);
  font-family: Georgia, serif;
  font-size: 14px;
}

.field-label {
  display: block;
  margin: 0 0 9px;
  color: #c8d2e5;
  font-size: 13px;
}

.text-field,
.room-input,
.invite-link-row input,
.chat-form input {
  width: 100%;
  border: 1px solid rgba(172, 192, 224, 0.2);
  outline: 0;
  background: rgba(4, 9, 18, 0.72);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.text-field:focus,
.room-input:focus,
.chat-form input:focus {
  border-color: rgba(230, 189, 105, 0.72);
  box-shadow: 0 0 0 3px rgba(230, 189, 105, 0.1);
}

.text-field {
  height: 52px;
  padding: 0 15px;
  border-radius: 12px;
}

.lobby-actions {
  margin-top: 24px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.chat-form button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 0.16s, filter 0.16s, border-color 0.16s;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover,
.chat-form button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.8);
  opacity: 0.48;
  transform: none;
}

.primary-button {
  min-height: 50px;
  padding: 0 18px;
  background: linear-gradient(135deg, #d7a84f, #f0d289);
  color: #201707;
}

.button-icon {
  margin-right: 7px;
  font-size: 20px;
  font-weight: 400;
}

.secondary-button {
  min-height: 46px;
  padding: 0 17px;
  border: 1px solid rgba(114, 167, 255, 0.35);
  background: rgba(50, 84, 139, 0.36);
  color: #dce9ff;
}

.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: #bdc9dc;
}

.divider {
  position: relative;
  margin: 22px 0;
  text-align: center;
  color: #69788f;
  font-size: 12px;
}

.divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--line);
}

.divider span {
  position: relative;
  padding: 0 12px;
  background: #111a2b;
}

.join-row,
.invite-link-row,
.share-actions,
.chat-form {
  display: flex;
  gap: 10px;
}

.room-input {
  height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.invite-hint,
.error-banner {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
}

.invite-hint {
  display: flex;
  justify-content: space-between;
  background: rgba(82, 214, 160, 0.09);
  color: #bcebd7;
}

.invite-hint span {
  color: var(--gold-bright);
  font-weight: 900;
  letter-spacing: 0.12em;
}

.error-banner {
  border: 1px solid rgba(240, 108, 120, 0.35);
  background: rgba(128, 38, 50, 0.23);
  color: #ffc1c7;
}

.room-topbar,
.game-topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 28px;
}

.room-topbar h1,
.game-topbar h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 5vw, 54px);
}

.room-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.78fr) minmax(340px, 1.22fr);
  gap: 18px;
  align-items: start;
}

.invite-card,
.players-card,
.chat-card,
.diagnostics-card,
.council-card,
.role-summary-card,
.score-card {
  padding: 24px;
}

.players-card {
  grid-row: span 2;
}

.section-title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.room-code-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid rgba(230, 189, 105, 0.22);
  border-radius: 13px;
  background: rgba(230, 189, 105, 0.06);
}

.room-code-block span {
  color: var(--muted);
  font-size: 13px;
}

.room-code-block strong {
  color: var(--gold-bright);
  font-family: Georgia, serif;
  font-size: 27px;
  letter-spacing: 0.18em;
}

.invite-link-row {
  margin-top: 12px;
}

.invite-link-row input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  color: #91a0b8;
  font-size: 12px;
}

.icon-button {
  padding: 0 15px;
  background: #263752;
}

.share-actions {
  margin-top: 12px;
}

.share-actions > * {
  flex: 1;
}

.qr-panel {
  margin-top: 18px;
  text-align: center;
}

#inviteQr {
  width: fit-content;
  margin: 0 auto;
  padding: 10px;
  border-radius: 12px;
  background: white;
}

#inviteQr img,
#inviteQr canvas {
  display: block;
}

.qr-panel p,
.host-note,
#roundHint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.minimum-badge {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.minimum-badge.ready {
  border-color: rgba(82, 214, 160, 0.32);
  color: #9de7c5;
}

.player-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.player-chip {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(3, 8, 17, 0.42);
}

.player-avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #334869, #1d2a41);
  color: var(--gold-bright);
  font-family: Georgia, serif;
  font-weight: 900;
}

.player-chip-copy {
  min-width: 0;
}

.player-chip strong,
.player-chip small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-chip strong {
  font-size: 14px;
}

.player-chip small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.full-width {
  width: 100%;
}

.chat-card {
  min-height: 310px;
}

.chat-messages {
  height: 190px;
  overflow-y: auto;
  padding-right: 5px;
}

.chat-message {
  width: fit-content;
  max-width: 88%;
  margin-bottom: 9px;
  padding: 9px 11px;
  border-radius: 12px 12px 12px 3px;
  background: rgba(50, 67, 95, 0.62);
  color: #e8edf7;
  font-size: 13px;
  line-height: 1.5;
}

.chat-message.mine {
  margin-left: auto;
  border-radius: 12px 12px 3px;
  background: rgba(75, 111, 166, 0.62);
}

.chat-message.system {
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  background: transparent;
  color: #8291a8;
  font-size: 11px;
  text-align: center;
}

.chat-message b {
  display: block;
  margin-bottom: 2px;
  color: var(--gold-bright);
  font-size: 11px;
}

.chat-form {
  margin-top: 12px;
}

.chat-form input {
  min-width: 0;
  height: 42px;
  padding: 0 13px;
  border-radius: 11px;
}

.chat-form button {
  padding: 0 16px;
  background: var(--gold);
  color: #201707;
}

.diagnostics-card {
  grid-column: 1 / -1;
}

.diagnostics-card summary {
  cursor: pointer;
  color: #aebbd0;
  font-size: 13px;
}

.diagnostic-log {
  max-height: 180px;
  overflow: auto;
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  color: #8798b1;
  font-family: Consolas, monospace;
  font-size: 11px;
  line-height: 1.7;
}

.diagnostic-entry.error {
  color: #ff9fa8;
}

.diagnostic-entry.success {
  color: #91e5bd;
}

.mission-track {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.mission-node {
  position: relative;
  min-height: 74px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(13, 21, 36, 0.76);
}

.mission-node.current {
  border-color: rgba(230, 189, 105, 0.52);
  box-shadow: inset 0 0 25px rgba(230, 189, 105, 0.06);
}

.mission-node.success {
  border-color: rgba(82, 214, 160, 0.45);
  background: rgba(31, 96, 73, 0.2);
}

.mission-node.fail {
  border-color: rgba(240, 108, 120, 0.45);
  background: rgba(112, 35, 45, 0.2);
}

.mission-node span,
.mission-node strong {
  display: block;
}

.mission-node span {
  color: var(--muted);
  font-size: 11px;
}

.mission-node strong {
  margin-top: 8px;
  font-family: Georgia, serif;
  font-size: 21px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
}

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

.council-player {
  position: relative;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(5, 10, 20, 0.48);
  cursor: default;
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
}

.council-player.selectable {
  cursor: pointer;
}

.council-player.selectable:hover {
  transform: translateY(-2px);
  border-color: rgba(230, 189, 105, 0.45);
}

.council-player.selected {
  border-color: var(--gold);
  background: rgba(142, 103, 37, 0.18);
}

.council-player.me::after {
  content: "你";
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(114, 167, 255, 0.16);
  color: #b9d3ff;
  font-size: 10px;
}

.council-player .player-avatar {
  width: 45px;
  height: 45px;
  margin-bottom: 12px;
}

.council-player strong,
.council-player small {
  display: block;
}

.council-player small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.leader-crown {
  color: var(--gold);
}

.game-action-panel {
  margin-top: 18px;
}

.action-note {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(4, 9, 18, 0.45);
  color: #aab8cc;
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
}

.vote-choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

.vote-button {
  min-height: 54px;
  border: 1px solid transparent;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 900;
}

.vote-button.success {
  border-color: rgba(82, 214, 160, 0.32);
  background: rgba(35, 115, 83, 0.35);
  color: #aff0d1;
}

.vote-button.fail {
  border-color: rgba(240, 108, 120, 0.32);
  background: rgba(125, 39, 50, 0.33);
  color: #ffc2c8;
}

.game-sidebar {
  display: grid;
  gap: 18px;
  align-content: start;
}

.role-summary-card {
  text-align: center;
}

.role-symbol,
.role-modal-symbol {
  display: grid;
  place-items: center;
  margin: 18px auto 13px;
  border: 1px solid rgba(230, 189, 105, 0.34);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: Georgia, serif;
}

.role-symbol {
  width: 72px;
  height: 72px;
  font-size: 33px;
}

.role-summary-card h2 {
  margin: 0;
}

.role-summary-card p {
  min-height: 56px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 18px;
}

.score-row div {
  text-align: center;
}

.score-row div + div {
  border-left: 1px solid var(--line);
}

.score-row strong,
.score-row span {
  display: block;
}

.score-row strong {
  color: var(--gold-bright);
  font-family: Georgia, serif;
  font-size: 36px;
}

.score-row span {
  color: var(--muted);
  font-size: 11px;
}

.modal-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 5, 11, 0.82);
  backdrop-filter: blur(10px);
}

.role-modal {
  position: relative;
  width: min(470px, 100%);
  padding: 35px;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 13px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
}

.role-modal-symbol {
  width: 88px;
  height: 88px;
  font-size: 40px;
}

.role-modal h2 {
  margin: 0 0 12px;
  font-family: Georgia, "Microsoft JhengHei", serif;
  font-size: 31px;
}

.role-modal > p {
  color: #aebbd0;
  line-height: 1.8;
}

.knowledge-box {
  margin: 20px 0;
  padding: 14px;
  border: 1px solid rgba(230, 189, 105, 0.22);
  border-radius: 13px;
  background: rgba(230, 189, 105, 0.06);
  color: #f0dba9;
  font-size: 13px;
  line-height: 1.7;
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(90vw, 460px);
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #172238;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.38);
  color: #e7edf8;
  font-size: 13px;
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .screen-lobby,
  .room-grid,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .screen-lobby {
    align-items: start;
    padding-top: 25px;
  }

  .hero-copy {
    max-width: none;
  }

  .players-card {
    grid-row: auto;
  }

  .diagnostics-card {
    grid-column: auto;
  }

  .game-sidebar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .site-header,
  .shell {
    width: min(100% - 24px, 1180px);
  }

  .site-header {
    padding: 15px 0;
  }

  .brand small {
    display: none;
  }

  .connection-pill {
    max-width: 145px;
    overflow: hidden;
    white-space: nowrap;
  }

  .shell {
    padding: 25px 0 55px;
  }

  .screen-lobby {
    gap: 30px;
    min-height: auto;
  }

  .hero-copy h1 {
    font-size: 43px;
  }

  .hero-copy > p {
    font-size: 15px;
    line-height: 1.75;
  }

  .lobby-card,
  .invite-card,
  .players-card,
  .chat-card,
  .diagnostics-card,
  .council-card,
  .role-summary-card,
  .score-card {
    padding: 19px;
    border-radius: 18px;
  }

  .join-row,
  .share-actions {
    flex-direction: column;
  }

  .room-topbar,
  .game-topbar {
    align-items: center;
  }

  .room-topbar h1,
  .game-topbar h1 {
    font-size: 31px;
  }

  .player-list,
  .council-grid {
    grid-template-columns: 1fr 1fr;
  }

  .game-sidebar {
    grid-template-columns: 1fr;
  }

  .mission-track {
    gap: 5px;
  }

  .mission-node {
    min-height: 62px;
    padding: 10px 7px;
  }

  .mission-node strong {
    font-size: 17px;
  }

  .role-modal {
    padding: 30px 22px 24px;
  }
}

@media (max-width: 390px) {
  .player-list,
  .council-grid {
    grid-template-columns: 1fr;
  }

  .feature-row {
    gap: 6px;
  }

  .feature-row span {
    font-size: 11px;
  }
}
