:root {
  --paper: #f7f1e6;
  --ink: #1f2722;
  --muted: #6f756f;
  --line: #d8cdbb;
  --panel: #fffaf0;
  --green: #1e6f57;
  --blue: #245b7a;
  --rust: #a5502b;
  --shadow: 0 18px 40px rgba(39, 33, 24, 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31, 39, 34, .045) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(var(--paper), #eee4d4);
  font-family: "Aptos", "Segoe UI", sans-serif;
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(2rem, 4vw, 4.2rem); line-height: 1; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.25rem; }
a { color: inherit; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 240, .86);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 4;
}
.brand { font-family: Georgia, "Times New Roman", serif; font-weight: 700; text-decoration: none; font-size: 1.2rem; }
nav { display: flex; align-items: center; gap: 16px; }
nav a { text-decoration: none; color: var(--muted); font-weight: 650; }
nav form { margin: 0; }

.shell { width: min(1180px, calc(100vw - 32px)); margin: 34px auto 72px; }
.page-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 28px; }
.eyebrow { color: var(--rust); text-transform: uppercase; font-size: .74rem; font-weight: 800; letter-spacing: .12em; margin: 0 0 8px; }
.metric-row { display: flex; gap: 10px; flex-wrap: wrap; }
.metric-row span { border: 1px solid var(--line); background: var(--panel); padding: 10px 12px; border-radius: 6px; min-width: 112px; }
.metric-row strong { font-size: 1.4rem; display: block; }

.band, .panel, .lesson-card, .review-surface, .login-panel {
  background: rgba(255, 250, 240, .9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.band { padding: 22px; margin: 18px 0; border-radius: 8px; }
.notice {
  border-left: 4px solid var(--blue);
  background: rgba(36, 91, 122, .08);
  padding: 12px 14px;
  margin: 18px 0;
  border-radius: 6px;
  font-weight: 700;
}
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 18px; }
.lesson-card { border-radius: 8px; padding: 18px; min-height: 190px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.lesson-card p { color: var(--muted); margin: 0; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 18px; }
.panel { border-radius: 8px; padding: 20px; }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-weight: 700; color: #3f463f; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  border-radius: 6px;
  padding: 11px 12px;
  font: inherit;
}
textarea { resize: vertical; }
button, .link-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
}
.primary { background: var(--green); color: white; border-color: var(--green); }
.secondary { background: transparent; color: var(--blue); }
.icon-button { background: transparent; color: var(--muted); }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 10px 8px; vertical-align: top; }
th { color: var(--blue); font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; }

.review-surface { width: min(780px, 100%); margin: 8vh auto; border-radius: 8px; padding: clamp(24px, 5vw, 56px); }
.card-face { font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.2rem, 7vw, 5rem); line-height: 1.05; margin: 28px 0; }
.answer-block { border-top: 1px solid var(--line); margin: 18px 0; padding-top: 18px; font-size: 1.4rem; }
.answer-form { display: grid; gap: 16px; }
.review-meta { display: flex; justify-content: space-between; gap: 16px; align-items: center; flex-wrap: wrap; }
.progress-label { color: var(--blue); font-weight: 800; margin: 6px 0 0; }
.timer-label { color: var(--muted); font-weight: 800; margin: 6px 0 0; }
#session-timer { color: var(--ink); font-variant-numeric: tabular-nums; }
.review-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.quiet-link { color: var(--blue); font-weight: 800; text-decoration: none; }
.quiet-link:hover { text-decoration: underline; }
.explain-stack {
  display: grid;
  gap: 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 24px 0;
  padding: 24px 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.empty { color: var(--muted); }
.error { background: #f9dddd; color: #7c1f1f; padding: 10px 12px; border-radius: 6px; }
.inline-setting { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; width: 100%; }
.inline-setting input { min-width: 0; }
.table-setting { display: flex; gap: 8px; align-items: center; }
.table-setting input { width: 86px; }

.login-page { display: grid; place-items: center; }
.login-shell { width: min(480px, calc(100vw - 32px)); }
.login-panel { border-radius: 8px; padding: 32px; }
.login-panel h1 { margin-bottom: 24px; }

@media (max-width: 720px) {
  .topbar { padding: 0 16px; }
  nav { gap: 8px; }
  .page-heading { align-items: start; flex-direction: column; }
  .grade-row { grid-template-columns: repeat(2, 1fr); }
  table { display: block; overflow-x: auto; }
}
