/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --bg:        #fdf6f0;
  --surface:   #ffffff;
  --surface2:  #f5ede6;
  --border:    #e8d5c8;
  --text:      #2d1f17;
  --text2:     #7a5c50;
  --primary:   #e8624a;
  --primary-h: #d44e38;
  --secondary: #9b6fd6;
  --accent:    #22c4c0;
  --success:   #34c97a;
  --warning:   #f5a623;
  --danger:    #e84a4a;
  --p1:        #e8624a;
  --p2:        #9b6fd6;
  --radius:    16px;
  --radius-sm: 8px;
  --shadow:    0 4px 24px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.14);
  --transition: .25s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0f0d14;
    --surface:  #1a1726;
    --surface2: #241f31;
    --border:   #2e2840;
    --text:     #f0e8ff;
    --text2:    #9a90b8;
    --shadow:   0 4px 24px rgba(0,0,0,.4);
    --shadow-lg:0 8px 40px rgba(0,0,0,.6);
  }
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  padding: 0 16px 32px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── Typography ──────────────────────────────────────────────────────────── */
h1 { font-size: 2rem; font-weight: 800; line-height: 1.1; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; }
.lead { font-size: 1.05rem; color: var(--text2); line-height: 1.5; }
.caption { font-size: .8rem; color: var(--text2); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
  min-height: 52px;
  min-width: 48px;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--primary); color: #fff; box-shadow: 0 4px 16px color-mix(in srgb, var(--primary) 40%, transparent); }
.btn-primary:hover  { background: var(--primary-h); }
.btn-secondary{ background: var(--secondary); color: #fff; box-shadow: 0 4px 16px color-mix(in srgb, var(--secondary) 30%, transparent); }
.btn-accent   { background: var(--accent); color: #fff; box-shadow: 0 4px 16px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn-ghost    { background: var(--surface2); color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-full     { width: 100%; }
.btn-sm       { padding: 8px 16px; font-size: .875rem; min-height: 36px; border-radius: var(--radius-sm); }
.btn-lg       { padding: 18px 32px; font-size: 1.1rem; min-height: 60px; border-radius: 20px; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-soft { background: var(--surface2); box-shadow: none; border: 1px solid var(--border); }

/* ── Card Flip Animation ─────────────────────────────────────────────────── */
.flip-container { perspective: 1000px; }
.flip-card {
  position: relative;
  transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.4,0,.2,1);
  width: 100%;
}
.flip-card.flipped { transform: rotateY(180deg); }
.flip-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
}
.flip-face.back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
}

/* ── Slide-in animation ──────────────────────────────────────────────────── */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.slide-in { animation: slideIn .3s ease forwards; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.fade-in { animation: fadeIn .3s ease forwards; }

@keyframes pulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}
.pulse { animation: pulse 1.5s ease-in-out infinite; }

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}
.header-inner {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-title { font-weight: 800; font-size: 1rem; flex: 1; }
.room-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--text2);
}

/* ── Player Indicators ───────────────────────────────────────────────────── */
.players-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.player-chip {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 2px solid transparent;
}
.player-chip.p1  { background: color-mix(in srgb, var(--p1) 15%, transparent); border-color: var(--p1); color: var(--p1); }
.player-chip.p2  { background: color-mix(in srgb, var(--p2) 15%, transparent); border-color: var(--p2); color: var(--p2); }
.player-chip.you { font-weight: 800; }
.player-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.player-score { margin-left: auto; font-size: .9rem; font-weight: 800; }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 3px;
  transition: width .4s ease;
}

/* ── Timer ───────────────────────────────────────────────────────────────── */
.timer-ring {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) var(--pct, 360deg), var(--surface2) 0deg);
  font-size: 1.5rem;
  font-weight: 800;
  position: relative;
  margin: 0 auto;
}
.timer-ring::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--surface);
}
.timer-ring span { position: relative; z-index: 1; }
.timer-urgent .timer-ring { background: conic-gradient(var(--danger) var(--pct, 360deg), var(--surface2) 0deg); }

/* ── Game card prompt ────────────────────────────────────────────────────── */
.prompt-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.prompt-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top right, rgba(255,255,255,.15), transparent 60%);
}
.prompt-card .prompt-level {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .8;
  margin-bottom: 16px;
}
.prompt-card .prompt-text {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.4;
  position: relative;
}

/* ── Choice buttons (WYR / This or That) ─────────────────────────────────── */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.choice-btn {
  padding: 20px 16px;
  border-radius: var(--radius);
  text-align: center;
  font-weight: 700;
  font-size: .95rem;
  line-height: 1.3;
  transition: all var(--transition);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.choice-btn:hover, .choice-btn.selected-a {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
}
.choice-btn.selected-b {
  background: color-mix(in srgb, var(--secondary) 15%, transparent);
  border-color: var(--secondary);
  color: var(--secondary);
  transform: translateY(-2px);
}
.choice-btn.revealed-winner { box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--text2); }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
.field textarea { resize: vertical; min-height: 100px; }

