/* ============================================================
   The Writing Sessions — Main Stylesheet
   ============================================================ */

/* --- Google Fonts (loaded in template head) --- */
/* Literata (serif, for headings/literary) & DM Sans (sans, for UI) */

:root {
  --ink: #1a1a2e;
  --parchment: #f5f0e8;
  --parchment-deep: #ebe4d6;
  --parchment-light: #faf7f2;
  --warm: #c4956a;
  --warm-light: #e8d5c0;
  --warm-glow: #f0e0cc;
  --accent: #6b5b4e;
  --accent-light: #8b7b6e;
  --green: #5a7a5a;
  --green-light: #d4e4d4;
  --blue: #5a6b7a;
  --blue-light: #d4dce4;
  --red: #9a5a5a;
  --red-light: #f0d4d4;
  --muted: #8a8578;
  --divider: #d8d0c4;
  --card-bg: #fffdf8;
  --shadow: rgba(26, 26, 46, 0.08);
  --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(--ink);
  color: #ccc;
  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: #aaa;
  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: rgba(255,255,255,0.08);
  color: #fff;
}

.sidebar-nav .nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-user {
  border-top: 1px solid rgba(255,255,255,0.1);
  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: #fff;
  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: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-credits {
  font-size: 11px;
  color: var(--warm);
}

.sidebar-logout {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 6px 2px 0;
  font-size: 13px;
  color: #888;
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-logout:hover {
  background: rgba(255,255,255,0.08);
  color: #ccc;
  text-decoration: underline;
}

/* Debug status bar at bottom of sidebar */
.nav-status-bar {
  margin-top: 8px;
  padding: 5px 8px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  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(--warm);
  color: #fff;
}

.btn-primary:hover { background: #b8845e; }

.btn-secondary {
  background: var(--parchment-deep);
  color: var(--accent);
}

.btn-secondary:hover { background: var(--divider); }

.btn-ghost {
  background: none;
  color: var(--accent);
  padding: 8px 12px;
}

.btn-ghost:hover { background: var(--parchment-deep); }

.btn-small {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-danger {
  background: var(--red);
  color: #fff;
}

.btn-danger:hover { background: #8a4a4a; }

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================================
   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: #fff;
  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 rgba(196, 149, 106, 0.15);
}

.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;
}

/* ============================================================
   XP & PROGRESS
   ============================================================ */

.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), #b8845e);
  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 rgba(26, 26, 46, 0.12);
  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: #333649;  /* overall content bg */
  border-left-color: transparent;
  color: #c7cdd8;  /* untyped text default */
}

.exercise-content.copy-exercise .content-text {
  background: #393c4f;  /* content text bg */
  padding: 16px;
  border-radius: var(--radius);
  border-left: 3px solid #5fa8d3;  /* left accent color on content text */
}

.exercise-content.copy-exercise .content-attribution {
  color: #8ba3b5;
}

.content-attribution {
  margin-top: 16px;
  font-size: 13px;
  color: var(--accent-light);
  font-style: italic;
}

.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(--text-secondary, #666);
  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: #fff;
}

.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: #fff;
}

/* ============================================================
   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: #f0f0f0;
}

.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(--ink);
  color: #fff;
  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: #fff;
  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-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(--ink) 0%, #2a2a4e 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); }
.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); }

/* ============================================================
   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: 20px;
  }

  .story-editor-page {
    margin: -20px -20px; /* Negate mobile main-content padding */
    padding: 20px 20px; /* Re-add padding inside */
  }

  .mobile-header {
    display: flex;
    padding: 12px 20px;
    background: var(--ink);
    color: #fff;
    align-items: center;
    gap: 12px;
  }

  .hamburger {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
  }
}

@media (min-width: 769px) {
  .mobile-header { display: none; }
}

/* ============================================================
   COPY EXERCISE — in-place char-by-char highlighting
   ============================================================ */

/* Passage text chars change color as the user types in the textarea below */
.ch {
  color: #c7cdd8;   /* untyped text color */
}

.ch.correct {
  color: #90e77f;   /* correct text color */
}

.ch.incorrect {
  background: #614757;   /* wrong text bg color */
  color: #f56a6b;        /* wrong text color */
  border-radius: 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;
}
