:root {
  --ink: #16343d;
  --foam: #f3faf8;
  --mist: #d7ebe6;
  --sea: #1c4d5e;
  --sea-deep: #0f3340;
  --sun: #e8a54b;
  --sun-deep: #c9842e;
  --coral: #d96a58;
  --ok: #2f8f6b;
  --shadow: rgba(15, 51, 64, 0.28);
  --font-display: "Songti SC", "STSong", "Noto Serif CJK SC", Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--sea-deep);
  -webkit-font-smoothing: antialiased;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 90% 60% at 10% -10%, rgba(232, 165, 75, 0.35), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 20%, rgba(88, 180, 170, 0.28), transparent 50%),
    linear-gradient(165deg, #246578 0%, #1c4d5e 42%, #123844 100%);
  animation: drift 18s ease-in-out infinite alternate;
  will-change: transform;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  opacity: 0.07;
  pointer-events: none;
}

@keyframes drift {
  from { transform: scale(1) translate3d(0, 0, 0); }
  to { transform: scale(1.03) translate3d(-0.4%, 0.4%, 0); }
}

#app {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.25rem 1rem 1.5rem;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-left)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-right));
}

.screen {
  display: none;
  animation: rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.screen.is-active { display: block; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

.brand {
  font-family: var(--font-display);
  font-size: 3.2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--foam);
  letter-spacing: 0;
  text-shadow: 0 10px 30px var(--shadow);
}

.brand-sm {
  font-size: 1.35rem;
  text-shadow: none;
}

.headline {
  margin-top: 1rem;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--mist);
  max-width: 20ch;
  letter-spacing: 0;
}

.lede {
  margin-top: 0.7rem;
  color: rgba(243, 250, 248, 0.78);
  line-height: 1.5;
  max-width: 34ch;
  font-size: 1rem;
}

.headline,
.lede,
.block-copy,
.reset-banner,
.guess-feed {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stack {
  display: grid;
  gap: 0.85rem;
  margin-top: 1.6rem;
}

label {
  display: grid;
  gap: 0.35rem;
}

label span {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0;
  color: rgba(243, 250, 248, 0.7);
}

input {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 6px;
  padding: 0.9rem 1rem;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: rgba(243, 250, 248, 0.96);
  outline: 2px solid transparent;
  transition: outline-color 0.15s ease, transform 0.15s ease;
}

input:focus {
  outline-color: var(--sun);
}

.btn {
  appearance: none;
  min-height: 48px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  border-radius: 6px;
  padding: 0.9rem 1.2rem;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn:focus-visible,
.chrome-toggle:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 3px;
}

.btn-primary {
  background: var(--sun);
  color: #2a1a05;
  box-shadow: 0 12px 28px rgba(232, 165, 75, 0.28);
}

.btn-primary:hover:not(:disabled) { background: #f0b45d; }

.btn-ghost {
  background: transparent;
  color: var(--foam);
  outline: 1.5px solid rgba(243, 250, 248, 0.4);
}

.btn-ghost:hover { background: rgba(243, 250, 248, 0.08); }

.error {
  color: #ffd0c8;
  font-size: 0.92rem;
  line-height: 1.4;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.topbar > div,
.room-tag {
  min-width: 0;
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  min-width: 0;
}

.topbar-actions .btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

.room-tag {
  margin-top: 0.2rem;
  color: rgba(243, 250, 248, 0.72);
  font-size: 0.95rem;
}

.room-tag strong {
  color: var(--foam);
  letter-spacing: 0.08em;
}

.phase-tag {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--sea-deep);
  background: var(--sun);
  padding: 0.4rem 0.65rem;
  border-radius: 4px;
  white-space: nowrap;
}

.player-list {
  list-style: none;
  display: grid;
  gap: 0.55rem;
  margin-bottom: 1.25rem;
}

.player-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(243, 250, 248, 0.14);
  color: var(--foam);
  animation: rise 0.4s ease both;
}

.player-list li > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.player-list .meta {
  flex: none;
  font-size: 0.85rem;
  text-align: right;
  color: rgba(243, 250, 248, 0.65);
}

.player-list .meta.is-ready { color: #9be7c4; }
.player-list .meta.is-away { color: #ffd0c8; }

.block {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
}

.block-title {
  font-family: var(--font-display);
  font-size: 1.45rem;
  color: var(--foam);
  margin-bottom: 0.35rem;
}

.block-copy {
  color: rgba(243, 250, 248, 0.75);
  line-height: 1.45;
  margin-bottom: 1rem;
}

.names-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.55rem;
  margin-bottom: 0.9rem;
}

.names-grid input {
  padding: 0.75rem 0.85rem;
  font-size: 0.98rem;
}

.ok-note {
  margin-top: 0.85rem;
  color: #9be7c4;
  font-weight: 600;
}

.reset-banner {
  margin: 0 0 0.9rem;
  padding: 0.75rem 0;
  color: var(--sun);
  font-weight: 600;
  line-height: 1.4;
  border-top: 1px solid rgba(232, 165, 75, 0.35);
  border-bottom: 1px solid rgba(232, 165, 75, 0.35);
}

.play-actions {
  margin-top: 1.4rem;
  padding-top: 0.9rem;
  border-top: 1px solid rgba(243, 250, 248, 0.14);
}

/* —— Fullscreen landscape game mode (countdown + play) —— */
body.is-game-mode {
  overflow: hidden;
}

body.is-game-mode .atmosphere {
  opacity: 0.85;
}

body.is-game-mode #app {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
}

body.is-game-mode #screen-countdown.is-active {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 1.25rem;
  padding: max(1rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  animation: none;
}

body.is-game-mode .countdown-label {
  margin-top: 0;
}

body.is-game-mode .countdown-num {
  font-size: clamp(5rem, 28vmin, 9rem);
}

body.is-playing {
  overflow: hidden;
}

body.is-playing .atmosphere {
  opacity: 0.85;
}

body.is-playing #app {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
}