/* ── Emoji feeling cards ─────────────────────────────────────────────────── */
.feelings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.feeling-card {
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: .8rem;
  font-weight: 600;
}
.feeling-card .icon { font-size: 1.6rem; margin-bottom: 4px; }
.feeling-card.selected {
  border-color: var(--secondary);
  background: color-mix(in srgb, var(--secondary) 15%, transparent);
  transform: scale(1.04);
}

/* ── Game picker grid ────────────────────────────────────────────────────── */
.games-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.game-tile {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.game-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--primary); }
.game-tile:active { transform: scale(.97); }
.game-tile .game-icon { font-size: 2rem; }
.game-tile .game-name { font-size: .85rem; font-weight: 700; line-height: 1.2; }
.game-tile .game-tag  {
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.tag-question { background: color-mix(in srgb,var(--primary) 15%,transparent); color: var(--primary); }
.tag-romantic { background: color-mix(in srgb,#e84a7c 15%,transparent); color: #e84a7c; }
.tag-active   { background: color-mix(in srgb,var(--success) 15%,transparent); color: var(--success); }
.tag-party    { background: color-mix(in srgb,var(--warning) 15%,transparent); color: var(--warning); }
.tag-compete  { background: color-mix(in srgb,var(--secondary) 15%,transparent); color: var(--secondary); }
.tag-build    { background: color-mix(in srgb,var(--accent) 15%,transparent); color: var(--accent); }

/* ── Category section headers ────────────────────────────────────────────── */
.cat-header {
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text2);
  padding: 4px 0 8px;
  margin-top: 16px;
}

/* ── Score display ───────────────────────────────────────────────────────── */
.scores-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 16px 0;
}
.score-block {
  flex: 1;
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface2);
}
.score-num  { font-size: 2.5rem; font-weight: 900; }
.score-name { font-size: .85rem; font-weight: 600; color: var(--text2); }
.score-block.p1 .score-num { color: var(--p1); }
.score-block.p2 .score-num { color: var(--p2); }

/* ── Waiting dots ────────────────────────────────────────────────────────── */
@keyframes dot-bounce {
  0%,80%,100% { transform: scale(0); }
  40%          { transform: scale(1); }
}
.waiting-dots { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
.waiting-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  animation: dot-bounce 1.4s ease-in-out infinite;
}
.waiting-dots span:nth-child(2) { animation-delay: .16s; }
.waiting-dots span:nth-child(3) { animation-delay: .32s; }

/* ── Code display ────────────────────────────────────────────────────────── */
.code-display {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: .3em;
  color: var(--primary);
  text-align: center;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  padding: 20px;
  line-height: 1;
}

/* ── Landing page hero ───────────────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}
.hero-logo { font-size: 3.5rem; margin-bottom: 8px; }
.hero h1   { background: linear-gradient(135deg, var(--primary), var(--secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.hero .lead { margin: 12px 0 32px; }

/* ── Toggle ──────────────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  background: var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle.on { background: var(--secondary); }
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
}
.toggle.on::after { transform: translateX(20px); }

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 24px 0; }

/* ── Ranking drag/drop ───────────────────────────────────────────────────── */
.rank-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rank-item {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: grab;
  transition: all var(--transition);
  user-select: none;
}
.rank-item:active { cursor: grabbing; }
.rank-item.dragging { opacity: .5; }
.rank-item.drag-over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.rank-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .85rem;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── Bucket list ─────────────────────────────────────────────────────────── */
.bucket-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.bucket-item.done { opacity: .5; text-decoration: line-through; }
.bucket-votes { font-size: .8rem; color: var(--text2); margin-left: auto; flex-shrink: 0; }

/* ── Timeline ────────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 8px; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-entry {
  position: relative;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.timeline-entry::before {
  content: attr(data-emoji);
  position: absolute;
  left: -24px;
  top: 10px;
  font-size: 1.1rem;
}

/* ── Full-screen overlay ─────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  z-index: 200;
}
.sheet {
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 24px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  animation: slideIn .3s ease;
}

/* ── Misc helpers ────────────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--text2); }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.flex   { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ── Green/Yellow/Red colour tokens ──────────────────────────────────────── */
.green-zone { --zone: #34c97a; }
.yellow-zone { --zone: #f5c623; }
.red-zone    { --zone: #e84a4a; }
.zone-card {
  border: 2px solid var(--zone);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: color-mix(in srgb, var(--zone) 10%, transparent);
  margin-bottom: 10px;
}
.zone-label {
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--zone);
  margin-bottom: 6px;
}
