/* ============================================================
   WaffleBrain — Unified Stylesheet
   Covers: index.html (Teacher) + student.html (Student)
   Sections:
     1. Reset
     2. Tokens (:root)
     3. Shared layout
     4. Shared components (badge, buttons, footer)
     5. Teacher-only
     6. Student-only
     7. Utilities & overrides
   ============================================================ */


/* ── 1. Reset ─────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Buttons across both pages: avoid the ~300ms tap delay and
   accidental double-tap zoom on mobile, without altering any
   other styling. */
button {
  touch-action: manipulation;
}


/* ── 2. Tokens ────────────────────────────────────────────── */

:root {
  /* Surface */
  --bg:           #F7F6F3;
  --surface:      #FFFFFF;
  --border:       #E4E2DC;
  --border-light: #EDECE8;

  /* Text */
  --text-primary:   #1C1C1E;
  --text-secondary: #5C5C6E;
  --text-tertiary:  #9898A6;

  /* Badge (default; overridden per mode below) */
  --badge-bg:   #EEF2FF;
  --badge-text: #3B5BDB;

  /* Teacher — constraint block */
  --constraint-bg:     #FFFBF0;
  --constraint-border: #FDE89A;
  --constraint-label:  #B45309;
  --constraint-text:   #44360A;

  /* Teacher buttons (blue) */
  --teacher-btn-bg:        #3B5BDB;
  --teacher-btn-bg-hover:  #3451C7;
  --teacher-btn-bg-active: #2F47B3;
  --teacher-flash-ring:    rgba(59, 91, 219, 0.18);

  /* Student buttons (orange) */
  --student-btn-bg:        #D4610B;
  --student-btn-bg-hover:  #C05509;
  --student-btn-bg-active: #AB4A08;
  --student-flash-ring:    rgba(212, 97, 11, 0.18);

  /* Student — Waffle Starters box */
  --starters-bg:     #FFF6EC;
  --starters-border: #FBDFC0;
  --starters-label:  #B45309;

  /* Active button (set per page via body class — see section 5 & 6) */
  --btn-bg:        var(--teacher-btn-bg);
  --btn-bg-hover:  var(--teacher-btn-bg-hover);
  --btn-bg-active: var(--teacher-btn-bg-active);
  --btn-text:      #FFFFFF;
  --flash-ring:    var(--teacher-flash-ring);
}

/* Student page overrides button tokens */
body.student {
  --btn-bg:        var(--student-btn-bg);
  --btn-bg-hover:  var(--student-btn-bg-hover);
  --btn-bg-active: var(--student-btn-bg-active);
  --flash-ring:    var(--student-flash-ring);
}


/* ── 3. Shared layout ─────────────────────────────────────── */

html {
  height: 100%;
  height: 100dvh;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  width: 100%;
  max-width: 380px;
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 20px;
}

/* Header */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0 2px;
  flex-shrink: 0;
}

.logo-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.logo-img {
  display: block;
  height: 44px;
  width: auto;
  object-fit: contain;
  object-position: left center;
}

.logo-subtitle {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
  line-height: 1;
  padding-left: 1px;
}

/* Version nav */

.version-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.version-link {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-decoration: none;
  padding: 4px 9px;
  border-radius: 6px;
  transition: background 0.1s ease, color 0.1s ease;
}

.version-link.active {
  background: var(--btn-bg);
  color: #fff;
}

.version-link.inactive {
  color: var(--text-tertiary);
  background: transparent;
  border: 1px solid var(--border);
}

.version-link.inactive:hover {
  color: var(--text-secondary);
  border-color: var(--text-tertiary);
  background: var(--bg);
}

/* Prompt card */

#prompt-card {
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Flash ring */

#prompt-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  box-shadow: 0 0 0 0 var(--flash-ring);
  transition: box-shadow 0s;
  pointer-events: none;
}

#prompt-card.flash::before {
  box-shadow: 0 0 0 4px var(--flash-ring);
}


/* ── 4. Shared components ─────────────────────────────────── */

/* Mode badge */

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px 3px 7px;
  border-radius: 100px;
  align-self: flex-start;
  white-space: nowrap;
}

.mode-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
  flex-shrink: 0;
}

