:root {
  --ink: #263238;
  --muted: #65746f;
  --line: #dbe7e1;
  --paper: #ffffff;
  --mint: #6fd1b5;
  --coral: #ff9f8f;
  --lemon: #ffd166;
  --sky: #8bb8ff;
  --berry: #f48fb1;
  --shadow: 0 16px 40px rgba(48, 69, 65, .12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #fbfffd 0%, #fff8f0 46%, #f6f9ff 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .6;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 44px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
}

.connection-status {
  min-width: 118px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.connection-status.connected {
  border-color: rgba(111, 209, 181, .65);
  color: #267662;
}

.connection-status.reconnecting {
  border-color: rgba(255, 159, 143, .75);
  color: #9b4c40;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 44px;
  flex: 1;
}

.home-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 18px;
  align-items: stretch;
}

.welcome-stage,
.panel,
.host-main,
.player-main {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .82);
  box-shadow: var(--shadow);
}

.welcome-stage {
  min-height: 560px;
  position: relative;
  overflow: hidden;
  padding: clamp(28px, 6vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.welcome-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(111, 209, 181, .18) 1px, transparent 1px),
    linear-gradient(0deg, rgba(139, 184, 255, .14) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(90deg, rgba(0,0,0,.35), transparent 70%);
  pointer-events: none;
}

.hero-copy,
.floating-mochi,
.book-credit {
  position: relative;
  z-index: 1;
}

.hero-copy h1 {
  max-width: 720px;
  margin: 0;
  font-size: 82px;
  line-height: .94;
  letter-spacing: 0;
}

.hero-copy p {
  max-width: 620px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 21px;
  line-height: 1.5;
}

.floating-mochi {
  width: min(260px, 46vw);
  margin-top: 36px;
  filter: drop-shadow(0 18px 24px rgba(57, 79, 74, .15));
  animation: float 5s ease-in-out infinite;
}

.book-credit {
  max-width: 520px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.book-credit a {
  color: #267662;
  font-weight: 800;
  text-decoration: none;
}

.book-credit a:hover,
.book-credit a:focus-visible {
  text-decoration: underline;
}

.home-actions {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 22px;
}

.panel h2,
.host-title h1,
.player-heading h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0;
}

.panel p,
.helper,
.tiny-note {
  color: var(--muted);
  line-height: 1.5;
}

.field-stack {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span,
.stepper-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.text-input,
.number-input,
.topic-input,
.response-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.text-input,
.number-input {
  min-height: 48px;
  padding: 12px 14px;
}

.room-code-input {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
}

.topic-input,
.response-input {
  min-height: 112px;
  padding: 14px;
  resize: vertical;
  line-height: 1.45;
}

.response-input {
  min-height: 180px;
}

.compact-response-form {
  gap: 10px;
}

.compact-response-form .response-input {
  min-height: 124px;
}

.text-input:focus,
.number-input:focus,
.topic-input:focus,
.response-input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 4px rgba(111, 209, 181, .2);
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(40px, 1fr));
  gap: 8px;
}

.icon-choice,
.icon-button,
.small-icon-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.icon-choice {
  min-height: 44px;
  font-size: 22px;
}

.icon-choice.selected {
  border-color: var(--mint);
  background: #eafff8;
  box-shadow: inset 0 0 0 2px rgba(111, 209, 181, .35);
}

.button-row,
.host-actions,
.player-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.primary-button,
.secondary-button,
.quiet-button,
.danger-button {
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 11px 16px;
  font-weight: 900;
  letter-spacing: 0;
}

.primary-button {
  background: var(--ink);
  color: #fff;
}

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

.quiet-button {
  background: rgba(255, 255, 255, .55);
  color: var(--muted);
  border-color: var(--line);
}

.danger-button {
  background: #fff5f4;
  color: #9b3f35;
  border-color: #ffd2ca;
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.quiet-button:hover:not(:disabled),
.danger-button:hover:not(:disabled),
.icon-choice:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(43, 62, 58, .1);
}

.host-layout,
.player-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.host-side,
.player-side {
  display: grid;
  gap: 18px;
}

.room-code-card {
  display: grid;
  gap: 12px;
  text-align: center;
}

.room-code-card .code {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 84px;
  padding: 12px;
  border-radius: var(--radius);
  background: #263238;
  color: #fff;
  font-size: 68px;
  font-weight: 1000;
  letter-spacing: 0;
}

.host-main,
.player-main {
  min-height: 640px;
  padding: clamp(20px, 4vw, 34px);
}

.host-title,
.player-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.stage-pill,
.status-pill,
.round-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.stage-pill {
  background: #f0f8ff;
  color: #39699d;
}

.status-pill {
  background: #f6f7f5;
  color: var(--muted);
}

