:root {
  --bg-1: #1e1b15;
  --bg-2: #2a261f;
  --paper: #2a261f;
  --paper-soft: #333029;
  --ink: #e8e2d7;
  --ink-strong: #fff8f0;
  --ink-accent: #ffb690;
  --muted: #887369;
  --accent: #974814;
  --accent-primary: #b65f2b;
  --accent-soft: rgba(182, 95, 43, 0.08);
  --accent-line: rgba(182, 95, 43, 0.4);
  --accent-line-soft: rgba(182, 95, 43, 0.25);
  --accent-line-focus: rgba(182, 95, 43, 0.6);
  --accent-weak-bg: rgba(182, 95, 43, 0.12);
  --line: rgba(232, 226, 215, 0.08);
  --line-soft: rgba(232, 226, 215, 0.12);
  --line-medium: rgba(232, 226, 215, 0.18);
  --line-strong: rgba(232, 226, 215, 0.25);
  --paper-raised: rgba(42, 38, 31, 0.9);
  --paper-raised-soft: rgba(42, 38, 31, 0.85);
  --paper-raised-strong: rgba(42, 38, 31, 0.95);
  --toolbar-bg: rgba(42, 38, 31, 0.9);
  --toolbar-bg-fullscreen: rgba(42, 38, 31, 0.92);
  --fade-clear: rgba(30, 27, 21, 0);
  --code-bg: rgba(232, 226, 215, 0.1);
  --line-text: rgba(232, 226, 215, 0.5);
  --line-text-muted: rgba(232, 226, 215, 0.45);
  --line-glow: rgba(182, 95, 43, 0.3);
  --shadow: rgba(0, 0, 0, 0.4);

  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-7: 2rem;
  --space-8: 2.5rem;
  --space-9: 3rem;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  --fade-height: clamp(120px, 16vh, 200px);
  --scrollbar-size: 8px;
  --blur-toolbar: 24px;

  --font-size-subtitle: 0.7rem;
  --font-size-input: 1.14rem;
  --font-size-control: 0.875rem;
  --font-size-meta: 0.75rem;
  --font-size-hint: 0.875rem;

  --font-headline: "Noto Serif", Georgia, serif;
  --font-body: "Newsreader", Georgia, serif;
  --font-label: "Work Sans", -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg-1);
}

main {
  max-width: 900px;
  margin: var(--space-0) auto;
  padding: clamp(3rem, 8vh, 5rem) var(--space-6) 9rem;
  text-align: center;
}

main.playback-focus {
  max-width: none;
  width: 100%;
  min-height: 100vh;
  padding: var(--space-4) var(--space-6) 9rem;
  display: flex;
  flex-direction: column;
  text-align: left;
}

main.playback-focus::before,
main.playback-focus::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  height: var(--fade-height);
  pointer-events: none;
  z-index: 4;
}

main.playback-focus::before {
  top: 0;
  background: linear-gradient(to bottom, #1e1b15 0%, rgba(30, 27, 21, 0.85) 30%, transparent 100%);
}

main.playback-focus::after {
  bottom: 0;
  background: linear-gradient(to top, #1e1b15 0%, rgba(30, 27, 21, 0.85) 30%, transparent 100%);
}

main.playback-focus .subtitle,
main.playback-focus .input-panel,
main.playback-focus .hint {
  display: none;
}

main.playback-focus .reader-panel {
  margin-top: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

main.playback-focus .line-list {
  text-align: center;
  padding-top: 15vh;
  padding-bottom: max(15vh, 10rem);
  max-height: none;
  flex: 1;
}

main.playback-focus .line-item {
  margin: clamp(3rem, 6vh, 6rem) var(--space-0);
}

main.playback-focus .line-item.active {
  transform: scale(1.15);
}

.title {
  font-family: var(--font-headline);
  font-size: clamp(1.75rem, 1.4rem + 2vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.015em;
  margin-bottom: var(--space-3);
  color: var(--ink-strong);
}

main.playback-focus .title {
  position: fixed;
  top: var(--space-5);
  left: var(--space-5);
  z-index: 45;
  margin: 0;
  font-size: clamp(1.25rem, 1rem + 1vw, 1.75rem);
  opacity: 0.6;
  transition: opacity 200ms ease;
  user-select: none;
  -webkit-user-select: none;
}

main.playback-focus .title:hover {
  opacity: 1;
}

.subtitle {
  margin: var(--space-0) auto var(--space-6);
  max-width: 42rem;
  color: var(--muted);
  font-size: var(--font-size-subtitle);
  font-family: var(--font-label);
  font-weight: 400;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 1.6;
}

.input-panel,
.reader-panel {
  background: transparent;
}

.input-panel {
  padding: var(--space-0);
}

textarea {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: var(--paper);
  color: var(--ink);
  padding: var(--space-5) var(--space-5);
  font-size: var(--font-size-input);
  font-family: var(--font-body);
  line-height: 1.72;
  text-align: left;
  transition: border-color 200ms ease;
}

textarea:focus {
  outline: none;
  border-color: var(--accent-line-focus);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

button,
select {
  border: 1px solid var(--line-soft);
  background: transparent;
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-control);
  font-family: var(--font-label);
  font-weight: 500;
  cursor: pointer;
  transition: all 160ms ease;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.icon-btn {
  padding: var(--space-2);
  width: 2.75rem;
  height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-family: system-ui, sans-serif;
}

.speed-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: calc(var(--space-5) + var(--space-2));
  padding-left: var(--space-3);
  background-color: transparent;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-accent) 50%),
    linear-gradient(135deg, var(--ink-accent) 50%, transparent 50%);
  background-position:
    calc(100% - var(--space-3)) calc(50% + 1px),
    calc(100% - var(--space-2)) calc(50% + 1px);
  background-size: 0.3rem 0.3rem, 0.3rem 0.3rem;
  background-repeat: no-repeat;
}

.speed-select:focus {
  outline: none;
  border-color: var(--accent-line-focus);
}

button:hover,
select:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

button.primary {
  border: 1px solid var(--accent-primary);
  background: var(--accent-primary);
  color: #fff;
  font-weight: 600;
}

button.primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.02);
}