/* Per-category badge colours — shared across both pages.
   Keys match the category/group names used in prompts.json exactly. */
#prompt-card[data-mode="Everyday Situations"] .mode-badge { --badge-bg: #EEF2FF; --badge-text: #3B5BDB; }
#prompt-card[data-mode="Describe"]            .mode-badge { --badge-bg: #E8F8F5; --badge-text: #0E7490; }
#prompt-card[data-mode="Explain and Show"]    .mode-badge { --badge-bg: #FFF3BF; --badge-text: #845E00; }
#prompt-card[data-mode="Simple Roleplay"]     .mode-badge { --badge-bg: #FFF0F6; --badge-text: #C2255C; }
#prompt-card[data-mode="Choose and Create"]   .mode-badge { --badge-bg: #F3F0FF; --badge-text: #6741D9; }
#prompt-card[data-mode="Guided Stories"]      .mode-badge { --badge-bg: #E8F5E9; --badge-text: #2E7D32; }

/* Prompt text */

#prompt-text {
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* Button row */

.btn-wrap {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-shrink: 0;
}

#back-btn {
  flex-shrink: 0;
  padding: 15px 14px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease, transform 0.07s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#back-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

#back-btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--text-tertiary);
  color: var(--text-primary);
}

#back-btn:active:not(:disabled) { transform: translateY(1px); }

#back-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#back-btn:focus-visible {
  outline: 2px solid var(--btn-bg);
  outline-offset: 3px;
}

#next-btn {
  flex: 1;
  min-width: 0;
  padding: 15px 16px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 10px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.1s ease, transform 0.07s ease, box-shadow 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: hidden;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.08);
}

#next-btn svg {
  width: 15px;
  height: 15px;
  opacity: 0.85;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

#next-btn:hover { background: var(--btn-bg-hover); }
#next-btn:hover svg { transform: translateX(2px); }

#next-btn:active {
  background: var(--btn-bg-active);
  transform: translateY(1px);
}

#next-btn:focus-visible {
  outline: 2px solid var(--btn-bg);
  outline-offset: 3px;
}

/* Footer */

footer {
  margin-top: 12px;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
  text-align: center;
  letter-spacing: 0.01em;
  flex-shrink: 0;
}

footer kbd {
  display: inline-block;
  background: var(--border);
  color: var(--text-secondary);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  border: 1px solid #D4D2CC;
}


/* ── 5. Teacher-only ──────────────────────────────────────── */

/* Waffle selector */
.waffle-select {
  position: relative;
  margin-bottom: 8px;
  padding: 0 2px;
  flex-shrink: 0;
}

.waffle-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
}

.waffle-trigger:focus-visible {
  outline: 2px solid var(--btn-bg);
  outline-offset: 2px;
}

.waffle-trigger-icon {
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

.waffle-trigger-label {
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.waffle-trigger-chevron {
  width: 10px;
  height: 6px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.waffle-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 2px;
  right: 2px;
  z-index: 20;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px;
  list-style: none;
}

.waffle-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.waffle-option:hover:not(.locked) { background: var(--bg); }

.waffle-option[aria-selected="true"] {
  background: var(--badge-bg);
  color: var(--badge-text);
  font-weight: 600;
}

.waffle-option-icon {
  font-size: 13px;
  flex-shrink: 0;
}

.waffle-option-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.waffle-option-tag {
  flex-shrink: 0;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  background: var(--border-light);
  padding: 2px 5px;
}

.waffle-option.locked {
  color: var(--text-tertiary);
  opacity: 0.62;
  cursor: not-allowed;
}

.waffle-separator {
  margin: 6px 4px 4px;
  padding-top: 7px;
  border-top: 1px solid var(--border-light);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Selector bar */
.selector-bar {
  margin-bottom: 10px;
  padding: 0 2px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#level-select {
  flex: 0 0 auto;
  width: 148px;
}

#category-select {
  flex: 1;
  min-width: 0;
}

#level-select,
#category-select {
  padding: 8px 32px 8px 11px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239898A6' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  transition: border-color 0.1s ease, box-shadow 0.1s ease;
}

#level-select:hover,
#category-select:hover { border-color: var(--text-tertiary); }

#level-select:focus,
#category-select:focus {
  outline: none;
  border-color: var(--btn-bg);
  box-shadow: 0 0 0 3px var(--flash-ring);
}

