:root {
  color-scheme: light;
  --bg: #f6f9ff;
  --panel: #ffffff;
  --panel-2: #f0f7ff;
  --ink: #172033;
  --muted: #61708a;
  --line: #dbe5f2;
  --green: #17b26a;
  --green-dark: #0f8f56;
  --amber: #f59e0b;
  --blue: #2563eb;
  --red: #e11d48;
  --coral: #ff6b6b;
  --yellow: #facc15;
  --shadow: 0 16px 34px rgba(38, 72, 112, 0.12);
  --wide-shell-width: min(1180px, calc(100% - 32px));
  --home-shell-width: min(920px, calc(100% - 28px));
  --body-bg: linear-gradient(180deg, #eaf7ff 0, #f6f9ff 260px, #f8fbff 100%);
  --hero-ink: #10213f;
  --input-bg: #ffffff;
  --control-bg: #ffffff;
  --soft-panel: #f8fbff;
  --success-bg: #ecfdf5;
  --info-bg: #eff6ff;
  --warning-bg: #fff7ed;
  --danger-bg: #fff1f2;
  --orange: #ea580c;
  --disabled-bg: #e2e8f0;
  --disabled-ink: #64748b;
  --timer-track: #dbe5f2;
  --tooltip-bg: #172033;
  --tooltip-ink: #ffffff;
  --toast-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
  --chat-shadow: 0 22px 54px rgba(15, 23, 42, 0.22);
  --overlay: rgba(15, 23, 42, 0.48);
  --overlay-hover: rgba(15, 23, 42, 0.56);
  --badge-border: #ffffff;
  --on-accent: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #111827;
  --panel-2: #172033;
  --ink: #e8eef8;
  --muted: #9aa8bd;
  --line: #27364a;
  --green: #22c55e;
  --green-dark: #16a34a;
  --amber: #fbbf24;
  --blue: #60a5fa;
  --red: #fb7185;
  --coral: #fb7185;
  --yellow: #fde047;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.38);
  --body-bg: linear-gradient(180deg, #101d33 0, #0b1220 280px, #08111f 100%);
  --hero-ink: #f8fbff;
  --input-bg: #0b1220;
  --control-bg: #101a2b;
  --soft-panel: #101a2b;
  --success-bg: rgba(34, 197, 94, 0.14);
  --info-bg: rgba(96, 165, 250, 0.14);
  --warning-bg: rgba(251, 191, 36, 0.14);
  --danger-bg: rgba(251, 113, 133, 0.14);
  --orange: #fb923c;
  --disabled-bg: #233247;
  --disabled-ink: #94a3b8;
  --timer-track: #223047;
  --tooltip-bg: #e8eef8;
  --tooltip-ink: #0b1220;
  --toast-shadow: 0 18px 36px rgba(0, 0, 0, 0.42);
  --chat-shadow: 0 24px 60px rgba(0, 0, 0, 0.46);
  --overlay: rgba(2, 6, 23, 0.68);
  --overlay-hover: rgba(2, 6, 23, 0.76);
  --badge-border: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--body-bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
}

button,
.mode-button {
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: var(--on-accent);
  cursor: pointer;
  font-weight: 800;
  min-height: 44px;
  padding: 0 18px;
  box-shadow: 0 8px 18px rgba(23, 178, 106, 0.18);
}

button:hover:not(:disabled),
.mode-button:hover {
  background: var(--green-dark);
  color: var(--on-accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

[hidden] {
  display: none !important;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  outline: none;
}

input {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 96px;
  padding: 12px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.sr-only {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: var(--wide-shell-width);
  margin: 0 auto;
  padding: 18px 0 6px;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 900;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.compact-brand {
  justify-self: start;
}

.brand-mark {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 8px 16px rgba(38, 72, 112, 0.12));
}

.home-shell {
  width: var(--home-shell-width);
  margin: 0 auto;
  padding: 24px 0 48px;
}

.hero-panel {
  padding: 24px 0 22px;
  text-align: center;
}

.flash-messages {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.flash-message {
  border: 1px solid rgba(245, 158, 11, 0.42);
  border-left: 5px solid var(--amber);
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--ink);
  font-weight: 800;
  line-height: 1.4;
  padding: 12px 14px;
}

.hero-panel h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: 0;
  color: var(--hero-ink);
}

.hero-panel p {
  max-width: 680px;
  margin: 14px auto 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.55;
}

.compact-hero h1 {
  font-size: clamp(2rem, 3vw, 3rem);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 10px;
}

.mode-card {
  min-width: 0;
  min-height: 230px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mode-card > .mode-button,
.mode-card.mode-button {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 230px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 26px;
  text-align: center;
  box-shadow: none;
}

.mode-card > .mode-button:hover,
.mode-card.mode-button:hover {
  border-color: rgba(37, 99, 235, 0.35);
  background: var(--panel-2);
  color: var(--ink);
  transform: translateY(-2px);
}

.mode-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: var(--success-bg);
  color: var(--green);
}

.mode-grid .mode-card:nth-child(2) .mode-icon {
  background: var(--info-bg);
  color: var(--blue);
}

.mode-grid .mode-card:nth-child(3) .mode-icon {
  background: var(--warning-bg);
  color: var(--orange);
}

.mode-grid .mode-card:nth-child(4) .mode-icon {
  background: var(--danger-bg);
  color: var(--red);
}

.mode-icon svg {
  width: 64px;
  height: 64px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.mode-card strong {
  display: block;
  font-size: 1.28rem;
  letter-spacing: 0;
}

.mode-card span {
  color: var(--muted);
  line-height: 1.4;
}

.create-room-card {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 22px;
}

.feedback-card {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 22px;
}

.link-mode-card {
  align-content: center;
  justify-items: center;
  text-align: center;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.link-mode-card .mode-card-heading {
  grid-template-columns: 1fr;
  justify-items: center;
}

.link-mode-card:hover,
.link-mode-card:focus-visible {
  border-color: rgba(37, 99, 235, 0.35);
  background: var(--panel-2);
  color: var(--ink);
  transform: translateY(-2px);
}

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

.game-guide {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
  align-items: stretch;
  margin-top: 22px;
}

.game-guide-intro,
.how-to-play li {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-guide-intro {
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 22px;
}

.game-guide-intro h2 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.15;
}

.game-guide-intro p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.58;
}

.how-to-play {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: guide-step;
}

.how-to-play li {
  position: relative;
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
  min-height: 136px;
  padding: 18px 18px 18px 58px;
  counter-increment: guide-step;
}

.how-to-play li::before {
  position: absolute;
  top: 18px;
  left: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--info-bg);
  color: var(--blue);
  content: counter(guide-step);
  font-size: 0.88rem;
  font-weight: 900;
}

.how-to-play strong {
  color: var(--ink);
  font-size: 1rem;
}

.how-to-play span {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

.create-room-form,
.feedback-form {
  display: grid;
  gap: 10px;
}

.create-room-form button,
.feedback-form button {
  width: 100%;
}

.home-ranking,
.ranking-list.full,
.locked-room,
.feedback-panel,
.create-room-panel,
.active-rooms-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.home-ranking {
  margin-top: 20px;
  padding: 20px;
}

.feedback-shell {
  width: min(660px, calc(100% - 28px));
}

.create-room-shell {
  width: min(980px, calc(100% - 28px));
}

.create-room-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(0, 1.18fr);
  gap: 18px;
  align-items: start;
}

.feedback-panel {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.create-room-panel,
.active-rooms-panel {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.feedback-panel-heading,
.page-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.feedback-panel-heading h2,
.page-panel-heading h2 {
  margin: 0;
  font-size: 1.2rem;
}

.feedback-home-link,
.panel-home-link,
.page-panel-heading > span {
  color: var(--blue);
  font-weight: 800;
  white-space: nowrap;
}

.page-panel-heading > span {
  color: var(--muted);
}

.feedback-panel .feedback-form {
  gap: 14px;
}

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

.active-room-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  padding: 12px;
}

.active-room-main {
  min-width: 0;
}

.active-room-main strong,
.active-room-code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-room-code {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.active-room-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.room-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  padding: 7px 9px;
}

.active-room-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 40px;
  border-radius: 8px;
  background: var(--green);
  color: var(--on-accent);
  font-weight: 850;
  padding: 0 14px;
}

.active-room-action:hover {
  background: var(--green-dark);
  color: var(--on-accent);
}

.active-room-action.disabled {
  background: var(--disabled-bg);
  color: var(--disabled-ink);
  pointer-events: none;
}

.empty-room-list {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  color: var(--muted);
  font-weight: 800;
  line-height: 1.4;
  padding: 18px;
  text-align: center;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin: 0;
}

.section-heading a {
  color: var(--blue);
  font-weight: 800;
}

.ranking-list {
  display: grid;
  gap: 10px;
}

.ranking-list.full {
  padding: 18px;
}

.ranking-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 14px;
  align-items: center;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  padding: 12px 14px;
}

.ranking-list.compact .ranking-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.ranking-row strong,
.ranking-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-row span,
.empty-ranking {
  color: var(--muted);
  font-weight: 700;
}

.app-shell {
  width: var(--wide-shell-width);
  margin: 0 auto;
  padding: 22px 0 32px;
}

.topbar {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 10px;
  min-width: 0;
}

.eyebrow,
.label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  overflow: hidden;
  font-size: clamp(1.55rem, 2.3vw, 2.25rem);
  line-height: 1.08;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-status {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 800;
  min-width: 104px;
  padding: 10px 14px;
  text-align: center;
}

.connection-status[data-mode="online"] {
  border-color: rgba(23, 178, 106, 0.42);
  background: var(--success-bg);
  color: var(--green);
}

.connection-status[data-mode="pending"] {
  border-color: rgba(245, 158, 11, 0.42);
  background: var(--warning-bg);
  color: var(--amber);
}

.connection-status[data-mode="offline"] {
  border-color: rgba(225, 29, 72, 0.28);
  background: var(--danger-bg);
  color: var(--red);
}

.secondary-button,
.ghost-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: none;
}

.secondary-button:hover:not(:disabled),
.ghost-button:hover:not(:disabled) {
  border-color: rgba(37, 99, 235, 0.36);
  background: var(--panel-2);
  color: var(--ink);
}

.game-layout {
  display: grid;
  min-height: calc(100vh - 132px);
  place-items: center;
}

.game-surface,
.chat-surface {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.game-surface {
  display: grid;
  grid-template-rows: auto auto auto minmax(320px, 1fr) auto auto;
  gap: 16px;
  min-height: 720px;
  padding: 20px;
}

.play-surface {
  display: grid;
  gap: 14px;
  width: min(680px, 100%);
}

.room-loading {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}

.room-loading-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--timer-track);
  border-top-color: var(--blue);
  border-radius: 999px;
  animation: room-loading-spin 800ms linear infinite;
}

.room-loading strong {
  font-size: 1.12rem;
}

.room-loading span {
  color: var(--muted);
  font-weight: 750;
  line-height: 1.45;
}

@keyframes room-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.room-action-center {
  display: grid;
  grid-template-columns: repeat(4, 44px);
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.lobby-controls {
  display: grid;
  justify-items: center;
  gap: 10px;
  min-height: 92px;
}

.lobby-status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
}

.lobby-action-button {
  min-width: 168px;
}

.icon-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  box-shadow: none;
}

