/* =========================================================
   JEDAI TOOLS — Paper Classroom theme
   (Mirrors the Weekly Planner aesthetic: paper-cut, crayon
   primaries, thick ink outlines, 3D drop shadows.)
   ========================================================= */

:root {
  /* Palette */
  --paper:        #fbf3df;
  --paper-warm:   #fae9c8;
  --paper-dark:   #2a2438;
  --ink:          #2a2438;
  --ink-soft:     #5a4f6a;
  --line:         #2a2438;

  /* Tool category colors (crayon primaries) */
  --c-decodable:  #ff7aa9;  /* decodable passages — pink */
  --c-reading:    #ffc24c;  /* reading passages — yellow */
  --c-phonics:    #5cd6b1;  /* phonics worksheets — teal */
  --c-worksheet:  #5ea7ff;  /* reading worksheets — blue */
  --c-assess:     #b07cff;  /* assessments — purple */
  --c-parents:    #ff945c;  /* parent letters — orange */
  --c-extras:     #c79fff;  /* extras — lavender */
  --c-fluency:    #a7e34f;  /* fluency drills — lime */

  /* Sky */
  --sky-1: #ffeec5;
  --sky-2: #ffd6e0;
  --sky-3: #cfe8ff;

  /* 3D shadows */
  --shadow-card:  6px 8px 0 var(--ink);
  --shadow-pop:   10px 14px 0 var(--ink);
  --shadow-soft:  0 18px 36px rgba(42, 36, 56, .18);

  --radius:       18px;
  --radius-lg:    28px;
  --radius-pill:  999px;
}

[data-theme="plasticine"] {
  --paper:      #f6efe0;
  --paper-warm: #f1e3c5;
  --ink:        #3a2c4a;
  --line:       #3a2c4a;
  --c-decodable: #ff8fa6; --c-reading: #ffd06b; --c-phonics: #82e0c2;
  --c-worksheet: #8fb9ff; --c-assess: #c79fff;
}

[data-theme="chalkboard"] {
  --paper:      #1f3a36;
  --paper-warm: #2c4842;
  --ink:        #fff7e0;
  --ink-soft:   #d6cca8;
  --line:       #fff7e0;
  --sky-1: #1a322f; --sky-2: #25433d; --sky-3: #18302c;
  --shadow-card: 4px 6px 0 rgba(0,0,0,.5);
  --shadow-pop:  8px 10px 0 rgba(0,0,0,.6);
}

[data-theme="blocks"] {
  --paper:      #fff3d6;
  --paper-warm: #ffe3a3;
  --c-decodable: #e3433f; --c-reading: #f5b316; --c-phonics: #3aa86b;
  --c-worksheet: #2f7adc; --c-assess: #8b50d6;
}

/* =========================================================
   Base
   ========================================================= */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Baloo 2", "Fredoka", ui-rounded, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior-x: none;
}

body {
  background:
    radial-gradient(1200px 800px at 12% 0%, var(--sky-1) 0%, transparent 55%),
    radial-gradient(900px 700px at 92% 8%, var(--sky-2) 0%, transparent 50%),
    radial-gradient(900px 700px at 60% 100%, var(--sky-3) 0%, transparent 55%),
    var(--paper);
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: "Fredoka", sans-serif; font-weight: 600; margin: 0; }

[data-motion="low"] *,
[data-motion="low"] *::before,
[data-motion="low"] *::after {
  animation-duration: 0.001s !important;
  transition-duration: 100ms !important;
}

/* =========================================================
   App layout
   ========================================================= */

#root {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  z-index: 1;
}

.app {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 22px 28px 100px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 18px;
  max-width: 1620px;
  margin: 0 auto;
}

/* =========================================================
   Top bar
   ========================================================= */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  position: relative;
  background: var(--paper-warm);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  transform: rotate(-4deg);
}
.brand-mark svg { width: 36px; height: 36px; }

.brand h1 {
  font-size: 36px;
  line-height: 1;
  letter-spacing: -0.5px;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
}
.brand .subline {
  font-size: 15px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .subline .pin {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--c-reading);
  border: 2px solid var(--ink);
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-card);
  font-weight: 700;
  font-size: 15px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.tool-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 8px 10px 0 var(--ink);
}
.tool-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 3px 0 var(--ink);
}
.tool-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: var(--shadow-card); }
.tool-btn.icon-only { padding: 10px; }
.tool-btn svg { width: 18px; height: 18px; }

