/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --ink: #14161A;
  --panel: #1C1F24;
  --panel-raised: #242830;
  --panel-line: #31363F;
  --steel: #AEB6C2;
  --steel-dim: #757C89;
  --paper: #F3F1EA;
  --orange: #E8722A;
  --orange-deep: #C75A18;
  --amber: #F0B429;
  --green: #3FA66B;
  --green-deep: #2C7A4E;
  --red: #D6483F;
  --red-deep: #A6332C;
  --blue-chalk: #5B8FB0;

  --font-display: "Oswald", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-deep: 0 18px 40px -12px rgba(0,0,0,0.55);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* faint diagonal hazard texture, very subtle, atelier floor feel */
.rivets-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 18px 18px, rgba(255,255,255,0.025) 1.6px, transparent 1.6px);
  background-size: 36px 36px;
  opacity: 0.6;
}

@media (prefers-reduced-motion: no-preference) {
  .pulse-on-enter { animation: fadeUp 0.45s ease both; }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

a { color: var(--orange); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: relative;
  z-index: 2;
  border-bottom: 3px solid var(--orange);
  background: linear-gradient(180deg, #1A1C20 0%, #15171B 100%);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { color: var(--orange); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-line1 {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--steel-dim);
  font-weight: 700;
}
.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 24px;
  letter-spacing: 0.01em;
  color: var(--paper);
  text-transform: uppercase;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.signature {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--steel);
  background: var(--panel-raised);
  border: 1px solid var(--panel-line);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
}
.signature strong { color: var(--amber); }

/* ============================================================
   GENERIC BUTTONS
   ============================================================ */
.ghost-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--paper);
  background: transparent;
  border: 1.5px solid var(--panel-line);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.ghost-btn:hover { border-color: var(--orange); color: var(--orange); }
.ghost-btn.small { padding: 6px 12px; font-size: 12.5px; }
.ghost-btn.danger:hover { border-color: var(--red); color: var(--red); }

.primary-btn {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 15px;
  color: var(--ink);
  background: var(--orange);
  border: none;
  padding: 13px 26px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: transform 0.12s, background 0.15s, box-shadow 0.15s;
  box-shadow: 0 6px 0 var(--orange-deep);
}
.primary-btn:hover { background: #F08038; }
.primary-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--orange-deep); }
.primary-btn:disabled {
  background: #4B4E54;
  box-shadow: 0 6px 0 #34363B;
  cursor: not-allowed;
  color: #8A8D93;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--steel);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.icon-btn:hover { color: var(--paper); }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
main#app {
  position: relative;
  z-index: 1;
  flex: 1;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.app-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--steel-dim);
  letter-spacing: 0.06em;
  border-top: 1px solid var(--panel-line);
}

/* ============================================================
   HOME / SETUP SCREEN
   ============================================================ */
.hero-panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow-deep);
  position: relative;
  overflow: hidden;
}
.hero-panel::before {
  content: "";
  position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(232,114,42,0.18), transparent 70%);
}
.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--orange);
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.hero-panel h2 {
  font-family: var(--font-display);
  font-size: 32px;
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}
.hero-panel p.lead {
  color: var(--steel);
  font-size: 15.5px;
  line-height: 1.6;
  max-width: 560px;
  margin: 0 0 28px;
}

.name-field {
  margin-bottom: 26px;
}
.name-field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--steel-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
}
.name-field input {
  width: 100%;
  max-width: 320px;
  background: var(--ink);
  border: 1.5px solid var(--panel-line);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s;
}
.name-field input:focus { border-color: var(--orange); }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.mode-card {
  background: var(--panel-raised);
  border: 1.5px solid var(--panel-line);
  border-radius: var(--radius-sm);
  padding: 18px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.1s;
  color: var(--paper);
  font-family: var(--font-body);
}
.mode-card:hover { border-color: var(--steel-dim); }
.mode-card.selected {
  border-color: var(--orange);
  background: linear-gradient(180deg, rgba(232,114,42,0.12), rgba(232,114,42,0.03));
}
.mode-card .mode-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--orange);
}
.mode-card .mode-title {
  font-weight: 800;
  font-size: 15.5px;
  margin: 6px 0 4px;
}
.mode-card .mode-desc {
  font-size: 12.5px;
  color: var(--steel-dim);
  line-height: 1.45;
}

.cat-section {
  margin-bottom: 28px;
}
.cat-section-title {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--steel-dim);
  text-transform: uppercase;
  margin-bottom: 12px;
}
.cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cat-chip {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--steel);
  background: var(--panel-raised);
  border: 1.5px solid var(--panel-line);
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cat-chip .count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--steel-dim);
}
.cat-chip.active {
  border-color: var(--orange);
  color: var(--orange);
  background: rgba(232,114,42,0.1);
}
.cat-chip.active .count { color: var(--orange); }

.start-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.start-hint {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--steel-dim);
}

/* ============================================================
   QUIZ SCREEN
   ============================================================ */
.quiz-wrap { display: flex; flex-direction: column; gap: 18px; }

.progress-rail {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}
.progress-track {
  flex: 1;
  height: 8px;
  background: var(--ink);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--orange-deep), var(--orange));
  border-radius: 999px;
  transition: width 0.35s ease;
}
.progress-label {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--steel);
  white-space: nowrap;
}
.progress-score {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--green);
  white-space: nowrap;
  font-weight: 700;
}