button.is-active {
  border: 1px solid var(--accent-line);
  background: var(--accent-weak-bg);
  color: var(--ink-accent);
  font-weight: 600;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.reader-panel {
  margin-top: var(--space-5);
  padding: var(--space-0);
}

.reader-toolbar {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: var(--space-3) var(--space-5);
  background: var(--toolbar-bg-fullscreen);
  -webkit-backdrop-filter: blur(var(--blur-toolbar));
  backdrop-filter: blur(var(--blur-toolbar));
  border-radius: var(--radius-lg);
  border: none;
  box-shadow: 0 8px 32px var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.05);
  max-width: 95vw;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
}

.divider {
  width: 1px;
  height: 1.5rem;
  background: var(--line-soft);
  margin: 0 var(--space-1);
}

.meta {
  color: var(--muted);
  font-size: var(--font-size-meta);
  font-family: var(--font-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  white-space: nowrap;
}

.line-list {
  max-height: 58vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-6) var(--space-2) 8rem var(--space-2);
  scroll-behavior: smooth;
  text-align: center;
  position: relative;
}

main.playback-focus.follow-active .line-list.apply-mask {
  /* Foveal masking gradient - creates spotlight effect */
  /* Only applied when following and not on first or last line */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 15%,
    black 85%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 15%,
    black 85%,
    transparent 100%
  );
}

.line-list::-webkit-scrollbar {
  width: var(--scrollbar-size);
}

.line-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--line-soft);
}

.line-item {
  margin-block: var(--space-7);
  margin-inline: auto;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  color: var(--line-text);
  font-family: var(--font-headline);
  font-size: clamp(1.5rem, 1.25rem + 2vw, 2.5rem);
  font-weight: 400;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1), 
              color 160ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 160ms cubic-bezier(0.4, 0, 0.2, 1),
              filter 250ms ease-out;
  filter: blur(0);
  transform: scale(0.73);
  max-width: min(75vw, 48ch);
  display: inline-block;
  text-align: left;
}

.line-item code {
  font-size: 0.72em;
  background: var(--code-bg);
  border-radius: var(--radius-sm);
  padding: 0.08em var(--space-1);
}

.line-item a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.line-item.active {
  color: var(--ink-strong);
  background: transparent;
  transform: scale(1.02);
  text-shadow: 0 0 40px var(--line-glow);
  filter: blur(0);
  position: relative;
  --line-progress: 0;
}

.line-item.active::before {
  content: "";
  position: absolute;
  left: -0.75rem;
  top: 50%;
  transform: translateY(-50%);
  transform-origin: top;
  width: 0.3rem;
  height: calc(1.5rem * (100 - var(--line-progress)) / 100);
  max-height: 1.5rem;
  background: var(--accent-primary);
  border-radius: var(--radius-pill);
  box-shadow: 0 0 15px rgba(182, 95, 43, 0.6);
  opacity: clamp(0, (100 - var(--line-progress)) / 20, 1);
  transition: height 50ms linear, opacity 200ms ease-out;
}

/* Paused state: dashed gutter thread */
.line-item.active.paused::before {
  background: linear-gradient(
    to bottom,
    var(--accent-primary) 40%,
    transparent 40%,
    transparent 60%,
    var(--accent-primary) 60%
  );
  background-size: 0.3rem 0.5rem;
  opacity: 0.7;
}

