/* =========================================================
   WhoDis — Visual Style Guide Implementation
   Editorial luxury × modern product clarity
   ========================================================= */

:root {
  /* Core Palette */
  --obsidian:  #000004;
  --forest:    #1D402D;
  --ivory:     #FFF9EC;
  --ivory-mid: #F5EDDA;   /* slightly darker warm neutral */
  --cedar:     #A85527;
  --gold:      #E4A030;

  /* Semantic aliases */
  --color-bg:           var(--ivory);
  --color-surface:      #FFFDF5;
  --color-surface-alt:  var(--ivory-mid);
  --color-primary:      var(--forest);
  --color-primary-text: var(--ivory);
  --color-text:         var(--obsidian);
  --color-text-muted:   rgba(0,0,4,0.45);
  --color-border:       rgba(0,0,4,0.10);
  --color-success:      var(--forest);
  --color-error:        var(--cedar);
  --color-reward:       var(--gold);

  /* Typography */
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Spacing */
  --radius:    14px;
  --radius-sm:  8px;
  --radius-pill: 999px;
  --shadow:    0 1px 4px rgba(0,0,4,0.07), 0 2px 12px rgba(0,0,4,0.05);
  --shadow-lg: 0 4px 24px rgba(0,0,4,0.12);
  --transition: 0.15s ease;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---- Typography ---- */
h1, h2 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
}
h3 { font-family: var(--font-sans); font-weight: 600; }

h1 { font-size: clamp(1.8rem, 5vw, 2.4rem); }
h2 { font-size: clamp(1.2rem, 3vw, 1.5rem); }

a { color: var(--forest); text-decoration: none; }

/* ---- Card ---- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  margin-bottom: 1rem;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  gap: 0.4rem;
  letter-spacing: 0.01em;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary  { background: var(--forest); color: var(--ivory); }
.btn-primary:hover:not(:disabled)  { background: #162f21; }

.btn-secondary {
  background: transparent;
  color: var(--forest);
  border: 1.5px solid var(--forest);
}
.btn-secondary:hover:not(:disabled) { background: rgba(29,64,45,0.06); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover:not(:disabled) { color: var(--color-text); }

.btn-large { padding: 1rem 2rem; font-size: 1rem; width: 100%; border-radius: var(--radius-sm); }
.btn-sm    { padding: 0.35rem 0.75rem; font-size: 0.82rem; }

/* ---- Form ---- */
.form-group { margin-bottom: 1rem; }

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.8rem 1rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 1rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition);
}
input[type="text"]:focus,
input[type="password"]:focus { border-color: var(--forest); }

.hint      { color: var(--color-text-muted); font-size: 0.875rem; margin-bottom: 0.75rem; line-height: 1.5; }
.optional  { color: var(--color-text-muted); font-size: 0.82rem; font-weight: 400; }
.error-msg { color: var(--cedar); font-size: 0.875rem; margin-top: 0.5rem; }
.hidden    { display: none !important; }

/* ---- Attendee photo ---- */
.attendee-photo {
  width: 100%;
  max-width: 300px;
  height: 300px;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
  margin: 0 auto;
  background: var(--ivory-mid);
}

/* =========================================================
   Admin Page
   ========================================================= */
.admin-page {
  max-width: 580px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
}

.admin-header {
  text-align: center;
  margin-bottom: 2rem;
  padding-top: 0.5rem;
}
.admin-header h1 { color: var(--forest); }
.admin-header .subtitle { color: var(--color-text-muted); font-size: 0.9rem; font-weight: 400; }

.events-list,
.groups-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  max-height: 340px;
  overflow-y: auto;
}

.event-card,
.group-card {
  width: 100%;
  text-align: left;
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: border-color var(--transition), background var(--transition);
}
.event-card:hover,
.group-card:hover  { border-color: var(--forest); }
.event-card.selected,
.group-card.selected {
  border-color: var(--forest);
  background: rgba(29,64,45,0.05);
}
.event-name { font-weight: 600; }
.event-meta { color: var(--color-text-muted); font-size: 0.82rem; }

