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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono {
  font-family: ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

.micro-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

/* Chrome */
.chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  padding-top: max(0.55rem, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.chrome-brand {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
}

.chrome-meta { color: var(--text-dim); font-size: 0.85rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius-panel);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--motion-fast), opacity var(--motion-fast);
}

.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn:disabled, .btn[disabled] {
  opacity: var(--disabled-opacity);
  pointer-events: none;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  min-height: 36px;
}

/* Home */
.home-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.home-hero {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

.home-hero h1 {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-tagline { color: var(--text-dim); margin-top: 0.5rem; font-size: 1.1rem; }

.convergence-motif {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 1.5rem auto;
  width: 200px;
  height: 40px;
  position: relative;
}

.convergence-motif::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 2px;
  background: var(--accent);
  opacity: 0.5;
}

.convergence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
  animation: converge 2s ease-in-out infinite;
}

.convergence-dot:nth-child(1) { animation-delay: 0s; }
.convergence-dot:nth-child(2) { animation-delay: 0.2s; }
.convergence-dot:nth-child(3) { animation-delay: 0.4s; }
.convergence-dot:nth-child(4) { animation-delay: 0.6s; }
.convergence-dot:nth-child(5) { animation-delay: 0.8s; }

@keyframes converge {
  0%, 100% { transform: translateY(-8px); opacity: 0.3; }
  50% { transform: translateY(0); opacity: 1; }
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.6rem 1.4rem;
  margin: 0 1rem 2rem;
  max-width: 480px;
  width: 100%;
  align-self: center;
}

.form-group { margin-bottom: 1.2rem; }
.form-group label { display: block; margin-bottom: 0.4rem; color: var(--text-dim); font-size: 0.9rem; }

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  color: var(--text);
  font-size: 1rem;
  min-height: 44px;
}

.form-input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.segmented {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.segmented input { display: none; }

.segmented label {
  flex: 1;
  min-width: 60px;
  text-align: center;
  padding: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--motion-fast), background var(--motion-fast);
}

.segmented input:checked + label {
  border-color: var(--accent);
  background: rgba(91, 141, 238, 0.1);
  color: var(--accent);
}

/* Shell layouts */
.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.shell-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}

.preview-strip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 50px;
}

.preview-value {
  flex: 1;
  font-family: ui-monospace, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-dim);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-value.has-value { color: var(--accent); }

.preview-error { color: var(--error); font-size: 0.85rem; }

.main-canvas {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  -webkit-overflow-scrolling: touch;
}

.context-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.context-section {
  padding: 0.75rem 1rem;
  overflow-y: auto;
}

.context-section + .context-section {
  border-top: 1px solid var(--border);
}

/* Player list */
.player-list { list-style: none; }
.player-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.player-row:last-child { border-bottom: none; }
.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.host-badge {
  font-size: 0.65rem;
  background: var(--accent);
  color: var(--bg);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 700;
}
.kick-btn {
  margin-left: auto;
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  line-height: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.kick-btn:hover {
  background: var(--danger, #ff1744);
  color: #fff;
  border-color: var(--danger, #ff1744);
}

/* Leaderboard */
.lb-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  font-size: 0.9rem;
}
.lb-row.first { background: rgba(91, 141, 238, 0.12); margin: 0 -0.5rem; padding: 0.4rem 0.5rem; border-radius: 6px; }
.lb-rank { width: 1.5rem; color: var(--text-dim); }
.lb-score { margin-left: auto; font-family: ui-monospace, monospace; }

/* Activity feed */
.activity-feed { list-style: none; font-size: 0.8rem; color: var(--text-dim); }
.activity-feed li { padding: 0.25rem 0; }

/* Timer */
.timer-bar-wrap {
  height: 4px;
  background: var(--surface2);
  flex-shrink: 0;
}
.timer-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
  position: relative;
}
.timer-bar.urgent { background: var(--error); }
.timer-display { font-family: ui-monospace, monospace; font-size: 1.1rem; font-weight: 700; }

/* Question */
.question-text {
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}
.question-hint { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 1rem; }

/* Bottom sheet (mobile) */
.sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
}
.sheet-backdrop.open { display: block; }

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--surface);
  border-radius: var(--radius-sheet);
  z-index: 101;
  transform: translateY(100%);
  transition: transform var(--motion-medium) ease;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0.75rem auto;
}

.context-fab {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 36px;
  padding: 0.3rem 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

/* Reveal overlay */
.reveal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 17, 23, 0.85);
  align-items: flex-end;
  justify-content: center;
}
.reveal-overlay.open { display: flex; }

.reveal-panel {
  background: var(--surface);
  border-radius: var(--radius-sheet);
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  animation: slideUp var(--motion-medium) ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.reveal-consensus {
  text-align: center;
  margin: 1rem 0;
  padding: 1rem;
  background: var(--surface2);
  border-radius: var(--radius-panel);
}

.reveal-footer {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.reveal-continue {
  width: 100%;
  max-width: 280px;
}

.reveal-waiting {
  color: var(--text-dim);
  font-size: 0.9rem;
}
.reveal-result-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.reveal-result-row .pts {
  margin-left: auto;
  font-family: ui-monospace, monospace;
  color: var(--success);
}

/* Toast */
.toast {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  z-index: 300;
  transition: transform var(--motion-medium) ease;
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Sticky footer */
.sticky-footer {
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sticky-footer .btn { width: 100%; }

/* Share link */
.share-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}
.share-url {
  flex: 1;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  padding: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-code {
  font-family: ui-monospace, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
}

.game-over-banner {
  background: var(--accent2);
  color: var(--text);
  text-align: center;
  padding: 0.75rem;
  font-weight: 700;
}

.canvas-frozen { pointer-events: none; opacity: 0.6; }

.flash-confirm {
  animation: flashConfirm var(--motion-celebratory) ease-out;
}

@keyframes flashConfirm {
  0% { transform: scale(1); }
  30% { transform: scale(1.15); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Desktop layout */
@media (min-width: 701px) {
  .shell-body {
    flex-direction: row;
  }

  .main-canvas {
    flex: 1;
  }

  .context-panel {
    width: var(--context-width);
    border-top: none;
    border-left: 1px solid var(--border);
  }

  .context-panel.sheet-mode {
    position: static;
    transform: none;
    max-height: none;
  }

  .context-fab { display: none; }
  .sheet-backdrop { display: none !important; }

  .reveal-overlay { align-items: center; }
  .reveal-panel {
    max-width: 640px;
    border-radius: var(--radius-card);
    max-height: 80vh;
  }

  .lobby-layout {
    display: grid;
    grid-template-columns: 1fr var(--context-width);
    flex: 1;
    overflow: hidden;
  }

  .sticky-footer.mobile-only { display: none; }
}

@media (max-width: 700px) {
  .context-panel.desktop-only { display: none; }
  .context-panel.mobile-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 60vh;
    z-index: 101;
    transform: translateY(100%);
    transition: transform var(--motion-medium) ease;
    border-radius: var(--radius-sheet);
  }
  .context-panel.mobile-sheet.open { transform: translateY(0); }
}
