:root {
  --ink: #17324d;
  --paper: #fff9e9;
  --cream: #f7ebc6;
  --yellow: #f5c842;
  --yellow-dark: #a66c00;
  --red: #bd3d2a;
  --red-dark: #842719;
  --turquoise: #087d7a;
  --white: #ffffff;
  --shadow: 0 8px 0 rgba(23, 50, 77, 0.2);
  --soft-shadow: 0 10px 30px rgba(23, 50, 77, 0.16);
  font-family: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: #e9d7aa;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--cream);
}

button { font: inherit; }

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 4px solid #086b9b;
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  transform: translateY(-150%);
  padding: 10px 14px;
  background: var(--white);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 8px;
}

.skip-link:focus { transform: translateY(0); }

.state-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 800;
}

.loader {
  font-size: 3rem;
  animation: pencil 900ms ease-in-out infinite alternate;
}

@keyframes pencil { to { transform: rotate(12deg) translateY(-5px); } }

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px clamp(14px, 3vw, 42px);
  background: var(--paper);
  border-bottom: 4px solid var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 900;
  cursor: pointer;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 3px solid var(--ink);
  border-radius: 50% 46% 52% 43%;
  background: var(--yellow);
  transform: rotate(-4deg);
}

.player-status,
.score {
  display: flex;
  align-items: center;
  gap: 10px;
}

.score {
  min-height: 44px;
  padding: 6px 14px;
  background: #fff1a6;
  border: 2px solid var(--yellow-dark);
  border-radius: 12px 9px 11px 8px;
}

.icon-button,
.grade-button,
.progress-button,
.back-button,
.primary-button,
.secondary-button,
.danger-button,
.text-button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
  font-weight: 900;
}

.icon-button {
  min-width: 44px;
  padding: 7px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
  color: var(--ink);
}

.grade-button {
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 9px 12px 8px 11px;
  background: var(--white);
  color: var(--ink);
}

.progress-button,
.primary-button {
  padding: 10px 18px;
  border: 3px solid var(--ink);
  border-radius: 11px 8px 12px 9px;
  background: var(--red);
  color: var(--white);
  box-shadow: 0 4px 0 var(--red-dark);
}

.progress-button:active,
.primary-button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--red-dark); }

.game-shell { min-height: calc(100vh - 78px); }

.screen { min-height: calc(100vh - 78px); }

.grade-screen {
  display: grid;
  place-items: center;
  padding: clamp(22px, 5vw, 64px);
  background:
    linear-gradient(rgba(23, 50, 77, 0.22), rgba(23, 50, 77, 0.22)),
    url("assets/ucionica.png") center / cover;
}

.grade-book {
  width: min(760px, 100%);
  padding: clamp(24px, 5vw, 54px);
  text-align: center;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 16px 10px 19px 12px;
  box-shadow: var(--shadow);
}

.grade-book > p:not(.eyebrow) { font-size: 1.12rem; font-weight: 700; }

.grade-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 28px;
}

.grade-option {
  min-height: 94px;
  padding: 12px 8px;
  border: 3px solid var(--ink);
  border-radius: 12px 8px 14px 9px;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(23, 50, 77, 0.2);
  font-weight: 900;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

.grade-option strong { display: block; color: var(--red-dark); font-size: 2rem; line-height: 1; }
.grade-option:hover { transform: translateY(-4px) rotate(-1deg); background: #fff1a6; }

.home-screen {
  position: relative;
  padding: clamp(18px, 3vw, 38px);
  background: #e9d7aa;
}

.welcome-note {
  position: relative;
  z-index: 2;
  width: min(570px, 92%);
  margin: 0 auto -28px;
  padding: 18px 24px 20px;
  text-align: center;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 14px 9px 17px 11px;
  box-shadow: var(--shadow);
  transform: rotate(-0.5deg);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red-dark);
  font-weight: 900;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 5px;
  font-size: clamp(1.65rem, 4vw, 2.7rem);
  line-height: 1.04;
}

.welcome-note p:last-child { margin-bottom: 0; font-size: clamp(0.98rem, 2vw, 1.18rem); }

.classroom-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.65fr);
  gap: clamp(14px, 2vw, 26px);
  width: min(1520px, 100%);
  margin: 0 auto;
  align-items: start;
}

.classroom {
  overflow: hidden;
  border: 5px solid var(--ink);
  border-radius: 18px 13px 20px 15px;
  box-shadow: var(--soft-shadow);
  background: #e4ba72;
}

.classroom img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.subject-shelf {
  min-height: 100%;
  padding: 20px 16px 18px;
  background: #9a5b2c;
  border: 5px solid var(--ink);
  border-radius: 12px 18px 11px 16px;
  box-shadow: var(--soft-shadow);
}

.shelf-heading {
  padding: 13px 14px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 10px 7px 12px 8px;
  transform: rotate(0.4deg);
}

.shelf-heading h2 { margin-bottom: 0; font-size: 1.45rem; }

.subject-buttons {
  display: grid;
  gap: 9px;
  max-height: 650px;
  margin-top: 14px;
  padding: 3px 5px 8px;
  overflow-y: auto;
  scrollbar-color: var(--yellow) #70401e;
  scrollbar-width: auto;
}