.share-box {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.share-box input { flex: 1; }

/* =========================================================
   Play / Join Page
   ========================================================= */
.play-page,
.leaderboard-page,
.tutorial-page {
  max-width: 460px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
}

.play-header {
  text-align: center;
  margin-bottom: 2rem;
}
.play-header h1 { color: var(--forest); margin-bottom: 0.25rem; }
.play-header .event-name { color: var(--color-text-muted); font-size: 0.9rem; }

.join-card { text-align: center; }
.join-card h2 { margin-bottom: 0.5rem; }
.join-card .hint { margin-bottom: 1.5rem; }
.join-card .form-group { text-align: left; margin-bottom: 1.25rem; }

/* =========================================================
   Game Page
   ========================================================= */
.game-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 600px;
  margin: 0 auto;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.game-header-left .event-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 500;
}

.phase-label {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--forest);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Progress bar — Gold fill */
.progress-bar-wrap { height: 3px; background: var(--color-border); }
.progress-bar {
  height: 100%;
  background: var(--gold);
  transition: width 0.35s ease;
}

.game-area {
  flex: 1;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
}

.loading {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---- Study Card ---- */
.study-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}
.study-photo-wrap { width: 100%; }
.study-info { text-align: center; }

.attendee-name {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--obsidian);
  margin-bottom: 0.3rem;
}
.attendee-title   { color: var(--color-text-muted); font-size: 0.9rem; margin-bottom: 0.15rem; }
.attendee-company { color: var(--color-text-muted); font-size: 0.85rem; }

/* ---- Mode instruction ---- */
.mode-instruction {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--obsidian);
  text-align: center;
  margin-bottom: 1.25rem;
  line-height: 1.2;
}

/* ---- Photo wrap ---- */
.photo-wrap { display: flex; justify-content: center; margin-bottom: 1.5rem; }

/* ---- Mode 1: Classic ---- */
.mode-classic { display: flex; flex-direction: column; }

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.option-btn {
  padding: 1rem 0.6rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  text-align: center;
  line-height: 1.3;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.option-btn:hover:not(:disabled) { border-color: var(--forest); }
.option-btn.correct { background: var(--forest); color: var(--ivory); border-color: var(--forest); }
.option-btn.wrong   { background: var(--cedar);  color: var(--ivory); border-color: var(--cedar); }

/* ---- Mode 2: Reverse ---- */
.mode-reverse { display: flex; flex-direction: column; }

.name-card {
  text-align: center;
  padding: 1.25rem;
  background: var(--ivory-mid);
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  border: 1px solid var(--color-border);
}
.name-card h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  margin-bottom: 0.25rem;
}

.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.photo-option {
  border: 2.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: none;
  padding: 0;
  aspect-ratio: 1;
  transition: border-color var(--transition);
}
.photo-option img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-option:hover:not(:disabled) { border-color: var(--forest); }
.photo-option.correct { border-color: var(--forest); }
.photo-option.wrong   { border-color: var(--cedar); }

/* ---- Mode 3: Lineup ---- */
.mode-lineup { display: flex; flex-direction: column; }
.lineup-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
  margin-top: -0.75rem;
}

.lineup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.lineup-col { display: flex; flex-direction: column; gap: 0.5rem; }

.lineup-item {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.lineup-photo { aspect-ratio: 1; overflow: hidden; padding: 0; }
.lineup-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lineup-name {
  padding: 0.75rem 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.83rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}

.lineup-item.selected    { border-color: var(--gold); background: rgba(228,160,48,0.08); }
.lineup-item.correct     { border-color: var(--forest); background: rgba(29,64,45,0.06); }
.lineup-item.wrong-flash { border-color: var(--cedar);  background: rgba(168,85,39,0.06); }
.lineup-item.matched     { opacity: 0.5; cursor: default; }

/* ---- Mode 4: Speed Round ---- */
.mode-speed { display: flex; flex-direction: column; }

.speed-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.speed-form input { flex: 1; }
.speed-form .btn  { white-space: nowrap; }

/* ---- Mode 5: Spot ---- */
.mode-spot {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.spot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
  width: 100%;
}
.spot-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
}
.spot-correct,
.spot-wrong {
  padding: 1.1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
}
.spot-correct { background: var(--forest); color: var(--ivory); }
.spot-wrong   { background: var(--cedar);  color: var(--ivory); }
.spot-correct:active,
.spot-wrong:active { transform: scale(0.97); }
.spot-correct:disabled,
.spot-wrong:disabled { opacity: 0.4; cursor: not-allowed; }

