/* ===========================================================
   Mensa Practice — Shared Stylesheet
   =========================================================== */

:root {
  --bg: #0f1419;
  --bg-card: #1a212b;
  --bg-card-hover: #232b37;
  --border: #2d3744;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #5eb1ff;
  --accent-glow: rgba(94, 177, 255, 0.15);
  --correct: #3fb950;
  --correct-glow: rgba(63, 185, 80, 0.18);
  --wrong: #f85149;
  --wrong-glow: rgba(248, 81, 73, 0.18);
  --gold: #ffd23f;
  --shape-fill: #e6edf3;
  --shape-stroke: #e6edf3;
  --shape-bg: #0f1419;

  --cat-01: #5eb1ff; /* figure */
  --cat-02: #b48bff; /* matrix */
  --cat-03: #ff8b9a; /* sequence */
  --cat-04: #ffd23f; /* logic */
  --cat-05: #4ade80; /* spatial */
  --cat-06: #fb923c; /* verbal */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
               "Noto Sans JP", sans-serif;
  background:
    radial-gradient(ellipse at top, #1a2533 0%, var(--bg) 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrapper {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.wrapper.wide { max-width: 1200px; }

/* === Header === */
.page-head { margin-bottom: 28px; }
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }

.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid var(--accent);
  font-weight: 600;
}
.subtitle { color: var(--text-muted); margin-top: 6px; font-size: 14px; }

/* === Progress board === */
.progress-board {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 20px 0 32px;
}
.progress-bar-outer {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--correct));
  width: 0%;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 999px;
}
.progress-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}
.score-chip {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 18px;
  color: var(--gold);
  background: rgba(255, 210, 63, 0.1);
  border: 1px solid rgba(255, 210, 63, 0.4);
  border-radius: 8px;
  padding: 6px 14px;
}

/* === Question card === */
.q-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 24px;
  position: relative;
  transition: border-color 0.3s;
}
.q-card.answered-correct {
  border-color: var(--correct);
  box-shadow: 0 0 0 1px var(--correct), 0 0 24px var(--correct-glow);
}
.q-card.answered-wrong {
  border-color: var(--wrong);
  box-shadow: 0 0 0 1px var(--wrong), 0 0 24px var(--wrong-glow);
}

.q-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.q-number {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.05em;
}
.q-title { font-size: 20px; font-weight: 600; margin: 0; flex: 1; }
.difficulty { display: inline-flex; gap: 2px; font-size: 12px; }
.star { color: var(--gold); }
.star.dim { color: #444; }

.q-prompt { margin: 0 0 24px; font-size: 15px; color: var(--text-muted); }
.q-prompt strong { color: var(--text); }

/* === Pattern row (SVG cells) === */
.pattern-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0.15));
  border-radius: 12px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}
.pattern-cell {
  width: 96px;
  height: 96px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.pattern-cell.unknown {
  border-style: dashed;
  border-color: var(--accent);
  background: var(--accent-glow);
}
.pattern-cell.unknown::before {
  content: "?";
  font-size: 40px;
  font-weight: 700;
  color: var(--accent);
}
.pattern-cell svg { width: 60%; height: 60%; }
.pattern-cell .full { width: 80%; height: 80%; }
.pattern-cell.numeric {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* === 3x3 Matrix === */
.matrix-3x3 {
  display: grid;
  grid-template-columns: repeat(3, 96px);
  gap: 12px;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0.15));
  border-radius: 12px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

/* === Choices === */
.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.choice {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  user-select: none;
  font-family: inherit;
  color: var(--text);
}
.choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}
.choice .choice-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}
.choice .choice-shape {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.choice .choice-text {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
  text-align: center;
}
.choice .choice-number {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.choice.correct { background: var(--correct-glow); border-color: var(--correct); }
.choice.correct .choice-label { color: var(--correct); }
.choice.wrong { background: var(--wrong-glow); border-color: var(--wrong); }
.choice.wrong .choice-label { color: var(--wrong); }
.choice:disabled { cursor: default; }
.choice.disabled-ghost { opacity: 0.4; }

/* === Result + Explanation === */
.result {
  margin-top: 24px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.5s ease, opacity 0.3s 0.1s ease, margin 0.3s;
}
.result.show { max-height: 3000px; opacity: 1; }

.result-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 10px;
  font-weight: 600;
  margin-bottom: 14px;
}
.result-banner.ok {
  background: var(--correct-glow);
  color: var(--correct);
  border: 1px solid var(--correct);
}
.result-banner.ng {
  background: var(--wrong-glow);
  color: var(--wrong);
  border: 1px solid var(--wrong);
}
.result-banner svg { width: 24px; height: 24px; flex-shrink: 0; }

.explanation {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 22px;
  font-size: 14px;
  line-height: 1.7;
}
.explanation h4 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.explanation ul { padding-left: 20px; margin: 8px 0; }
.explanation li { margin: 4px 0; }
.explanation .rule-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: 8px;
  margin: 8px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  flex-wrap: wrap;
}
.explanation .rule-arrow { color: var(--text-muted); }
.explanation .rule-final { color: var(--correct); font-weight: 700; }
.explanation .tip {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.retry-btn {
  margin-top: 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.retry-btn:hover { color: var(--text); border-color: var(--accent); }

/* === Summary === */
.summary-card {
  margin-top: 40px;
  padding: 24px;
  background: linear-gradient(135deg, rgba(94,177,255,0.06), rgba(63,185,80,0.06));
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
}
.summary-card h3 { margin: 0 0 6px; }
.summary-card p { color: var(--text-muted); margin: 0; font-size: 14px; }

/* === Legend === */
details.legend {
  margin-top: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 18px;
}
details.legend summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
}
details.legend[open] summary { color: var(--text); margin-bottom: 10px; }
details.legend ul { margin: 8px 0; padding-left: 20px; }
details.legend li { font-size: 13px; color: var(--text-muted); margin: 4px 0; }

/* === Animations === */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.choice.wrong { animation: shake 0.35s; }

@keyframes pop {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.result.show .result-banner { animation: pop 0.3s ease; }

/* ===========================================================
   Index page specific styles
   =========================================================== */
.hero {
  text-align: center;
  padding: 60px 20px 40px;
  position: relative;
}
.hero h1 {
  font-size: 42px;
  margin: 0 0 10px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}
.hero .lead {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto;
}
.hero .stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 28px;
  flex-wrap: wrap;
}
.hero .stat {
  text-align: center;
}
.hero .stat .num {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  display: block;
}
.hero .stat .lbl {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.section-title {
  font-size: 20px;
  margin: 48px 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 20px;
  background: var(--accent);
  border-radius: 2px;
}

/* Roadmap timeline */
.timeline {
  position: relative;
  padding-left: 28px;
  margin: 20px 0;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, var(--accent), var(--gold), var(--correct));
  border-radius: 2px;
}
.tl-item {
  position: relative;
  padding: 16px 20px;
  margin-bottom: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: transform 0.2s, border-color 0.2s;
}
.tl-item:hover { transform: translateX(4px); border-color: var(--accent); }
.tl-item::before {
  content: "";
  position: absolute;
  left: -27px;
  top: 22px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg);
  border: 3px solid var(--accent);
}
.tl-item .tl-phase { font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: 0.05em; }
.tl-item .tl-title { font-size: 16px; font-weight: 600; margin: 4px 0; }
.tl-item .tl-desc { font-size: 13px; color: var(--text-muted); margin: 0; }
.tl-item a { display: block; color: inherit; }

