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

:root {
  --bg:       #0f0f1e;
  --bg2:      #1a1a2e;
  --bg3:      #13132a;
  --border:   #2a2a45;
  --gold:     #e8c97a;
  --purple:   #9b8ec4;
  --green:    #7ecfa8;
  --text:     #d4c8f8;
  --muted:    #6b6b8a;
  --correct:  #1d6e4a;
  --present:  #8b6914;
  --absent:   #2a2a2a;
}

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

#app {
  max-width: 420px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 2rem;
}

/* Header */
header {
  background: var(--bg2);
  padding: 14px 16px 10px;
  text-align: center;
  border-bottom: 0.5px solid var(--border);
}
.logo { font-size: 22px; font-weight: 600; color: var(--gold); letter-spacing: 3px; }
.sub  { font-size: 11px; color: var(--purple); margin-top: 2px; }

/* Stats bar */
.stats-bar {
  display: flex;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
}
.stat-item { flex: 1; padding: 10px 14px; }
.stat-divider { width: 0.5px; background: var(--border); }
.stat-label { display: block; font-size: 10px; color: var(--purple); margin-bottom: 2px; }
.stat-label small { color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 600; letter-spacing: 2px; }
.countdown { color: var(--gold); font-variant-numeric: tabular-nums; }
.pool-val  { color: var(--green); }

/* Topic bar */
.topic-bar {
  display: flex;
  align-items: center;
  background: var(--bg3);
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--border);
  gap: 10px;
}
.topic-info { flex: 1; }
.topic-label { display: block; font-size: 10px; color: var(--purple); }
.topic-title { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-top: 1px; }
.topic-desc  { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; line-height: 1.4; }
.ticket-info { text-align: right; flex-shrink: 0; }
.ticket-label { display: block; font-size: 10px; color: var(--purple); }
.ticket-count { display: block; font-size: 20px; font-weight: 600; color: var(--gold); }
.ticket-total { display: block; font-size: 10px; color: var(--muted); }

/* Slot indicator */
.slot-indicator {
  text-align: center;
  padding: 5px 14px;
  font-size: 11px;
  color: var(--purple);
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
}

