/* ------------------------------------------------------------------ *
 * Classroom worksheet app — sewing/paper theme.
 * Palette grounded in the Dorcas story (ink blue heading, thread red).
 * ------------------------------------------------------------------ */

:root {
  --ink: #1f3a5f;
  --ink-soft: #3a5578;
  --paper: #faf9f6;
  --card: #ffffff;
  --thread: #d5573b;
  --thread-dark: #b6432c;
  --green: #3f8f6b;
  --green-soft: #e4f2ea;
  --blank: #eef2f7;
  --blank-border: #b9c6da;
  --line: #e7e2d8;
  --muted: #6b7688;
  --shadow: 0 1px 2px rgba(31, 58, 95, 0.08), 0 8px 24px rgba(31, 58, 95, 0.06);
  --radius: 14px;
  --tag-radius: 11px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(31, 58, 95, 0.05) 1px, transparent 0);
  background-size: 22px 22px;
  line-height: 1.6;
  font-size: 17px;
}

h1, h2, h3, .display {
  font-family: "Baloo 2", "Nunito", sans-serif;
  color: var(--ink);
  line-height: 1.15;
  margin: 0;
}

a { color: var(--thread-dark); }

.wrap { max-width: 780px; margin: 0 auto; padding: 20px 18px 120px; }
.wrap--wide { max-width: 1040px; }

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0 18px;
}
.spool {
  width: 46px; height: 46px; flex: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #2b7a78 0%, #3aa9a6 100%);
  display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.spool::before {
  content: "";
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--thread);
  box-shadow: inset 0 0 0 5px #fff, inset 0 0 0 7px var(--thread-dark);
}
.topbar h1 { font-size: 1.7rem; }
.topbar .sub { color: var(--muted); font-size: 0.95rem; margin-top: 2px; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ---------- cards & buttons ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

button, .btn {
  font-family: "Baloo 2", sans-serif;
  font-size: 1rem;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  background: var(--ink);
  color: #fff;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}
button:hover, .btn:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:focus-visible, .btn:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--thread);
  outline-offset: 2px;
}
.btn--primary { background: var(--thread); }
.btn--primary:hover { background: var(--thread-dark); }
.btn--ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--blank-border); }
.btn--ghost:hover { background: #f0f3f8; }
.btn--danger { background: transparent; color: var(--thread-dark); border: 1.5px solid #e6c3ba; padding: 8px 14px; font-size: 0.9rem; }
.btn--sm { padding: 8px 14px; font-size: 0.9rem; }
button[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

input[type="text"], input[type="password"], textarea, select {
  font-family: "Nunito", sans-serif;
  font-size: 1rem;
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--blank-border);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--thread);
  box-shadow: 0 0 0 3px rgba(213, 87, 59, 0.15);
}
label { font-weight: 700; font-size: 0.92rem; display: block; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 5px; }

/* ---------- name / gate screen ---------- */
.gate { text-align: center; padding: 10px 4px; }
.gate h2 { font-size: 1.5rem; margin-bottom: 6px; }
.gate p { color: var(--muted); margin: 0 0 20px; }
.pick-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pick-row select { max-width: 320px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 22px 0; font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }

/* ---------- word bank tray ---------- */
.tray-wrap { position: sticky; top: 0; z-index: 20; padding-top: 8px; }
.tray {
  background: var(--card);
  border: 1.5px dashed var(--blank-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.tray-label { font-family: "Baloo 2"; font-size: 0.95rem; color: var(--ink-soft); margin: 0 0 10px; }
.tray-chips { display: flex; flex-wrap: wrap; gap: 10px; min-height: 44px; }
.tray.is-empty .tray-chips::after {
  content: "All words placed — check your story below.";
  color: var(--muted); font-size: 0.9rem; font-style: italic;
}

/* ---------- word chip (draggable paper tag) ---------- */
.chip {
  font-family: "Baloo 2", sans-serif;
  font-size: 1.05rem;
  padding: 8px 15px;
  border-radius: var(--tag-radius);
  background: #fff8ee;
  border: 1.5px solid #edd9b8;
  color: var(--ink);
  cursor: grab;
  user-select: none;
  touch-action: none;
  position: relative;
  box-shadow: 0 1px 0 #e7d3ad;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}
.chip::before { /* the tag hole */
  content: ""; position: absolute; left: 7px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: #fff; box-shadow: inset 0 0 0 1.5px #d8bf94;
}
.chip { padding-left: 22px; }
.chip:hover { box-shadow: 0 3px 8px rgba(31,58,95,0.12); }
.chip.is-selected { border-color: var(--thread); box-shadow: 0 0 0 3px rgba(213,87,59,0.2); }
.chip.is-ghosting { opacity: 0.25; }
.chip.chip--drag { /* the floating clone */
  position: fixed; z-index: 999; pointer-events: none;
  transform: rotate(-2deg) scale(1.05);
  box-shadow: 0 12px 26px rgba(31,58,95,0.25);
  cursor: grabbing;
}

/* ---------- story with blanks ---------- */
.story { }
.story h2 { font-size: 1.35rem; color: var(--thread-dark); margin: 26px 0 10px; }
.story p { margin: 0 0 16px; font-size: 1.12rem; line-height: 1.85; }

.blank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: baseline;
  min-width: 118px;
  min-height: 40px;
  margin: 0 3px;
  padding: 2px 8px;
  border-radius: var(--tag-radius);
  background: var(--blank);
  border: 2px dashed var(--blank-border);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.blank.is-over { border-color: var(--thread); background: #fdeee9; box-shadow: 0 0 0 3px rgba(213,87,59,0.15); }
.blank.is-filled { border-style: solid; border-color: transparent; background: transparent; padding: 0; min-width: 0; }
.blank.is-filled .chip { cursor: grab; margin: 0; }

/* review colouring after submit */
.blank.correct .chip { background: var(--green-soft); border-color: #a9d9c1; box-shadow: 0 1px 0 #bfe3d1; }
.blank.wrong .chip { background: #fdeae6; border-color: #eab6a8; box-shadow: 0 1px 0 #f0c4b8; }
.blank .mark { font-family: "Baloo 2"; margin-left: 6px; font-weight: 700; }
.blank.correct .mark { color: var(--green); }
.blank.wrong .mark { color: var(--thread-dark); }
.answer-hint { color: var(--green); font-weight: 700; font-size: 0.82rem; margin-left: 4px; }

/* ---------- reflection ---------- */
.reflection { margin-top: 8px; }
.reflection h2 { color: var(--thread-dark); font-size: 1.2rem; margin-bottom: 10px; }

/* ---------- submit bar ---------- */
.submitbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(250, 249, 246, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 18px;
}
.submitbar-inner {
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: center; gap: 14px;
}
.progress { flex: 1; }
.progress .bar { height: 10px; background: var(--blank); border-radius: 99px; overflow: hidden; }
.progress .bar > span { display: block; height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width 0.25s ease; }
.progress .count { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }

/* ---------- results ---------- */
.result-badge {
  text-align: center; padding: 8px 0 4px;
}
.result-badge .score { font-family: "Baloo 2"; font-size: 3rem; color: var(--thread); line-height: 1; }
.result-badge .score small { font-size: 1.4rem; color: var(--muted); }
.result-badge .msg { font-size: 1.15rem; margin-top: 6px; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  background: transparent; color: var(--ink-soft); border: none;
  border-radius: 10px 10px 0 0; padding: 10px 16px; font-size: 0.98rem;
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: 0 -2px 0 var(--thread) inset; border: 1px solid var(--line); border-bottom: none; }

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: "Baloo 2"; color: var(--ink-soft); font-weight: 600; font-size: 0.85rem; }
tr:last-child td { border-bottom: none; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 0.8rem; font-family: "Baloo 2"; }
.pill--active { background: var(--green-soft); color: var(--green); }
.pill--score { background: var(--blank); color: var(--ink-soft); }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 720px) { .split { grid-template-columns: 1fr; } }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-family: "Baloo 2"; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--thread-dark); }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px; font-style: italic; }
.preview-blank { display:inline-block; min-width: 90px; border-bottom: 2px dashed var(--blank-border); text-align:center; color: var(--green); font-weight:700; margin: 0 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .story p { font-size: 1.05rem; }
  .blank { min-width: 92px; }
  .card { padding: 16px; }
}