/* Subject grid */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.subject-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}
.subject-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--cat-color, var(--accent));
}
.subject-card:hover {
  transform: translateY(-4px);
  border-color: var(--cat-color, var(--accent));
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  text-decoration: none;
}
.subject-card .sc-icon {
  width: 48px;
  height: 48px;
  background: var(--bg);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.subject-card .sc-icon svg { width: 28px; height: 28px; color: var(--cat-color, var(--accent)); }
.subject-card .sc-num {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.1em;
}
.subject-card .sc-title { font-size: 17px; font-weight: 600; margin: 4px 0 6px; }
.subject-card .sc-desc { font-size: 13px; color: var(--text-muted); margin: 0 0 12px; }
.subject-card .sc-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}
.subject-card .sc-freq { display: inline-flex; gap: 2px; }

/* Subject card wrapper + set selector */
.subject-card-wrap {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.subject-card-wrap .subject-card {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
}
.sc-sets {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 1px solid color-mix(in srgb, var(--cat-color, var(--accent)) 30%, var(--border));
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  overflow: hidden;
}
.sc-sets a {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.18s;
  border-right: 1px solid var(--border);
}
.sc-sets a:last-child { border-right: none; }
.sc-sets a:hover {
  background: var(--cat-color, var(--accent));
  color: var(--bg);
  text-decoration: none;
}

/* Test info panel */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.info-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.info-tile .ti-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.info-tile .ti-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.info-tile .ti-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Resource cards */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.resource-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.resource-card:hover {
  border-color: var(--accent);
  transform: translateX(4px);
  text-decoration: none;
}
.resource-card .rc-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-glow);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.resource-card .rc-title { font-size: 14px; font-weight: 600; margin: 0; }
.resource-card .rc-desc { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

/* CTA */
.cta {
  margin-top: 48px;
  padding: 32px;
  background: linear-gradient(135deg, rgba(94,177,255,0.1), rgba(255,210,63,0.06));
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
}
.cta h2 { margin: 0 0 8px; font-size: 22px; }
.cta p { color: var(--text-muted); margin: 0 0 20px; }
.cta .cta-btn {
  display: inline-block;
  padding: 12px 28px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 10px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.cta .cta-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(94,177,255,0.3);
  text-decoration: none;
}

/* === Set navigation (prev / next problem set) === */
.set-nav {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  flex-wrap: wrap;
}
.set-nav .nav-btn {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
}
.set-nav .nav-btn:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  text-decoration: none;
}
.set-nav .nav-btn.disabled {
  opacity: 0.35;
  pointer-events: none;
}
.set-nav .nav-btn.next { justify-content: flex-end; text-align: right; }
.set-nav .nav-btn .arrow {
  font-size: 20px;
  color: var(--accent);
}
.set-nav .nav-btn .nav-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.set-nav .nav-btn .nav-title {
  font-size: 14px;
  font-weight: 600;
}

/* === Set selector pills (top of problem page) === */
.set-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.set-pill {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  text-decoration: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-card);
  transition: all 0.18s;
}
.set-pill:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.set-pill.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 700;
}

footer.site-foot {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

@media (max-width: 600px) {
  .hero h1 { font-size: 32px; }
  .pattern-cell { width: 72px; height: 72px; }
  .matrix-3x3 { grid-template-columns: repeat(3, 72px); }
}
