:root {
  color-scheme: light;
  --page: #f1ecdf;
  --surface: #f8f3e9;
  --paper: #fffdf7;
  --ink: #142a46;
  --muted: #667284;
  --line: #d9cfbd;
  --blue: #255fae;
  --blue-soft: #e5edf8;
  --gold: #b4893c;
  --gold-soft: #f3ead6;
  --terracotta: #b65f43;
  --terracotta-soft: #f4e5de;
  --shadow: rgba(25, 42, 64, 0.15);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 320px; width: 100%; height: 100%; min-height: 100%; margin: 0; overflow: hidden; background: var(--page); color: var(--ink); }
button { font: inherit; }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 48%, transparent); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

.app-shell {
  width: min(1800px, calc(100% - clamp(20px, 3vw, 56px)));
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  min-height: 0;
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    radial-gradient(circle at 10% 8%, color-mix(in srgb, var(--blue) 11%, transparent), transparent 28%),
    radial-gradient(circle at 92% 88%, color-mix(in srgb, var(--gold) 13%, transparent), transparent 28%),
    var(--surface);
  box-shadow: 0 24px 70px var(--shadow);
}

.game-header, .game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: clamp(12px, 2.2vh, 18px) clamp(18px, 2.25vw, 34px);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(12px);
}
.game-header { border-bottom: 1px solid var(--line); }
.game-footer { border-top: 1px solid var(--line); }
.brand, .session-summary { display: flex; align-items: center; gap: 14px; }
.brand > span:last-child, .game-footer > div { display: grid; gap: 3px; }
.game-footer > div:first-child { min-width: 0; flex: 1 1 auto; }
.brand small, .game-footer small { color: var(--muted); }
.brand strong { letter-spacing: -0.02em; }

.logo-mark {
  position: relative;
  display: block;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 14px;
  background: var(--blue);
  box-shadow: 0 9px 20px color-mix(in srgb, var(--blue) 28%, transparent);
  transform: rotate(-3deg);
}
.logo-mark i { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: var(--paper); }
.logo-mark i:nth-child(1) { top: 9px; left: 9px; }
.logo-mark i:nth-child(2) { top: 16px; right: 8px; }
.logo-mark i:nth-child(3) { bottom: 8px; left: 16px; }

.session-summary { justify-content: flex-end; flex-wrap: wrap; color: var(--muted); font-weight: 600; }
.host-button, .header-story-button, .secondary-action, .primary-action {
  min-height: 44px;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}
.host-button, .header-story-button, .secondary-action { border: 1px solid var(--line); color: var(--ink); background: transparent; }
.header-story-button { border-color: color-mix(in srgb, var(--gold) 38%, var(--line)); background: color-mix(in srgb, var(--gold-soft) 62%, var(--paper)); }

.game-main {
  min-height: 0;
  display: grid;
  align-content: center;
  gap: clamp(11px, 2vh, 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(16px, 3.5vh, 36px) clamp(18px, 4.5vw, 80px);
}
.status-banner { justify-self: center; max-width: 760px; padding: 10px 16px; border: 1px solid color-mix(in srgb, var(--gold) 40%, var(--line)); border-radius: 14px; color: var(--ink); background: color-mix(in srgb, var(--gold-soft) 72%, var(--paper)); text-align: center; font-weight: 650; }
.phase-copy { display: grid; justify-items: center; gap: 7px; text-align: center; }
.phase-copy h1, .phase-copy p, .game-footer p { margin: 0; }
.phase-copy h1 { font-size: clamp(1.7rem, 3.4vw, 3rem); letter-spacing: -0.035em; }
.phase-copy p, .word-card small, .game-footer small, .available-summary { color: var(--muted); }
.phase-label { justify-self: center; padding: 6px 12px; border-radius: 999px; color: var(--blue); background: var(--blue-soft); font-weight: 700; }

.turn-steps { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }
.turn-steps span { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; }
.turn-steps b { display: inline-grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; color: inherit; background: color-mix(in srgb, var(--line) 72%, transparent); }
.turn-steps span[aria-current="step"] { color: var(--blue); }
.turn-steps span[aria-current="step"] b, .turn-steps span.is-done b { color: var(--paper); background: var(--blue); }
.turn-steps i { color: color-mix(in srgb, var(--muted) 60%, transparent); font-style: normal; }

.word-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.word-grid.count-2 { grid-template-columns: repeat(2, minmax(0, 360px)); justify-content: center; }
.word-grid.count-1 { grid-template-columns: minmax(0, 380px); justify-content: center; }
.word-card {
  position: relative;
  isolation: isolate;
  min-height: clamp(170px, 28vh, 320px);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 16px;
  padding: 24px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--ink);
  background: linear-gradient(145deg, color-mix(in srgb, var(--paper) 80%, transparent), transparent 58%), var(--paper);
  box-shadow: 0 15px 38px color-mix(in srgb, var(--shadow) 60%, transparent);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}
