/* ==========================================================================
   Worksheet Boss — design system
   "Paper & ink": warm cream stock, ink navy, a teacher's red-pen accent.
   Dark mode reads as a chalkboard.
   ========================================================================== */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400..900;1,9..144,400..700&family=Instrument+Sans:ital,wght@0,400..700;1,400..600&display=swap");

:root {
  /* Palette — light (paper) */
  --paper: #f5efe1;
  --paper-2: #efe7d4;
  --card: #fffdf7;
  --ink: #211d1a;
  --ink-soft: #5b534a;
  --ink-faint: #8a8071;
  --line: #e2d8c3;
  --line-strong: #d3c6ab;

  --red: #d7452f;        /* teacher's red pen */
  --red-deep: #b5341f;
  --teal: #1f7a6d;       /* supporting */
  --teal-deep: #155e54;
  --amber: #e9a13b;

  --rule: #cfe0ee;       /* worksheet ruled-line blue */
  --rule-margin: #e7b3a6;/* worksheet margin red */

  --shadow-sm: 0 1px 2px rgba(33, 29, 26, 0.06), 0 2px 6px rgba(33, 29, 26, 0.05);
  --shadow-md: 0 4px 12px rgba(33, 29, 26, 0.08), 0 12px 32px rgba(33, 29, 26, 0.08);
  --shadow-lg: 0 12px 28px rgba(33, 29, 26, 0.12), 0 30px 60px rgba(33, 29, 26, 0.12);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 22px;
  --maxw: 1180px;

  --bg: var(--paper);
  --bg-2: var(--paper-2);
  --accent: var(--red);
  --accent-deep: var(--red-deep);
}

:root[data-theme="dark"] {
  /* Palette — dark (chalkboard) */
  --paper: #14201c;
  --paper-2: #101a17;
  --card: #1b2a25;
  --ink: #f2efe4;
  --ink-soft: #b9c3ba;
  --ink-faint: #869089;
  --line: #2a3c35;
  --line-strong: #374c43;

  --red: #ff6a4d;
  --red-deep: #ff8168;
  --teal: #4fd1b8;
  --teal-deep: #37b79f;
  --amber: #f0b45f;

  --rule: #2f4a44;
  --rule-margin: #5a4038;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);

  --bg: var(--paper);
  --bg-2: var(--paper-2);
  --accent: var(--red);
  --accent-deep: var(--red-deep);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14201c;
    --paper-2: #101a17;
    --card: #1b2a25;
    --ink: #f2efe4;
    --ink-soft: #b9c3ba;
    --ink-faint: #869089;
    --line: #2a3c35;
    --line-strong: #374c43;
    --red: #ff6a4d;
    --red-deep: #ff8168;
    --teal: #4fd1b8;
    --teal-deep: #37b79f;
    --amber: #f0b45f;
    --rule: #2f4a44;
    --rule-margin: #5a4038;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
  }
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(33, 29, 26, 0.05) 1px, transparent 0);
  background-size: 22px 22px;
  line-height: 1.6;
  font-size: 17px;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

:root[data-theme="dark"] body {
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.035) 1px, transparent 0);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 0.5em;
  font-optical-sizing: auto;
}

h1 { font-size: clamp(2.5rem, 6vw, 4.5rem); font-weight: 640; }
h2 { font-size: clamp(1.9rem, 4vw, 2.9rem); }
h3 { font-size: clamp(1.3rem, 2.4vw, 1.7rem); }

p { margin: 0 0 1rem; }

a {
  color: var(--accent-deep);
  text-decoration: none;
  text-underline-offset: 3px;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

::selection { background: var(--accent); color: #fff; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.eyebrow {
  font-family: var(--font-body);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent-deep);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.eyebrow::before {
  content: "";
  width: 26px;
  height: 2px;
  background: var(--accent);
  display: inline-block;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1;
  border: 1.5px solid transparent;
  border-radius: 999px;
  padding: 0.85rem 1.5rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.18s ease,
    border-color 0.18s ease, color 0.18s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--accent-deep);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-ink {
  background: var(--ink);
  color: var(--paper);
}
.btn-ink:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.btn-outline {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-outline:hover { border-color: var(--ink); background: var(--card); }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  padding: 0.6rem 0.9rem;
}
.btn-ghost:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }

.btn-sm { padding: 0.55rem 1rem; font-size: 0.9rem; }
.btn-lg { padding: 1rem 1.9rem; font-size: 1.08rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

/* --------------------------------------------------------------------------
   Cards & surfaces
   -------------------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--teal) 15%, transparent);
  color: var(--teal-deep);
  border: 1px solid color-mix(in srgb, var(--teal) 30%, transparent);
}
.badge-red {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent-deep);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* --------------------------------------------------------------------------
   Top navigation
   -------------------------------------------------------------------------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1.5px solid var(--line);
}
.site-nav .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.28rem;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  list-style: none;
  padding: 0;
}
.nav-links a {
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.96rem;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
}
.nav-links a:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); text-decoration: none; }

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1.5px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.theme-toggle:hover { border-color: var(--ink); }
.theme-toggle .sun { display: none; }
.theme-toggle .moon { display: block; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}

.nav-toggle { display: none; }

@media (max-width: 820px) {
  .nav-links {
    position: fixed;
    inset: 0 0 auto 0;
    top: 61px;
    flex-direction: column;
    align-items: stretch;
    gap: 0.2rem;
    background: var(--bg);
    border-bottom: 1.5px solid var(--line);
    padding: 1rem 1.5rem 1.4rem;
    transform: translateY(-120%);
    transition: transform 0.28s ease;
  }
  .nav-links.open { transform: translateY(0); }
  .nav-links a { padding: 0.8rem; font-size: 1.05rem; }
  .nav-toggle {
    display: inline-grid;
    place-items: center;
    margin-left: auto;
    width: 42px; height: 42px;
    background: transparent; border: 1.5px solid var(--line-strong);
    border-radius: 10px; color: var(--ink); cursor: pointer;
  }
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
label { font-weight: 600; font-size: 0.92rem; color: var(--ink); display: block; margin-bottom: 0.4rem; }
.field { margin-bottom: 1.1rem; }
.hint { font-size: 0.82rem; color: var(--ink-faint); margin-top: 0.35rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 84px; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235b534a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.2rem;
  cursor: pointer;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }

/* --------------------------------------------------------------------------
   Worksheet "paper" — the printable artifact
   -------------------------------------------------------------------------- */
.sheet {
  background: #fffef9;
  color: #1a1a1a;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  padding: 3.2rem 3rem 3.6rem;
  position: relative;
  max-width: 780px;
  margin: 0 auto;
  font-family: "Fraunces", Georgia, serif;
  font-optical-sizing: auto;
  border: 1px solid #e7e0cd;
  overflow: hidden;
  overflow-wrap: break-word;
}
/* three-hole punch + red margin line, like real notebook paper */
.sheet::before {
  content: "";
  position: absolute;
  left: 2.1rem; top: 0; bottom: 0;
  width: 2px;
  background: #efb8ad;
}
.sheet-head {
  border-bottom: 2.5px solid #1a1a1a;
  padding-bottom: 1rem;
  margin-bottom: 1.4rem;
}
.sheet-namebar {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: #333;
  margin-bottom: 1.1rem;
}
.sheet-namebar span { flex: 1; border-bottom: 1.5px solid #333; padding-bottom: 2px; }
.sheet-namebar span::before { content: attr(data-label); color: #666; margin-right: 0.4rem; }
.sheet h1.sheet-title { font-size: 1.9rem; margin: 0; color: #1a1a1a; }
.sheet .sheet-intro {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: #444;
  font-style: italic;
  margin: 0.4rem 0 0;
}
.q {
  margin: 0 0 1.5rem;
  padding-left: 0.4rem;
  page-break-inside: avoid;
  break-inside: avoid;
}
.q-prompt {
  display: flex;
  gap: 0.6rem;
  font-size: 1.05rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}
.q-num {
  font-weight: 700;
  color: var(--accent-deep);
  font-family: var(--font-body);
  flex: 0 0 auto;
}
.q-choices { list-style: none; margin: 0.4rem 0 0; padding: 0 0 0 1.6rem; font-family: var(--font-body); font-size: 0.98rem; }
.q-choices li { margin: 0.35rem 0; display: flex; gap: 0.6rem; align-items: baseline; }
.q-choices .bubble {
  flex: 0 0 auto;
  width: 1.35rem; height: 1.35rem;
  border: 1.5px solid #555;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 0.78rem; font-weight: 700; color: #555;
}
.q-lines { margin: 0.5rem 0 0 1.6rem; }
.q-lines .rule { height: 1.7rem; border-bottom: 1.5px solid #c9d6e2; }
.q-tf { font-family: var(--font-body); padding-left: 1.6rem; margin-top: 0.35rem; display: flex; gap: 1.4rem; }
.q-tf label { font-weight: 500; display: inline-flex; gap: 0.4rem; align-items: center; }
.q-tf .box { width: 1.1rem; height: 1.1rem; border: 1.5px solid #555; border-radius: 3px; display: inline-block; }
.q-match { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.4rem 2rem; font-family: var(--font-body); font-size: 0.96rem; padding-left: 1.6rem; margin-top: 0.5rem; }
.q-match .col-head { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #777; border-bottom: 1px solid #ccc; padding-bottom: 0.2rem; }
.q-match .m-left { display: flex; gap: 0.6rem; }
.q-match .m-left .slot { width: 1.6rem; border-bottom: 1.5px solid #555; flex: 0 0 auto; }
.q-match .m-letter { font-weight: 700; color: #555; margin-right: 0.5rem; }
.q-blank-word { display: inline-block; min-width: 90px; border-bottom: 1.5px solid #555; }

/* reading passage */
.q-passage {
  border: 1.5px solid #d8d0ba;
  border-left: 4px solid var(--accent);
  background: #fbf8ef;
  border-radius: 4px;
  padding: 1.1rem 1.3rem;
  margin: 0 0 1.5rem;
  font-size: 1.02rem;
  line-height: 1.65;
  color: #222;
}
.q-passage-label {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-deep);
  margin-bottom: 0.5rem;
}
.q-passage p { margin: 0 0 0.7rem; }
.q-passage p:last-child { margin-bottom: 0; }

/* word bank */
.word-bank {
  border: 1.5px dashed #b9ae92;
  border-radius: 6px;
  padding: 0.8rem 1rem;
  margin: 0 0 1.6rem;
  font-family: var(--font-body);
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.word-bank-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #857a60;
  margin-right: 0.4rem;
}
.word-chip {
  background: #f3eeda;
  border: 1px solid #ddd3b5;
  border-radius: 999px;
  padding: 0.18rem 0.75rem;
  font-size: 0.92rem;
  color: #333;
}

/* sheet footer credit */
.sheet-foot {
  margin-top: 2.2rem;
  text-align: right;
  font-family: var(--font-body);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: #b6ac93;
}

/* answer key */
.answer-key {
  margin-top: 2rem;
  border-top: 2px dashed #bbb;
  padding-top: 1.2rem;
  font-family: var(--font-body);
}
.answer-key h2 { font-family: var(--font-display); font-size: 1.3rem; color: #1a1a1a; }
.answer-key ol { padding-left: 1.4rem; }
.answer-key li { margin: 0.3rem 0; font-size: 0.95rem; color: #333; }
.answer-key .exp { color: #777; font-style: italic; }

/* narrow phones: tighter paper margins, same layout */
@media (max-width: 560px) {
  .sheet { padding: 2.2rem 1.3rem 2.6rem 1.7rem; }
  .sheet::before { left: 0.85rem; }
  .q-match { gap: 0.4rem 1rem; padding-left: 0.9rem; }
  .q-choices { padding-left: 0.9rem; }
  .q-lines { margin-left: 0.9rem; }
  .q-tf { padding-left: 0.9rem; }
}

/* --------------------------------------------------------------------------
   Utility
   -------------------------------------------------------------------------- */
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.grow { flex: 1 1 0; }
.hidden { display: none !important; }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 1.5rem; left: 50%;
  transform: translateX(-50%) translateY(140%);
  background: var(--ink);
  color: var(--paper);
  padding: 0.8rem 1.3rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-weight: 500;
  font-size: 0.95rem;
  z-index: 200;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red-deep); color: #fff; }

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
.rise { animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) both; }

/* Scroll reveal: elements with [data-reveal] rise in when they enter the
   viewport (ui.js adds .revealed). Hidden ONLY when JS is running (ui.js puts
   .js-reveal on <html>), so content stays visible if scripts fail to load.
   Stagger with data-reveal="2|3". */
.js-reveal [data-reveal] {
  opacity: 0;
  transform: translateY(26px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1), transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}
.js-reveal [data-reveal].revealed { opacity: 1; transform: none; }
.js-reveal [data-reveal="2"].revealed { transition-delay: 0.12s; }
.js-reveal [data-reveal="3"].revealed { transition-delay: 0.24s; }
@media (prefers-reduced-motion: reduce) {
  .js-reveal [data-reveal] { opacity: 1; transform: none; }
}

/* modal overlay (sign-up prompt etc.) */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  backdrop-filter: blur(3px);
  padding: 1rem;
  animation: fadeIn 0.2s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%;
  max-width: 440px;
  padding: 2rem 1.9rem;
  animation: rise 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

/* --------------------------------------------------------------------------
   Print — only the worksheet paper survives
   -------------------------------------------------------------------------- */
@media print {
  @page { margin: 0.6in; }
  body { background: #fff !important; }
  body * { visibility: hidden; }
  .sheet, .sheet * { visibility: visible; }
  .sheet {
    position: absolute;
    left: 0; top: 0;
    box-shadow: none;
    border: none;
    max-width: none;
    width: 100%;
    padding: 0;
  }
  .sheet::before { display: none; }
  .no-print { display: none !important; }
  .answer-key { page-break-before: always; }
}