.icon-control svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.icon-control[data-tooltip]::before,
.icon-control[data-tooltip]::after {
  position: absolute;
  left: 50%;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.icon-control[data-tooltip]::before {
  top: calc(100% + 3px);
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--tooltip-bg);
  border-left: 6px solid transparent;
  content: "";
}

.icon-control[data-tooltip]::after {
  top: calc(100% + 9px);
  border-radius: 6px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  content: attr(data-tooltip);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1;
  padding: 8px 10px;
  white-space: nowrap;
}

.icon-control[data-tooltip]:hover::before,
.icon-control[data-tooltip]:hover::after,
.icon-control[data-tooltip]:focus-visible::before,
.icon-control[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.profile-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.theme-toggle,
.profile-button {
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--ink);
}

.theme-toggle:hover:not(:disabled),
.theme-toggle[aria-pressed="true"],
.profile-button:hover:not(:disabled),
.profile-button[aria-expanded="true"] {
  border-color: rgba(37, 99, 235, 0.36);
  background: var(--panel-2);
  color: var(--ink);
}

.theme-icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-icon-sun {
  display: block;
}

.profile-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 40;
  display: grid;
  gap: 14px;
  width: min(330px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 92px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}

.profile-panel-header {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 12px;
}

.avatar-swatch {
  --avatar-bg: var(--success-bg);
  --avatar-ink: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--avatar-bg);
  color: var(--avatar-ink);
  font-weight: 900;
  letter-spacing: 0;
}