#category-select.filtered {
  border-color: var(--btn-bg);
  color: var(--btn-bg);
  font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%233B5BDB' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Teacher prompt text sizing */
body:not(.student) #prompt-text {
  font-size: 20px;
  margin-bottom: 18px;
}

/* Teacher badge margin */
body:not(.student) .mode-badge {
  margin-bottom: 14px;
}

/* Divider */
.divider {
  width: 100%;
  height: 1px;
  background: var(--border-light);
  margin-bottom: 14px;
}

/* Constraint block */
.constraint-block {
  background: var(--constraint-bg);
  border: 1px solid var(--constraint-border);
  border-radius: 8px;
  padding: 11px 13px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.constraint-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--constraint-label);
}

#constraint-text {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--constraint-text);
}

/* Copy button */
#copy-btn {
  align-self: flex-start;
  margin-top: 12px;
  padding: 5px 11px;
  background: transparent;
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: color 0.1s ease, border-color 0.1s ease, background 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

#copy-btn svg {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}

#copy-btn:hover {
  color: var(--text-secondary);
  border-color: var(--text-tertiary);
  background: var(--bg);
}

#copy-btn:active { transform: translateY(1px); }

#copy-btn.copied {
  color: #2E7D32;
  border-color: #A5D6A7;
  background: #F1F8F1;
}

#copy-btn:focus-visible {
  outline: 2px solid var(--btn-bg);
  outline-offset: 2px;
}


/* ── 6. Student-only ──────────────────────────────────────── */
/* Fresh architecture: the student page shows one standalone Waffle
   at a time — no topic strip, no category badge, no legacy prompt
   text. Three parts only: 🧇 Waffle, 🎯 Goal, 💬 Waffle Starters. */

/* Extra vertical space (e.g. on tall/large-screen viewports) collects
   here, below the Waffle Starters, instead of being distributed above
   or around the Waffle group. Student page only — the teacher page's
   #prompt-card keeps its own layout. */
.student #prompt-card::after {
  content: '';
  flex: 1;
  min-height: 0;
}

/* Waffle section (🧇) — the dominant element on the page. Largest
   type, most vertical room: this is what pulls the student's eye
   first, and the only thing on the page framed as a task. Sized to
   its content and anchored to the top of the card — see the
   #prompt-card::after spacer below, which absorbs any extra height
   so it collects under the Waffle Starters instead of around the
   Waffle. */
.waffle-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 10px;
}

.waffle-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--student-btn-bg);
}

.waffle-text {
  font-family: 'Lora', Georgia, serif;
  font-weight: 500;
  font-size: 26px;
  line-height: 1.35;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* Goal section (🎯) — one quiet supporting sentence underneath the
   Waffle. Smaller and quieter than the Waffle text; it explains,
   it doesn't compete. */
.goal-section {
  flex-shrink: 0;
  padding: 0 2px 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-light);
}

.goal-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.goal-text {
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* Waffle Starters (💬) — always visible, never collapsible.
   Exactly three ready-to-use conversation starters inside a single
   pale box. The starters are plain lines separated by a hairline,
   not individual cards — the box is the container, not each item. */
.starters-section {
  flex-shrink: 0;
  padding: 13px 14px 14px;
  background: var(--starters-bg);
  border: 1px solid var(--starters-border);
  border-radius: 10px;
}

.starters-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--starters-label);
  margin-bottom: 8px;
}

.starters-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.starters-list li {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary);
  padding: 7px 0;
}

.starters-list li + li {
  border-top: 1px solid var(--starters-border);
}


/* ── 7. Utilities & overrides ─────────────────────────────── */

/* Narrow viewport (320–360px) */
@media (max-width: 360px) {
  #app {
    padding: 12px 12px 16px;
  }

  #prompt-card {
    padding: 14px 14px 16px;
  }

  #level-select {
    width: 120px;
  }

  .waffle-text {
    font-size: 22px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #next-btn,
  #prompt-card::before {
    transition: none;
  }
}