.play-screen.is-active {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: block;
  animation: none;
}

.nameboard {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem 1.25rem;
  padding: max(1rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(232, 165, 75, 0.18), transparent 60%),
    linear-gradient(120deg, #1a5a6c 0%, #0f3340 55%, #16343d 100%);
}

.nameboard-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 4rem;
  line-height: 1.08;
  letter-spacing: 0;
  color: var(--foam);
  text-align: center;
  max-width: 92vw;
  max-height: 80vh;
  max-height: 80dvh;
  overflow-wrap: anywhere;
  text-shadow: 0 12px 40px var(--shadow);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  transform: rotate(180deg);
}

.nameboard.is-unflipped .nameboard-text {
  transform: none;
}

/* Force a landscape reading plane even if the phone is still portrait */
@media (orientation: portrait) {
  .nameboard-text {
    font-size: 3.6rem;
    max-width: 82dvh;
    transform: rotate(90deg);
  }
  .nameboard.is-flipped-across .nameboard-text,
  .nameboard:not(.is-unflipped) .nameboard-text {
    transform: rotate(270deg);
  }
  .nameboard.is-unflipped .nameboard-text {
    transform: rotate(90deg);
  }
}

@media (orientation: landscape) {
  .nameboard-text {
    font-size: 5.5rem;
    max-width: 90vw;
  }
}

.chrome-toggle {
  position: fixed;
  right: 0.75rem;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: 0.75rem;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 8;
  border: none;
  border-radius: 999px;
  min-width: 48px;
  min-height: 48px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--sea-deep);
  background: rgba(243, 250, 248, 0.92);
  box-shadow: 0 8px 24px var(--shadow);
  cursor: pointer;
}

.play-chrome {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  max-height: min(72vh, 560px);
  max-height: min(72dvh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 1.1rem 4.75rem;
  padding: 1rem 1.1rem max(4.75rem, calc(env(safe-area-inset-bottom) + 4rem));
  background: linear-gradient(180deg, rgba(15, 51, 64, 0.2), rgba(15, 51, 64, 0.96) 28%);
  animation: rise 0.35s ease both;
}

.chrome-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}

