/* ============================================================
   The Writing Sessions — Base Stylesheet
   Layout, components, typography, and responsive rules.
   Color variables are defined in themes/light.css or themes/dark.css.
   ============================================================ */

/* --- Google Fonts (loaded in template head) --- */
/* Literata (serif, for headings/literary) & DM Sans (sans, for UI) */

:root {
  /* Structural (non-color) variables — safe defaults */
  --radius: 12px;
  --radius-sm: 8px;
  --font-ui: 'DM Sans', sans-serif;
  --font-literary: 'Literata', Georgia, serif;
  --font-writing: 'Literata', Georgia, serif;
  --font-writing-size: 16px;
  --transition: 0.25s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; }

body {
  font-family: var(--font-ui);
  background: var(--parchment);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.6;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--panel-bg);
  color: var(--panel-text);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  font-family: var(--font-literary);
  font-size: 18px;
  font-weight: 700;
  color: var(--warm);
  margin-bottom: 32px;
  padding: 0 8px;
  line-height: 1.3;
}

.sidebar-nav {
  list-style: none;
  flex: 1;
}

.sidebar-nav li {
  margin-bottom: 4px;
}

.sidebar-nav a,
.sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: none;
  color: var(--panel-text-muted);
  font-family: var(--font-ui);
  font-size: 14px;
  text-decoration: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.sidebar-nav a:hover,
.sidebar-nav button:hover,
.sidebar-nav a.active,
.sidebar-nav button.active {
  background: var(--panel-hover-bg);
  color: var(--panel-text-active);
}

.sidebar-nav .nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-user {
  border-top: 1px solid var(--panel-border);
  padding-top: 16px;
  margin-top: auto;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin-bottom: 8px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--panel-text-active);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-user-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-user-name {
  font-size: 13px;
  color: var(--panel-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-credits {
  font-size: 11px;
  color: var(--warm);
  cursor: default;
}

/* Sign-out in sidebar-user section */
.sidebar-signout {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 0;
  border: none;
  background: none;
  color: var(--panel-text-faint);
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s;
}
.sidebar-signout:hover {
  color: var(--panel-text);
  text-decoration: underline;
}

/* Debug status bar at bottom of sidebar */
.nav-status-bar {
  margin-top: 8px;
  padding: 5px 8px;
  border-top: 1px solid var(--panel-border);
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 10px;
  color: var(--panel-status-text);
  min-height: 22px;
  word-break: break-all;
  line-height: 1.5;
  letter-spacing: 0.01em;
}

.main-content {
  flex: 1;
  padding: 32px 40px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   TYPOGRAPHY
   ============================================================ */

h1, h2, h3, h4 {
  font-family: var(--font-literary);
  color: var(--ink);
  line-height: 1.3;
}

h1 { font-size: 28px; font-weight: 700; margin-bottom: 16px; }
h2 { font-size: 22px; font-weight: 600; margin-bottom: 12px; }
h3 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
h4 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }

.subtitle {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 24px;
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-family: var(--font-literary);
  font-size: 16px;
  font-weight: 600;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--btn-primary-bg, var(--warm));
  color: var(--btn-text-on-color);
}

.btn-primary:hover { background: var(--btn-primary-hover, var(--warm-hover)); }

.btn-secondary {
  background: var(--btn-secondary-bg, var(--parchment-deep));
  color: var(--btn-secondary-text, var(--accent));
}

.btn-secondary:hover { background: var(--btn-secondary-hover, var(--divider)); }

.btn-ghost {
  background: none;
  color: var(--accent);
  padding: 8px 12px;
}

.btn-ghost:hover { background: var(--parchment-deep); }

/* When a <summary> is styled as a button, hide the disclosure triangle */
summary.btn::marker,
summary.btn::-webkit-details-marker { display: none; content: ''; }

.btn-small {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-danger {
  background: var(--red);
  color: var(--btn-danger-text, var(--btn-text-on-color));
}

.btn-danger:hover { background: var(--red-hover); }

.btn:disabled,
.btn.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Inline spinner for buttons during htmx requests ---- */
.btn .btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
  flex-shrink: 0;
}

.btn.htmx-request .btn-spinner { display: inline-block; }
.btn.htmx-request .btn-label   { opacity: 0.7; }

.btn.htmx-request {
  pointer-events: none;
  opacity: 0.8;
}

/* ============================================================
   FORMS
   ============================================================ */

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: var(--input-bg);
  transition: border-color var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--warm);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

