/* Subject learning workspace (public/workspace.js). Mobile first (360 px), then tablet and
   desktop. Theme from docs/master/APPROVED_HOMEPAGE_REFERENCE.png: deep purple and lavender with
   warm gold, frosted rounded panels. Lesson screens are deliberately calmer than the homepage
   (design spec "Lesson screens"). Logical properties throughout so right-to-left works.
   Status colours follow the Okabe–Ito colour-blind-safe palette and always come with a symbol
   and a word, never colour alone. No external assets or fonts. */

.ws {
  --ws-violet: #5b3fd6;
  --ws-violet-deep: #3b2391;
  --ws-ink: #1f1640;
  --ws-ink-soft: #4a3f6b;
  --ws-lavender: #efe9ff;
  --ws-lavender-2: #ddd2ff;
  --ws-gold: #f2b632;
  --ws-gold-ink: #6b4500;
  --ws-glass: rgba(255, 255, 255, 0.86);
  --ws-glass-edge: rgba(255, 255, 255, 0.6);
  --ws-radius: 24px;
  --ws-radius-sm: 16px;
  --ws-touch: 44px;
  /* Okabe–Ito */
  --ws-blue: #0072b2;
  --ws-orange: #e69f00;
  --ws-orange-ink: #7a4b00;
  --ws-green: #009e73;
  --ws-green-ink: #00624a;
  --ws-vermillion: #d55e00;
  --ws-grey: #6b6680;

  display: flex;
  flex-direction: column;
  block-size: 100dvh;
  min-block-size: 0;
  overflow: hidden;
  color: var(--ws-ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(242, 182, 50, 0.22), transparent 60%),
    radial-gradient(100% 70% at 0% 100%, rgba(168, 133, 255, 0.35), transparent 60%),
    linear-gradient(160deg, #2b1a6b 0%, #4b2fa8 45%, #8c6fe0 100%);
}

.ws *, .ws *::before, .ws *::after { box-sizing: border-box; }
.ws [hidden] { display: none !important; }
.ws button { font: inherit; color: inherit; }
.ws :focus-visible { outline: 3px solid var(--ws-gold); outline-offset: 2px; }

.ws-icon { inline-size: 22px; block-size: 22px; fill: currentColor; flex: none; }
[dir="rtl"] .ws-back .ws-icon, [dir="rtl"] .ws-send .ws-icon { transform: scaleX(-1); }

/* ---------- Buttons ---------- */

.ws-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-block-size: var(--ws-touch);
  min-inline-size: var(--ws-touch);
  padding-block: 8px;
  padding-inline: 16px;
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  white-space: normal; /* longer translations wrap instead of overflowing */
}
.ws-btn:disabled { opacity: 0.55; cursor: progress; }
.ws-btn-primary { background: var(--ws-violet); color: #fff; box-shadow: 0 6px 16px rgba(59, 35, 145, 0.35); }
.ws-btn-primary:hover:not(:disabled) { background: var(--ws-violet-deep); }
.ws-btn-soft { background: var(--ws-lavender); color: var(--ws-violet-deep); border: 2px solid var(--ws-lavender-2); }
.ws-btn-soft:hover:not(:disabled) { background: var(--ws-lavender-2); }
.ws-btn-ghost { background: rgba(255, 255, 255, 0.14); color: #fff; border: 1px solid rgba(255, 255, 255, 0.28); }

.ws-tool {
  display: inline-grid;
  place-items: center;
  inline-size: var(--ws-touch);
  block-size: var(--ws-touch);
  border: 0;
  border-radius: 50%;
  background: var(--ws-lavender);
  color: var(--ws-violet-deep);
  cursor: pointer;
  flex: none;
}
.ws-tool[aria-pressed="true"] { background: var(--ws-violet); color: #fff; }
.ws-file { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; pointer-events: none; }

.ws-row { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 8px; }

/* ---------- Top bar ---------- */

.ws-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 6px;
  padding-inline: 8px;
  color: #fff;
  background: rgba(31, 18, 82, 0.72);
  backdrop-filter: blur(10px);
  flex: none;
}
.ws-back span { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ws-heading { flex: 1; min-inline-size: 0; }
.ws-title { margin: 0; font-size: 1.05rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-sub { margin: 0; font-size: 0.85rem; opacity: 0.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-top-end { display: flex; align-items: center; gap: 6px; flex: none; }
.ws-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-block: 4px;
  padding-inline: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}
.ws-stars { color: #fff3cf; }
.ws-stars::before { content: "\2605"; color: var(--ws-gold); }
.ws-ai { display: none; }
.ws-drawer-btn span:first-of-type { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ws-badge {
  padding-inline: 8px;
  border-radius: 999px;
  background: var(--ws-orange);
  color: #1f1300;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

/* ---------- Body ---------- */

.ws-body { position: relative; display: flex; flex: 1; min-block-size: 0; }
.ws-main { display: flex; flex-direction: column; flex: 1; min-inline-size: 0; min-block-size: 0; }
.ws-notice { margin: 0; padding-block: 4px; padding-inline: 12px; color: #f3eeff; font-size: 0.78rem; text-align: center; }

.ws-log {
  flex: 1;
  min-block-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block: 8px 16px;
  padding-inline: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-padding-block-start: 8px;
}

.ws-msg {
  max-inline-size: 46rem;
  padding: 12px 14px;
  border-radius: var(--ws-radius);
  background: var(--ws-glass);
  border: 1px solid var(--ws-glass-edge);
  box-shadow: 0 8px 24px rgba(31, 18, 82, 0.18);
  backdrop-filter: blur(12px);
  overflow-wrap: anywhere;
}
.ws-msg p { margin-block: 0 6px; }
.ws-msg p:last-child { margin-block-end: 0; }
.ws-tutor { align-self: flex-start; border-start-start-radius: 8px; }
.ws-student {
  align-self: flex-end;
  background: var(--ws-violet);
  color: #fff;
  border-color: transparent;
  border-start-end-radius: 8px;
}
.ws-author { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 800; color: var(--ws-ink-soft); }
.ws-student .ws-author { color: #e8e0ff; }
.ws-avatar {
  inline-size: 22px;
  block-size: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 18%, var(--ws-lavender-2) 19% 55%, var(--ws-violet) 56%);
  flex: none;
}
.ws-msg-title { margin-block: 2px 6px; font-size: 1.1rem; line-height: 1.25; }

.ws-question { border: 2px solid var(--ws-violet); }
.ws-question > p:not(.ws-author) { font-size: 1.2rem; font-weight: 700; }
.ws-correct { border-inline-start: 6px solid var(--ws-green); }
.ws-correct .ws-msg-title { color: var(--ws-green-ink); }
.ws-correct .ws-msg-title::before { content: "\2713  "; }
.ws-incorrect { border-inline-start: 6px solid var(--ws-orange); }
.ws-incorrect .ws-msg-title { color: var(--ws-orange-ink); }
.ws-incorrect .ws-msg-title::before { content: "\21BB  "; }
.ws-hint { border-inline-start: 6px solid var(--ws-gold); }
.ws-error { border-inline-start: 6px solid var(--ws-vermillion); }
.ws-badge-msg, .ws-badge { font-weight: 800; }
.ws-star { font-weight: 800; color: var(--ws-gold-ink); }
.ws-star::before { content: "\2605 "; color: var(--ws-gold); }
.ws-teach { margin-block-start: 8px; padding: 10px 12px; border-radius: var(--ws-radius-sm); background: #fff7e3; }
.ws-teach-title { font-weight: 800; }

.ws-typing { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--ws-ink-soft); }
.ws-dots { inline-size: 28px; block-size: 8px; background: radial-gradient(circle, var(--ws-violet) 40%, transparent 42%) 0 0 / 10px 8px repeat-x; animation: ws-pulse 1.2s ease-in-out infinite; }
@keyframes ws-pulse { 50% { opacity: 0.35; } }

/* Labels: provenance, how it was checked, simulated. Text always, colour second. */
.ws-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-block-start: 8px; }
.ws-chip { display: inline-block; padding-block: 2px; padding-inline: 8px; border-radius: 999px; font-size: 0.74rem; font-weight: 700; border: 1px solid currentColor; }
.ws-chip-aligned { color: var(--ws-blue); }
.ws-chip-aligned::before { content: "\2713 "; }
.ws-chip-general { color: var(--ws-ink-soft); }
.ws-chip-check { color: var(--ws-green-ink); }
.ws-chip-sim { color: #5c2d00; background: #ffe7b3; border-style: dashed; }

.ws-help { margin-block: 4px; font-size: 0.85rem; color: var(--ws-ink-soft); }
.ws-error-text { color: #8a2c00; font-weight: 700; }

/* Answer options: large, two per row on phones. */
.ws-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-block-start: 10px; }
.ws-option {
  min-block-size: 52px;
  padding: 8px 10px;
  border-radius: var(--ws-radius-sm);
  border: 2px solid var(--ws-lavender-2);
  background: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
}
.ws-option[aria-pressed="true"] { border-color: var(--ws-violet); background: var(--ws-lavender); box-shadow: inset 0 0 0 2px var(--ws-violet); }

/* ---------- Dock ---------- */

.ws-dock {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-block: 6px calc(6px + env(safe-area-inset-bottom, 0px));
  padding-inline: 8px;
  background: rgba(250, 247, 255, 0.94);
  border-start-start-radius: var(--ws-radius);
  border-start-end-radius: var(--ws-radius);
  box-shadow: 0 -8px 24px rgba(31, 18, 82, 0.2);
  max-block-size: 60dvh;
  overflow-y: auto;
}
.ws-actions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-block-end: 2px; }
.ws-actions .ws-btn { flex: none; padding-inline: 14px; white-space: nowrap; }
.ws-actions .ws-btn-primary { order: -1; }

.ws-working, .ws-voice { padding: 8px 10px; border-radius: var(--ws-radius-sm); background: #fff; border: 1px solid var(--ws-lavender-2); }
.ws-working-input { inline-size: 100%; min-block-size: 88px; padding: 8px; border-radius: 12px; border: 2px solid var(--ws-lavender-2); font: inherit; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; resize: vertical; }
.ws-steps { margin: 6px 0; padding-inline-start: 0; list-style: none; }
.ws-steps li { padding-block: 2px; }
.ws-steps li[data-status="correct"]::before { content: "\2713 "; color: var(--ws-green-ink); font-weight: 800; }
.ws-steps li[data-status="wrong"]::before { content: "\25B2 "; color: var(--ws-orange-ink); }
.ws-steps li[data-status="unchecked"]::before { content: "\25CB "; color: var(--ws-grey); }

.ws-voice-head { display: flex; align-items: center; gap: 8px; }
.ws-voice-state { margin: 0; font-weight: 800; }
.ws-voice-dot { inline-size: 14px; block-size: 14px; border-radius: 50%; background: var(--ws-grey); flex: none; }
.ws-voice[data-state="listening"] .ws-voice-dot { background: var(--ws-blue); box-shadow: 0 0 0 6px rgba(0, 114, 178, 0.2); animation: ws-pulse 1.4s ease-in-out infinite; }
.ws-voice[data-state="speaking"] .ws-voice-dot { background: var(--ws-violet); border-radius: 3px; }
.ws-voice[data-state="thinking"] .ws-voice-dot { background: var(--ws-gold); }
.ws-voice[data-state="paused"] .ws-voice-dot { background: transparent; border: 3px solid var(--ws-grey); }
.ws-voice[data-state="unavailable"] .ws-voice-dot { background: var(--ws-vermillion); border-radius: 2px; }

.ws-modes { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--ws-lavender); align-self: flex-start; }
.ws-seg { min-block-size: 36px; padding-inline: 14px; border: 0; border-radius: 999px; background: transparent; font-weight: 700; font-size: 0.88rem; cursor: pointer; }
.ws-seg[aria-pressed="true"] { background: #fff; color: var(--ws-violet-deep); box-shadow: 0 2px 6px rgba(59, 35, 145, 0.18); }
/* 36 px segment + 3 px pill padding gives a 42 px hit row; extend the hit area to 44 px. */
.ws-seg { position: relative; }
.ws-seg::after { content: ""; position: absolute; inset: -4px 0; }

.ws-composer { display: flex; flex-direction: column; gap: 6px; }
.ws-inputrow { display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; }
.ws-input {
  flex: 1 1 100%;
  min-block-size: 48px;
  max-block-size: 30dvh;
  padding: 11px 14px;
  border-radius: 24px;
  border: 2px solid var(--ws-lavender-2);
  background: #fff;
  font: inherit;
  font-size: 1.05rem;
  resize: none;
}
.ws-input:focus { border-color: var(--ws-violet); outline: none; box-shadow: 0 0 0 3px rgba(91, 63, 214, 0.25); }
.ws-tools { display: flex; gap: 6px; }
.ws-send { margin-inline-start: auto; }
.ws-send[data-mode="answer"] { background: var(--ws-green-ink); }

/* ---------- Concept panel (drawer on phones) ---------- */

.ws-panel {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  z-index: 20;
  inline-size: min(88vw, 380px);
  padding: 12px;
  overflow-y: auto;
  background: rgba(247, 243, 255, 0.97);
  box-shadow: -12px 0 32px rgba(31, 18, 82, 0.35);
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}
[dir="rtl"] .ws-panel, .ws[dir="rtl"] .ws-panel { transform: translateX(-105%); }
.ws-panel[data-open="true"] { transform: none; visibility: visible; transition: transform 0.22s ease; }
.ws-scrim { position: fixed; inset: 0; z-index: 19; background: rgba(20, 10, 50, 0.45); }
.ws-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ws-panel-title { margin: 0; font-size: 1.15rem; }

.ws-chapters { display: flex; flex-direction: column; gap: 10px; margin-block-start: 8px; }
.ws-chapter, .ws-weak {
  padding: 10px;
  border-radius: var(--ws-radius-sm);
  background: #fff;
  border: 1px solid var(--ws-lavender-2);
}
.ws-weak { margin-block-start: 8px; border: 2px solid var(--ws-orange); background: #fff8ea; display: flex; flex-direction: column; gap: 6px; }
.ws-chapter-title { margin-block: 0 6px; font-size: 0.95rem; color: var(--ws-violet-deep); }
.ws-concepts { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.ws-concept {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  inline-size: 100%;
  min-block-size: var(--ws-touch);
  padding-block: 6px;
  padding-inline: 12px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--ws-lavender);
  text-align: start;
  cursor: pointer;
}
.ws-concept[aria-current="true"] { border-color: var(--ws-violet); background: #fff; }
.ws-concept-title { font-weight: 700; min-inline-size: 0; }
.ws-concept-compact { inline-size: auto; }

.ws-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  padding-block: 1px;
  padding-inline: 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  border: 1.5px solid currentColor;
  background: #fff;
}
.ws-status[data-status="new"] { color: var(--ws-grey); }
.ws-status[data-status="new"]::before { content: "\25CB"; }
.ws-status[data-status="learning"] { color: var(--ws-blue); }
.ws-status[data-status="learning"]::before { content: "\25D0"; }
.ws-status[data-status="weak"] { color: var(--ws-orange-ink); background: #fff1cf; }
.ws-status[data-status="weak"]::before { content: "\25B2"; }
.ws-status[data-status="mastered"] { color: var(--ws-green-ink); }
.ws-status[data-status="mastered"]::before { content: "\2713"; }

/* ---------- Tablet ---------- */

@media (min-width: 600px) {
  .ws { font-size: 18px; }
  .ws-back span { position: static; inline-size: auto; block-size: auto; clip: auto; overflow: visible; }
  .ws-ai { display: inline-flex; }
  .ws-drawer-btn span:first-of-type { position: static; inline-size: auto; block-size: auto; clip: auto; overflow: visible; }
  .ws-log { padding-inline: 20px; }
  .ws-inputrow { flex-wrap: nowrap; }
  .ws-input { flex: 1 1 auto; }
  .ws-send { margin-inline-start: 0; }
  .ws-options { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .ws-dock { margin-inline: 12px; }
}

/* ---------- Desktop: the panel sits on the right ---------- */

@media (min-width: 1024px) {
  .ws-top { padding-inline: 20px; }
  .ws-drawer-btn, .ws-panel-close, .ws-scrim { display: none !important; }
  .ws-body { gap: 16px; padding-inline: 16px; padding-block-end: 12px; }
  .ws-main { max-inline-size: 56rem; margin-inline: auto; }
  .ws-dock { margin-inline: 0; border-radius: var(--ws-radius); }
  .ws-panel {
    position: static;
    transform: none;
    visibility: visible;
    transition: none;
    inline-size: 340px;
    flex: none;
    margin-block-start: 12px;
    border-radius: var(--ws-radius);
    background: var(--ws-glass);
    border: 1px solid var(--ws-glass-edge);
    box-shadow: 0 12px 32px rgba(31, 18, 82, 0.25);
    backdrop-filter: blur(14px);
  }
  [dir="rtl"] .ws-panel, .ws[dir="rtl"] .ws-panel { transform: none; }
}

/* Short phones in landscape: keep the question and the composer both on screen. */
@media (max-height: 480px) {
  .ws-notice { display: none; }
  .ws-dock { max-block-size: 70dvh; }
}

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

@media (forced-colors: active) {
  .ws-status, .ws-chip, .ws-option, .ws-concept { border: 1px solid CanvasText; }
}