.avatar-swatch[data-avatar-key="cat"] {
  --avatar-bg: linear-gradient(135deg, #facc15, #fb923c);
  --avatar-ink: #172033;
}

.avatar-swatch[data-avatar-key="dog"] {
  --avatar-bg: linear-gradient(135deg, #94a3b8, #475569);
  --avatar-ink: #ffffff;
}

.avatar-swatch[data-avatar-key="fox"] {
  --avatar-bg: linear-gradient(135deg, #fb7185, #f97316);
  --avatar-ink: #ffffff;
}

.avatar-swatch[data-avatar-key="panda"] {
  --avatar-bg: linear-gradient(135deg, #f8fbff, #cbd5e1);
  --avatar-ink: #172033;
}

:root[data-theme="dark"] .avatar-swatch[data-avatar-key="panda"] {
  --avatar-bg: linear-gradient(135deg, #e8eef8, #94a3b8);
}

.avatar-swatch[data-avatar-key="owl"] {
  --avatar-bg: linear-gradient(135deg, #a78bfa, #60a5fa);
  --avatar-ink: #ffffff;
}

.avatar-swatch[data-avatar-key="rabbit"] {
  --avatar-bg: linear-gradient(135deg, #f0abfc, #f9a8d4);
  --avatar-ink: #172033;
}

.avatar-swatch svg {
  width: 74%;
  height: 74%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.avatar-swatch .avatar-dot {
  fill: currentColor;
  stroke: none;
}

.profile-avatar {
  width: 44px;
  height: 44px;
  font-size: 0.82rem;
}

.profile-panel h2 {
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-panel-header [data-profile-id] {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-close {
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--muted);
}

.profile-close svg {
  width: 18px;
  height: 18px;
}

.avatar-picker {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  padding: 12px;
}

.avatar-picker-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.avatar-picker-heading strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.avatar-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--control-bg);
  box-shadow: none;
  padding: 0;
}

.avatar-option:hover:not(:disabled),
.avatar-option.active {
  border-color: rgba(37, 99, 235, 0.44);
  background: var(--info-bg);
}

.avatar-option:disabled {
  opacity: 0.68;
}

.avatar-option .avatar-swatch {
  width: 34px;
  height: 34px;
  font-size: 0.68rem;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
}

.profile-stats > div {
  min-width: 0;
  padding: 12px;
}

.profile-stats > div:nth-child(2n) {
  border-left: 1px solid var(--line);
}

.profile-stats > div:nth-child(n + 3) {
  border-top: 1px solid var(--line);
}

.profile-stats strong {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  font-size: 1.2rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-confirm {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  padding: 12px;
}

.account-confirm-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-confirm-heading strong {
  color: var(--ink);
  font-size: 0.84rem;
  white-space: nowrap;
}

.account-form {
  display: grid;
  gap: 10px;
}

.account-form input {
  min-height: 40px;
}

.account-form button {
  width: 100%;
  min-height: 40px;
}

.profile-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
}

.leave-room-button {
  border: 1px solid rgba(225, 29, 72, 0.28);
  background: var(--danger-bg);
  color: var(--red);
}

.leave-room-button:hover:not(:disabled) {
  border-color: var(--red);
  background: var(--red);
  color: var(--on-accent);
}

.copy-room-link-button {
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
}

.copy-room-link-button:hover:not(:disabled) {
  background: var(--blue);
}

.room-settings-button:disabled {
  border-color: var(--line);
  background: var(--disabled-bg);
  color: var(--disabled-ink);
  opacity: 1;
}

.room-member-count {
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--ink);
}

.player-count-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  border: 2px solid var(--badge-border);
  border-radius: 999px;
  background: var(--green);
  color: var(--on-accent);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  padding: 0 4px;
  white-space: nowrap;
}

.join-bar {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(150px, 1fr) auto auto auto;
  gap: 12px;
  align-items: end;
}

label span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.player-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 70px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  padding: 14px;
}

.player-slot.active {
  border-color: rgba(23, 178, 106, 0.38);
  border-left-color: var(--green);
  background: var(--success-bg);
}

.player-slot strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-slot span {
  color: var(--muted);
  flex: 0 0 auto;
  font-weight: 750;
}

.room-avatars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  min-height: 104px;
}

.room-avatar-player {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 92px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.room-avatar-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
}

.room-avatar-swatch {
  width: 56px;
  height: 56px;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.room-avatar-player strong {
  max-width: 100px;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-avatar-player span:not(.room-avatar-host-star) {
  color: var(--muted);
}

.room-avatar-host-star {
  position: absolute;
  top: -15px;
  left: 50%;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--badge-border);
  border-radius: 999px;
  background: var(--yellow);
  color: #172033;
  transform: translateX(-50%);
}

.room-avatar-host-star svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
  stroke: currentColor;
  stroke-linejoin: round;
  stroke-width: 1.4;
}

.room-avatar-kick {
  position: absolute;
  top: -7px;
  right: -9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  min-width: 26px;
  height: 26px;
  min-height: 26px;
  border: 2px solid var(--badge-border);
  border-radius: 999px;
  background: var(--danger-bg);
  box-shadow: 0 8px 16px rgba(225, 29, 72, 0.18);
  color: var(--red);
  padding: 0;
}

.room-avatar-kick:hover:not(:disabled),
.room-avatar-kick:focus-visible {
  background: var(--red);
  color: var(--on-accent);
}

.room-avatar-kick svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2.2;
}

.turn-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
}

.turn-strip > div {
  min-width: 0;
  padding: 14px;
}

.turn-strip > div + div {
  border-left: 1px solid var(--line);
}

.turn-strip strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
}

