:root {
  --red: #d52b1e;
  --red-dark: #a51f15;
  --blue: #0f6cbd;
  --green: #1f8a4c;
  --green-bg: #e7f6ec;
  --red-bg: #fdecea;
  --ink: #1d2330;
  --muted: #5d6576;
  --line: #e3e6ec;
  --bg: #f6f7f9;
  --card: #fff;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--blue); }
h1 { font-size: clamp(1.5rem, 3vw, 2rem); line-height: 1.2; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.ok { color: var(--green); }
.ko { color: var(--red); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem clamp(1rem, 4vw, 2rem);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;

  nav {
    display: flex;
    gap: 1.25rem;

    a { color: var(--ink); text-decoration: none; font-weight: 500; }
    a:hover { color: var(--red); }
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;

  small { display: block; font-weight: 400; color: var(--muted); font-size: 0.75rem; }
}

.brand-flag {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: url("/icon.svg") center / cover;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 4vw, 2rem) 3rem;
}

.footer {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.flash {
  background: #fff8e1;
  border: 1px solid #f3d27a;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
}

.pill {
  display: inline-block;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  background: #eef1f6;
  color: var(--ink);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;

  &.ok { background: var(--green-bg); color: var(--green); }
  &.ko { background: var(--red-bg); color: var(--red); }
}

a.pill:hover { background: #e1e6ef; }

.button, .link-button {
  display: inline-block;
  font: inherit;
  cursor: pointer;
  border: 0;
  text-decoration: none;
}

.button {
  padding: 0.75rem 1.4rem;
  border-radius: 999px;
  font-weight: 600;
  background: #eef1f6;
  color: var(--ink);

  &.primary { background: var(--red); color: #fff; }
  &.primary:hover { background: var(--red-dark); }
}

.link-button {
  background: none;
  color: var(--muted);
  padding: 0;
  margin-top: 2rem;
  text-decoration: underline;

  &.danger:hover { color: var(--red); }
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #e8ebf0;
  overflow: hidden;

  span {
    display: block;
    height: 100%;
    width: var(--value);
    background: linear-gradient(90deg, var(--red), #ef6b4f);
    border-radius: inherit;
    transition: width 0.4s ease;
  }
}

.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.5rem;
  align-items: center;
  margin-bottom: 1rem;

  @media (width < 760px) { grid-template-columns: 1fr; }
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;

  strong { display: block; font-size: 1.6rem; line-height: 1.1; }
  span { color: var(--muted); font-size: 0.85rem; }
}

.resume {
  background: var(--card);
  border-left: 4px solid var(--blue);
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

.start-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;

  form { display: contents; }
}

.start-card {
  text-align: left;
  font: inherit;
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  transition: transform 0.15s, border-color 0.15s;

  strong { display: block; font-size: 1.1rem; margin-bottom: 0.25rem; }
  span { color: var(--muted); font-size: 0.9rem; }

  &:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--red); }
  &:disabled { opacity: 0.55; cursor: default; }
  &.exam { background: linear-gradient(135deg, #fff, #fff4f2); }
}

.columns {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 2rem;

  @media (width < 760px) { grid-template-columns: 1fr; }
}

.topic-list, .hard-list, .exam-list, .link-list, .review-list {
  padding: 0;
  margin: 0;
}

.topic-list, .exam-list, .link-list { list-style: none; }

.topic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;

  &:hover { outline: 2px solid var(--line); }
}

.topic-name small { display: block; color: var(--muted); }
.topic-progress { width: 110px; flex-shrink: 0; }

.hard-list {
  padding-left: 1.2rem;

  li { margin-bottom: 0.75rem; }
  .answer { display: block; color: var(--green); font-weight: 500; }
  small { display: block; }
}

.exam-list a {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.link-list li { margin-bottom: 0.5rem; }

.topic-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.topic-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--card);
  padding: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;

  small { color: var(--muted); }
  &:hover { outline: 2px solid var(--red); }
}

.summary p { margin-top: 0; }

.learn-box {
  background: #f1f6fd;
  border: 1px solid #d5e4f7;
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1rem 0;

  h2 { margin-top: 0; font-size: 1rem; }
  ul { margin: 0; padding-left: 1.2rem; }
  li { margin-bottom: 0.3rem; }
  .links { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0; }
}

.quiz-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;

  .score { margin-left: auto; font-weight: 700; color: var(--green); }
}

.question-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.2rem, 4vw, 2rem);
  margin-top: 1rem;
}

.question-topic { color: var(--muted); font-size: 0.85rem; margin: 0; }
.question-text { font-size: clamp(1.25rem, 2.6vw, 1.6rem); }

.question-image {
  display: block;
  max-width: min(100%, 420px);
  border-radius: 10px;
  margin-bottom: 1rem;

  &.small { max-width: 240px; }
}

.options {
  display: grid;
  gap: 0.6rem;
  list-style: none;
  padding: 0;
  margin: 1rem 0;

  &.image-options { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

.option {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  width: 100%;
  text-align: left;
  font: inherit;
  padding: 0.85rem 1rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);

  &:is(button) { cursor: pointer; }
  &:is(button):hover { border-color: var(--red); background: #fff7f6; }

  .letter {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: #eef1f6;
    font-weight: 700;
  }

  &.correct { border-color: var(--green); background: var(--green-bg); }
  &.correct .letter { background: var(--green); color: #fff; }
  &.wrong { border-color: var(--red); background: var(--red-bg); }
  &.wrong .letter { background: var(--red); color: #fff; }
}

.option-image {
  max-width: 100%;
  max-height: 140px;
  display: block;
}

.feedback {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  margin: 1rem 0;
  animation: pop 0.25s ease-out;

  strong { font-size: 1.2rem; }
  &.good { background: var(--green-bg); color: #145c33; }
  &.bad { background: var(--red-bg); color: #8a1c13; }
}

@keyframes pop {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result {
  text-align: center;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  border-top: 6px solid var(--green);

  &.failed { border-top-color: var(--red); }
  .big { font-size: 3rem; font-weight: 800; margin: 0; }
}

.review-list {
  padding-left: 1.4rem;

  li {
    background: var(--card);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.6rem;
    box-shadow: var(--shadow);
  }

  p { margin: 0.2rem 0; }
  .wrong { color: var(--red); }
  .right { color: var(--green); font-weight: 500; }
}

.image-answers {
  display: flex;
  gap: 1rem;

  figure { margin: 0; text-align: center; font-size: 0.8rem; }
  img { max-height: 110px; max-width: 180px; }
  .wrong figcaption { color: var(--red); }
  .right figcaption { color: var(--green); }
}

.catalog summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 1rem;
}

.history {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);

  th, td { text-align: left; padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); }
  th { background: #f0f2f6; font-size: 0.85rem; }
}

.button.auto-advance {
  background: linear-gradient(90deg, var(--red-dark) 50%, var(--red) 50%) right / 200% 100% no-repeat;
  animation: fill-button 2s linear forwards;
}

@keyframes fill-button {
  to { background-position: left; }
}
