/* ============================
   Piper GenUI — Styles
   ============================ */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Manrope:wght@400;500;600;700&display=swap");

:root {
  --bg: #f6f1ee;
  --bg-strong: #efe6e2;
  --panel: #ffffff;
  --panel-soft: #fbf7f6;
  --border: #e6dcda;
  --text: #2e2e2e;
  --muted: #6e6664;
  --accent: #c9898e;
  --accent-dark: #8b565b;
  --accent-soft: #f2d7da;
  --teal: #4a5f73;
  --blue: #4a5f73;
  --blue-dark: #2f4052;
  --shadow: 0 24px 60px rgba(47, 64, 82, 0.14);
  --radius: 14px;
  --radius-sm: 10px;
}

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

body {
  margin: 0;
  font-family: "Manrope", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at top, #fbf3f4, var(--bg));
  color: var(--text);
  min-height: 100vh;
}

h1,
h2,
h3 {
  font-family: "Fraunces", "Times New Roman", serif;
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
  line-height: 1.6;
}

/* ---- Root layout ---- */
#genui-root {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* ---- Input region ---- */
#genui-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.genui-header {
  text-align: center;
}

.genui-header h1 {
  font-size: 2.4rem;
  color: var(--teal);
}

.genui-subtitle {
  color: var(--muted);
  font-size: 1rem;
  margin-top: 0.4rem;
}

/* Form */
#genui-form {
  width: 100%;
  max-width: 640px;
}

.genui-input-row {
  display: flex;
  gap: 0.5rem;
}

#genui-prompt {
  flex: 1;
  padding: 0.85rem 1.1rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

#genui-prompt:focus {
  border-color: var(--accent);
}

#genui-submit {
  padding: 0.85rem 1.6rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

#genui-submit:hover {
  background: var(--blue-dark);
}

/* Chips */
.genui-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  max-width: 700px;
}

.chip {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--accent-soft);
}

/* ---- Surface region ---- */
#genui-surface {
  min-height: 0;
  transition: opacity 0.3s ease;
}

#genui-surface.loading {
  opacity: 0.4;
  pointer-events: none;
}

/* ---- Shared surface elements ---- */
.surface-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 6px 24px rgba(47, 64, 82, 0.07);
}

.surface-heading {
  font-size: 1.5rem;
  color: var(--teal);
  margin-bottom: 0.75rem;
}