.word-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  padding: 12px 14px;
}

.word-list strong {
  min-width: 0;
  color: var(--blue);
  font-size: 1.04rem;
  overflow-wrap: anywhere;
}

.word-list span,
.empty-row {
  color: var(--muted);
  font-weight: 700;
}

.word-entry,
.chat-entry,
.password-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.play-surface .word-entry {
  grid-template-columns: minmax(0, 1fr);
}

.word-prompt {
  display: block;
  min-height: 1.4em;
  color: var(--ink);
  font-size: 1.18rem;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}

.round-timer {
  display: grid;
  gap: 7px;
  width: min(420px, 100%);
  justify-self: center;
}

.round-timer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.round-timer-meta strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.round-timer-track {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: var(--timer-track);
}

.round-timer-bar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition:
    width 120ms linear,
    background 160ms ease;
}

.round-timer[data-mode="urgent"] .round-timer-bar {
  background: var(--red);
}

.word-input-wrap {
  position: relative;
  min-width: 0;
}

.play-surface .word-input-wrap input {
  min-height: 76px;
  border-width: 2px;
  font-size: 1.3rem;
  font-weight: 800;
  padding-left: 76px;
  padding-right: 76px;
  text-align: center;
}

.play-surface .word-submit-button {
  position: absolute;
  top: 50%;
  right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  min-width: 54px;
  height: 54px;
  min-height: 54px;
  padding: 0;
  transform: translateY(-50%);
  transition:
    background 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.word-submit-button svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.play-surface .word-submit-button:active:not(:disabled) {
  transform: translateY(-50%) scale(0.95);
}

.play-surface .word-submit-button.is-loading:disabled {
  cursor: progress;
  opacity: 1;
}

.word-submit-button.is-loading svg {
  opacity: 0;
  transform: scale(0.7);
}

.word-submit-button.is-loading::after {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid rgba(255, 255, 255, 0.38);
  border-top-color: #ffffff;
  border-radius: 50%;
  content: "";
  animation: submit-spin 700ms linear infinite;
}

@keyframes submit-spin {
  to {
    transform: rotate(360deg);
  }
}

.notice {
  min-height: 22px;
  color: var(--red);
  font-weight: 760;
  opacity: 0;
  transition: opacity 160ms ease;
}

.notice.visible {
  opacity: 1;
}

#notice {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 80;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  min-height: 0;
  color: var(--ink);
  opacity: 1;
  pointer-events: none;
}