.tool-btn.tb-primary  { background: var(--c-phonics); }
.tool-btn.tb-back     { background: var(--paper-warm); }
.tool-btn.tb-danger   { background: var(--c-decodable); color: #fff; }
.tool-btn.tb-danger svg { stroke: #fff; }
.tool-btn.account-chip {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #fff;
}

.sync-line {
  margin-top: -8px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 800;
}

/* =========================================================
   Account gate
   ========================================================= */

.auth-page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(22px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  overflow: hidden;
}

.auth-card {
  position: relative;
  z-index: 3;
  width: min(520px, 100%);
  padding: 28px;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  background: rgba(255, 250, 240, 0.94);
  box-shadow: var(--shadow-pop);
}

.auth-brand { align-items: flex-start; margin-bottom: 22px; }
.auth-brand h1 { font-size: 34px; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.auth-tabs button {
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius-pill);
  background: #fff;
  box-shadow: 4px 5px 0 var(--ink);
}
.auth-tabs button.active { background: var(--c-reading); }

.auth-field { display: grid; gap: 6px; margin-bottom: 13px; }
.auth-field span {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.auth-field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 3px solid rgba(42, 36, 56, 0.5);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.auth-error {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: #ffe0e8;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
  background: var(--c-phonics);
}

.auth-note {
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

/* =========================================================
   Tools gallery (landing grid)
   ========================================================= */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px;
  padding: 8px 0 24px;
}

.tool-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px 22px 24px;
  background: var(--card-color, #fff);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transform: rotate(var(--rot, -0.6deg));
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease;
  text-align: left;
  font: inherit;
  color: inherit;
  overflow: hidden;
}
.tool-card:hover {
  transform: rotate(0deg) translate(-3px, -4px);
  box-shadow: 10px 12px 0 var(--ink);
}
.tool-card:active {
  transform: rotate(0deg) translate(2px, 3px);
  box-shadow: 3px 4px 0 var(--ink);
}
.tool-card.coming-soon {
  cursor: not-allowed;
  opacity: 0.78;
}
.tool-card.coming-soon:hover {
  transform: rotate(var(--rot, -0.6deg));
  box-shadow: var(--shadow-card);
}

.tool-card .tape {
  position: absolute;
  width: 64px;
  height: 18px;
  background: rgba(255, 220, 120, .8);
  border: 1px dashed rgba(42,36,56,.4);
  border-left: 1px solid rgba(42,36,56,.2);
  border-right: 1px solid rgba(42,36,56,.2);
  top: -8px;
  left: 50%;
  transform: translateX(-50%) rotate(-3deg);
  z-index: 2;
  pointer-events: none;
}

.tool-card .tc-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: rgba(255,255,255,.92);
  border: 3px solid var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 3px 4px 0 var(--ink);
}
.tool-card .tc-icon svg { width: 30px; height: 30px; }

.tool-card .tc-title {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 22px;
  line-height: 1.1;
}
.tool-card .tc-desc {
  font-size: 14px;
  font-weight: 600;
  color: rgba(42,36,56,.78);
  line-height: 1.35;
}
.tool-card .tc-tag {
  position: absolute;
  top: 18px;
  right: 18px;
  background: rgba(255,255,255,.85);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}
.tool-card .tc-tag.live  { background: var(--c-phonics); }
.tool-card .tc-tag.soon  { background: var(--paper-warm); }

.gallery-intro {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  margin-bottom: 6px;
}
.gallery-intro .gi-mark {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 14px;
  background: var(--c-reading);
  border: 3px solid var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 3px 4px 0 var(--ink);
}
.gallery-intro .gi-mark svg { width: 30px; height: 30px; }
.gallery-intro p {
  margin: 0;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
  line-height: 1.45;
}
.gallery-intro p strong { color: var(--ink); }

/* =========================================================
   Workspace layout (tool detail page)
   ========================================================= */

.workspace {
  display: grid;
  /* minmax(0, 1fr) is critical — without the 0 lower bound, the right
     column's content can push the column wider than the grid intends,
     causing it to bleed into / overlap the controls column. */
  grid-template-columns: minmax(340px, 400px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 980px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
}

.ws-controls {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ===== Week hero — the primary control ===== */

.ws-week-hero {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-warm);
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: 3px 4px 0 var(--ink);
}
.ws-week-badge {
  flex-shrink: 0;
  width: 46px; height: 46px;
  display: grid;
  place-items: center;
  background: var(--c-decodable);
  color: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  font-family: "Fredoka", sans-serif;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 2px 3px 0 var(--ink);
}
.ws-week-info {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}
.ws-week-select {
  border: 0;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  font-family: "Fredoka", sans-serif;
  color: var(--ink);
  padding: 0;
  cursor: pointer;
  outline: none;
  min-width: 0;
  width: 100%;
  text-overflow: ellipsis;
}
.ws-week-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}
.ws-link {
  background: transparent;
  border: 0;
  color: var(--c-assess);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: underline;
  padding: 2px 6px;
  border-radius: 6px;
}
.ws-link:hover { background: rgba(176, 124, 255, 0.12); }

/* ===== Sections with colored left bar ===== */

.ws-section {
  display: flex;
  gap: 0;
  min-width: 0;
}
.ws-section-bar {
  flex-shrink: 0;
  width: 5px;
  border-radius: 5px;
  background: var(--accent, var(--c-reading));
  margin-right: 14px;
}
.ws-section-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 10px;
}
.ws-adv-fields {
  display: grid;
  gap: 10px;
}

.ws-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 4px 0;
  background: transparent;
  border: 0;
  text-align: left;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  cursor: pointer;
}
.ws-group-toggle:hover { color: var(--c-assess); }
.ws-chev {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--paper-warm);
  border: 2px solid var(--ink);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1;
}

