/* Polished dark UI for the BaPsy-DGPs Lerntool. */
:root {
  --bg: #0d1117;
  --bg-elev-1: #151b24;
  --bg-elev-2: #1c2330;
  --bg-elev-3: #232c3b;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  --accent: #58a6ff;
  --accent-strong: #1f6feb;
  --accent-soft: rgba(88, 166, 255, 0.10);
  --green: #3fb950;
  --green-soft: rgba(63, 185, 80, 0.12);
  --red: #f85149;
  --red-soft: rgba(248, 81, 73, 0.10);
  --orange: #d29922;
  --orange-soft: rgba(210, 153, 34, 0.12);
  --border: #30363d;
  --border-soft: #21262d;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.25);
  --shadow: 0 4px 12px rgba(0,0,0,0.30);
  --transition: 0.18s ease;
}

* { box-sizing: border-box; }
*::selection { background: var(--accent-soft); }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #79b8ff; }

h1 { font-size: 28px; line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 8px; }
h2 { font-size: 20px; line-height: 1.3; font-weight: 650; letter-spacing: -0.01em; margin: 24px 0 12px; }
h3 { font-size: 16px; line-height: 1.35; font-weight: 600; margin: 0 0 6px; }
p  { margin: 0 0 12px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 28px;
  background: var(--bg-elev-1);
  border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(180%) blur(8px);
}
.topbar .brand {
  font-weight: 700; font-size: 15px; color: var(--text);
  letter-spacing: -0.01em; display: inline-flex; align-items: center; gap: 8px;
}
.topbar nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.topbar nav a {
  color: var(--text-muted);
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 14px; transition: background var(--transition), color var(--transition);
}
.topbar nav a:hover { color: var(--text); background: var(--bg-elev-2); }
.topbar nav .user {
  color: var(--text); font-size: 13px; padding-left: 12px; margin-left: 4px;
  border-left: 1px solid var(--border-soft);
  display: inline-flex; align-items: center; gap: 6px;
}
.topbar nav .logout {
  color: var(--text-dim);
  background: none; border: 0; cursor: pointer;
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit;
  transition: background var(--transition), color var(--transition);
}
.topbar nav .logout:hover { color: var(--red); background: var(--red-soft); }
.topbar nav .logout-form { margin: 0; padding: 0; display: inline; }

.container { max-width: 980px; margin: 32px auto 80px; padding: 0 24px; }
.foot { text-align: center; color: var(--text-dim); padding: 32px 24px; font-size: 12px; }

