:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --ink: #16202a;
  --muted: #647384;
  --line: #d8e0ea;
  --blue: #1f5f99;
  --blue-dark: #16466f;
  --green: #25785b;
  --amber: #a76619;
  --red: #b33a3a;
  --shadow: 0 12px 28px rgba(22, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #172332;
  color: #f8fbff;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #dce9f5;
  color: #172332;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand h1,
.brand p,
.progress-panel h2,
.progress-panel p,
.topbar h2,
.topbar p,
.section-heading h3,
.section-heading p {
  margin: 0;
}

.brand h1 {
  font-size: 1.3rem;
}

.brand p,
.progress-panel p {
  color: #c4d2e0;
  font-size: 0.92rem;
}

.level-nav {
  display: grid;
  gap: 8px;
}

.level-button,
.ghost-button,
.primary-button,
.tab,
.answer-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
}

.level-button {
  background: transparent;
  color: #f8fbff;
  text-align: left;
}

.level-button:hover,
.level-button.active {
  background: #26384c;
  border-color: #3d536b;
}

.progress-panel {
  border-top: 1px solid #35485f;
  padding-top: 22px;
  display: grid;
  gap: 14px;
}

.progress-ring {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: conic-gradient(#66b58d var(--progress, 0deg), #35485f 0);
  display: grid;
  place-items: center;
}

.progress-ring span {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: #172332;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
}

.main {
  padding: 24px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
}

.eyebrow {
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1.05;
}

.search-wrap {
  display: grid;
  gap: 6px;
  min-width: min(360px, 100%);
}

.search-wrap label {
  font-size: 0.82rem;
  color: var(--muted);
}

.search-wrap input,
.filters select {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button.done {
  background: var(--green);
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-card span {
  font-size: 1.7rem;
  font-weight: 800;
}

.stat-card p {
  margin: 4px 0 0;
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(380px, 1.25fr);
  gap: 18px;
  align-items: start;
}

.course-list,
.detail-panel {
  min-width: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

.section-heading p {
  color: var(--muted);
  font-size: 0.9rem;
}

.cards {
  display: grid;
  gap: 10px;
}

.course-card {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 14px;
  text-align: left;
  box-shadow: var(--shadow);
  display: grid;
  gap: 9px;
}

.course-card:hover,
.course-card.active {
  border-color: var(--blue);
}

.card-top {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
}

.pill.level {
  background: #dce9f5;
  color: var(--blue-dark);
}

.pill.done {
  background: #dcefe7;
  color: var(--green);
}

.course-card h4 {
  margin: 0;
  font-size: 1.02rem;
}

.course-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 520px;
  box-shadow: var(--shadow);
}

.empty-state {
  min-height: 520px;
  display: grid;
  place-content: center;
  padding: 32px;
  text-align: center;
}

.empty-state p {
  max-width: 420px;
  color: var(--muted);
  line-height: 1.5;
}

.detail-view {
  padding: 20px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

.detail-header h3 {
  margin: 5px 0 0;
  font-size: 1.6rem;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-top: 18px;
}

.tab {
  background: transparent;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
}

.tab.active {
  background: var(--surface-2);
  color: var(--ink);
}

.tab-panel {
  padding-top: 18px;
  line-height: 1.58;
}

.tab-panel h4 {
  margin: 0 0 8px;
}

.tab-panel ul,
.tab-panel ol {
  padding-left: 22px;
  margin-top: 0;
}

.revision-brief {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  margin-bottom: 14px;
}

.revision-brief p {
  margin: 0 0 8px;
}

.revision-brief p:last-child {
  margin-bottom: 0;
}

.term-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.term-chip {
  border-radius: 999px;
  background: #e8eef4;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
  padding: 6px 9px;
}

.quiz-question {
  margin: 0 0 12px;
  font-weight: 800;
}

.quiz-answers {
  display: grid;
  gap: 8px;
}

.full-course {
  display: grid;
  gap: 12px;
}

.course-section {
  border-left: 4px solid var(--blue);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px;
}

.course-section h5 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.course-section p {
  margin: 0;
  color: var(--ink);
}

.source-note {
  color: var(--muted);
}

.moodle-links {
  display: grid;
  gap: 8px;
}

.moodle-link {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.moodle-link a {
  color: var(--blue-dark);
  font-weight: 800;
  text-decoration: none;
}

.moodle-link a:hover {
  text-decoration: underline;
}

.moodle-link p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.annales-box {
  display: grid;
  gap: 12px;
}

.codes-box {
  display: grid;
  gap: 12px;
}

.code-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.code-card h5 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.code-card p {
  margin: 0 0 8px;
  color: var(--muted);
}

.code-card ul {
  margin-bottom: 10px;
}

.code-card a {
  color: var(--blue-dark);
  font-weight: 800;
  text-decoration: none;
}

.code-card a:hover {
  text-decoration: underline;
}

.annales-semester {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.annales-semester h5 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.year-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.year-link,
.year-missing {
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
}

.year-link {
  background: #dce9f5;
  color: var(--blue-dark);
}

.year-link:hover {
  text-decoration: underline;
}

.year-missing {
  background: #e8eaed;
  color: #7b8794;
}

.annales-viewer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.viewer-header h4 {
  margin: 0;
}

.viewer-link {
  color: var(--blue-dark);
  font-weight: 800;
  text-decoration: none;
}

.viewer-link:hover {
  text-decoration: underline;
}

.annales-viewer iframe {
  display: block;
  width: 100%;
  min-height: 520px;
  border: 0;
  background: var(--surface-2);
}

.answer-button {
  background: var(--surface-2);
  border-color: var(--line);
  text-align: left;
  min-height: 48px;
}

.answer-button.correct {
  background: #dcefe7;
  border-color: var(--green);
}

.answer-button.wrong {
  background: #f6dfdf;
  border-color: var(--red);
}

.feedback {
  margin: 12px 0 0;
  color: var(--muted);
}

.hidden {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .level-nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .level-button {
    text-align: center;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .detail-header,
  .section-heading {
    display: grid;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }

  .level-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
