:root {
  --ink: #14231f;
  --ink-soft: #3d524b;
  --paper: #f3f6f2;
  --paper-2: #e7eee8;
  --accent: #0f8f6e;
  --accent-deep: #0a5f4a;
  --sun: #e8a317;
  --danger: #c44b2f;
  --line: rgba(20, 35, 31, 0.12);
  --shadow: 0 18px 40px rgba(20, 35, 31, 0.08);
  --radius: 18px;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, sans-serif;
  --duration: 1.5;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15, 143, 110, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(232, 163, 23, 0.16), transparent 50%),
    linear-gradient(165deg, #eef4ef 0%, #f7f4ea 48%, #e8f1ec 100%);
  line-height: 1.5;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(20, 35, 31, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 35, 31, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
  z-index: 0;
}

.bg-glow {
  position: fixed;
  width: 42vw;
  height: 42vw;
  right: -8vw;
  bottom: -12vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(15, 143, 110, 0.22), transparent 70%);
  filter: blur(8px);
  pointer-events: none;
  z-index: 0;
  animation: drift 14s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-4vw, -3vh) scale(1.08); }
}

main {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: rgba(243, 246, 242, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar[hidden],
.dock[hidden] {
  display: none !important;
}

.topbar__brand {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 1rem;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex: 1;
  justify-content: flex-end;
  max-width: 520px;
}

.timer {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}

.timer__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.timer__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
}

.timer.is-warn .timer__value { color: var(--sun); }
.timer.is-danger .timer__value { color: var(--danger); }

.progress-wrap {
  flex: 1;
  min-width: 120px;
}

.progress-wrap__label {
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-bottom: 0.25rem;
  text-align: right;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(20, 35, 31, 0.08);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent) 55%, #3cbc8f);
  border-radius: inherit;
  transition: width 0.35s ease;
}

/* SCREENS */
.screen {
  display: none;
  padding: 2rem 1.25rem 7rem;
  animation: rise 0.45s ease both;
}

.screen.is-active {
  display: block;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* HERO */
.screen--hero {
  min-height: 100vh;
  padding-bottom: 2rem;
  display: none;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 2rem;
  align-items: end;
  max-width: 1120px;
  margin: 0 auto;
}

.screen--hero.is-active {
  display: grid;
}

.hero {
  padding: 18vh 0 2rem;
}

.hero__brand {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3.2rem, 10vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: -0.04em;
  background: linear-gradient(120deg, var(--ink) 20%, var(--accent) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero__title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.55rem, 3.4vw, 2.35rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  max-width: 14ch;
}

.hero__lead {
  margin: 0 0 1.75rem;
  max-width: 34ch;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.reveal {
  opacity: 0;
  transform: translateY(18px);
  animation: reveal 0.7s ease forwards;
}

.reveal--delay-1 { animation-delay: 0.12s; }
.reveal--delay-2 { animation-delay: 0.22s; }
.reveal--delay-3 { animation-delay: 0.34s; }

@keyframes reveal {
  to { opacity: 1; transform: translateY(0); }
}

.hero-panel {
  align-self: center;
  padding: 1.5rem 0;
}

.hero-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.hero-list li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
  animation: reveal 0.7s ease forwards;
  opacity: 0;
  transform: translateY(12px);
}

.hero-list li:nth-child(1) { animation-delay: 0.28s; }
.hero-list li:nth-child(2) { animation-delay: 0.38s; }
.hero-list li:nth-child(3) { animation-delay: 0.48s; }
.hero-list li:nth-child(4) { animation-delay: 0.58s; }

.hero-list span {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-size: 0.95rem;
  min-width: 1.6rem;
}

/* PANELS & TESTS */
.panel,
.test {
  max-width: 760px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.panel--narrow { max-width: 480px; }

.panel__title,
.test__title {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-weight: 750;
  font-size: clamp(1.6rem, 3vw, 2rem);
  letter-spacing: -0.02em;
}

.panel__text {
  margin: 0 0 1.25rem;
  color: var(--ink-soft);
}

.panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.panel__actions--wrap { justify-content: flex-start; }

.rules {
  margin: 0;
  padding-left: 1.15rem;
  display: grid;
  gap: 0.75rem;
  color: var(--ink-soft);
}

.rules strong { color: var(--ink); }

.test__head { margin-bottom: 1.5rem; }

.test__kicker {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-deep);
  font-weight: 700;
}

.test__intro {
  margin: 0.5rem 0 0;
  color: var(--ink-soft);
}

.q {
  padding: 1.25rem 0;
  border-top: 1px solid var(--line);
}

.q:first-of-type { border-top: none; padding-top: 0; }

.q h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.q p {
  margin: 0 0 0.85rem;
  color: var(--ink-soft);
}

.q code,
.broken {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  list-style: none;
  margin: 0 0 0.85rem;
  padding: 0;
}

.chip-list li {
  padding: 0.35rem 0.7rem;
  border-radius: 10px;
  background: rgba(15, 143, 110, 0.1);
  border: 1px solid rgba(15, 143, 110, 0.18);
  font-size: 0.9rem;
}

.broken {
  margin: 0 0 0.75rem;
  padding: 0.85rem 0.85rem 0.85rem 2rem;
  background: rgba(196, 75, 47, 0.06);
  border-radius: 12px;
  border: 1px dashed rgba(196, 75, 47, 0.25);
}

textarea,
input[type="text"],
select {
  width: 100%;
  margin-top: 0.45rem;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(20, 35, 31, 0.16);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  resize: vertical;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 143, 110, 0.18);
}

.field {
  display: grid;
  gap: 0.4rem;
  font-weight: 600;
}

.tf-list {
  display: grid;
  gap: 0.85rem;
}

.tf {
  margin: 0;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.4);
  display: grid;
  gap: 0.55rem;
}

