:root {
  --paper: #f7f8f5;
  --surface: #ffffff;
  --ink: #242521;
  --muted: #6c7068;
  --line: #d9ddd5;
  --line-strong: #bec5ba;
  --coral: #ed695a;
  --coral-dark: #c94b40;
  --coral-soft: #fbe4df;
  --teal: #168d7b;
  --teal-dark: #0c6d60;
  --teal-soft: #dcefeb;
  --yellow: #f2c84b;
  --yellow-soft: #fff2ba;
  --danger: #b84239;
  --shadow-sm: 0 2px 0 rgba(36, 37, 33, 0.08);
  --shadow-die: 0 8px 0 #d8dbd3, 0 12px 24px rgba(36, 37, 33, 0.12);
  --radius-sm: 4px;
  --radius-md: 8px;
  --header-height: 64px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  padding: calc(var(--header-height) + env(safe-area-inset-top)) 0 env(safe-area-inset-bottom);
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(var(--line), var(--line)) 0 calc(var(--header-height) + env(safe-area-inset-top)) / 100% 1px no-repeat,
    var(--paper);
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled),
[role="button"]:not([aria-disabled="true"]) {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(22, 141, 123, 0.28);
  outline-offset: 2px;
}

button:disabled,
button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.46;
  box-shadow: none;
}

[hidden] {
  display: none !important;
}