.writing-textarea {
  font-family: var(--font-writing);
  font-size: var(--font-writing-size);
  line-height: 1.8;
}
/* 3 lines tall: 3 × line-height × font-size + top/bottom padding */
.writing-textarea-rows-3 {
  height: calc(5.4 * var(--font-writing-size) + 20px);
  min-height: 0;
  resize: vertical;
}
/* 2 lines tall */
.writing-textarea-rows-2 {
  height: calc(3.6 * var(--font-writing-size) + 20px);
  min-height: 0;
  resize: vertical;
}

/* ============================================================
   COMPACT STATS BAR  (replaces XP hero + streak row on dashboard)
   ============================================================ */

.stats-bar {
  display: flex;
  align-items: stretch;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
  position: relative;
}

.stats-bar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--warm), var(--green), var(--blue));
}

.stats-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 12px 12px;
  text-align: center;
}

.stats-bar-level {
  flex: 1.8;
  border-left: 1px solid var(--divider);
  border-right: 1px solid var(--divider);
}

.stats-bar-divider { display: none; }

.stats-bar-value {
  font-family: var(--font-literary);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
  margin-bottom: 2px;
}

.stats-bar-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-bar-progress-bg {
  width: 100%;
  height: 4px;
  background: var(--parchment-deep);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.stats-bar-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--warm), var(--warm-hover));
  border-radius: 2px;
  transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
  width: 0;
}

/* ============================================================
   XP & PROGRESS  (used on Progress page, kept for backward compat)
   ============================================================ */

.xp-hero {
  text-align: center;
  padding: 40px 24px 32px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.xp-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--warm), var(--green), var(--blue));
}

.xp-label {
  font-family: var(--font-literary);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.xp-number {
  font-family: var(--font-literary);
  font-size: 56px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 4px;
}

.xp-suffix {
  font-family: var(--font-literary);
  font-size: 18px;
  font-weight: 300;
  color: var(--accent-light);
  letter-spacing: 0.04em;
}

.level-track {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--divider);
}

.level-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.level-current {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.level-next {
  font-size: 13px;
  color: var(--muted);
}

.progress-bar-bg {
  height: 10px;
  background: var(--parchment-deep);
  border-radius: 5px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--warm), var(--warm-hover));
  border-radius: 5px;
  transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============================================================
   STREAK
   ============================================================ */

.streak-row {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.streak-icon { font-size: 28px; line-height: 1; }
.streak-count {
  font-family: var(--font-literary);
  font-size: 20px;
  font-weight: 700;
}
.streak-label { font-size: 12px; color: var(--muted); }

.streak-dots {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.streak-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--parchment-deep);
}
.streak-dot.filled { background: var(--warm); }
.streak-dot.today {
  background: var(--warm);
  box-shadow: 0 0 0 2px var(--warm-light);
}

/* ============================================================
   SKILL CARDS
   ============================================================ */

.skill-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  padding: 16px 20px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.skill-card:hover {
  box-shadow: 0 4px 16px var(--hover-shadow);
  transform: translateY(-1px);
}

.skill-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.skill-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--parchment-deep);
}

.skill-name {
  flex: 1;
  font-family: var(--font-literary);
  font-size: 14px;
  font-weight: 600;
}

.skill-fraction {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.skill-bar-bg {
  height: 6px;
  background: var(--parchment-deep);
  border-radius: 3px;
  overflow: hidden;
}

.skill-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--warm);
  transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============================================================
   EXERCISE
   ============================================================ */

.exercise-header {
  margin-bottom: 24px;
}