.subject-button {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 6px 12px 6px 7px;
  text-align: left;
  border: 3px solid var(--ink);
  border-radius: 8px 12px 7px 10px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(23, 50, 77, 0.26);
  transition: transform 140ms ease, background 140ms ease;
}

.subject-button:nth-child(3n + 2) { transform: rotate(-0.35deg); }
.subject-button:hover { transform: translateX(-5px); background: #fff1a6; }

.pin-icon {
  display: grid;
  place-items: center;
  min-width: 40px;
  min-height: 38px;
  padding: 2px 8px;
  border-radius: 9px 6px 10px 7px;
  background: var(--yellow);
  font-size: 1.15rem;
}

.lesson-screen {
  padding: clamp(18px, 4vw, 52px);
  background-color: #e9d7aa;
  background-image: radial-gradient(rgba(23, 50, 77, 0.07) 1px, transparent 1px);
  background-size: 16px 16px;
}

.back-button {
  margin-bottom: 18px;
  padding: 9px 14px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
}

.workbook {
  width: min(820px, 100%);
  min-height: 500px;
  margin: 0 auto;
  padding: clamp(22px, 5vw, 52px);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 12px 19px 15px 10px;
  box-shadow: var(--shadow);
}

.lesson-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.lesson-heading h2 { margin-bottom: 14px; font-size: clamp(1.7rem, 4vw, 2.6rem); }

.question-count {
  flex: 0 0 auto;
  padding: 7px 12px;
  background: #fff1a6;
  border: 2px solid var(--yellow-dark);
  border-radius: 10px 7px 11px 8px;
  font-weight: 900;
}

.lesson-progress {
  height: 16px;
  overflow: hidden;
  margin-bottom: clamp(28px, 5vw, 52px);
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: var(--cream);
}

.lesson-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--turquoise);
  transition: width 260ms ease;
}

.question-prompt {
  margin-bottom: 26px;
  text-align: center;
  font-size: clamp(1.4rem, 4vw, 2.25rem);
  line-height: 1.25;
  font-weight: 900;
}

.answer-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.answer-button {
  min-height: 76px;
  padding: 14px;
  border: 3px solid var(--ink);
  border-radius: 10px 15px 9px 13px;
  background: var(--white);
  color: var(--ink);
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.answer-button:hover { transform: translateY(-3px); background: #fff5c9; }
.answer-button.correct { background: #cce9d7; border-color: #17653b; }
.answer-button.incorrect { background: #f6cfca; border-color: var(--red-dark); }
.answer-button:disabled { cursor: default; opacity: 0.72; }
.answer-button.correct:disabled { opacity: 1; }

.feedback {
  min-height: 32px;
  margin: 20px 0 12px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 900;
}

#next-button { display: block; margin: 0 auto; }
#next-button[hidden] { display: none; }

.completion-area { text-align: center; padding: 24px 0; }
.completion-area h2 { font-size: clamp(2rem, 5vw, 3rem); }
.completion-bell { font-size: 4rem; animation: bell 700ms ease-in-out 2; }

@keyframes bell {
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}

.completion-actions,
.dialog-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.secondary-button,
.danger-button {
  padding: 10px 18px;
  border: 3px solid var(--ink);
  border-radius: 9px;
}

.secondary-button { background: var(--white); color: var(--ink); }
.danger-button { background: var(--red); color: var(--white); }
.text-button { padding: 9px; background: transparent; color: var(--red-dark); text-decoration: underline; }

dialog {
  width: min(560px, calc(100% - 28px));
  padding: clamp(22px, 4vw, 36px);
  border: 4px solid var(--ink);
  border-radius: 14px 9px 17px 11px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--soft-shadow);
}

dialog::backdrop { background: rgba(23, 50, 77, 0.64); }

.dialog-heading {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.progress-list { display: grid; gap: 10px; margin: 18px 0 26px; }
.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 2px dashed #b89c65;
  font-weight: 800;
}

.empty-progress { padding: 22px; text-align: center; background: var(--cream); border-radius: 10px; }

@media (max-width: 800px) {
  .topbar { align-items: flex-start; }
  .brand span:last-child { display: none; }
  .player-status { flex-wrap: wrap; justify-content: flex-end; }
  .score span:last-child { display: none; }
  .home-screen { padding: 14px; }
  .welcome-note { margin-bottom: 14px; }
  .classroom-layout { grid-template-columns: 1fr; }
  .classroom { border-width: 3px; }
  .classroom img { border-radius: inherit; }
  .subject-shelf { min-height: 0; border-width: 3px; }
  .subject-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; }
}

@media (max-width: 520px) {
  .topbar { gap: 8px; padding: 10px; }
  .player-status { flex-wrap: nowrap; gap: 5px; }
  .score { gap: 4px; padding-inline: 7px; }
  .progress-button { padding-inline: 7px; font-size: 0.78rem; }
  .grade-button { padding-inline: 7px; font-size: 0.8rem; }
  .grade-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .welcome-note { width: 100%; padding: 16px; }
  .subject-buttons { grid-template-columns: 1fr; }
  .answer-options { grid-template-columns: 1fr; }
  .lesson-screen { padding: 14px; }
  .workbook { padding: 20px 16px; border-width: 3px; }
  .lesson-heading { display: block; }
  .question-count { display: inline-block; margin-bottom: 14px; }
  .completion-actions { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