/* =========================================================
   Feedback Overlay
   ========================================================= */
.feedback-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
  animation: fadeIn 0.1s ease;
}
.feedback-correct { background: rgba(29,64,45,0.10); }
.feedback-wrong   { background: rgba(168,85,39,0.10); }

.feedback-content {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 300px;
  width: 90%;
}
.feedback-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  line-height: 1;
}
.feedback-text {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--obsidian);
  margin-bottom: 0.25rem;
  line-height: 1.3;
}
.feedback-photo {
  width: 90px;
  height: 90px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-top: 0.85rem;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =========================================================
   Leaderboard Overlay
   ========================================================= */
.lb-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,4,0.4);
  z-index: 50;
  display: flex;
  align-items: flex-end;
}
.lb-panel {
  background: var(--color-surface);
  width: 100%;
  max-height: 70vh;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
}
.lb-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
}
.lb-panel-header h2 { font-size: 1.1rem; }
.lb-content { overflow-y: auto; padding: 1rem 1.25rem; flex: 1; }

.lb-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.lb-table th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--color-border);
}
.lb-table td {
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-me {
  background: rgba(29,64,45,0.05);
  font-weight: 700;
}
.lb-me td:first-child { color: var(--gold); font-weight: 700; }

/* =========================================================
   Round Complete / All Done
   ========================================================= */
.round-complete,
.all-done {
  position: fixed;
  inset: 0;
  background: rgba(0,0,4,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 1.25rem;
}
.round-complete .card,
.all-done .card {
  max-width: 360px;
  width: 100%;
  text-align: center;
  padding: 2rem;
}
.round-complete h2,
.all-done h2 { margin-bottom: 0.5rem; }

.round-stats {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  margin: 1.5rem 0;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.stat-val {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--forest);
  line-height: 1;
}
.stat-lbl {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* =========================================================
   Tutorial
   ========================================================= */
.tutorial-steps {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.75rem;
}
.tutorial-step {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.1rem;
}
.step-icon { font-size: 1.3rem; flex-shrink: 0; width: 1.75rem; text-align: center; padding-top: 0.1rem; }
.tutorial-step h3 { margin-bottom: 0.2rem; font-size: 0.95rem; }
.tutorial-step p  { font-size: 0.875rem; color: var(--color-text-muted); }

/* =========================================================
   Leaderboard Page (standalone)
   ========================================================= */
.leaderboard-page .card { padding: 0; overflow: hidden; }
.leaderboard-page .lb-table th,
.leaderboard-page .lb-table td { padding: 0.75rem 1.25rem; }

/* =========================================================
   Tablet / Desktop (≥ 768px)
   ========================================================= */
@media (min-width: 768px) {
  .game-page { padding: 0; }
  .game-area { padding: 1.75rem 2rem; }

  .attendee-photo { max-width: 320px; height: 320px; }

  /* Classic: photo left, options right */
  .mode-classic {
    flex-direction: row;
    align-items: flex-start;
    gap: 2rem;
  }
  .mode-classic .photo-wrap { flex: 0 0 260px; margin-bottom: 0; }
  .mode-classic .mode-instruction { text-align: left; }
  .mode-classic .options-grid {
    flex: 1;
    grid-template-columns: 1fr;
    align-content: start;
    padding-top: 0.5rem;
  }

  /* Speed: photo left, input right */
  .mode-speed {
    flex-direction: row;
    align-items: flex-start;
    gap: 2rem;
  }
  .mode-speed .photo-wrap { flex: 0 0 260px; margin-bottom: 0; }
  .mode-speed > .mode-instruction { display: none; }
  .mode-speed .speed-form {
    flex: 1;
    flex-direction: column;
    margin-top: 3rem;
  }
  .mode-speed .speed-form input { width: 100%; }

  .lb-overlay { align-items: center; }
  .lb-panel {
    max-width: 480px;
    border-radius: var(--radius);
    max-height: 80vh;
    margin: auto;
  }

  .admin-page { padding: 2.5rem 1.5rem 5rem; }
  .play-page, .leaderboard-page, .tutorial-page { padding: 2.5rem 1.5rem 5rem; }
}