.exercise-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.exercise-meta-item {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.exercise-content {
  background: var(--warm-glow);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  font-family: var(--font-literary);
  font-size: 16px;
  line-height: 1.8;
  color: var(--accent);
}

.exercise-content .content-text {
  white-space: pre-wrap;
  border-left: 3px solid var(--warm);
  padding-left: 16px;
}

.exercise-content .content-attribution {
  color: var(--accent);
}

/* Copy/reconstruct exercises need dark background for character highlighting */
.exercise-content.copy-exercise {
  background: var(--copy-bg);  /* overall content bg */
  border-left-color: transparent;
  color: var(--copy-text);  /* untyped text default */
}

.exercise-content.copy-exercise .content-text {
  background: var(--copy-inner-bg);  /* content text bg */
  padding: 16px;
  border-radius: var(--radius);
  border-left: 3px solid var(--copy-accent);  /* left accent color on content text */
}

.exercise-content.copy-exercise .content-attribution {
  color: var(--copy-attribution);
}

.content-attribution {
  margin-top: 16px;
  font-size: 13px;
  color: var(--accent-light);
  font-style: italic;
}

.author-note-details {
  margin-top: 6px;
}

.author-note-details summary {
  cursor: pointer;
  list-style: none;
  font-style: normal;
  font-size: 12px;
  color: inherit;
}

.author-note-details summary::-webkit-details-marker {
  display: none;
}

.author-note-details[open] .author-chevron-open { display: none; }
.author-note-details:not([open]) .author-chevron-close { display: none; }

.author-chevron-open,
.author-chevron-close {
  font-size: 1.6em;
  line-height: 1;
  vertical-align: middle;
}

.author-note-text {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.6;
  color: inherit;
  font-style: normal;
}

.exercise-content.copy-exercise .author-note-details summary,
.exercise-content.copy-exercise .author-note-text {
  color: var(--copy-attribution);
}

.passage-pair-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
}

.exercise-instructions {
  margin-bottom: 20px;
}

.instructions-list {
  counter-reset: instruction-counter;
}

.instruction-numbered {
  counter-increment: instruction-counter;
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.5;
  align-items: flex-start;
}

.instruction-numbered > div {
  flex: 1;
}

.instruction-numbered::before {
  content: counter(instruction-counter) ".";
  min-width: 18px;
  font-weight: 500;
  flex-shrink: 0;
  padding-top: 0;
}

.exercise-sub-instructions {
  list-style: disc;
  margin-top: 4px;
  margin-bottom: 0;
  padding-left: 20px;
}

.exercise-sub-instructions li {
  margin-bottom: 4px;
  font-size: 14px;
}

.instruction-note {
  font-style: italic;
  color: var(--note-text);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 8px;
  padding-left: 0;
}

.eval-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.eval-option {
  padding: 8px 16px;
  border: 2px solid var(--divider);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition);
  background: var(--input-bg);
}

.eval-option:hover { border-color: var(--warm); }

.eval-option.selected {
  border-color: var(--warm);
  background: var(--warm-glow);
  font-weight: 600;
}

.eval-option.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   TAB BAR
   ============================================================ */

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--divider);
  padding-bottom: 0;
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}

.tab-btn:hover {
  color: var(--ink);
  background: var(--parchment-deep);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ============================================================
   CONTENT FILTERS
   ============================================================ */

.content-filters {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.content-filters select {
  padding: 6px 12px;
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--input-bg);
  color: var(--ink);
}

/* ============================================================
   STORY READER (paged reader for short stories)
   ============================================================ */

/* Viewport: masks the horizontal film strip */
.story-reader {
  overflow: hidden;
  position: relative;
  font-family: var(--font-literary);
  font-size: 16px;
  line-height: 1.9;
  padding: 24px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--divider);
  box-sizing: border-box;
}

/* Film strip: all pages laid out as CSS columns */
.story-reader .content-text {
  height: 100%;
  column-fill: auto;
  column-gap: 40px;
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

.story-reader .content-text p {
  margin-top: 0;
  margin-bottom: 0.8em;
  text-indent: 1.5em;
}

.story-reader .content-text p:first-of-type {
  text-indent: 0;
}

.reader-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}

.reader-page-info {
  font-size: 13px;
  color: var(--muted);
}

/* ============================================================
   STORY EDITOR
   ============================================================ */

/* Story Editor Page - Full height layout */
.story-editor-page {
  position: relative; /* For mode-overlay positioning */
  height: 100%;
  display: flex;
  flex-direction: column;
  margin: -32px -40px; /* Negate main-content padding */
  padding: 32px 40px; /* Re-add padding inside */
}

.story-editor-page .editor-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0; /* Important for flexbox child to shrink */
}

.story-editor-page .feedback-bar {
  flex-shrink: 0;
}

.editor-container {
  display: flex;
  flex-direction: column;
}

.editor-tabs {
  display: flex;
  gap: 2px;
  background: var(--parchment-deep);
  border-radius: 10px 10px 0 0;
  padding: 4px 4px 0;
  overflow-x: auto;
  flex-shrink: 0;
}

.editor-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: all var(--transition);
  white-space: nowrap;
}

.editor-tab.active {
  background: var(--card-bg);
  color: var(--ink);
  font-weight: 500;
}

.editor-tab:hover:not(.active) { color: var(--accent); }

