:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #273549;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --danger: #ef4444;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.brand {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.room-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.hidden {
  display: none !important;
}

h1, h2, h3 {
  margin-top: 0;
}

.subtitle {
  color: var(--muted);
  line-height: 1.5;
}

.form-group {
  margin-bottom: 16px;
}

label, .label-small {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"], select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input[type="text"]:focus, select:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #06281e;
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #334155;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

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

.split-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.divider {
  text-align: center;
  position: relative;
  color: var(--muted);
  font-size: 0.85rem;
}

.join-row {
  display: flex;
  gap: 10px;
}

.join-row input {
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-align: center;
  max-width: 140px;
}

.join-row .btn {
  flex: 1;
}

.error-text {
  color: #f87171;
  margin-top: 12px;
  font-weight: 500;
}

.invite-banner {
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}

/* LOBBY */
.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.code-display {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.14em;
  color: var(--primary);
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 680px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge-host {
  font-size: 0.75rem;
  background: rgba(16, 185, 129, 0.2);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
}

.settings-box {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 12px;
}

.mode-desc {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.guest-mode-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

/* PLAYING */
.play-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.pill, .timer-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
}

.timer-pill.urgent {
  border-color: var(--danger);
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.15);
}

.story-history-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.story-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}

.story-history-item {
  padding-left: 10px;
  border-left: 3px solid var(--primary);
}

.prev-image-box {
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 16px;
  text-align: center;
}

.prev-image-box .label-small {
  color: #475569;
}

.prev-image-box img {
  max-width: 100%;
  max-height: 360px;
  border-radius: 8px;
}

.write-input-row {
  display: flex;
  gap: 8px;
}

@media (max-width: 540px) {
  .write-input-row {
    flex-direction: column;
  }
}

.prompt-banner {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
  text-align: center;
}

.prompt-banner-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.prompt-target {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}

.canvas-wrapper {
  position: relative;
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  width: 100%;
  aspect-ratio: 4 / 3;
}

#drawCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.onion-skin {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.28;
  pointer-events: none;
  user-select: none;
}

.peek-overlay {
  position: absolute;
  inset: 0;
  background: #ffffff;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.peek-header {
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
}

.peek-overlay img {
  width: 100%;
  flex: 1;
  object-fit: contain;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  background: var(--bg);
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-swatch.active {
  border-color: #fff;
  transform: scale(1.15);
}

.btn-tool {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-tool.active {
  background: var(--primary);
  color: #06281e;
  border-color: var(--primary);
}

.waiting-box {
  text-align: center;
  padding: 40px 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.9s linear infinite;
}

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

/* REVEAL */
.reveal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
  margin-bottom: 16px;
  gap: 10px;
  flex-wrap: wrap;
}

.flipbook-player {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
  text-align: center;
}

.flipbook-stage {
  background: #fff;
  border-radius: 10px;
  padding: 8px;
  display: inline-block;
  max-width: 100%;
}

.flipbook-stage img {
  max-width: 100%;
  max-height: 340px;
  display: block;
  border-radius: 6px;
}

.flipbook-caption {
  color: #334155;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 6px;
}

.flipbook-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.reveal-timeline {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
}

.reveal-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.reveal-author {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.reveal-text {
  font-size: 1.15rem;
  font-weight: 700;
}

.reveal-img {
  background: #fff;
  border-radius: 8px;
  max-width: 100%;
  max-height: 340px;
  display: block;
  margin-top: 6px;
}

.reveal-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.reveal-controls .btn-primary {
  flex: 2;
}

.active-color-dot {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background-color: #0f172a;
  border: 2px solid #f8fafc;
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.55);
  flex-shrink: 0;
}

#brushSizeGroup.dimmed {
  opacity: 0.45;
}

.guest-cat-tag {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.guest-cat-tag strong {
  color: var(--primary);
}

.random-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.category-mini-select {
  width: auto !important;
  padding: 10px 10px !important;
  font-size: 0.9rem !important;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

#randomDrawControls .category-mini-select {
  padding: 5px 8px !important;
  font-size: 0.85rem !important;
  border-radius: 8px;
}