.question-card {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  overflow: hidden;
}
.question-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--panel-line);
  background: var(--panel-raised);
  flex-wrap: wrap;
}
.question-ref {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--orange);
  font-weight: 700;
  letter-spacing: 0.05em;
}
.question-cat {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--steel-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.question-body { padding: 26px 24px 24px; }

.question-img-wrap {
  margin: 0 0 20px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--panel-line);
  background: #0E0F11;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 320px;
}
.question-img-wrap img {
  width: 100%;
  height: 100%;
  max-height: 320px;
  object-fit: contain;
  display: block;
}

.question-text {
  font-size: 18.5px;
  font-weight: 600;
  line-height: 1.45;
  margin: 0 0 22px;
  color: var(--paper);
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  background: var(--panel-raised);
  border: 1.5px solid var(--panel-line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  color: var(--paper);
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--steel-dim);
  transform: translateX(2px);
}
.option-btn:disabled { cursor: default; }
.option-letter {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--ink);
  border: 1.5px solid var(--panel-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--steel);
}
.option-btn.correct {
  border-color: var(--green);
  background: linear-gradient(90deg, rgba(63,166,107,0.16), rgba(63,166,107,0.04));
}
.option-btn.correct .option-letter { background: var(--green); border-color: var(--green); color: var(--ink); }
.option-btn.wrong {
  border-color: var(--red);
  background: linear-gradient(90deg, rgba(214,72,63,0.16), rgba(214,72,63,0.04));
}
.option-btn.wrong .option-letter { background: var(--red); border-color: var(--red); color: var(--ink); }
.option-btn.dim { opacity: 0.45; }

.option-mark {
  margin-left: auto;
  font-size: 18px;
  font-weight: 800;
  flex-shrink: 0;
}
.option-mark.ok { color: var(--green); }
.option-mark.ko { color: var(--red); }

.feedback-panel {
  margin-top: 20px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--panel-line);
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.feedback-panel.ok { border-color: var(--green); background: rgba(63,166,107,0.08); }
.feedback-panel.ko { border-color: var(--red); background: rgba(214,72,63,0.08); }
.feedback-stamp {
  flex-shrink: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 5px;
  border: 2px solid currentColor;
  transform: rotate(-4deg);
}
.feedback-panel.ok .feedback-stamp { color: var(--green); }
.feedback-panel.ko .feedback-stamp { color: var(--red); }
.feedback-text { font-size: 14.5px; line-height: 1.55; color: var(--steel); }
.feedback-text strong { color: var(--paper); }

.question-footer {
  display: flex;
  justify-content: flex-end;
  padding: 18px 24px 24px;
}

/* ============================================================
   RESULTS SCREEN
   ============================================================ */
.results-panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  padding: 40px 32px;
  text-align: center;
}
.results-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--steel-dim);
  text-transform: uppercase;
  margin-bottom: 14px;
}
.results-score-big {
  font-family: var(--font-display);
  font-size: 76px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
}
.results-score-big.tier-gold { color: var(--amber); }
.results-score-big.tier-green { color: var(--green); }
.results-score-big.tier-orange { color: var(--orange); }
.results-score-big.tier-red { color: var(--red); }
.results-sub {
  font-size: 15px;
  color: var(--steel);
  margin-bottom: 28px;
}
.results-stamp-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}
.stat-pill {
  background: var(--panel-raised);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius-sm);
  padding: 14px 22px;
  min-width: 110px;
}
.stat-pill .num { font-family: var(--font-mono); font-size: 24px; font-weight: 700; display:block; }
.stat-pill .lbl { font-size: 11.5px; color: var(--steel-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-pill.ok .num { color: var(--green); }
.stat-pill.ko .num { color: var(--red); }
.stat-pill.time .num { color: var(--blue-chalk); }

.results-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.review-list {
  margin-top: 36px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.review-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel-raised);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.review-item .dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}
.review-item.ok .dot { background: var(--green); }
.review-item.ko .dot { background: var(--red); }
.review-item .ritext { color: var(--steel); flex: 1; }
.review-item .ritext strong { color: var(--paper); font-weight: 600;}

/* ============================================================
   MODAL / LEADERBOARD
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8,9,11,0.72);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] {
  display: none !important;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  padding: 26px;
  box-shadow: var(--shadow-deep);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.modal-head h2 {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 21px;
  margin: 0;
}
.modal-sub {
  color: var(--steel-dim);
  font-size: 13px;
  margin: 0 0 18px;
}
.leaderboard-body { display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-raised);
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-line);
}
.lb-rank {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--steel-dim);
  width: 24px;
  flex-shrink: 0;
}
.lb-row:nth-child(1) .lb-rank { color: var(--amber); }
.lb-row:nth-child(2) .lb-rank { color: var(--steel); }
.lb-row:nth-child(3) .lb-rank { color: var(--orange-deep); }
.lb-name { font-weight: 700; flex: 1; }
.lb-meta { font-family: var(--font-mono); font-size: 12px; color: var(--steel-dim); }
.lb-score { font-family: var(--font-mono); font-weight: 700; color: var(--green); }
.modal-actions { margin-top: 18px; display: flex; justify-content: flex-end; }
.empty-state { color: var(--steel-dim); font-size: 13.5px; padding: 18px 0; text-align: center; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  .hero-panel { padding: 26px 20px; }
  .hero-panel h2 { font-size: 25px; }
  .brand-text h1 { font-size: 18px; }
  .results-score-big { font-size: 56px; }
  .question-text { font-size: 16.5px; }
  .topbar-inner { padding: 14px 16px; }
  .signature { display: none; }
}