.editor-tab.archived-tab {
  opacity: 0.6;
  font-style: italic;
  border-bottom: 2px solid var(--muted-light);
}

.editor-tab.archived-tab.active {
  opacity: 1;
  background: var(--archived-tab-bg);
}

.editor-tab-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
  padding: 4px;
}

/* Dropdown menu */
.dropdown-menu {
  display: none;
  position: fixed;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 180px;
  z-index: 1000;
  padding: 4px 0;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
}

.dropdown-item:hover {
  background: var(--parchment-light);
}

.dropdown-divider {
  height: 1px;
  margin: 4px 0;
  background: var(--border);
  border: none;
}

.editor-area {
  flex: 1;
  background: var(--card-bg);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 0;
  position: relative;
  min-height: 0; /* Important for flexbox child to shrink */
}

.editor-textarea {
  width: 100%;
  height: 100%;
  border: none;
  padding: 24px 32px;
  font-family: var(--font-writing);
  font-size: var(--font-writing-size);
  line-height: 1.9;
  color: var(--ink);
  background: transparent;
  resize: none;
  outline: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Placeholder for contenteditable */
.editor-textarea:empty:before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  font-style: italic;
}

/* Remove default focus outline for contenteditable */
.editor-textarea:focus {
  outline: none;
}

.editor-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--divider);
  background: var(--card-bg);
  align-items: center;
  flex-shrink: 0;
}

.toolbar-btn {
  padding: 4px 8px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  border-radius: 4px;
  transition: all var(--transition);
}

.toolbar-btn:hover { background: var(--parchment-deep); color: var(--ink); }
.toolbar-btn.active { color: var(--warm); }

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--divider);
  margin: 0 4px;
}

/* Toolbar dropdowns */
.toolbar-dropdown {
  position: relative;
}

.toolbar-dropdown-menu {
  display: none;
  position: fixed;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 140px;
  z-index: 1000;
  padding: 4px 0;
}

.toolbar-dropdown-menu.show {
  display: block;
}

.toolbar-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: none;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
}

.toolbar-dropdown-item:hover {
  background: var(--parchment-deep);
  color: var(--accent);
}

.editor-status {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  border-top: 1px solid var(--divider);
  font-size: 12px;
  color: var(--muted);
  background: var(--card-bg);
  border-radius: 0 0 var(--radius) var(--radius);
  flex-shrink: 0;
}

.word-count { font-weight: 500; }

/* Sprint/Flow mode overlay */
.mode-overlay {
  position: absolute;
  top: 0; left: 0; right: 0;
  background: var(--panel-bg);
  color: var(--panel-text-active);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

.mode-timer {
  font-family: var(--font-literary);
  font-size: 24px;
  font-weight: 700;
}

.mode-word-count {
  font-size: 16px;
  color: var(--warm);
}

/* ============================================================
   BADGES
   ============================================================ */

.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.badge-item {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: 0 1px 6px var(--shadow);
  transition: all var(--transition);
}

.badge-item.earned {
  border: 2px solid var(--warm);
}

.badge-item.unearned {
  opacity: 0.45;
}

.badge-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.badge-title {
  font-family: var(--font-literary);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.badge-desc {
  font-size: 11px;
  color: var(--muted);
}

/* ============================================================
   FEEDBACK BAR
   ============================================================ */

.feedback-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 0;
  margin-top: 20px;
  border-top: 1px solid var(--divider);
}

.feedback-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  background: var(--input-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 4px;
}

.feedback-btn:hover {
  border-color: var(--warm);
  background: var(--warm-glow);
}

.feedback-btn.active {
  border-color: var(--warm);
  background: var(--warm-glow);
}

.feedback-btn svg {
  width: 16px;
  height: 16px;
}

.feedback-icon { display: inline-flex; }

/* ============================================================
   TOOLTIPS
   ============================================================ */

.content-tooltip {
  position: absolute;
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: 0 4px 16px var(--shadow);
  max-width: 320px;
  font-size: 13px;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.tooltip-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  padding: 0;
  line-height: 1;
}

.tooltip-close:hover {
  background: var(--parchment-deep);
  color: var(--ink);
}

.tooltip-label {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

.tooltip-text {
  line-height: 1.5;
  margin-bottom: 8px;
}

.tooltip-text:last-child { margin-bottom: 0; }

/* ============================================================
   NOTIFICATIONS
   ============================================================ */

.notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--card-bg);
  border: 1px solid var(--warm);
  border-radius: var(--radius);
  padding: 16px 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  z-index: 9999;
  animation: slideUp 0.3s ease;
  max-width: 360px;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--panel-bg) 0%, var(--login-bg-end) 100%);
}