.word-card:not(:disabled) { cursor: pointer; }
.word-card:not(:disabled):hover { transform: translateY(-5px) rotate(-0.35deg); border-color: color-mix(in srgb, var(--blue) 55%, var(--line)); box-shadow: 0 21px 45px color-mix(in srgb, var(--shadow) 75%, transparent); }
.word-card.is-rolling { animation: card-pulse 760ms ease-in-out infinite alternate; }
.word-card.is-rolling:disabled, .word-card.is-settled:disabled { opacity: 1; }
.word-card:nth-child(2).is-rolling { animation-duration: 890ms; animation-delay: -140ms; }
.word-card:nth-child(3).is-rolling { animation-duration: 1020ms; animation-delay: -290ms; }
.word-card.is-rolling small::after { content: '  ↓'; color: var(--blue); font-weight: 800; }
.word-card:nth-child(2).is-rolling small::after { color: var(--gold); }
.word-card:nth-child(3).is-rolling small::after { color: var(--terracotta); }
.word-card.is-settled { animation: card-settle 260ms ease-out both; }
.word-card.is-settled .reel-word { animation: word-reveal 260ms cubic-bezier(0.2, 0.76, 0.3, 1) both; }
.word-card.is-selected { border-color: var(--gold); box-shadow: 0 18px 46px color-mix(in srgb, var(--gold) 27%, transparent); transform: translateY(-4px); }
.word-card.is-dimmed { opacity: 0.34; transform: scale(0.98); }
.word-card::before { content: attr(data-mark); position: absolute; z-index: -1; top: 12px; right: 16px; color: color-mix(in srgb, var(--blue) 18%, transparent); font-size: 2.5rem; transform: rotate(8deg); }
.word-card:nth-child(2)::before { color: color-mix(in srgb, var(--gold) 22%, transparent); }
.word-card:nth-child(3)::before { color: color-mix(in srgb, var(--terracotta) 20%, transparent); }
.word-card::after { content: ''; position: absolute; z-index: -1; right: 16%; bottom: -1px; left: 16%; height: 5px; border-radius: 999px 999px 0 0; background: #6f9cdb; }
.word-card:nth-child(2)::after { background: #c19a4f; }
.word-card:nth-child(3)::after { background: #bd7258; }
.word-card small { font-weight: 650; }
.reel-window {
  position: relative;
  width: 100%;
  height: clamp(92px, 13vh, 160px);
  display: block;
  overflow: hidden;
}
.reel-strip {
  width: 100%;
  height: 100%;
  display: grid;
  grid-auto-rows: 100%;
  transform: translateY(0);
  will-change: transform;
}
.reel-strip.is-prepared { transform: translateY(-100%); }
.reel-strip.is-advancing {
  transform: translateY(0);
  transition: transform var(--reel-duration, 140ms) cubic-bezier(0.32, 0.72, 0.34, 1);
}
.word-card.is-rolling .reel-window::before,
.word-card.is-rolling .reel-window::after {
  content: '';
  position: absolute;
  z-index: 2;
  right: 0;
  left: 0;
  height: 20px;
  pointer-events: none;
}
.word-card.is-rolling .reel-window::before { top: 0; background: linear-gradient(var(--paper), transparent); }
.word-card.is-rolling .reel-window::after { bottom: 0; background: linear-gradient(transparent, var(--paper)); }
.word-card strong {
  min-width: 0;
  max-width: 100%;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  justify-self: center;
  color: var(--ink);
  font-size: clamp(2.7rem, 5.6vw, 4.7rem);
  line-height: 0.96;
  letter-spacing: -0.05em;
  overflow-wrap: normal;
  text-align: center;
  text-wrap: balance;
}
.reel-word:not(.is-phrase) { white-space: nowrap; }
.reel-word.is-long-word { font-size: clamp(2.2rem, 4vw, 3.35rem); letter-spacing: -0.055em; }
.reel-word.is-extra-long-word { font-size: clamp(1.95rem, 3.35vw, 2.8rem); letter-spacing: -0.06em; }
.reel-word.is-phrase { max-width: 95%; font-size: clamp(2.3rem, 4.25vw, 3.65rem); line-height: 1.02; letter-spacing: -0.04em; }
.reel-word.is-long-phrase { max-width: 90%; font-size: clamp(2.05rem, 3.5vw, 2.9rem); line-height: 1.04; }
.reel-word.is-extra-long-phrase { font-size: clamp(1.95rem, 3.15vw, 2.65rem); }

.game-actions { min-height: 48px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.secondary-action { justify-self: start; }
.game-actions > .secondary-action { grid-column: 1; }
.game-actions > .primary-action { grid-column: 2; }
.primary-action { min-width: 190px; border: 1px solid transparent; color: #fff; background: var(--blue); box-shadow: 0 11px 27px color-mix(in srgb, var(--blue) 32%, transparent); }
.primary-action.is-stop { background: var(--terracotta); box-shadow: 0 11px 27px color-mix(in srgb, var(--terracotta) 30%, transparent); }
.secondary-action.is-reroll { grid-column: 3; justify-self: end; min-height: 36px; padding: 6px 12px; border-color: transparent; color: var(--muted); background: transparent; font-size: 0.9rem; font-weight: 650; box-shadow: none; }
.secondary-action.is-reroll:not(:disabled):hover { color: var(--ink); background: var(--gold-soft); transform: none; filter: none; }
.primary-action:not(:disabled):hover, .secondary-action:not(:disabled):hover, .host-button:not(:disabled):hover, .header-story-button:not(:disabled):hover { filter: brightness(1.04); transform: translateY(-1px); }
.story-timeline {
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
  font-size: clamp(1.1rem, 2.2vw, 1.45rem);
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  scrollbar-width: thin;
}
.story-timeline span { padding: 0 6px; color: var(--terracotta); }
.available-summary { text-align: right; }
.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; }

.game-dialog { width: min(560px, calc(100% - 28px)); max-height: min(760px, calc(100vh - 28px)); padding: 0; overflow: auto; border: 0; border-radius: 24px; color: var(--ink); background: var(--paper); box-shadow: 0 28px 90px rgba(9, 20, 34, 0.34); }
.game-dialog::backdrop { background: rgba(8, 17, 29, 0.52); backdrop-filter: blur(5px); }
.dialog-panel { display: grid; gap: 20px; padding: 26px; }
.compact-dialog { gap: 14px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-heading h2, .compact-dialog h2, .compact-dialog p, .used-summary p { margin: 0; }
.dialog-heading h2, .compact-dialog h2 { margin-top: 4px; letter-spacing: -0.025em; }
.dialog-kicker { color: var(--blue); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: transparent; cursor: pointer; font-size: 1.5rem; line-height: 1; }
.used-summary { display: grid; gap: 4px; padding: 16px; border-radius: 16px; background: var(--blue-soft); }
.used-summary p, .compact-dialog p { color: var(--muted); line-height: 1.5; }
.used-list { min-height: 76px; max-height: 260px; display: flex; align-content: flex-start; flex-wrap: wrap; gap: 8px; overflow: auto; padding: 4px; }
.used-list span { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 0.9rem; font-weight: 700; }
.used-list .empty-used-list { width: 100%; border-style: dashed; color: var(--muted); text-align: center; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; }
.split-actions { justify-content: space-between; }
.danger-action { min-height: 44px; padding: 10px 16px; border: 1px solid color-mix(in srgb, var(--terracotta) 50%, var(--line)); border-radius: 999px; color: var(--terracotta); background: transparent; font-weight: 750; cursor: pointer; }

@keyframes card-pulse {
  from { transform: translateY(-2px); box-shadow: 0 14px 34px color-mix(in srgb, var(--blue) 10%, var(--shadow)); }
  to { transform: translateY(2px); box-shadow: 0 20px 46px color-mix(in srgb, var(--blue) 25%, var(--shadow)); }
}

@keyframes card-settle {
  0% { transform: translateY(-4px) scale(0.992); border-color: color-mix(in srgb, var(--gold) 58%, var(--line)); box-shadow: 0 16px 38px color-mix(in srgb, var(--gold) 14%, var(--shadow)); }
  58% { transform: translateY(2px) scale(1.006); }
  100% { transform: translateY(0); border-color: var(--line); }
}

@keyframes word-reveal {
  from { opacity: 0.35; transform: translateY(-18px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 16px, 620px); height: calc(100vh - 16px); height: calc(100dvh - 16px); margin: 8px auto; border-radius: 20px; }
  .game-header, .game-footer { align-items: flex-start; flex-direction: column; padding: 16px; }
  .session-summary { justify-content: flex-start; }
  .game-main { align-content: start; padding: 24px 14px; }
  .word-grid { grid-template-columns: 1fr; }
  .word-grid.count-2, .word-grid.count-1 { grid-template-columns: 1fr; }
  .word-card { min-height: 150px; }
  .reel-window { height: clamp(104px, 27vw, 140px); }
  .word-card strong { font-size: clamp(2.75rem, 13vw, 4.6rem); }
  .reel-word.is-long-word { font-size: clamp(2.2rem, 9.2vw, 3.35rem); }
  .reel-word.is-extra-long-word { font-size: clamp(1.95rem, 7.8vw, 2.8rem); }
  .reel-word.is-phrase { font-size: clamp(2.4rem, 10vw, 3.7rem); }
  .reel-word.is-long-phrase { font-size: clamp(2.2rem, 9vw, 3.25rem); }
  .reel-word.is-extra-long-phrase { font-size: clamp(2.05rem, 8.2vw, 3rem); }
  .game-actions { grid-template-columns: 1fr; }
  .secondary-action, .primary-action { width: 100%; justify-self: stretch; }
  .game-actions > .secondary-action, .game-actions > .primary-action { grid-column: 1; }
  .secondary-action.is-reroll { width: auto; justify-self: end; }
  .game-actions > span { display: none; }
  .available-summary { text-align: left; }
  .dialog-actions, .split-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

@media (max-width: 420px) {
  .turn-steps { gap: 7px; }
  .turn-steps i { display: none; }
}

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