: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: "Fraunces", Georgia, serif;
  --font-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

html, body {
  min-height: 100%;
  min-height: 100dvh;
}

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

.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 { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(12deg); }
}

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

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

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

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

.brand {
  font-family: var(--font-display);
  font-size: clamp(2.8rem, 12vw, 3.6rem);
  font-weight: 700;
  line-height: 0.95;
  color: var(--foam);
  letter-spacing: -0.02em;
  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: clamp(1.35rem, 5.5vw, 1.7rem);
  font-weight: 600;
  line-height: 1.25;
  color: var(--mist);
  max-width: 18ch;
}

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

.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.04em;
  text-transform: uppercase;
  color: rgba(243, 250, 248, 0.7);
}

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

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

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

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

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

.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.06em;
  text-transform: uppercase;
  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 .meta {
  font-size: 0.85rem;
  color: rgba(243, 250, 248, 0.65);
}

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

.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;
  gap: 0.5rem;
  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: 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: 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: 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: 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: clamp(2.8rem, 14vmin, 7rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--foam);
  text-align: center;
  max-width: 92vw;
  overflow-wrap: anywhere;
  text-shadow: 0 12px 40px var(--shadow);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  /* Default: readable for the person sitting across the table */
  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: clamp(2.4rem, 11vh, 5.5rem);
    max-width: 85vh;
    transform: rotate(90deg) scale(1.05);
  }
  .nameboard.is-flipped-across .nameboard-text,
  .nameboard:not(.is-unflipped) .nameboard-text {
    transform: rotate(270deg) scale(1.05);
  }
  .nameboard.is-unflipped .nameboard-text {
    transform: rotate(90deg) scale(1.05);
  }
}

@media (orientation: landscape) {
  .nameboard-text {
    font-size: clamp(3rem, 16vmin, 7.5rem);
    max-width: 90vw;
  }
}

.chrome-toggle {
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 8;
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  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;
  padding: 1rem 1.1rem max(1.2rem, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(15, 51, 64, 0.2), rgba(15, 51, 64, 0.94) 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-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.12em;
  text-transform: uppercase;
  color: rgba(243, 250, 248, 0.7);
}

.countdown-num {
  font-family: var(--font-display);
  font-size: clamp(5rem, 28vw, 9rem);
  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 {
  padding-top: 12vh;
}

#screen-over {
  padding-top: 14vh;
}

@media (max-width: 380px) {
  .headline { max-width: 16ch; }
}