.chrome-row .phase-tag {
  min-width: 0;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chrome-copy {
  margin-bottom: 0.65rem;
  font-size: 0.92rem;
}

.guess-feed {
  margin: 0.35rem 0 0.75rem;
  color: rgba(243, 250, 248, 0.85);
  font-size: 0.95rem;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.75rem;
}

.countdown-label {
  margin-top: 18vh;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0;
  color: rgba(243, 250, 248, 0.7);
}

.countdown-num {
  font-family: var(--font-display);
  font-size: 7rem;
  line-height: 1;
  color: var(--sun);
  text-shadow: 0 12px 40px var(--shadow);
  animation: countPulse 1s ease-in-out infinite;
}

@keyframes countPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.9; }
}

#screen-join {
  width: min(520px, 100%);
  margin: 0 auto;
  padding-top: max(3rem, 10vh);
}

#screen-over {
  width: min(560px, 100%);
  margin: 0 auto;
  padding-top: max(2rem, 8vh);
  padding-bottom: 2rem;
}

@media (min-width: 620px) {
  .names-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand { font-size: 3.6rem; }
  .headline { font-size: 1.75rem; }
  .cta-row .btn { flex: 1 1 180px; }
}

@media (max-width: 420px) {
  .brand { font-size: 2.7rem; }
  .headline { font-size: 1.45rem; max-width: 18ch; }
  .lede { font-size: 0.95rem; }
  .topbar, .chrome-row { gap: 0.5rem; }
  .chrome-row { flex-wrap: wrap; }
  .turn-countdown { margin-left: 0; }
  .cta-row { display: grid; grid-template-columns: minmax(0, 1fr); }
  .cta-row .btn { width: 100%; }
  .nameboard-text { font-size: 3.2rem; }
  .play-chrome { padding-inline: 0.85rem; }
}

@media (min-width: 900px) and (orientation: landscape) {
  .nameboard-text { font-size: 6.5rem; }
  .play-chrome {
    left: 50%;
    right: auto;
    bottom: 1rem;
    width: min(760px, calc(100% - 2rem));
    border-radius: 8px;
    transform: translateX(-50%);
  }
}

@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;
  }
}

/* —— 新增：回合倒计时、结束揭晓、断线提示 —— */
.turn-countdown {
  flex: none;
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--sun);
  white-space: nowrap;
}

.reveal-list {
  list-style: none;
  display: grid;
  gap: 0.5rem;
  margin: 1.1rem 0 0.4rem;
}

.reveal-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border-radius: 6px;
  background: rgba(243, 250, 248, 0.08);
  color: var(--foam);
}

.reveal-list li strong {
  flex: none;
  max-width: 55%;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--sun);
  overflow-wrap: anywhere;
}

.reveal-list li span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.reveal-list li.is-winner {
  outline: 1.5px solid var(--sun);
  background: rgba(232, 165, 75, 0.12);
}

.disconnect-banner {
  position: fixed;
  top: 0.6rem;
  top: max(0.6rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  background: rgba(217, 106, 88, 0.95);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  max-width: 90vw;
  text-align: center;
}

@media (max-width: 420px) {
  .turn-countdown { margin-left: 0; }
}

/* ===== E1 主题词库选择器 ===== */
.theme-block {
  margin-top: 0.4rem;
}

.theme-block-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.theme-hint {
  font-size: 0.78rem;
  font-weight: 500;
  color: rgba(243, 250, 248, 0.6);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-top: 0.7rem;
}

.theme-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0.1rem 0.5rem;
  padding: 0.6rem 0.7rem;
  border: 1.5px solid rgba(243, 250, 248, 0.22);
  border-radius: 8px;
  background: rgba(243, 250, 248, 0.06);
  color: var(--foam);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.theme-card:disabled {
  cursor: default;
  opacity: 0.82;
}

.theme-card .theme-icon {
  grid-row: 1 / 3;
  font-size: 1.4rem;
}

.theme-card .theme-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.theme-card .theme-meta {
  font-size: 0.75rem;
  color: rgba(243, 250, 248, 0.6);
}

.theme-card.is-selected {
  border-color: var(--sun);
  background: rgba(232, 165, 75, 0.16);
}

.theme-card.is-selected .theme-meta {
  color: rgba(255, 236, 200, 0.85);
}

@media (min-width: 520px) {
  .theme-grid { grid-template-columns: repeat(3, 1fr); }
}