.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 48px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
  max-width: 420px;
  width: 90%;
  text-align: center;
}

.login-brand {
  font-family: var(--font-literary);
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 32px;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--muted);
  font-size: 13px;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--divider);
}

/* ============================================================
   TABLES (admin)
   ============================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--divider);
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
}

.data-table tr:hover td {
  background: var(--parchment);
}

/* ============================================================
   SUBSCRIPTION
   ============================================================ */

.plan-card {
  background: var(--card-bg);
  border: 2px solid var(--divider);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  margin-bottom: 20px;
}

.plan-card.active-plan {
  border-color: var(--warm);
}

.plan-price {
  font-family: var(--font-literary);
  font-size: 40px;
  font-weight: 700;
  color: var(--ink);
}

.plan-period {
  font-size: 14px;
  color: var(--muted);
}

.plan-features {
  list-style: none;
  margin: 24px 0;
  text-align: left;
}

.plan-features li {
  padding: 6px 0;
  font-size: 14px;
  color: var(--accent);
}

.plan-features li::before {
  content: '✓ ';
  color: var(--green);
  font-weight: 700;
}

/* ============================================================
   PEER EVALUATION
   ============================================================ */

.peer-item {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--divider);
}

.peer-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.peer-status.queued { background: var(--warm-glow); color: var(--accent); }
.peer-status.accepted { background: var(--blue-light); color: var(--blue); }
.peer-status.completed { background: var(--green-light); color: var(--green); }

/* ============================================================
   UTILITIES
   ============================================================ */

.text-center { text-align: center; }
.text-muted { color: var(--muted); }

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
.text-small { font-size: 13px; }
.text-warm { color: var(--warm); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }

.error {
  background: var(--red-light);
  color: var(--red);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}

.success {
  background: var(--green-light);
  color: var(--green);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}

.loading {
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--divider);
  border-top-color: var(--warm);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   MODAL / DIALOG
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 520px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--parchment-deep);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.modal-close:hover { background: var(--divider); color: var(--ink); }

/* ============================================================
   FOCUS VISIBILITY (keyboard navigation)
   ============================================================ */

/* Visible focus ring for interactive elements when navigating by keyboard */
:focus-visible {
  outline: 2px solid var(--warm);
  outline-offset: 2px;
}

/* Remove default outline when using mouse */
:focus:not(:focus-visible) {
  outline: none;
}

/* Sidebar nav buttons: keep custom focus ring on dark background */
.sidebar-nav button:focus-visible,
.sidebar-nav a:focus-visible {
  outline: 2px solid var(--warm);
  outline-offset: 1px;
}

/* ============================================================
   SKIP NAVIGATION (accessibility)
   ============================================================ */