.app-header {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto;
  height: calc(var(--header-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(247, 248, 245, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  position: relative;
  width: 25px;
  height: 21px;
  flex: 0 0 auto;
}

.brand-mark span {
  position: absolute;
  top: 3px;
  width: 14px;
  height: 14px;
  border: 3px solid currentColor;
  border-radius: 50%;
  background: var(--paper);
}

.brand-mark span:first-child {
  left: 0;
  color: var(--coral);
}

.brand-mark span:last-child {
  right: 0;
  color: var(--teal);
}

.header-status {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.connection-status,
.room-badge,
.level-badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.connection-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 3px var(--yellow-soft);
}

.connection-status[data-state="online"] {
  color: var(--teal-dark);
  border-color: #acd4cc;
  background: var(--teal-soft);
}

.connection-status[data-state="online"] .connection-dot {
  background: var(--teal);
  box-shadow: 0 0 0 3px rgba(22, 141, 123, 0.14);
}

.connection-status[data-state="offline"] {
  color: var(--danger);
  border-color: #e9b8b2;
  background: var(--coral-soft);
}

.connection-status[data-state="offline"] .connection-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(184, 66, 57, 0.12);
}

.room-badge {
  max-width: 104px;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
}

.app-main {
  width: min(100%, 560px);
  min-height: calc(100vh - var(--header-height) - env(safe-area-inset-top));
  min-height: calc(100svh - var(--header-height) - env(safe-area-inset-top));
  margin: 0 auto;
  padding: 24px max(18px, env(safe-area-inset-right)) 32px max(18px, env(safe-area-inset-left));
}

.screen {
  width: 100%;
  animation: screen-enter 260ms ease-out both;
}

.screen h1 {
  max-width: 100%;
  margin: 0;
  font-size: 30px;
  font-weight: 850;
  line-height: 1.18;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
}

.lead {
  max-width: 26em;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.intro-layout {
  min-height: 176px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  align-items: center;
  gap: 10px;
  padding: 4px 0 20px;
}

.intro-copy {
  min-width: 0;
}

.scene-art {
  display: block;
  width: min(100%, 280px);
  height: auto;
}

.scene-art-home {
  width: 132px;
  justify-self: end;
}

.entry-flow {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.segmented-control {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #ecefe9;
}

.segment {
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
}

.segment.is-active,
.segment[aria-selected="true"] {
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.field-group {
  margin-top: 18px;
}

.field-group label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.field-group input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--surface);
  font-size: 16px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field-group input::placeholder {
  color: #979b93;
}

.field-group input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(22, 141, 123, 0.12);
}

.room-code-input {
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

.entry-panel {
  margin-top: 18px;
}

.button,
.icon-text-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  transition: transform 120ms ease, background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.button svg,
.button [data-lucide],
.icon-text-button svg,
.icon-text-button [data-lucide] {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  stroke-width: 2.2;
}

.button-block {
  width: 100%;
}

.button-primary {
  color: #ffffff;
  background: var(--teal);
  box-shadow: 0 3px 0 var(--teal-dark);
}

.button-primary:hover:not(:disabled) {
  background: #117e6e;
}

.button-coral {
  color: #ffffff;
  background: var(--coral);
  box-shadow: 0 3px 0 var(--coral-dark);
}

.button-coral:hover:not(:disabled) {
  background: #df5b4e;
}

.button-secondary {
  min-height: 44px;
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--surface);
}

.button:active:not(:disabled),
.icon-text-button:active:not(:disabled),
.level-option:active:not(:disabled),
.question-card:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.screen-waiting,
.screen-message {
  text-align: center;
}

.waiting-visual {
  width: 170px;
  margin: 0 auto 6px;
}

.room-code-block {
  margin: 24px 0 0;
  padding: 20px 0;
  border-block: 1px solid var(--line);
}

.room-code-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.room-code {
  display: block;
  margin: 5px 0 15px;
  color: var(--ink);
  font-size: 38px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  letter-spacing: 0;
}

.room-code-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.room-code-actions .button {
  min-width: 104px;
}

.waiting-details {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  text-align: left;
}

.qr-frame {
  width: 112px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.qr-frame canvas,
.qr-frame img,
.qr-frame svg {
  display: block;
  width: 96px;
  height: 96px;
}

.qr-frame > [data-lucide] {
  width: 48px;
  height: 48px;
  color: var(--line-strong);
  stroke-width: 1.5;
}

.waiting-copy {
  min-width: 0;
}

.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.player-chip {
  min-height: 29px;
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.player-chip.is-ready {
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.player-chip.is-pending {
  color: #7a6414;
  background: var(--yellow-soft);
}

.status-copy {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.status-copy.centered {
  text-align: center;
}

.level-options {
  margin-top: 24px;
  display: grid;
  gap: 10px;
}

.level-option {
  width: 100%;
  min-height: 82px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.level-option:hover,
.level-option[aria-checked="true"] {
  border-color: var(--teal);
  background: #f3fbf8;
}

.level-option[aria-checked="true"] {
  box-shadow: inset 4px 0 0 var(--teal);
}

.level-number {
  color: var(--coral-dark);
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.level-copy {
  min-width: 0;
}

.level-copy strong,
.level-copy small {
  display: block;
  overflow-wrap: anywhere;
}

.level-copy strong {
  font-size: 16px;
  line-height: 1.35;
}

.level-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.level-option > svg,
.level-option > [data-lucide] {
  width: 19px;
  height: 19px;
  color: var(--muted);
}

.round-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.level-badge {
  flex: 0 0 auto;
  margin-top: 2px;
  color: var(--teal-dark);
  border-color: #b9d9d2;
  background: var(--teal-soft);
}

.dice-stage {
  margin-top: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 26px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.player-panel {
  min-width: 0;
  min-height: 272px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.player-panel[data-result="winner"],
.player-panel.is-winner {
  border-color: var(--teal);
  box-shadow: inset 0 4px 0 var(--teal);
  background: #f3fbf8;
}

.player-panel[data-result="loser"],
.player-panel.is-loser {
  opacity: 0.7;
}

.player-panel-heading {
  width: 100%;
  min-height: 51px;
  text-align: center;
}

.player-panel-heading h2 {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-state {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.die {
  --die-size: clamp(84px, 25vw, 108px);
  width: var(--die-size);
  height: var(--die-size);
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  margin: 10px auto 26px;
  padding: 13px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-die);
}

.die.is-muted,
.player-panel[data-player-state="waiting"] .die {
  border-color: var(--line-strong);
  box-shadow: 0 8px 0 #e2e5df;
}

.pip {
  width: clamp(10px, 3.4vw, 14px);
  aspect-ratio: 1;
  border-radius: 50%;
  visibility: hidden;
  background: var(--ink);
}

.die[data-value="1"] .pip:nth-child(5),
.die[data-value="2"] .pip:nth-child(1),
.die[data-value="2"] .pip:nth-child(9),
.die[data-value="3"] .pip:nth-child(1),
.die[data-value="3"] .pip:nth-child(5),
.die[data-value="3"] .pip:nth-child(9),
.die[data-value="4"] .pip:nth-child(1),
.die[data-value="4"] .pip:nth-child(3),
.die[data-value="4"] .pip:nth-child(7),
.die[data-value="4"] .pip:nth-child(9),
.die[data-value="5"] .pip:nth-child(1),
.die[data-value="5"] .pip:nth-child(3),
.die[data-value="5"] .pip:nth-child(5),
.die[data-value="5"] .pip:nth-child(7),
.die[data-value="5"] .pip:nth-child(9),
.die[data-value="6"] .pip:nth-child(1),
.die[data-value="6"] .pip:nth-child(3),
.die[data-value="6"] .pip:nth-child(4),
.die[data-value="6"] .pip:nth-child(6),
.die[data-value="6"] .pip:nth-child(7),
.die[data-value="6"] .pip:nth-child(9) {
  visibility: visible;
}

.die[data-value="rolling"] .pip {
  visibility: visible;
  animation: pip-pulse 520ms ease-in-out infinite alternate;
}

.die[data-value="rolling"] .pip:nth-child(2n) {
  animation-delay: 120ms;
}

.player-panel .button {
  min-height: 44px;
  padding-inline: 10px;
  font-size: 14px;
}

.opponent-placeholder {
  width: 100%;
  min-height: 44px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 700;
}

.versus {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #705e15;
  background: var(--yellow);
  font-size: 9px;
  font-weight: 900;
}

.outcome-banner {
  width: 100%;
  min-height: 66px;
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #abd5cc;
  border-radius: var(--radius-md);
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.outcome-banner[data-result="loser"] {
  color: var(--coral-dark);
  border-color: #efbcb5;
  background: var(--coral-soft);
}

.outcome-banner[data-result="tie"] {
  color: #705e15;
  border-color: #e0c866;
  background: var(--yellow-soft);
}

.outcome-banner > svg,
.outcome-banner > [data-lucide] {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.outcome-banner strong,
.outcome-banner span {
  display: block;
}

.outcome-banner strong {
  font-size: 14px;
}

.outcome-banner span {
  margin-top: 2px;
  font-size: 12px;
}

.icon-text-button {
  min-height: 44px;
  flex: 0 0 auto;
  padding: 9px 10px;
  border-color: var(--line-strong);
  background: transparent;
  font-size: 13px;
}

.icon-text-button:hover:not(:disabled) {
  border-color: var(--teal);
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.question-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.question-grid:empty {
  min-height: 220px;
  place-items: center;
}

.question-grid:empty::after {
  content: "正在取题…";
  color: var(--muted);
  font-size: 14px;
}

.question-card {
  position: relative;
  width: 100%;
  min-height: 112px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  column-gap: 10px;
  align-items: start;
  padding: 15px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.question-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  content: "";
  background: var(--coral);
}

.question-card:nth-child(even)::before {
  background: var(--teal);
}

.question-card:hover,
.question-card[aria-pressed="true"],
.question-card.is-selected {
  border-color: var(--teal);
  background: #f5fbf9;
}

.question-index {
  grid-row: 1 / span 2;
  color: var(--coral-dark);
  font-size: 13px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.question-tag,
.selected-tag {
  width: fit-content;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--teal-dark);
  background: var(--teal-soft);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.question-card strong {
  align-self: center;
  margin-top: 8px;
  font-size: 16px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.selected-question-wrap {
  margin-top: 28px;
  padding: 24px 0;
  border-block: 1px solid var(--line);
  text-align: center;
}

.selected-tag {
  color: #735f12;
  background: var(--yellow-soft);
}

.selected-question-wrap blockquote {
  max-width: 16em;
  margin: 16px auto 0;
  font-size: 25px;
  font-weight: 850;
  line-height: 1.45;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.conversation-pause {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.conversation-pause span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--coral);
  animation: listening 1.4s ease-in-out infinite;
}

.conversation-pause span:nth-child(2) {
  background: var(--yellow);
  animation-delay: 160ms;
}

.conversation-pause span:nth-child(3) {
  background: var(--teal);
  animation-delay: 320ms;
}

.screen-answering .button {
  margin-top: 18px;
}

.message-symbol {
  width: 64px;
  height: 64px;
  margin: 34px auto 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--coral-dark);
  background: var(--coral-soft);
}

.message-symbol svg,
.message-symbol [data-lucide] {
  width: 31px;
  height: 31px;
}

.message-text {
  max-width: 26em;
  margin: 12px auto 24px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.screen-message .button {
  max-width: 360px;
  margin-inline: auto;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100vw - 36px);
  min-height: 42px;
  padding: 11px 15px;
  transform: translateX(-50%);
  border-radius: var(--radius-md);
  color: #ffffff;
  background: var(--ink);
  box-shadow: 0 8px 24px rgba(36, 37, 33, 0.2);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
  text-align: center;
}

body.is-offline .requires-connection {
  opacity: 0.46;
  pointer-events: none;
}

@media (min-width: 480px) {
  .app-main {
    padding-inline: 24px;
  }

  .intro-layout {
    grid-template-columns: minmax(0, 1fr) 170px;
  }

  .scene-art-home {
    width: 164px;
  }

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

@media (max-width: 359px) {
  .app-header {
    padding-inline: max(12px, env(safe-area-inset-left));
  }

  .brand {
    gap: 6px;
    font-size: 14px;
  }

  .connection-status {
    padding-inline: 7px;
  }

  .room-badge {
    display: none;
  }

  .app-main {
    padding-inline: 14px;
  }

  .screen h1 {
    font-size: 27px;
  }

  .intro-layout {
    grid-template-columns: minmax(0, 1fr) 104px;
  }

  .scene-art-home {
    width: 104px;
  }

  .dice-stage {
    grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr);
    gap: 5px;
  }

  .player-panel {
    padding-inline: 7px;
  }

  .die {
    --die-size: 76px;
    padding: 10px;
  }

  .player-panel .button {
    font-size: 12px;
  }
}

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

@keyframes screen-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pip-pulse {
  from {
    transform: scale(0.72);
    opacity: 0.38;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes listening {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-7px);
  }
}
