:root {
  --bg: #edf6f1;
  --bg-deep: #d7ede1;
  --surface: #ffffff;
  --surface-soft: #f7fbf8;
  --surface-tint: #eef8f2;
  --text: #12211b;
  --muted: #64746c;
  --line: #d8e7de;
  --green: #13794d;
  --green-strong: #0d5f3d;
  --green-soft: #e6f6ed;
  --mint: #6fd6a5;
  --blue: #2563eb;
  --blue-soft: #e9f0ff;
  --red: #bd3030;
  --red-soft: #fff0f0;
  --yellow: #9a6a00;
  --yellow-soft: #fff8df;
  --shadow: 0 18px 45px rgba(17, 57, 39, .11);
  --shadow-soft: 0 8px 24px rgba(17, 57, 39, .08);
  --radius: 8px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(19, 121, 77, .12) 0 25%, transparent 25% 50%, rgba(111, 214, 165, .14) 50% 75%, transparent 75%) 0 0 / 34px 34px,
    linear-gradient(180deg, #f6fbf8 0, var(--bg) 380px, #f9fbf8 100%);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-strong); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 24px;
  background: rgba(255,255,255,.86);
  border-bottom: 1px solid rgba(216, 231, 222, .82);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(17, 57, 39, .06);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0;
  color: var(--text);
  font-weight: 900;
  font-size: 0;
}

.brand::before {
  content: "Quiz";
  min-width: 72px;
  height: 38px;
  padding: 0 14px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--green-strong), var(--green) 58%, #21a56d);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 0 10px 22px rgba(19, 121, 77, .25), inset 0 1px 0 rgba(255,255,255,.28);
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.topbar nav a {
  color: #22352c;
  font-weight: 800;
  padding: 8px 11px;
  border-radius: var(--radius);
  transition: background .14s ease, color .14s ease, transform .14s ease;
}

.topbar nav a:hover {
  background: var(--green-soft);
  color: var(--green-strong);
  transform: translateY(-1px);
}

.container {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 34px 18px 64px;
}

.focus-container {
  width: min(840px, 100%);
  margin: 0 auto;
}

.hero,
.panel,
.card {
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(216, 231, 222, .95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 30px;
  margin-bottom: 18px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.96), rgba(239, 249, 243, .96)),
    var(--surface);
}

.hero::after {
  content: "";
  position: absolute;
  right: 24px;
  bottom: 18px;
  width: 190px;
  height: 74px;
  border: 1px solid rgba(19, 121, 77, .16);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(19,121,77,.08) 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(0deg, rgba(19,121,77,.08) 1px, transparent 1px) 0 0 / 18px 18px;
  opacity: .72;
  pointer-events: none;
}

.hero > * { position: relative; z-index: 1; }

.panel {
  padding: 24px;
  background: rgba(255,255,255,.96);
}