.skip-nav {
  position: absolute;
  top: -100%;
  left: 8px;
  z-index: 10000;
  background: var(--panel-bg);
  color: var(--panel-text-active);
  padding: 8px 16px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-nav:focus {
  top: 0;
  outline: 2px solid var(--warm);
  outline-offset: 2px;
}

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -240px;
    z-index: 100;
    transition: left 0.3s ease;
  }

  .sidebar.open {
    left: 0;
  }

  .main-content {
    padding: 16px;
  }

  /* Stats bar: stack on small screens */
  .stats-bar {
    flex-wrap: wrap;
  }

  .stats-bar-group {
    min-width: 33%;
    flex: 1 1 33%;
    padding: 12px 8px 10px;
  }

  .stats-bar-level {
    flex: 1 1 100%;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--divider);
  }

  .stats-bar-value {
    font-size: 18px;
  }

  /* Streak row: compact on mobile */
  .streak-dots {
    display: none;
  }

  /* Cards: tighter padding */
  .card {
    padding: 16px;
  }

  /* Badges grid: 2 columns on mobile */
  .badges-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Content filters: stack */
  .content-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .content-filters select {
    width: 100%;
  }

  /* Story editor: full-bleed, adjusted margins */
  .story-editor-page {
    margin: -16px -16px;
    padding: 16px 16px;
  }

  /* Editor toolbar: wrap on mobile */
  .editor-toolbar {
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
  }

  /* Move right-aligned toolbar group to its own full-width row */
  .editor-toolbar > div[style*="margin-left:auto"] {
    margin-left: 0 !important;
    width: 100%;
    flex-wrap: wrap;
    gap: 4px;
  }

  /* Sprint/Flow/Feedback buttons text: shorter on very small screens */
  .toolbar-dropdown .btn {
    font-size: 12px;
    padding: 6px 10px;
  }

  /* Editor tabs: scrollable and touch-friendly */
  .editor-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .editor-tabs::-webkit-scrollbar {
    display: none;
  }

  .editor-tab {
    padding: 10px 14px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Copy exercise: readable on small screens */
  .exercise-content {
    padding: 16px;
    font-size: 15px;
  }

  .copy-textarea {
    font-size: 15px;
    min-height: 140px;
  }

  /* Exercise meta: smaller gaps */
  .exercise-meta {
    gap: 8px;
  }

  .exercise-meta-item {
    font-size: 12px;
  }

  /* Mode overlay: compact */
  .mode-overlay {
    padding: 8px 16px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .mode-timer {
    font-size: 20px;
  }

  /* Reader controls: spread evenly */
  .reader-controls {
    padding: 8px 0;
  }

  /* Plan cards / subscription: full width */
  .plan-card {
    padding: 20px;
  }

  /* Data tables: horizontal scroll */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Skill cards: tighter */
  .skill-card {
    padding: 12px 14px;
  }

  /* Notification: full width bottom */
  .notification {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: none;
  }

  /* Eval selector: stack on very small screens */
  .eval-selector {
    flex-direction: column;
  }

  .eval-option {
    text-align: center;
  }

  .mobile-header {
    display: flex;
    padding: 12px 20px;
    background: var(--panel-bg);
    color: var(--panel-text-active);
    align-items: center;
    gap: 12px;
  }

  .hamburger {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    color: var(--panel-text-active);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.15s;
  }

  .hamburger:hover,
  .hamburger:focus-visible {
    background: var(--panel-hover-bg);
  }

  .hamburger:focus-visible {
    outline: 2px solid var(--warm);
    outline-offset: 2px;
  }
}

@media (max-width: 480px) {
  .main-content {
    padding: 12px;
  }

  .story-editor-page {
    margin: -12px -12px;
    padding: 12px 12px;
  }

  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  h3 { font-size: 15px; }

  .stats-bar-group {
    min-width: 50%;
    flex: 1 1 50%;
  }

  .stats-bar-level {
    border-top: 1px solid var(--divider);
    flex: 1 1 100%;
  }

  /* Toolbar dropdowns: position fixed full-width on very small screens */
  .toolbar-dropdown-menu {
    left: 8px !important;
    right: 8px;
    min-width: unset;
    width: calc(100vw - 16px);
  }

  /* Badges: single column on very small screens */
  .badges-grid {
    grid-template-columns: 1fr;
  }

  .editor-textarea {
    padding: 16px;
    font-size: 15px;
  }

  /* Peer items */
  .peer-status {
    display: block;
    margin-bottom: 4px;
  }
}

@media (min-width: 769px) {
  .mobile-header { display: none; }
  .sidebar-overlay { display: none !important; }
}

/* ============================================================
   COPY EXERCISE — in-place char-by-char highlighting
   ============================================================ */

/* Passage text chars change color as the user types in the textarea below */
.ch {
  color: var(--ch-untyped);   /* untyped text color */
}

.ch.correct {
  color: var(--ch-correct);   /* correct text color */
}

.ch.incorrect {
  background: var(--ch-incorrect-bg);   /* wrong text bg color */
  color: var(--ch-incorrect);        /* wrong text color */
  border-radius: 2px;
  text-decoration: underline;         /* non-colour cue for colour-blind users */
  text-underline-offset: 2px;
}

.ch.cursor {
  border-bottom: 2px solid var(--warm);
  animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
  0%, 100% { border-bottom-color: var(--warm); }
  50% { border-bottom-color: transparent; }
}

.copy-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}

.copy-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--divider);
  border-radius: 2px;
  overflow: hidden;
}

.copy-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.15s ease;
  width: 0%;
}

.copy-progress-label {
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Copy exercise textarea — visible, used for the user's writing */
.copy-textarea {
  width: 100%;
  min-height: 180px;
  padding: 16px;
  font-family: var(--body-font);
  font-size: 16px;
  line-height: 1.8;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  margin-bottom: 16px;
}

/* ============================================================
   HTMX LOADING INDICATOR
   ============================================================ */

.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}