.surface-piper-response {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.surface-prompt-label {
  font-weight: 600;
  color: var(--teal);
  margin-bottom: 0.4rem;
}

.surface-learner-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.surface-learner-input:focus {
  border-color: var(--accent);
}

/* Toggle group */
.toggle-group {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.toggle-btn {
  padding: 0.45rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.2s;
}

.toggle-btn.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.toggle-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ===========================
   FRACTION SURFACE
   =========================== */
.fraction-viz {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.fraction-bar-container {
  display: flex;
  gap: 2px;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--bg-strong);
}

.fraction-segment {
  flex: 1;
  cursor: pointer;
  transition: background 0.2s;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.fraction-segment:last-child {
  border-right: none;
}

.fraction-segment.selected {
  background: var(--accent);
}

.fraction-segment:hover:not(.selected) {
  background: var(--accent-soft);
}

.fraction-label {
  text-align: center;
  font-weight: 600;
  color: var(--teal);
  font-size: 1.1rem;
}

/* Area model */
.area-model {
  display: grid;
  gap: 3px;
  width: 220px;
  height: 220px;
  margin: 0 auto;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.area-cell {
  cursor: pointer;
  background: var(--panel);
  transition: background 0.2s;
}

.area-cell.selected {
  background: var(--accent);
}

.area-cell:hover:not(.selected) {
  background: var(--accent-soft);
}

/* Number line */
.number-line-wrap {
  position: relative;
  height: 80px;
  margin: 1rem 0;
}

.number-line-track {
  position: absolute;
  top: 36px;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

.number-line-tick {
  position: absolute;
  top: 28px;
  width: 2px;
  height: 20px;
  background: var(--muted);
  transform: translateX(-50%);
}

.number-line-tick-label {
  position: absolute;
  top: 52px;
  font-size: 0.75rem;
  color: var(--muted);
  transform: translateX(-50%);
}

.number-line-point {
  position: absolute;
  top: 30px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--accent-dark);
  transform: translateX(-50%);
  cursor: grab;
  z-index: 2;
}

/* Divide controls */
.divide-controls {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.divide-controls span {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.divide-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--panel);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--teal);
  transition: all 0.2s;
}

.divide-btn.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.divide-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ===========================
   GEOMETRY SURFACE
   =========================== */
.geo-canvas-wrap {
  position: relative;
  margin-bottom: 1.25rem;
}

.geo-canvas-wrap svg {
  width: 100%;
  height: 340px;
  background: var(--panel-soft);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  display: block;
}

.geo-vertex {
  cursor: grab;
  transition: r 0.15s;
}

.geo-vertex:hover {
  r: 10;
}

.geo-edge {
  stroke: var(--teal);
  stroke-width: 2.5;
  fill: none;
}

.geo-fill {
  fill: rgba(201, 137, 142, 0.15);
  stroke: none;
}

.geo-label {
  font-family: "Manrope", sans-serif;
  font-size: 13px;
  fill: var(--muted);
  pointer-events: none;
}

.geo-angle-arc {
  fill: rgba(74, 95, 115, 0.12);
  stroke: var(--teal);
  stroke-width: 1.5;
}

/* ===========================
   MISSED CLASS SURFACE
   =========================== */
.missed-class-surface {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.lesson-title-card {
  background: var(--teal);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.lesson-title-card h2 {
  color: #fff;
  margin: 0;
}

.lesson-title-card p {
  opacity: 0.8;
  margin-top: 0.3rem;
  font-size: 0.9rem;
}

.launch-task-card {
  background: var(--panel);
  border: 2px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.launch-task-card h3 {
  color: var(--accent-dark);
}

.notice-wonder {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.notice-wonder .nw-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.nw-card h3 {
  font-size: 1rem;
  color: var(--teal);
}

.reveal-btn {
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.reveal-btn:hover {
  background: var(--accent-dark);
}

.hidden-summary {
  display: none;
}

.hidden-summary.visible {
  display: block;
  animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===========================
   TEACHER SURFACE
   =========================== */
.teacher-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.teacher-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}

.teacher-card h3 {
  font-size: 0.95rem;
  color: var(--accent-dark);
  margin-bottom: 0.5rem;
}

.teacher-card p {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.55;
}

.teacher-card .card-icon {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  text-align: center;
  line-height: 28px;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

/* ===========================
   GENERATED SURFACE COMPONENTS
   =========================== */
.genui-generated-surface {
  animation: fadeUp 0.4s ease;
}

.genui-text-block {
  margin-bottom: 1rem;
  line-height: 1.6;
}

.genui-input-block {
  margin-bottom: 1rem;
}

.genui-frac-component {
  margin-bottom: 1.5rem;
}

.genui-geo-component {
  margin-bottom: 1.5rem;
}

.genui-geo-svg {
  width: 100%;
  height: 340px;
  background: var(--panel-soft);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  display: block;
}

.genui-reveal-component {
  margin-bottom: 1rem;
}

.genui-toggle-component {
  margin-bottom: 1.25rem;
}

.genui-toggle-label {
  font-weight: 600;
  color: var(--teal);
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.genui-teacher-cards {
  margin-bottom: 1.25rem;
}

.genui-interactive-block {
  background: var(--panel);
  border: 2px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.genui-interactive-block h3 {
  font-size: 1rem;
  color: var(--accent-dark);
  margin-bottom: 0.4rem;
}

.genui-interactive-block p {
  margin-bottom: 0.5rem;
}

.genui-interaction-hint {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.genui-error-surface {
  border-left: 4px solid var(--accent);
}

.genui-debug-rationale {
  font-size: 0.76rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.85;
}

/* ===========================
   GRAPH SURFACES
   =========================== */
.genui-graph-component {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
  padding: 0.85rem;
  margin-bottom: 1.25rem;
}

.graph-frame {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.graph-svg {
  width: 100%;
  height: 320px;
  display: block;
}

.graph-axis {
  stroke: #b8aeac;
  stroke-width: 1.6;
}

.graph-curve {
  fill: none;
  stroke: var(--teal);
  stroke-width: 2.6;
}

.graph-tangent {
  stroke: var(--accent-dark);
  stroke-width: 2.2;
  stroke-dasharray: 8 5;
}

.graph-secant {
  stroke: #8f7b4f;
  stroke-width: 2.2;
  stroke-dasharray: 4 5;
}

.graph-rate-line {
  stroke: #6a7d93;
  stroke-width: 2.2;
  stroke-dasharray: 2 4;
}

.graph-area-fill {
  fill: rgba(201, 137, 142, 0.32);
  stroke: rgba(201, 137, 142, 0.75);
  stroke-width: 1.2;
}

.graph-boundary {
  stroke: #a68489;
  stroke-width: 1.8;
  stroke-dasharray: 5 4;
}

.graph-riemann-rect {
  fill: rgba(74, 95, 115, 0.2);
  stroke: rgba(74, 95, 115, 0.55);
  stroke-width: 1;
}

.graph-point {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2;
}

.graph-point.secondary {
  fill: #8f7b4f;
}

.graph-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.graph-controls label {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.graph-controls input[type="range"] {
  width: 65%;
}

.graph-readout {
  margin-top: 0.6rem;
  font-size: 0.88rem;
  color: var(--teal);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}

.genui-followup-composer {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.95rem;
}

.genui-followup-row {
  display: flex;
  gap: 0.55rem;
  align-items: center;
}

.genui-followup-btn {
  border: none;
  background: var(--teal);
  color: #fff;
  border-radius: 10px;
  padding: 0.72rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.genui-followup-btn:hover {
  background: var(--blue-dark);
}

/* ===========================
   GAME SURFACES
   =========================== */
.genui-game-shell {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  margin-bottom: 0.9rem;
}

.genui-game-title {
  font-size: 1rem;
  color: var(--teal);
  margin-bottom: 0.2rem;
}

.genui-game-subtitle {
  font-size: 0.86rem;
  color: var(--muted);
}

.genui-quiz,
.genui-matching,
.genui-flashcards,
.genui-compare {
  margin-bottom: 1rem;
}

.genui-quiz-question {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--teal);
}

.genui-quiz-choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
}

.genui-quiz-choice {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-family: inherit;
}

.genui-quiz-choice.correct {
  background: #e7f3ea;
  border-color: #90ba98;
}

.genui-quiz-choice.incorrect {
  background: #fbeaea;
  border-color: #d59c9c;
}

.genui-quiz-feedback {
  min-height: 1.2rem;
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.genui-matching-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.genui-match-card {
  padding: 0.6rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-family: inherit;
}

.genui-match-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.genui-match-card.done {
  border-color: #8fb39b;
  background: #e6f4ea;
}

.genui-match-card.incorrect {
  border-color: #d59c9c;
  background: #fbeaea;
}

.genui-match-status {
  margin-top: 0.55rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.genui-flashcards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}

.genui-flashcard {
  position: relative;
  min-height: 86px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 0.8rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.flash-face {
  display: block;
}

.flash-back {
  display: none;
  color: var(--teal);
}

.genui-flashcard[data-flipped="true"] .flash-front {
  display: none;
}

.genui-flashcard[data-flipped="true"] .flash-back {
  display: block;
}

/* ===========================
   COMPARE REPRESENTATIONS
   =========================== */
.genui-compare-title {
  font-size: 1rem;
  color: var(--teal);
  margin-bottom: 0.5rem;
}

.genui-compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.genui-compare-section {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 0.75rem;
}

.genui-compare-section h4 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--accent-dark);
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 600px) {
  #genui-root {
    padding: 1.2rem 1rem 3rem;
  }
  .genui-header h1 {
    font-size: 1.8rem;
  }
  .genui-input-row {
    flex-direction: column;
  }
  .genui-followup-row {
    flex-direction: column;
    align-items: stretch;
  }
  .genui-followup-btn {
    width: 100%;
  }
  #genui-submit {
    width: 100%;
  }
  .teacher-cards {
    grid-template-columns: 1fr;
  }
  .notice-wonder {
    grid-template-columns: 1fr;
  }
  .geo-canvas-wrap svg,
  .genui-geo-svg {
    height: 260px;
  }
}