.card {
  padding: 18px;
  color: var(--text);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

a.card:hover,
.card:hover {
  border-color: rgba(19, 121, 77, .34);
  box-shadow: 0 18px 38px rgba(17, 57, 39, .12);
  transform: translateY(-2px);
}

h1, h2, h3 {
  line-height: 1.18;
  margin: 0 0 12px;
  letter-spacing: 0;
}

h1 { font-size: 34px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin-top: 0; }
.muted { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 16px 0 0;
}

.actions.compact { margin-top: 12px; }

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 17px;
  border-radius: var(--radius);
  border: 1px solid var(--green);
  background: linear-gradient(135deg, var(--green), #18a66b);
  color: #fff;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(19, 121, 77, .18);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
}

.btn:hover,
button:hover {
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(19, 121, 77, .24);
}

.btn.secondary,
button.secondary {
  background: #fff;
  color: var(--green-strong);
  border-color: #a8d9bf;
  box-shadow: none;
}

.btn.secondary:hover,
button.secondary:hover {
  background: var(--green-soft);
  color: var(--green-strong);
}

.btn.danger,
button.danger {
  background: linear-gradient(135deg, var(--red), #d95353);
  border-color: var(--red);
  color: #fff;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: 0;
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(19, 121, 77, .14);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

label {
  display: block;
  color: #263a31;
  font-weight: 800;
  margin: 13px 0;
}

.check {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 800;
}

.check input,
.answer-card input {
  width: auto;
  min-height: auto;
  accent-color: var(--green);
}

.question-text {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0;
  margin: 18px 0;
}

.question-image {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin-bottom: 14px;
  box-shadow: var(--shadow-soft);
}

.answer-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 12px;
  padding: 16px;
  margin: 12px 0;
  border: 1px solid #dceae1;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, var(--surface-soft));
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(17, 57, 39, .03);
}

.answer-card:hover {
  border-color: rgba(19, 121, 77, .42);
  background: #fff;
  box-shadow: 0 12px 24px rgba(17, 57, 39, .08);
}

.alert {
  padding: 13px 15px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 800;
  box-shadow: 0 5px 18px rgba(17, 57, 39, .05);
}

.alert.success { border-color: #91d7ad; color: var(--green-strong); background: var(--green-soft); }
.alert.error { border-color: #efaaa8; color: var(--red); background: var(--red-soft); }
.alert.warning { border-color: #f0ce6f; color: var(--yellow); background: var(--yellow-soft); }
.alert.info { border-color: #9fd4ba; color: var(--green-strong); background: var(--green-soft); }

.result-hero {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: var(--radius);
  margin: 18px 0;
}

.result-hero h2 { margin-bottom: 4px; }
.result-hero p { margin: 0; color: var(--muted); }

.result-hero.is-correct {
  background: linear-gradient(135deg, var(--green-soft), #f8fffb);
  border: 1px solid #91d7ad;
}

.result-hero.is-wrong {
  background: linear-gradient(135deg, var(--red-soft), #fffafa);
  border: 1px solid #efaaa8;
}

.result-icon {
  width: 50px;
  height: 50px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: #fff;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(17, 57, 39, .06);
}

.is-correct .result-icon { color: var(--green); }
.is-wrong .result-icon { color: var(--red); }

.review-list {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.review-option {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(17, 57, 39, .05);
}

.review-option.correct { border-color: #84cf9f; background: #f3fbf6; }
.review-option.wrong { border-color: #eba3a3; background: var(--red-soft); }
.review-option.neutral { background: #fff; }

.review-main {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px 15px 10px;
}

.review-check {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 900;
}

.correct .review-check { color: var(--green); border-color: #80c99e; }
.wrong .review-check { color: var(--red); border-color: #eba3a3; }

.review-copy strong {
  display: block;
  font-size: 17px;
  margin-top: 2px;
}

.review-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  background: #edf2ef;
  color: var(--muted);
}

.tag.selected { background: var(--blue-soft); color: var(--blue); }
.tag.correct { background: #dff4e7; color: var(--green-strong); }
.tag.wrong { background: #ffe1e1; color: var(--red); }

.answer-explanation {
  padding: 12px 15px 15px 63px;
  border-top: 1px solid rgba(17, 57, 39, .08);
  color: #34463d;
}

.explanation-panel,
.next-panel {
  margin-top: 16px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, var(--surface-soft));
}

.explanation-lead span {
  display: inline-flex;
  font-size: 13px;
  font-weight: 900;
  color: var(--green-strong);
  text-transform: uppercase;
}

.explanation-lead p {
  margin: 7px 0 0;
  font-size: 18px;
  font-weight: 800;
}

.explain {
  background: #fff;
  border: 1px solid #d9c069;
  border-radius: var(--radius);
  padding: 15px;
  margin: 12px 0 0;
}

.note-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.hidden { display: none; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th,
td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  background: #eef8f2;
  font-size: 13px;
  text-transform: uppercase;
  color: #557064;
}

tr:last-child td { border-bottom: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat {
  position: relative;
  overflow: hidden;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--mint), var(--green));
}

.stat span {
  display: block;
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  font-size: 30px;
  margin-top: 3px;
}

.category-row {
  margin: 18px 0;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.child {
  margin-top: 12px;
  margin-left: 18px;
  padding: 12px 0 0 14px;
  border-left: 3px solid #a7dabb;
}

.answer-editor {
  padding: 14px;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.code-textarea {
  min-height: 420px;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre;
}

.code-textarea.compact { min-height: 260px; }
.ai-export-form textarea { min-height: 260px; }

@media (max-width: 720px) {
  body { background-size: 26px 26px, auto; }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 13px 14px;
  }

  .topbar nav { justify-content: flex-start; }
  .container { padding: 18px 12px 42px; }
  .hero, .panel, .card { padding: 16px; }
  .hero::after { display: none; }
  h1 { font-size: 27px; }
  .question-text { font-size: 23px; }
  .btn, button { width: 100%; }
  .actions { align-items: stretch; }
  .result-hero { grid-template-columns: 42px 1fr; }
  .result-icon { width: 42px; height: 42px; }
  .answer-explanation { padding-left: 15px; }
  table { display: block; overflow-x: auto; }
}