/* Field label hints */
.ws-field label .ws-hint,
.ws-hint {
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: rgba(90, 79, 106, 0.7);
  font-size: 11px;
}

/* ===== Generate CTA ===== */

.ws-cta {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 2px dashed rgba(42,36,56,.12);
}
.ws-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}
.ws-mode-opt {
  display: grid;
  gap: 2px;
  align-content: center;
  justify-items: center;
  padding: 9px 8px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--paper-warm);
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
}
.ws-mode-opt:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 2px 0 var(--ink);
}
.ws-mode-opt:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.ws-mode-opt.active {
  background: var(--c-phonics);
  box-shadow: 0 2px 0 var(--ink);
}
.ws-mode-opt .ws-mode-label {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.ws-mode-opt .ws-mode-sub {
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ws-mode-opt.active .ws-mode-sub {
  color: var(--ink);
}
.ws-model-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  font-weight: 800;
}
.ws-model-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--ink);
  background: var(--paper-warm);
  border: 1.5px solid var(--ink);
  padding: 1px 7px;
  border-radius: 999px;
}
.ws-model-tag {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  letter-spacing: 0.06em;
}
.ws-model-tag.ok   { background: var(--c-phonics); color: var(--ink); }
.ws-model-tag.warn { background: var(--c-decodable); color: #fff; }
.ws-model-fallback {
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: lowercase;
  letter-spacing: 0;
}

/* Recent section */
.ws-section-recent .history-list {
  max-height: 240px;
  overflow-y: auto;
}

.ws-field { display: grid; gap: 5px; }
.ws-field label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.ws-field input,
.ws-field select,
.ws-field textarea {
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
  outline: none;
  box-shadow: inset 0 -2px 0 rgba(42,36,56,.05);
}
.ws-field textarea { resize: vertical; min-height: 68px; line-height: 1.4; }
.ws-field input:focus,
.ws-field select:focus,
.ws-field textarea:focus {
  box-shadow: 3px 4px 0 var(--ink);
  transform: translate(-1px,-1px);
}

.ws-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ws-generate {
  width: 100%;
  justify-content: center;
  background: var(--c-decodable);
  color: #fff;
  font-size: 16px;
  padding: 14px 18px;
}
.ws-generate svg { stroke: #fff; }
.ws-generate:disabled { background: var(--paper-warm); color: var(--ink); }
.ws-generate:disabled svg { stroke: var(--ink); }

/* Scope chips — show graphemes in-scope */
.scope-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 110px;
  overflow-y: auto;
  overflow-x: hidden;     /* never escape the column */
  padding: 6px;
  border: 2px dashed rgba(42,36,56,.35);
  border-radius: 10px;
  background: rgba(255,255,255,.6);
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}
.scope-chip {
  font-size: 12px;
  font-weight: 800;
  padding: 2px 9px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--paper-warm);
  letter-spacing: 0.04em;
  font-family: "Fredoka", sans-serif;
}
.scope-chip.new { background: var(--c-phonics); }