.notice-toast {
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--toast-shadow);
  color: var(--ink);
  font-weight: 800;
  line-height: 1.35;
  opacity: 0;
  overflow-wrap: anywhere;
  padding: 12px 14px;
  transform: translateY(-8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.notice-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.chat-surface {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 720px;
  padding: 16px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.chat-header span {
  overflow: hidden;
  color: var(--muted);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-log {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  padding: 14px 2px;
}

.chat-message {
  display: grid;
  gap: 3px;
  max-width: 90%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  padding: 10px 12px;
}

.chat-message.mine {
  justify-self: end;
  border-color: rgba(23, 178, 106, 0.28);
  background: var(--success-bg);
}

.chat-message strong {
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-message span {
  overflow-wrap: anywhere;
}

.floating-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
}

.floating-chat-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  min-width: 58px;
  height: 58px;
  min-height: 58px;
  border-radius: 999px;
  background: var(--blue);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.28);
  padding: 0;
}

.floating-chat-toggle:hover:not(:disabled) {
  background: var(--blue);
}

.floating-chat-toggle svg,
.floating-chat-close svg,
.floating-chat-form button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.floating-chat-online-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border: 2px solid var(--badge-border);
  border-radius: 999px;
  background: var(--green);
  color: var(--on-accent);
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1;
  padding: 0 6px;
}

