:root {
  --bg: #fff8e7;
  --ink: #221f1c;
  --muted: #6c665f;
  --line: #eadcc4;
  --panel: #fffdf7;
  --panel-strong: #ffffff;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --gold: #f59e0b;
  --rose: #be123c;
  --shadow: 0 18px 50px rgba(84, 54, 15, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(255, 255, 255, 0.58) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.58) 1px, transparent 1px),
    linear-gradient(135deg, #fff8e7 0%, #fef3c7 46%, #fff7ed 100%);
  background-size: 28px 28px, 28px 28px, auto;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.scroll-locked {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar,
.phase-banner,
.toolbar,
.board-header,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 24px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.5rem);
  line-height: 0.95;
}

h2 {
  font-size: clamp(1.55rem, 3vw, 2.4rem);
  line-height: 1.1;
}

h3 {
  font-size: 1.1rem;
}

.eyebrow,
.small {
  color: var(--muted);
  font-size: 0.85rem;
}

.eyebrow {
  text-transform: uppercase;
  font-weight: 800;
}

.timer,
.copy-code {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.panel,
.room-card,
.stage {
  border: 1px solid rgba(234, 220, 196, 0.9);
  background: rgba(255, 253, 247, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.entry-panel {
  border-radius: 8px;
  padding: clamp(20px, 4vw, 40px);
}

.profile-panel {
  display: grid;
  place-items: center;
  min-height: 560px;
  border-radius: 8px;
  padding: clamp(20px, 5vw, 52px);
}

.profile-form {
  width: min(100%, 460px);
}

.profile-form p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.entry-copy {
  max-width: 760px;
  margin-bottom: 28px;
}

.entry-copy p {
  margin-top: 10px;
  color: var(--muted);
}

.entry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.card,
.room-card {
  border-radius: 8px;
  background: var(--panel-strong);
}

.form-card,
.room-card {
  padding: 20px;
}

.form-card {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.primary,
.secondary,
.danger,
.ghost {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.primary {
  background: #f97316;
  color: #fff;
  box-shadow: 0 8px 20px rgba(234, 88, 12, 0.18);
}

.primary:hover {
  background: #ea580c;
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.danger {
  background: #fff1f2;
  color: var(--rose);
}

.ghost {
  background: transparent;
  color: var(--muted);
}

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

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

.lobby-main,
.online-panel {
  border-radius: 8px;
  padding: 22px;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.room-list,
.online-list {
  display: grid;
  gap: 10px;
}

.lobby-room-card,
.online-row,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.lobby-room-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
}

.lobby-room-card strong,
.online-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.room-state {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 3px 8px;
  background: #ecfeff;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 900;
}

.room-state.playing {
  background: #fff7ed;
  color: var(--gold);
}

.lobby-room-card p {
  margin-top: 5px;
}

.online-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 240px;
  padding: 24px;
  color: var(--muted);
  font-weight: 800;
}

.sidebar,
.stage {
  display: grid;
  align-content: start;
  gap: 14px;
}

.stage {
  border-radius: 8px;
  padding: 20px;
  min-height: 680px;
}

.room-card {
  box-shadow: none;
}

.copy-code {
  width: 100%;
  margin: 12px 0;
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0;
}

.full-button {
  width: 100%;
  margin-top: 8px;
}

.player-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

.player-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.player-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
}

.status-dot.done {
  background: var(--accent);
}

.host-only.room-card {
  gap: 10px;
}

.chat-card {
  display: grid;
  gap: 12px;
}

.chat-list {
  display: grid;
  align-content: start;
  gap: 10px;
  max-height: 18rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.chat-message {
  display: grid;
  gap: 4px;
  justify-items: start;
}

.chat-message.mine {
  justify-items: end;
}

.chat-message div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.chat-message strong {
  font-size: 0.86rem;
}

.chat-message span {
  color: var(--muted);
  font-size: 0.75rem;
}

.chat-message p {
  max-width: min(82%, 260px);
  border-radius: 8px;
  background: #f6f3ee;
  padding: 8px 10px;
  color: var(--ink);
  line-height: 1.35;
  word-break: break-word;
}

.chat-message.mine p {
  background: #fed7aa;
  text-align: right;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.topic-section,
.board-section,
.play-section {
  display: grid;
  gap: 16px;
}

.topic-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  flex: 1;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.topic-card {
  position: relative;
  display: grid;
  gap: 10px;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.topic-card.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.22);
}

.vote-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece6dc;
}

.vote-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #f97316;
}

.roulette {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.roulette-track {
  display: flex;
  gap: 8px;
  padding: 10px;
  transform: translateX(0);
  transition: transform 2.4s cubic-bezier(0.13, 0.78, 0.22, 1);
}

.roulette-item {
  flex: 0 0 170px;
  border-radius: 8px;
  background: #fff7ed;
  padding: 12px;
  text-align: center;
  font-weight: 900;
}

.bingo-board {
  position: relative;
  display: grid;
  gap: 8px;
  width: min(100%, 680px);
  aspect-ratio: 1;
}

.cell {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  resize: none;
  color: var(--ink);
  font: 700 clamp(0.62rem, 1.8vw, 0.98rem) / 1.25 ui-sans-serif, system-ui, sans-serif;
  text-align: center;
}

.cell.called {
  border-color: #f59e0b;
  background: #facc15;
}

.cell.bingo-line {
  box-shadow: none;
}

.board-line-layer {
  position: absolute;
  inset: -1px;
  z-index: 3;
  pointer-events: none;
}

.board-line {
  position: absolute;
  display: block;
  border-radius: 999px;
  pointer-events: none;
  filter: saturate(1.08);
}

.board-line::before,
.mini-line::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    repeating-linear-gradient(0deg, rgba(234, 88, 12, 0.98) 0 2px, rgba(234, 88, 12, 0.74) 2px 3px, rgba(234, 88, 12, 0.98) 3px 5px),
    #ea580c;
  box-shadow: 0 1px 0 rgba(154, 52, 18, 0.22), 0 -1px 0 rgba(255, 237, 213, 0.32);
}

.board-line.row,
.board-line.diag,
.board-line.anti {
  height: 9px;
  margin-top: -4.5px;
  transform-origin: left center;
}

.board-line.col {
  width: 9px;
  margin-left: -4.5px;
  transform-origin: center top;
}

.board-line.fresh.row,
.board-line.fresh.diag,
.board-line.fresh.anti {
  animation: drawLineX 0.48s ease-out both;
}

.board-line.fresh.col {
  animation: drawLineY 0.48s ease-out both;
}

.board-line.drawn {
  clip-path: inset(0 0 0 0);
}

.cell.callable {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(192, 132, 18, 0.22);
  cursor: pointer;
}

.cell.my-turn {
  animation: turnPulse 1s ease-in-out infinite;
}

.cell.callable:hover {
  background: #fff7ed;
}

.cell:disabled {
  opacity: 1;
  color: var(--ink);
}

.callout {
  display: grid;
  gap: 10px;
  max-width: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

.callout h3 {
  font-size: 1.6rem;
}

.turn-order {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.turn-chip {
  display: inline-grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  max-width: 180px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 7px 10px;
  color: var(--muted);
}

.turn-chip span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f6f3ee;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
}

.turn-chip strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
}

.turn-chip.active {
  border-color: var(--gold);
  color: var(--ink);
  box-shadow: 0 0 0 3px rgba(192, 132, 18, 0.16);
}

.turn-chip.mine {
  border-color: var(--accent);
}

.turn-separator {
  color: var(--muted);
  font-weight: 900;
}

.history {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.history-item span {
  color: var(--muted);
  font-weight: 800;
}

.spectator-section {
  display: grid;
  gap: 16px;
}

.result-section {
  display: grid;
  gap: 16px;
}

.ranking-list {
  display: grid;
  gap: 12px;
}

.ranking-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.ranking-card.winner {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(192, 132, 18, 0.18);
}

.ranking-summary {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.ranking-summary > span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f6f3ee;
  font-weight: 900;
}

.ranking-summary strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spectator-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.spectator-board-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.spectator-board-card h3 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spectator-board,
.mini-board {
  position: relative;
  display: grid;
  gap: 5px;
  width: 100%;
  aspect-ratio: 1;
}

.spectator-cell,
.mini-cell {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.spectator-cell.called,
.mini-cell.called {
  border-color: #f59e0b;
  background: #facc15;
}

.mini-cell.line {
  border-color: #ea580c;
}

.mini-line {
  position: absolute;
  z-index: 2;
  display: block;
  border-radius: 999px;
  pointer-events: none;
}

.mini-line.row,
.mini-line.diag,
.mini-line.anti {
  height: 3px;
  margin-top: -1.5px;
}

.mini-line.col {
  width: 3px;
  margin-left: -1.5px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  max-width: min(460px, calc(100% - 32px));
  transform: translate(-50%, 20px);
  border-radius: 8px;
  background: #1f2937;
  color: #fff;
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  width: min(440px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(34, 31, 28, 0.42);
}

.modal-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.turn-modal {
  width: min(360px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.turn-modal::backdrop {
  background: rgba(34, 31, 28, 0.28);
}

.turn-modal-card {
  display: grid;
  place-items: center;
  gap: 8px;
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: #fff;
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}

@keyframes turnPulse {
  0%,
  100% {
    box-shadow: inset 0 0 0 2px rgba(192, 132, 18, 0.22), 0 0 0 0 rgba(192, 132, 18, 0.42);
  }

  50% {
    box-shadow: inset 0 0 0 2px rgba(192, 132, 18, 0.5), 0 0 0 5px rgba(192, 132, 18, 0.18);
  }
}

@keyframes drawLineX {
  from {
    clip-path: inset(0 100% 0 0);
  }

  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes drawLineY {
  from {
    clip-path: inset(0 0 100% 0);
  }

  to {
    clip-path: inset(0 0 0 0);
  }
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f6f3ee;
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 14px, 1180px);
    padding: 10px 0 28px;
  }

  .topbar,
  .phase-banner,
  .toolbar,
  .board-header,
  .lobby-header {
    align-items: stretch;
    flex-direction: column;
  }

  .entry-grid,
  .lobby-layout,
  .room-layout,
  .inline-fields {
    grid-template-columns: 1fr;
  }

  .lobby-room-card {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .lobby-room-card .secondary {
    width: 100%;
  }

  .room-title-line {
    align-items: flex-start;
  }

  .room-state {
    margin-top: 1px;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    margin-bottom: 10px;
  }

  h1 {
    font-size: 1.85rem;
    line-height: 1;
  }

  h2 {
    font-size: 1.35rem;
  }

  .profile-panel {
    min-height: calc(100vh - 90px);
    padding: 14px;
  }

  .form-card,
  .room-card,
  .lobby-main,
  .online-panel {
    padding: 14px;
  }

  .lobby-layout,
  .room-layout,
  .sidebar,
  .stage {
    gap: 10px;
  }

  .room-layout {
    display: flex;
    flex-direction: column;
  }

  .stage {
    order: 1;
  }

  .sidebar {
    order: 2;
  }

  .room-card {
    border-radius: 8px;
  }

  .room-card h2 {
    font-size: 1.15rem;
  }

  .copy-code {
    min-height: 40px;
    margin: 8px 0;
    font-size: 1rem;
  }

  .stage {
    min-height: 0;
    padding: 12px;
  }

  .phase-banner {
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 253, 247, 0.94);
    padding-bottom: 10px;
    backdrop-filter: blur(14px);
  }

  .timer {
    width: 100%;
    text-align: center;
    font-weight: 900;
  }

  .topic-form,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .toolbar {
    gap: 10px;
  }

  .topic-grid {
    grid-template-columns: 1fr;
  }

  .board-header {
    gap: 10px;
  }

  .board-header .primary,
  .callout .primary,
  .toolbar .primary,
  .toolbar .secondary {
    width: 100%;
  }

  .play-section,
  .board-section,
  .topic-section,
  .result-section,
  .spectator-section {
    gap: 12px;
  }

  .callout {
    max-width: none;
    padding: 14px;
  }

  .callout h3 {
    font-size: 1.35rem;
  }

  .turn-order {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }

  .turn-chip {
    flex: 0 0 auto;
    max-width: 150px;
  }

  .player-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .player-actions {
    justify-content: space-between;
  }

  .mini-button {
    min-height: 36px;
  }

  .chat-list {
    max-height: 14rem;
  }

  .bingo-board {
    width: 100%;
    gap: 4px;
  }

  .cell {
    border-radius: 7px;
    padding: 3px;
    font-size: clamp(0.56rem, 2.6vw, 0.82rem);
    line-height: 1.12;
  }

  .board-line.row,
  .board-line.diag,
  .board-line.anti {
    height: 7px;
    margin-top: -3.5px;
  }

  .board-line.col {
    width: 7px;
    margin-left: -3.5px;
  }

  .ranking-card {
    grid-template-columns: minmax(0, 1fr) 78px;
    gap: 10px;
    padding: 12px;
  }

  .spectator-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .spectator-board-card {
    padding: 10px;
  }

  .modal,
  .turn-modal {
    width: min(100% - 18px, 440px);
  }

  .modal-card {
    max-height: min(86vh, 680px);
    overflow: auto;
    padding: 16px;
  }
}