/* Board */
.board-wrap { padding: 14px 16px 8px; background: var(--bg); }
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  max-width: 230px;
  margin: 0 auto;
}
.cell {
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  border: 1.5px solid var(--border);
  background: var(--bg2);
  transition: background 0.15s, border-color 0.15s;
  text-transform: uppercase;
}
.cell.correct { background: var(--correct); border-color: var(--correct); }
.cell.present { background: var(--present); border-color: var(--present); }
.cell.absent  { background: var(--absent);  border-color: var(--absent); }
.cell.active  { border-color: #b0a0f0; background: #1e1e38; }
.cell.cursor  { border-color: var(--gold); }

/* Keyboard */
.keyboard { padding: 4px 10px 10px; background: var(--bg); }
.kb-row { display: flex; justify-content: center; gap: 4px; margin-bottom: 5px; }
.kb-key {
  min-width: 28px;
  padding: 10px 4px;
  border-radius: 4px;
  border: none;
  background: #2a2a45;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}
.kb-key.wide { min-width: 44px; font-size: 10px; }
.kb-key.correct { background: var(--correct); color: var(--green); }
.kb-key.present { background: var(--present); color: #f0c060; }
.kb-key.absent  { background: #1a1a1a; color: #444; }
.kb-key:active  { transform: scale(0.95); }

/* Participation grid */
.section-label {
  font-size: 10px;
  color: var(--purple);
  padding: 8px 14px 4px;
  background: var(--bg3);
  border-top: 0.5px solid var(--border);
  letter-spacing: 0.4px;
}
.part-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 0 12px 12px;
  background: var(--bg3);
}
.part-card {
  background: var(--bg2);
  border-radius: 8px;
  border: 0.5px solid var(--border);
  padding: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.part-card:hover:not(.disabled):not(.used-card) { border-color: var(--purple); }
.part-card.disabled { opacity: 0.45; cursor: not-allowed; }
.part-card.used-card { border-color: var(--correct); opacity: 0.75; }
.part-card.active-card { border-color: var(--gold); }
.part-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  margin-bottom: 6px;
}
.badge-free   { background: #1d3a2a; color: var(--green); }
.badge-ads    { background: #2a2414; color: #c4954a; }
.badge-pi2    { background: #1a1a38; color: var(--purple); }
.badge-pi5    { background: #2a1a2e; color: #c47eb8; }
.badge-used   { background: #1a2e1a; color: #5a9a6a; }
.badge-active { background: #2e2800; color: var(--gold); }
.part-title   { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.part-desc    { font-size: 10px; color: var(--muted); line-height: 1.4; }
.part-ticket  { font-size: 10px; color: var(--green); margin-top: 4px; }

/* Bottom buttons */
.bottom-btns {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg);
  border-top: 0.5px solid var(--border);
  margin-top: auto;
}
.btn-outline {
  flex: 1; padding: 10px 4px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: var(--purple);
  font-size: 12px;
  cursor: pointer;
}
.btn-outline:hover { background: var(--bg2); }
.btn-primary {
  flex: 1; padding: 10px 4px;
  border-radius: 8px;
  border: none;
  background: #2a1a4e;
  color: #c4a8f8;
  font-size: 12px;
  cursor: pointer;
}
.btn-primary:hover { background: #3a2a5e; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 20px 16px;
  overflow-y: auto;
}
.modal-box {
  background: var(--bg2);
  border-radius: 12px;
  border: 0.5px solid #3a3a5a;
  padding: 20px;
  width: 100%;
  max-width: 400px;
  margin: auto;
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-close {
  background: none;
  border: none;
  color: var(--purple);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.modal-body { font-size: 12px; color: #a0a0c0; line-height: 1.7; }
.modal-body p { margin-bottom: 8px; }
.modal-body strong { color: var(--text); font-weight: 600; }
.modal-body ul { padding-left: 14px; margin-bottom: 8px; }
.modal-body li { margin-bottom: 4px; }
.modal-body code { background: #0f0f1e; padding: 1px 5px; border-radius: 3px; font-size: 11px; color: var(--green); }
.modal-section { border-top: 0.5px solid var(--border); margin-top: 12px; padding-top: 12px; }
.disclaimer { font-size: 10px; color: var(--muted); margin-top: 10px; }
.note { font-size: 10px; color: var(--muted); }

.clue { padding: 1px 6px; border-radius: 3px; font-weight: 700; font-size: 11px; }
.correct-ex { background: var(--correct); color: var(--green); }
.present-ex { background: var(--present); color: #f0c060; }
.absent-ex  { background: var(--absent);  color: #888; }

/* Pay modal */
.pay-amount { font-size: 28px; font-weight: 700; color: var(--gold); text-align: center; margin: 10px 0 2px; }
.pay-sub { font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 14px; }
.terms-row { display: flex; gap: 8px; align-items: flex-start; margin: 14px 0 10px; }
.terms-row input { margin-top: 2px; accent-color: var(--purple); width: 14px; height: 14px; flex-shrink: 0; }
.terms-row label { font-size: 11px; color: #a0a0c0; line-height: 1.5; cursor: pointer; }
.btn-confirm {
  width: 100%; padding: 11px;
  border-radius: 8px; border: none;
  background: #4a3a8a; color: var(--text);
  font-size: 13px; font-weight: 600;
  cursor: pointer; opacity: 0.45;
  transition: opacity 0.15s;
}
.btn-confirm:not(:disabled) { opacity: 1; }
.btn-confirm:not(:disabled):hover { background: #5a4a9a; }

/* Resources links */
.resource-link {
  display: block;
  color: #7b9ec4;
  font-size: 12px;
  margin-bottom: 4px;
  text-decoration: none;
}
.resource-link:hover { text-decoration: underline; }

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  border: 1px solid var(--purple);
  border-radius: 8px;
  padding: 14px 24px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.toast.show { opacity: 1; }

/* Loading state */
.loading-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 300; flex-direction: column; gap: 12px;
}
.loading-logo { font-size: 36px; color: var(--gold); letter-spacing: 4px; }
.loading-sub  { font-size: 12px; color: var(--purple); }