.status-pill.done {
  background: #eafff8;
  color: #267662;
}

.round-chip {
  background: #fff3d2;
  color: #7d5b00;
}

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

.stepper {
  display: grid;
  gap: 7px;
}

.progress-wrap {
  display: grid;
  gap: 8px;
  margin: 18px 0 24px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.progress-track {
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--mint), var(--lemon), var(--coral));
  transition: width .35s ease;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 12px;
}

.player-card {
  --player-color: var(--mint);
  position: relative;
  min-height: 118px;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 7px solid transparent;
  border-radius: var(--radius);
  background: #fff;
  padding: 14px 38px 14px 14px;
  transition: transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease;
  overflow: hidden;
}

.player-card.done {
  border-left-color: var(--player-color);
  background: linear-gradient(135deg, #ffffff 0%, #effff9 100%);
  box-shadow: 0 12px 26px rgba(61, 109, 97, .12);
}

.player-card.pop .avatar {
  animation: pop .55s cubic-bezier(.18, .89, .32, 1.28);
}

.avatar {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--player-color);
  color: var(--ink);
  font-size: 28px;
  box-shadow: inset 0 -7px 0 rgba(255, 255, 255, .28);
}

.player-name {
  min-width: 0;
  font-size: 17px;
  line-height: 1.15;
  font-weight: 1000;
  overflow-wrap: anywhere;
}

.player-meta {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.dot-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: #b8c3bf;
}

.dot.connected {
  background: var(--mint);
  box-shadow: 0 0 0 4px rgba(111, 209, 181, .2);
}

.dot.done {
  background: var(--coral);
  box-shadow: 0 0 0 4px rgba(255, 159, 143, .2);
}

.remove-player {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, .84);
  color: var(--muted);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 280px;
  border: 1px dashed #bfd7cf;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  padding: 28px;
  background: rgba(255, 255, 255, .55);
}

.topic-banner {
  border: 1px solid #ccebe2;
  border-radius: var(--radius);
  background: #f0fff9;
  padding: 18px;
  margin-bottom: 20px;
}

.topic-banner h2 {
  margin: 0 0 8px;
  font-size: 15px;
  color: #267662;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topic-banner p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 28px;
  font-weight: 900;
}

.assignment-list {
  display: grid;
  gap: 12px;
  margin: 18px 0 24px;
}

.response-card {
  --player-color: var(--mint);
  border: 1px solid var(--line);
  border-left: 7px solid var(--player-color);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.response-card.depth-1 {
  margin-left: 18px;
  background: #fbfdfc;
}

.response-card.depth-2,
.response-card.depth-3,
.response-card.depth-4,
.response-card.depth-5 {
  margin-left: 18px;
  background: #ffffff;
}

.response-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 14px;
  text-align: left;
}

.response-toggle:disabled {
  cursor: default;
  opacity: 1;
}

.mini-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--player-color);
  font-size: 22px;
}

.response-body {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.response-author {
  font-weight: 1000;
}

.response-text {
  margin: 0;
  color: #314541;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.expand-indicator {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
  font-weight: 900;
}

.reference-stack {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.result-focus {
  display: grid;
  gap: 12px;
}

.result-focus > .response-card {
  box-shadow: 0 14px 28px rgba(48, 69, 65, .08);
}

.result-focus .reference-stack {
  padding-bottom: 16px;
}

.draft-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.sentence-meter.ready {
  color: #267662;
}

.submitted-note {
  display: grid;
  gap: 10px;
  border: 1px solid #ccebe2;
  border-radius: var(--radius);
  background: #f0fff9;
  padding: 16px;
}

.submitted-note strong {
  color: #267662;
}

.player-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.strip-avatar {
  --player-color: var(--mint);
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--player-color);
  opacity: .55;
}

.strip-avatar.done {
  opacity: 1;
  box-shadow: 0 0 0 4px rgba(111, 209, 181, .2);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, calc(100% + 48px));
  max-width: min(520px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform .2s ease, opacity .2s ease;
  z-index: 10;
}

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

.hidden {
  display: none !important;
}

@keyframes pop {
  0% {
    transform: scale(.84) translateY(3px);
  }
  55% {
    transform: scale(1.18) translateY(-5px);
  }
  100% {
    transform: scale(1) translateY(0);
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotate(-2deg);
  }
  50% {
    transform: translateY(-10px) rotate(2deg);
  }
}

@media (max-width: 920px) {
  .home-layout,
  .host-layout,
  .player-layout {
    grid-template-columns: 1fr;
  }

  .welcome-stage {
    min-height: auto;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 4px;
  }

  .settings-grid,
  .host-title,
  .player-heading {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

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

  .icon-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .room-code-card .code {
    font-size: 48px;
  }

  .hero-copy h1 {
    font-size: 44px;
  }
}