/* Cards */
.card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  background: var(--accent-strong); color: white; border: 1px solid transparent;
  cursor: pointer; font: inherit; font-weight: 600; font-size: 14px;
  text-decoration: none; user-select: none;
  transition: background var(--transition), transform 0.05s ease, box-shadow var(--transition), border-color var(--transition);
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: #2876f4; }
.btn:active { transform: translateY(1px); }
.btn.secondary {
  background: var(--bg-elev-3); color: var(--text);
  border-color: var(--border);
}
.btn.secondary:hover { background: #2c3848; border-color: var(--accent); color: var(--text); }
.btn.ghost {
  background: transparent; color: var(--text-muted); border-color: var(--border);
  box-shadow: none;
}
.btn.ghost:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #d8423b; }
.btn.large { padding: 12px 22px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
input[type=text], input[type=password], input[type=email], textarea, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit; font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, textarea:focus, select:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label {
  display: block; margin-bottom: 6px;
  color: var(--text-muted); font-size: 12px;
  font-weight: 500; letter-spacing: 0.02em;
}

/* Layout helpers */
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1 1 240px; }
.muted { color: var(--text-muted); }
.dim   { color: var(--text-dim); }
.right { text-align: right; }
.hr { height: 1px; background: var(--border-soft); margin: 16px 0; border: 0; }
.flash {
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 12px;
  font-size: 14px; border: 1px solid;
}
.flash.error { background: var(--red-soft); color: #ffb3b0; border-color: rgba(248,81,73,0.30); }
.flash.ok    { background: var(--green-soft); color: #95eaa6; border-color: rgba(63,185,80,0.30); }

/* Subtest grid (Home, Practice index) */
.subtest-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.subtest-card {
  padding: 18px; background: var(--bg-elev-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color var(--transition), transform var(--transition);
}
.subtest-card:hover { border-color: var(--border); }
.subtest-card h3 { font-size: 15px; }
.subtest-card .meta { color: var(--text-dim); font-size: 12px; line-height: 1.5; }

.progress {
  height: 4px; background: var(--bg-elev-3); border-radius: 999px; overflow: hidden;
}
.progress > div {
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  height: 100%; transition: width 0.4s ease;
}

/* Question view */
.question {
  background: var(--bg-elev-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 28px 30px;
}
.meta-line {
  color: var(--text-dim); font-size: 13px; margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.meta-line a { color: var(--text-muted); }
.meta-line a:hover { color: var(--accent); }

.question .stem {
  font-size: 16px; line-height: 1.65; white-space: pre-line;
  color: var(--text); font-weight: 450;
}
.question .passage {
  background: var(--bg-elev-2);
  border-left: 3px solid var(--accent);
  padding: 16px 20px;
  margin-bottom: 20px;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  font-size: 14px; line-height: 1.6;
  color: var(--text);
}
.question .passage b { color: var(--text); font-weight: 600; }

.question .stem-image {
  display: block; max-width: 100%;
  margin: 16px 0;
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 8px;
  border: 1px solid var(--border-soft);
}

/* Options */
.options { list-style: none; padding: 0; margin: 22px 0 0; display: flex; flex-direction: column; gap: 8px; }
.options li { padding: 0; }
.options label {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg-elev-2);
  color: var(--text); font-size: 14px;
  line-height: 1.55;
  transition: border-color var(--transition), background var(--transition);
}
.options label:hover { border-color: var(--accent); background: var(--bg-elev-3); }
.options input[type=radio] {
  margin: 4px 0 0 0;
  accent-color: var(--accent-strong);
  flex: 0 0 auto;
}
.options .opt-letter {
  font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--text-muted); text-transform: lowercase;
  flex: 0 0 22px;
}
.options .opt-body {
  flex: 1 1 auto;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.options label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.options.review label.correct {
  border-color: rgba(63,185,80,0.50);
  background: var(--green-soft);
}
.options.review label.correct .opt-letter { color: var(--green); }
.options.review label.wrong {
  border-color: rgba(248,81,73,0.50);
  background: var(--red-soft);
}
.options.review label.wrong .opt-letter { color: var(--red); }
.options.review label.chosen { box-shadow: 0 0 0 2px var(--accent) inset; }

.opt-explain {
  display: block; font-size: 13px; color: var(--text-muted);
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border-soft);
  line-height: 1.55;
}

.actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 24px; align-items: center;
}
.actions .grow { flex: 1; }

/* Timer */
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 13px;
  padding: 4px 8px 4px 12px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  letter-spacing: 0.02em;
  display: inline-flex; align-items: center; gap: 8px;
  min-width: 86px; justify-content: space-between;
}
.timer.warn { color: var(--orange); border-color: rgba(210,153,34,0.40); }
.timer.crit { color: var(--red); border-color: rgba(248,81,73,0.40); animation: pulse 1.2s ease-in-out infinite; }
.timer.hidden-mode { color: var(--text-dim); }
.timer.hidden-mode .timer-value { font-size: 0; color: transparent; position: relative; min-width: 60px; }
.timer.hidden-mode .timer-value::before {
  content: "Timer aus"; font-size: 12px; font-weight: 500;
  color: var(--text-dim); position: absolute; left: 0; top: 50%; transform: translateY(-50%);
}
.timer .timer-value { display: inline-block; }

.timer-toggle {
  background: transparent; border: 0;
  color: var(--text-dim); cursor: pointer;
  padding: 2px 4px;
  font-size: 12px; line-height: 1;
  display: inline-flex; align-items: center;
  border-radius: 999px;
  transition: background var(--transition), color var(--transition);
}
.timer-toggle:hover { color: var(--text); background: var(--bg-elev-3); }

@keyframes pulse {
  50% { opacity: 0.55; }
}

/* AI panel */
.ai-panel {
  margin-top: 24px;
  padding: 20px 22px;
  background: var(--bg-elev-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.ai-panel h3 {
  font-size: 14px; color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
}
.ai-msgs {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 360px; overflow-y: auto;
  padding: 8px 4px;
  margin-top: 8px;
}
.ai-msgs:empty { display: none; }
.ai-msg {
  padding: 10px 14px; border-radius: var(--radius-sm);
  max-width: 88%; white-space: pre-wrap;
  font-size: 14px; line-height: 1.55;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--accent-soft); color: var(--text);
  border: 1px solid rgba(88,166,255,0.20);
}
.ai-msg.assistant {
  align-self: flex-start;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
}
.ai-input { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.ai-input textarea { resize: vertical; min-height: 40px; max-height: 200px; }

/* Stats */
.summary-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.summary-row .stat {
  flex: 1 1 160px;
  padding: 14px 18px;
  background: var(--bg-elev-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.summary-row .stat b {
  display: block;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

/* Tables */
table {
  width: 100%; border-collapse: collapse;
  background: var(--bg-elev-1);
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border-soft);
}
table thead tr {
  background: var(--bg-elev-2);
  text-align: left;
}
table thead th {
  padding: 10px 14px; font-size: 12px;
  font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
table tbody tr { border-top: 1px solid var(--border-soft); }
table tbody td { padding: 10px 14px; font-size: 14px; }
table tbody tr:hover { background: var(--bg-elev-2); }

/* Subtest list (used in many places) */
.subtest-list { list-style: none; padding: 0; margin: 0; }
.subtest-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.subtest-list li:last-child { border-bottom: 0; }

/* Tags */
.tag {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-elev-3); color: var(--text-muted);
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase;
}
.tag.green  { background: var(--green-soft);  color: var(--green); }
.tag.red    { background: var(--red-soft);    color: var(--red); }
.tag.orange { background: var(--orange-soft); color: var(--orange); }

/* Detail block (for solution explanation) */
details summary { cursor: pointer; }
details summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: "▸ "; transition: transform var(--transition);
  display: inline-block; color: var(--text-dim);
}
details[open] > summary::before { content: "▾ "; }

/* Scrollbar (subtle) */
.ai-msgs::-webkit-scrollbar { width: 6px; }
.ai-msgs::-webkit-scrollbar-thumb { background: var(--bg-elev-3); border-radius: 999px; }

/* Responsive */
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .topbar nav { gap: 0; }
  .container { margin: 20px auto 60px; padding: 0 16px; }
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }
  .question { padding: 22px 18px; }
  .options label { padding: 10px 12px; grid-template-columns: 22px 1fr; gap: 8px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions .btn { justify-content: center; }
}

/* Small reset for the question stem image when it's a figural */
.question.has-figural .stem-image {
  background: #fafbfc;
  padding: 14px;
  margin-top: 18px;
}

/* ---------- Utility classes referenced by templates ---------- */
.small { font-size: 12px; }
.card.no-pad { padding: 4px 6px; }
.card-section-header { padding: 10px 14px 4px; margin: 0; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

.mode-row { margin-top: 8px; margin-bottom: 8px; }
.mode-card { display: flex; flex-direction: column; gap: 10px; padding: 22px; }
.mode-card h2 { margin: 0; font-size: 17px; }
.mode-card .actions { margin-top: 4px; }

.hint-box {
  background: var(--orange-soft);
  color: #f5d488;
  border: 1px solid rgba(210,153,34,0.30);
  padding: 11px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 14px; line-height: 1.55;
}
.hint-box .hint-icon { color: var(--orange); font-size: 16px; line-height: 1.2; }
.hint-text { font-size: 13px; }

/* Subtest-list inner content polish */
.subtest-list .list-stem { margin-left: 8px; }
.subtest-list .list-stem-body { margin-top: 4px; }

/* Simulation: list of questions inside a subtest run */
.sim-q { margin-bottom: 14px; }

/* Simulation index: form below table */
.sim-start { margin-top: 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sim-start-hint { font-size: 13px; }

/* Simulation result */
.result-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
}
.result-header h3 { margin: 0 0 4px; }
.result-score {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.result-score--good { color: var(--green); }
.result-score--mid  { color: var(--orange); }
.result-score--bad  { color: var(--red); }
.result-details { margin-top: 12px; }
.result-details summary { font-size: 13px; }
.result-details ul { margin-top: 8px; }