.line-item.before,
.line-item.after {
  color: var(--line-text-muted);
}

/* Blur only applies when BOTH in focus mode AND following */
main.playback-focus.follow-active .line-item.before,
main.playback-focus.follow-active .line-item.after {
  filter: blur(var(--blur-strength, 1.5px));
}

/* When not following, keep dimmed but clear - "Reader Mode" */
main.playback-focus:not(.follow-active) .line-item.before,
main.playback-focus:not(.follow-active) .line-item.after {
  opacity: 0.6;
  filter: blur(0);
}

/* Always prevent selection on non-active in focus mode */
main.playback-focus .line-item.before,
main.playback-focus .line-item.after {
  user-select: none;
  -webkit-user-select: none;
}

.line-item.dist-1 {
  opacity: 0.85;
}

.line-item.dist-2 {
  opacity: 0.65;
}

.line-item.dist-3 {
  opacity: 0.45;
}

.line-item.dist-far {
  opacity: 0.25;
}

.hint {
  color: var(--muted);
  font-size: var(--font-size-hint);
  font-family: var(--font-label);
  margin-top: var(--space-4);
  opacity: 0.6;
  font-weight: 400;
}

.progress-bar-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  overflow: hidden;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent-primary);
  transition: width 180ms cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px rgba(182, 95, 43, 0.5);
  border-radius: var(--radius-lg) 0 0 0;
}

/* Resume Flow Button */
.resume-flow-btn {
  position: fixed;
  bottom: 7rem;
  right: 2rem;
  z-index: 45;
  padding: var(--space-2) var(--space-4);
  background: var(--ink-strong);
  color: var(--accent-primary);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-lg);
  font-family: var(--font-label);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 180ms cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 16px rgba(182, 95, 43, 0.3);
}

.resume-flow-btn:hover {
  background: var(--accent-primary);
  color: var(--bg);
  box-shadow: 0 6px 24px rgba(182, 95, 43, 0.5);
  transform: translateY(-1px);
}

/* Eye-line Anchor */
.eye-line-anchor {
  position: fixed;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent 0%,
    rgba(182, 95, 43, 0.05) 20%,
    rgba(182, 95, 43, 0.05) 80%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 10;
}

/* Completion Overlay */
.completion-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background: rgba(30, 27, 21, 0.97);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.completion-content {
  text-align: center;
  max-width: 40rem;
}

.completion-title {
  font-family: var(--font-headline);
  font-size: clamp(2rem, 1.5rem + 3vw, 3.5rem);
  font-weight: 700;
  color: var(--ink-strong);
  margin-bottom: var(--space-6);
  letter-spacing: -0.02em;
}

.completion-stats {
  display: flex;
  gap: var(--space-6);
  justify-content: center;
  margin-bottom: var(--space-7);
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 8rem;
}

.stat-label {
  font-family: var(--font-label);
  font-size: var(--font-size-hint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  font-family: var(--font-headline);
  font-size: clamp(1.75rem, 1.5rem + 1vw, 2.25rem);
  font-weight: 700;
  color: var(--accent-primary);
  line-height: 1.2;
}

.completion-close {
  padding: var(--space-3) var(--space-6);
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-soft);
  font-size: 1rem;
  font-weight: 500;
  transition: all 180ms ease;
}

.completion-close:hover {
  background: var(--line-soft);
  color: var(--ink-strong);
  border-color: var(--accent-primary);
}

@media (max-width: 768px) {
  main {
    padding: var(--space-4) var(--space-3) 8rem;
  }

  .line-list {
    max-height: 52vh;
    padding-bottom: 7rem;
  }

  main.playback-focus {
    padding: var(--space-4) var(--space-4) 8rem;
  }

  main.playback-focus .line-list {
    padding-bottom: 8rem;
  }

  .reader-toolbar {
    bottom: 1rem;
    padding: var(--space-2) var(--space-3);
    gap: var(--space-1);
  }

  .icon-btn {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.1rem;
  }

  button {
    font-size: 0.75rem;
    padding: var(--space-1) var(--space-2);
  }

  .speed-select {
    font-size: 0.75rem;
    padding: var(--space-1) var(--space-2);
    padding-right: calc(var(--space-4) + var(--space-2));
  }

  .meta {
    font-size: 0.65rem;
  }

  .resume-flow-btn {
    bottom: 6rem;
    right: 1rem;
    padding: var(--space-2) var(--space-3);
    font-size: 0.75rem;
  }

  .completion-title {
    font-size: clamp(1.5rem, 1.25rem + 2vw, 2.5rem);
  }

  .completion-stats {
    gap: var(--space-4);
  }

  .stat {
    min-width: 6rem;
  }

  .stat-value {
    font-size: clamp(1.25rem, 1.125rem + 0.75vw, 1.75rem);
  }
}