.floating-chat-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  width: min(360px, calc(100vw - 28px));
  height: min(520px, calc(100vh - 112px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--chat-shadow);
}

.floating-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
}

.floating-chat-header strong {
  font-size: 1rem;
}

.floating-chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--ink);
  box-shadow: none;
  padding: 0;
}

.floating-chat-close:hover:not(:disabled) {
  border-color: rgba(37, 99, 235, 0.36);
  background: var(--panel-2);
  color: var(--ink);
}

.floating-chat-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 10px;
}

.floating-chat-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--control-bg);
  color: var(--muted);
  box-shadow: none;
  padding: 0 12px;
}

.floating-chat-tab:hover:not(:disabled),
.floating-chat-tab.active {
  border-color: rgba(37, 99, 235, 0.32);
  background: var(--info-bg);
  color: var(--blue);
}

.floating-chat-tab strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--disabled-bg);
  color: var(--ink);
  font-size: 0.74rem;
  line-height: 1;
  padding: 0 6px;
}

.floating-chat-tab.active strong {
  background: var(--blue);
  color: var(--on-accent);
}

.floating-chat-log {
  display: grid;
  align-content: start;
  gap: 9px;
  overflow: auto;
  min-height: 0;
  background: var(--soft-panel);
  padding: 12px;
}

