/* TU Wien Raumplanung - Dark Theme
   Brand: TU Wien blue #006699, accent #00a3e0
   Decision: D003 in docs/DECISIONS.md */

:root {
  --tu-blue: #006699;
  --tu-blue-light: #0088cc;
  --tu-accent: #00a3e0;
  --tu-dark: #1a1a2e;
  --tu-darker: #0f0f1e;
  --tu-surface: #16213e;
  --tu-surface-light: #1e2d4d;
  --tu-border: #2a3a5c;
  --tu-success: #4caf50;
  --tu-warning: #ff9800;
  --tu-error: #f44336;
  --tu-text: #e0e0e0;
  --tu-text-bright: #ffffff;
  --tu-text-muted: #9e9e9e;
  --tu-text-dim: #6c7a96;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--tu-darker);
  color: var(--tu-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Layout ---- */
.page-wrapper {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--tu-dark);
  border-right: 1px solid var(--tu-border);
  padding: 1.5rem 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-logo {
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid var(--tu-border);
  margin-bottom: 1rem;
}

.sidebar-logo h2 {
  color: var(--tu-accent);
  font-size: 1.1rem;
  font-weight: 600;
}

.sidebar-logo .subtitle {
  color: var(--tu-text-muted);
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.nav-section {
  padding: 0.5rem 1.5rem 0;
  margin-top: 0.5rem;
}

.nav-section-title {
  color: var(--tu-text-dim);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0;
  user-select: none;
}

.nav-section-title:hover { color: var(--tu-text-muted); }

.nav-section-title::after {
  content: '\25B8'; /* right triangle */
  font-size: 0.6rem;
  transition: transform 0.2s;
}

.nav-section-title.open::after {
  transform: rotate(90deg);
}

.nav-section-links {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.nav-section-links.open {
  max-height: 500px;
}

.nav-link {
  display: block;
  padding: 0.5rem 1.5rem;
  color: var(--tu-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--tu-text-bright);
  background: var(--tu-surface);
  border-left-color: var(--tu-accent);
}

.nav-link.active {
  color: var(--tu-accent);
  background: var(--tu-surface);
  border-left-color: var(--tu-accent);
}

.nav-link .icon { margin-right: 0.5rem; }

.main-content {
  margin-left: 260px;
  flex: 1;
  padding: 2rem 3rem;
  max-width: 1000px;
}

/* ---- Top bar ---- */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--tu-border);
}

.lang-toggle {
  display: flex;
  gap: 0.25rem;
  background: var(--tu-surface);
  border-radius: var(--radius);
  padding: 0.25rem;
}

.lang-btn {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--tu-text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.lang-btn.active {
  background: var(--tu-blue);
  color: var(--tu-text-bright);
}

/* ---- Typography ---- */
h1 {
  font-size: 2rem;
  color: var(--tu-text-bright);
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.5rem;
  color: var(--tu-accent);
  margin: 2rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--tu-border);
}

h3 {
  font-size: 1.15rem;
  color: var(--tu-text-bright);
  margin: 1.5rem 0 0.75rem;
}

h4 {
  font-size: 1rem;
  color: var(--tu-accent);
  margin: 1rem 0 0.5rem;
}

p { margin-bottom: 1rem; }

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

/* ---- Cards ---- */
.card {
  background: var(--tu-surface);
  border: 1px solid var(--tu-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.1rem;
  color: var(--tu-text-bright);
  font-weight: 600;
}

/* ---- Stats grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--tu-surface);
  border: 1px solid var(--tu-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--tu-accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--tu-text-muted);
  margin-top: 0.25rem;
}

.stat-card.urgent .stat-value { color: var(--tu-error); }
.stat-card.warning .stat-value { color: var(--tu-warning); }
.stat-card.good .stat-value { color: var(--tu-success); }

/* ---- Tables ---- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--tu-border);
}

th {
  background: var(--tu-surface-light);
  color: var(--tu-accent);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:hover { background: var(--tu-surface); }

/* ---- Tabs ---- */
.tab-container { margin: 1.5rem 0; }

.tab-buttons {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--tu-border);
}

.tab-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--tu-text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.tab-btn:hover { color: var(--tu-text-bright); }

.tab-btn.active {
  color: var(--tu-accent);
  border-bottom-color: var(--tu-accent);
}

.tab-content { display: none; padding: 1.5rem 0; }
.tab-content.active { display: block; }

/* ---- Countdown ---- */
.countdown-display {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin: 2rem 0;
}

.countdown-unit {
  text-align: center;
  background: var(--tu-surface);
  border: 1px solid var(--tu-border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  min-width: 90px;
}

.countdown-number {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--tu-accent);
  font-family: var(--font-mono);
}

.countdown-label {
  font-size: 0.75rem;
  color: var(--tu-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ---- Quiz ---- */
.quiz-question {
  background: var(--tu-surface);
  border: 1px solid var(--tu-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.quiz-question-text {
  font-size: 1.05rem;
  color: var(--tu-text-bright);
  margin-bottom: 1rem;
}

.quiz-option {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
  background: var(--tu-dark);
  border: 1px solid var(--tu-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.quiz-option:hover {
  border-color: var(--tu-accent);
  background: var(--tu-surface-light);
}

.quiz-option.selected {
  border-color: var(--tu-blue);
  background: rgba(0, 102, 153, 0.2);
}

.quiz-option.correct {
  border-color: var(--tu-success);
  background: rgba(76, 175, 80, 0.15);
}

.quiz-option.incorrect {
  border-color: var(--tu-error);
  background: rgba(244, 67, 54, 0.15);
}

.quiz-option input[type="checkbox"] {
  margin-right: 0.75rem;
  accent-color: var(--tu-accent);
}

.quiz-explanation {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(0, 163, 224, 0.1);
  border-left: 3px solid var(--tu-accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
  display: none;
}

.quiz-explanation.visible { display: block; }

/* ---- Progress bars ---- */
.progress-bar {
  height: 8px;
  background: var(--tu-dark);
  border-radius: 4px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  background: linear-gradient(90deg, var(--tu-blue), var(--tu-accent));
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: rgba(76,175,80,0.2); color: var(--tu-success); }
.badge-warning { background: rgba(255,152,0,0.2); color: var(--tu-warning); }
.badge-error { background: rgba(244,67,54,0.2); color: var(--tu-error); }
.badge-info { background: rgba(0,163,224,0.2); color: var(--tu-accent); }

/* ---- Alerts ---- */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  border-left: 4px solid;
}

.alert-info { background: rgba(0,163,224,0.1); border-color: var(--tu-accent); }
.alert-warning { background: rgba(255,152,0,0.1); border-color: var(--tu-warning); }
.alert-success { background: rgba(76,175,80,0.1); border-color: var(--tu-success); }
.alert-error { background: rgba(244,67,54,0.1); border-color: var(--tu-error); }

/* ---- Lists ---- */
ul, ol { margin: 0.5rem 0 1rem 1.5rem; }
li { margin: 0.4rem 0; }

/* ---- Sidebar toggle ---- */
.sidebar-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  width: 40px;
  height: 40px;
  border: 1px solid var(--tu-border);
  border-radius: var(--radius);
  background: var(--tu-surface);
  color: var(--tu-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: var(--tu-surface-light);
  color: var(--tu-accent);
}

.sidebar-open .sidebar-toggle { left: 270px; }

/* Sidebar collapsed state */
.sidebar-collapsed .sidebar { transform: translateX(-260px); }
.sidebar-collapsed .main-content { margin-left: 0; }
.sidebar-collapsed .sidebar-toggle { left: 1rem; }

.sidebar {
  transition: transform 0.3s ease;
}

.main-content {
  transition: margin-left 0.3s ease;
}

/* ---- Mobile responsive ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-260px); }
  .main-content { margin-left: 0; padding: 1rem 1rem 1rem 3.5rem; }
  .sidebar-toggle { left: 0.5rem; top: 0.5rem; width: 36px; height: 36px; font-size: 1rem; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-toggle { left: 270px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .countdown-display { flex-wrap: wrap; }
  .tab-buttons { flex-wrap: wrap; }
  .tab-btn { font-size: 0.8rem; padding: 0.5rem 0.75rem; }
  .card { padding: 1rem; }
  table { font-size: 0.8rem; }
  th, td { padding: 0.5rem; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.2rem; }
  .matrix-grid { gap: 0.3rem; }
  .matrix-cell { width: 50px; height: 50px; }
  .matrix-cell .shape { font-size: 1.2rem; }
}

/* ---- Visual Matrizen ---- */
.matrix-grid {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 1rem;
  background: var(--tu-dark);
  border-radius: var(--radius);
  border: 1px solid var(--tu-border);
}

.matrix-cell {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--tu-surface);
  border: 1px solid var(--tu-border);
  position: relative;
  overflow: hidden;
}

.matrix-cell .shape {
  font-size: 2rem;
  line-height: 1;
}

.matrix-cell svg {
  display: inline-block;
  vertical-align: middle;
}

.matrix-cell.empty {
  background: rgba(0, 163, 224, 0.15);
  border: 2px dashed var(--tu-accent);
}

.matrix-cell.empty::after {
  content: '?';
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--tu-accent);
}

/* 4x4 matrices: column count comes from an inline style set by renderMatrixGrid.
   Placed after the base rules so the narrow-screen sizes actually apply. */
.matrix-grid-4 {
  gap: 0.4rem;
  padding: 0.75rem;
  max-width: 100%;
  box-sizing: border-box;
}
.matrix-grid-4 .matrix-cell svg {
  max-width: 100%;
  height: auto;
}
@media (max-width: 768px) {
  /* Fluid on phones: the grid fills the available width (main-content + card padding leave
     only ~256px at 360px) and square cells shrink with it, so there is never a horizontal scroll. */
  .matrix-grid-4 { display: grid; width: 100%; max-width: 340px; gap: 4px; padding: 6px; }
  .matrix-grid-4 .matrix-cell { width: auto; height: auto; aspect-ratio: 1 / 1; min-width: 0; overflow: hidden; }
  .matrix-grid-4 .matrix-cell > div { max-width: 100%; max-height: 100%; }
  .matrix-grid-4 .matrix-cell > div svg { max-height: 60%; width: auto; }
}

/* Shape colors — high contrast on dark backgrounds */
.shape-black { color: #ffffff; }
.shape-white { color: #cccccc; -webkit-text-stroke: 2px #cccccc; }
.shape-grey { color: #999999; }
.shape-striped { color: #ffffff; opacity: 0.5; }

/* Size modifiers */
.size-big .shape { font-size: 2.5rem; }
.size-medium .shape { font-size: 1.8rem; }
.size-small .shape { font-size: 1.2rem; }

/* ---- Utility ---- */
.text-center { text-align: center; }
.text-muted { color: var(--tu-text-muted); }
.text-accent { color: var(--tu-accent); }
.text-bright { color: var(--tu-text-bright); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none; }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--tu-blue);
  color: var(--tu-text-bright);
}

.btn-primary:hover {
  background: var(--tu-blue-light);
  text-decoration: none;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--tu-border);
  color: var(--tu-text);
}

.btn-outline:hover {
  border-color: var(--tu-accent);
  color: var(--tu-accent);
  text-decoration: none;
}


/* ---- Würfelnetz (cube net) + alternative explanations ---- */
.net-wrap {
  display: inline-block;
  margin: 0.75rem 0;
  padding: 0.75rem;
  max-width: 100%;
  background: var(--tu-dark);
  border: 1px solid var(--tu-border);
  border-radius: var(--radius);
}
.net-svg { display: block; }
.net-cell rect {
  fill: var(--tu-surface-light);
  stroke: var(--tu-accent);
  stroke-width: 1.5;
}
.net-cell text {
  fill: var(--tu-text-bright);
  font-size: 22px;
  font-weight: 600;
  font-family: inherit;
}

.exp-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}
.exp-switch-label {
  font-size: 0.8rem;
  color: var(--tu-text-muted);
  margin-right: 0.25rem;
}
.exp-btn {
  min-height: 36px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--tu-text);
  background: transparent;
  border: 1px solid var(--tu-border);
  border-radius: var(--radius);
  cursor: pointer;
}
.exp-btn:hover { border-color: var(--tu-accent); color: var(--tu-accent); }
.exp-btn:focus-visible { outline: 2px solid var(--tu-accent); outline-offset: 2px; }
.exp-btn[aria-pressed="true"] {
  background: var(--tu-blue);
  border-color: var(--tu-blue);
  color: var(--tu-text-bright);
}
.exp-panel { line-height: 1.5; }


/* ---- Reading passages (Teil B, data/passages.json) ---- */
.qe-passage {
  background: var(--tu-dark);
  border: 1px solid var(--tu-border);
  border-left: 4px solid var(--tu-accent);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin: 2rem 0 1rem;
}
.qe-passage-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.qe-passage-range { font-size: 0.8rem; color: var(--tu-text-muted); }
.qe-passage-title {
  margin: 0.6rem 0 0.75rem;
  font-size: 1.15rem;
  color: var(--tu-text-bright);
}
.qe-passage-par {
  margin: 0 0 0.85rem;
  line-height: 1.7;
  color: var(--tu-text);
  max-width: 75ch;
}
.qe-par-no {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--tu-text-muted);
}
.qe-passage-src { font-size: 0.78rem; color: var(--tu-text-muted); }
.qe-passage-task {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--tu-border);
  font-size: 0.9rem;
  color: var(--tu-text-bright);
}
.qe-passage-ref {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--tu-text-muted);
}
@media (max-width: 600px) {
  .qe-passage { padding: 1rem; }
}