.tf legend {
  padding: 0 0.25rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.tf label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-right: 1rem;
  font-size: 0.95rem;
}

.rank-list {
  display: grid;
  gap: 0.65rem;
}

.rank {
  display: grid;
  grid-template-columns: 1fr minmax(140px, 180px);
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--line);
}

.rank span { font-size: 0.95rem; }
.rank select { margin-top: 0; }

.test__nav {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

/* BUTTONS */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  padding: 0.8rem 1.2rem;
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}

.btn:active { transform: translateY(1px) scale(0.99); }

.btn--primary {
  background: var(--ink);
  color: #f4f8f5;
}

.btn--primary:hover {
  background: var(--accent-deep);
}

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(20, 35, 31, 0.22);
}

.btn--ghost:hover {
  background: rgba(20, 35, 31, 0.05);
}

/* DONE */
.done__brand {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 1.25rem 0 0.25rem;
}

.stat {
  padding: 0.9rem;
  border-radius: 14px;
  background: rgba(15, 143, 110, 0.08);
  border: 1px solid rgba(15, 143, 110, 0.12);
  text-align: center;
}

.stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.stat span {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* DOCK */
.dock {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  gap: 0.35rem;
  padding: 0.4rem;
  background: rgba(20, 35, 31, 0.92);
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(20, 35, 31, 0.25);
}

.dock__item {
  appearance: none;
  border: none;
  cursor: pointer;
  background: transparent;
  color: rgba(244, 248, 245, 0.72);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  min-width: 72px;
  transition: background 0.2s ease, color 0.2s ease;
}

.dock__item span {
  font-family: var(--font-display);
  font-size: 0.72rem;
  opacity: 0.7;
}

.dock__item:hover,
.dock__item.is-active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.dock__item.is-active {
  background: var(--accent);
  color: #fff;
}

@media (max-width: 860px) {
  .screen--hero.is-active {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .hero {
    padding-top: 12vh;
  }

  .hero-panel {
    padding-top: 0;
  }

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

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

  .dock {
    width: calc(100% - 1.5rem);
    overflow-x: auto;
  }

  .dock__item {
    min-width: 64px;
    font-size: 0.75rem;
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar__meta {
    max-width: none;
  }

  .test__nav {
    flex-direction: column-reverse;
  }

  .btn {
    width: 100%;
    text-align: center;
  }
}

/* AI grading */
.ai-box {
  margin-top: 1.5rem;
  padding: 1.2rem;
  border-radius: 16px;
  border: 1px solid rgba(15, 143, 110, 0.22);
  background: linear-gradient(160deg, rgba(15, 143, 110, 0.08), rgba(255, 255, 255, 0.55));
}

.ai-box__head h3 {
  margin: 0 0 0.3rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.ai-box__head p {
  margin: 0 0 1rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.ai-loading {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 1rem;
  color: var(--ink-soft);
}

.ai-loading[hidden],
.ai-error[hidden],
.ai-result[hidden] {
  display: none !important;
}

.ai-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(15, 143, 110, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.ai-error {
  margin-top: 0.9rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(196, 75, 47, 0.08);
  border: 1px solid rgba(196, 75, 47, 0.25);
  color: #8a2f1d;
  font-size: 0.95rem;
}

.ai-result {
  margin-top: 1.1rem;
}

.ai-scoreline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem 1.25rem;
  margin-bottom: 1rem;
}

.ai-scoreline__big {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  letter-spacing: -0.03em;
  color: var(--accent-deep);
}

.ai-scoreline__pct {
  font-weight: 700;
  color: var(--ink-soft);
}

.ai-summary {
  margin: 0 0 1rem;
  color: var(--ink);
}

.ai-tags {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.ai-tags ul {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.ai-tags h4 {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-deep);
}

.grade-list {
  display: grid;
  gap: 0.55rem;
}

.grade-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem 0.85rem;
  align-items: start;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--line);
}

.grade-item__score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  min-width: 3.2rem;
  color: var(--accent-deep);
}

.grade-item__score.is-low { color: var(--danger); }
.grade-item__score.is-mid { color: #b57900; }
.grade-item__score.is-high { color: var(--accent-deep); }

.grade-item__q {
  margin: 0.15rem 0 0;
  font-weight: 600;
  font-size: 0.92rem;
}

.grade-item__fb {
  margin: 0.2rem 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.grade-item__block {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

@media (max-width: 640px) {
  .ai-tags {
    grid-template-columns: 1fr;
  }
}

@media print {
  .bg-grid,
  .bg-glow,
  .topbar,
  .dock,
  .hero__actions,
  .test__nav,
  .panel__actions,
  .btn {
    display: none !important;
  }

  body {
    background: white;
  }

  .screen {
    display: block !important;
    padding: 0;
    animation: none;
  }

  .screen--hero,
  #screen-about,
  #screen-name,
  #screen-done {
    display: none !important;
  }

  .panel,
  .test {
    box-shadow: none;
    border: none;
    background: white;
    max-width: none;
    padding: 0;
  }

  textarea,
  input,
  select {
    border: 1px solid #999;
    box-shadow: none;
  }
}