.floating-chat-message {
  display: grid;
  gap: 3px;
  max-width: 88%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  padding: 9px 11px;
}

.floating-chat-message.mine {
  justify-self: end;
  border-color: rgba(23, 178, 106, 0.32);
  background: var(--success-bg);
}

.floating-chat-message-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.floating-chat-message-meta strong {
  color: var(--muted);
  font-size: 0.76rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.floating-chat-message-meta time {
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 800;
}

.floating-chat-message span {
  overflow-wrap: anywhere;
}

.floating-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 10px;
}

.floating-chat-form input {
  min-height: 42px;
}

.floating-chat-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
}

.room-dialog {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
}

.room-dialog-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 0;
  background: var(--overlay);
  box-shadow: none;
}

.room-dialog-backdrop:hover:not(:disabled) {
  background: var(--overlay-hover);
}

.room-dialog-panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 16px;
  overflow: auto;
  width: min(560px, 100%);
  max-height: min(780px, calc(100vh - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.room-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.room-full-panel {
  width: min(420px, 100%);
}

.room-full-message {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.5;
}

.room-full-panel button {
  justify-self: end;
}

.room-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
}

.room-details > div {
  min-width: 0;
  padding: 12px;
}

.room-details > div + div {
  border-left: 1px solid var(--line);
}

.room-details strong {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  padding: 12px;
}

.settings-block strong {
  display: block;
  margin-top: 4px;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  padding: 4px;
}

.segment-button {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  padding: 0 12px;
}

.segment-button:hover:not(:disabled),
.segment-button.active {
  background: var(--blue);
  color: var(--on-accent);
}

.room-dialog-panel .word-list {
  max-height: 220px;
}

.room-dialog-panel .chat-surface {
  min-height: 320px;
  box-shadow: none;
}

.locked-room {
  width: min(520px, 100%);
  margin: 60px auto 0;
  padding: 24px;
}

.locked-room p {
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 900px) {
  .mode-grid,
  .game-guide,
  .create-room-layout,
  .room-details {
    grid-template-columns: 1fr;
  }

  .room-details > div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .ranking-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .ranking-row span {
    white-space: normal;
  }
}

@media (max-width: 760px) {
  :root {
    --wide-shell-width: min(100% - 20px, 720px);
    --home-shell-width: min(100% - 20px, 720px);
  }

  .site-header,
  .home-shell,
  .app-shell {
    padding-top: 14px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar-actions,
  .connection-status {
    justify-self: start;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .theme-toggle {
    margin-left: auto;
  }

  .game-surface,
  .chat-surface {
    min-height: 580px;
  }

  .join-bar,
  .settings-block,
  .active-room-row,
  .how-to-play,
  .turn-strip,
  .players,
  .word-entry,
  .chat-entry,
  .password-form {
    grid-template-columns: 1fr;
  }

  .room-action-center {
    grid-template-columns: repeat(4, 44px);
    gap: 10px;
  }

  .floating-chat {
    right: 14px;
    bottom: 14px;
  }

  .floating-chat-panel {
    bottom: 68px;
    width: calc(100vw - 28px);
    height: min(500px, calc(100vh - 96px));
  }

  .play-surface .word-input-wrap input {
    min-height: 64px;
    font-size: 1.08rem;
    padding-left: 64px;
    padding-right: 64px;
  }

  .play-surface .word-submit-button {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
  }

  .word-prompt {
    font-size: 1rem;
  }

  .turn-strip > div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .active-room-action {
    width: 100%;
  }
}