/* =========================================================
   Output panel: passage preview + agent trace
   ========================================================= */

.ws-output {
  display: grid;
  gap: 18px;
  /* Don't let the right column's contents push the column wider than its
     grid track. Required when the parent grid uses minmax(0, 1fr). */
  min-width: 0;
}

.ws-output > * {
  /* Same defensive constraint for every direct child card. */
  min-width: 0;
  max-width: 100%;
}

.passage-card {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 26px 28px;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.passage-card .pc-title {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 26px;
  line-height: 1.1;
  margin-bottom: 14px;
  padding-right: 80px;
}
.passage-card .pc-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.passage-card .pc-meta .meta-pill {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--paper-warm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.passage-card .pc-meta .meta-pill.ok { background: var(--c-phonics); }
.passage-card .pc-meta .meta-pill.warn { background: var(--c-reading); }
.passage-card .pc-meta .meta-pill.fail { background: var(--c-decodable); color: #fff; }
.passage-card .pc-meta .meta-pill.ccss {
  background: #fff;
  border-color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.3px;
}

.passage-body {
  font-family: "Baloo 2", sans-serif;
  font-size: 19px;
  line-height: 1.7;
  font-weight: 500;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.passage-body .target { background: rgba(92, 214, 177, 0.42); border-radius: 4px; padding: 0 2px; font-weight: 700; }
.passage-body .sight  { background: rgba(255, 194, 76, 0.42); border-radius: 4px; padding: 0 2px; }
.passage-body .untaught { background: rgba(255, 122, 169, 0.45); border-radius: 4px; padding: 0 2px; text-decoration: underline wavy var(--ink); }

.passage-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 2px dashed rgba(42,36,56,.2);
}

/* Validator report */
.validator-report {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 22px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.validator-report h3 {
  font-size: 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.validator-report h3 .badge-pill {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.validator-report h3 .badge-pill.pass { background: var(--c-phonics); }
.validator-report h3 .badge-pill.fail { background: var(--c-decodable); color: #fff; }
.validator-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
}
.validator-list li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.6);
  border: 2px solid rgba(42,36,56,.15);
  font-size: 14px;
  font-weight: 600;
}
.validator-list li.ok { background: #e9faf2; border-color: rgba(60, 170, 130, 0.35); }
.validator-list li.fail { background: #ffe6ee; border-color: rgba(220, 80, 120, 0.35); }
.validator-list .v-mark {
  font-weight: 900;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  background: var(--ink);
  color: var(--paper);
}
.validator-list .fail .v-mark { background: var(--c-decodable); }
.validator-list .ok .v-mark   { background: var(--c-phonics); }
.validator-list .v-detail { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }

/* Comprehension questions card uses a numbered list, not the validator grid. */
.questions-list {
  list-style: decimal;
  padding-left: 24px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.questions-list li {
  padding: 8px 12px;
  border-radius: 10px;
  background: #e9faf2;
  border: 2px solid rgba(60, 170, 130, 0.35);
  font-size: 14px;
}
.questions-list .q-text { font-weight: 700; }
.questions-list .q-answer { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }
.questions-list .q-meta { color: var(--ink-soft); font-size: 11px; opacity: 0.7; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Agent trace */
.agent-trace {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 22px;
  min-width: 0;
}
.agent-trace h3 {
  font-size: 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.trace-steps {
  display: grid;
  gap: 8px;
}
.trace-step {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid rgba(42,36,56,.18);
  background: rgba(255,255,255,.6);
  transition: background .2s ease;
  min-width: 0;
}
.trace-step.active {
  background: var(--paper-warm);
  border-color: var(--ink);
  animation: trace-pulse 1.4s ease-in-out infinite;
}
.trace-step.done   { background: #eaf8f1; border-color: rgba(60, 170, 130, 0.35); }
.trace-step.failed { background: #ffe6ee; border-color: rgba(220, 80, 120, 0.35); }

@keyframes trace-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(176, 124, 255, .35); }
  50%     { box-shadow: 0 0 0 8px rgba(176, 124, 255, 0); }
}

.trace-step .ts-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--c-assess);
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
}
.trace-step .ts-icon svg { width: 18px; height: 18px; }
.trace-step.done   .ts-icon { background: var(--c-phonics); }
.trace-step.failed .ts-icon { background: var(--c-decodable); }
.trace-step.failed .ts-icon svg { stroke: #fff; }

.trace-step .ts-body {
  min-width: 0;
  overflow: hidden;
}
.trace-step .ts-name {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trace-step .ts-sub {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trace-step .ts-time {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-soft);
  white-space: nowrap;
  padding-left: 8px;
}

/* Empty workspace state */
.ws-empty {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 64px 24px;
  border: 3px dashed rgba(42,36,56,.3);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.5);
  color: var(--ink-soft);
  font-weight: 700;
}
.ws-empty .we-mark {
  width: 80px; height: 80px;
  border-radius: 22px;
  background: var(--c-reading);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-card);
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  transform: rotate(-3deg);
}
.ws-empty .we-mark svg { width: 44px; height: 44px; }
.ws-empty h3 { font-size: 22px; margin-bottom: 6px; color: var(--ink); }
.ws-empty p { max-width: 380px; line-height: 1.45; font-size: 15px; font-weight: 600; }

/* =========================================================
   History list (sidebar / inline)
   ========================================================= */

.history-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
  transition: transform .15s ease;
}
.history-item:hover {
  transform: translate(-1px,-1px);
  box-shadow: 3px 4px 0 var(--ink);
}
.history-item.selected {
  background: var(--c-reading);
}
.history-title {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-meta {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.history-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.history-badge.pass { background: var(--c-phonics); }
.history-badge.fail { background: var(--c-decodable); color: #fff; }
.history-badge.draft { background: var(--paper-warm); }

/* =========================================================
   Background scene (clouds, sun, stars)
   ========================================================= */

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.scene .cloud,
.scene .sun-bg,
.scene .star-bg,
.scene .planet-bg {
  position: absolute;
}

.scene .cloud { width: 160px; }
.scene .cloud svg { width: 100%; }

.scene .sun-bg {
  top: 80px; right: 8%;
  width: 220px; height: 220px;
  animation: spin-slow 60s linear infinite;
}

@keyframes spin-slow { to { transform: rotate(360deg); } }
@keyframes float-1 {
  0%,100% { transform: translateY(0) translateX(0); }
  50%     { transform: translateY(-18px) translateX(10px); }
}
@keyframes float-2 {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-12px); }
}
@keyframes drift {
  from { transform: translateX(-200px); }
  to   { transform: translateX(calc(100vw + 200px)); }
}

.scene .cloud-1 { top: 18%; left: -200px; animation: drift 80s linear infinite; }
.scene .cloud-2 { top: 6%;  left: -200px; animation: drift 110s linear infinite 20s; opacity: .7; }
.scene .cloud-3 { top: 38%; left: -200px; animation: drift 95s linear infinite 40s; opacity: .85; }

.scene .planet-bg {
  bottom: 8%;
  right: 4%;
  width: 90px; height: 90px;
  animation: float-1 8s ease-in-out infinite;
}

.scene .star-bg {
  animation: float-2 4s ease-in-out infinite;
}

/* =========================================================
   Toast
   ========================================================= */

.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translate(-50%, -80px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 200;
  transition: transform .35s cubic-bezier(.4,1.4,.5,1);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.toast.show { transform: translate(-50%, 0); }
.toast svg { stroke: var(--paper); width: 16px; height: 16px; }

/* =========================================================
   Disclaimer banner (the SoR-honesty note)
   ========================================================= */

.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: #fff6d1;
  border: 2px dashed var(--ink);
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.5;
}
.disclaimer svg {
  flex-shrink: 0;
  width: 20px; height: 20px;
  margin-top: 1px;
}

/* =========================================================
   Loading shimmer / spinner
   ========================================================= */

.shimmer {
  position: relative;
  overflow: hidden;
  background: rgba(255,255,255,.6);
  border: 2px dashed rgba(42,36,56,.2);
  border-radius: 16px;
  min-height: 80px;
}
.shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent);
  animation: shimmer-sweep 1.4s linear infinite;
}
@keyframes shimmer-sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

.spinner {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 3px solid rgba(42,36,56,.25);
  border-top-color: var(--ink);
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   Generating Animation
   ========================================================= */

.gen-anim {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fef9f0;
  border: 3px solid var(--ink);
}

.gen-anim-rainbow {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(255,107,107,.15),
    rgba(255,183,77,.15),
    rgba(255,213,79,.15),
    rgba(129,199,132,.15),
    rgba(100,181,246,.15),
    rgba(186,147,214,.15),
    rgba(255,107,107,.15)
  );
  background-size: 400% 400%;
  animation: gen-rainbow 6s ease infinite;
}

@keyframes gen-rainbow {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.gen-anim-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 40px 24px;
  text-align: center;
}

.gen-anim-pencil svg {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.1));
}

.gen-pencil-bob {
  animation: gen-bob 1.2s ease-in-out infinite;
  transform-origin: 32px 36px;
}

@keyframes gen-bob {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50%      { transform: translateY(-8px) rotate(5deg); }
}

.gen-anim-letters {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  font-family: var(--f-head);
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
}

.gen-letter {
  display: inline-block;
  animation: gen-wave 1.8s ease-in-out infinite;
}

@keyframes gen-wave {
  0%, 100% { transform: translateY(0); color: var(--ink); }
  25%      { transform: translateY(-6px); color: #EF5350; }
  50%      { transform: translateY(0); color: #AB47BC; }
  75%      { transform: translateY(-3px); color: #42A5F5; }
}

.gen-anim-msg {
  font-family: var(--f-head);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  opacity: .75;
  animation: gen-fade 3s ease-in-out infinite;
  min-height: 1.4em;
}

@keyframes gen-fade {
  0%, 100% { opacity: .5; }
  30%, 70% { opacity: 1; }
}

.gen-anim-dots {
  display: flex;
  gap: 8px;
}

.gen-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
  opacity: .3;
  animation: gen-bounce 1.4s ease-in-out infinite;
}

.gen-dot:nth-child(2) { animation-delay: .2s; }
.gen-dot:nth-child(3) { animation-delay: .4s; }

@keyframes gen-bounce {
  0%, 80%, 100% { transform: scale(1); opacity: .3; }
  40%           { transform: scale(1.5); opacity: .8; }
}

/* =========================================================
   Print
   ========================================================= */

@media print {
  body { background: #fff; }
  .scene, .toolbar, .ws-controls, .agent-trace, .validator-report, .toast { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .passage-card { box-shadow: none; border-width: 2px; }
  .passage-body { font-size: 16px; }
}

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 720px) {
  :root {
    --shadow-card: 4px 5px 0 var(--ink);
    --shadow-pop: 6px 8px 0 var(--ink);
  }
  .app {
    padding:
      max(12px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(82px, calc(72px + env(safe-area-inset-bottom)))
      max(10px, env(safe-area-inset-left));
    gap: 12px;
  }
  .topbar { display: grid; gap: 12px; }
  .brand { gap: 10px; min-width: 0; }
  .brand h1 { font-size: 24px; line-height: 1.02; }
  .brand .subline { font-size: 13px; }
  .brand-mark { width: 44px; height: 44px; border-radius: 14px; }
  .brand-mark svg { width: 30px; height: 30px; }
  .toolbar {
    gap: 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 2px 2px 8px;
    margin-inline: -2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .tool-btn { flex: 0 0 auto; min-height: 44px; padding: 9px 13px; font-size: 14px; box-shadow: 4px 5px 0 var(--ink); }
  .tool-btn:hover { transform: none; box-shadow: 4px 5px 0 var(--ink); }
  .tool-btn.account-chip { max-width: 190px; }

  .gallery { grid-template-columns: 1fr; gap: 16px; }
  .tool-card { padding: 18px; }
  .tool-card:hover { transform: none; box-shadow: var(--shadow-card); }

  .workspace { gap: 14px; }
  .ws-controls { position: static; padding: 16px; }
  .passage-card { padding: 18px; }
  .passage-card .pc-title { font-size: 22px; padding-right: 0; }
  .passage-body { font-size: 17px; }

  .auth-page {
    align-items: start;
    padding:
      max(18px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .auth-card { margin-top: 42px; padding: 20px; border-radius: 22px; box-shadow: 6px 8px 0 var(--ink); }
  .auth-brand h1 { font-size: 27px; }
  .auth-tabs { gap: 8px; }
  .auth-tabs button { min-height: 44px; padding: 8px 10px; box-shadow: 3px 4px 0 var(--ink); }

  .scene .cloud,
  .scene .planet-bg,
  .scene .star-bg { display: none; }
  .scene .sun-bg {
    top: 70px;
    right: -34px;
    width: 150px;
    height: 150px;
    animation: none;
    opacity: .72;
  }
}
