:root {
  --bg: #0f1115;
  --fg: #e8e8ea;
  --muted: #7a7f8a;
  --accent: #ff4d4d;
  --panel: #171a21;
  --panel-elevated: #1c2028;
  --border: #262a33;
  --topbar-h: 56px;
  --bottombar-h: 72px;
  --sidebar-w: 300px;

  /* Fonts — split by purpose so each mode gets its optimal face */
  --font-ui:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-read:   'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-editor: 'Literata', Georgia, 'Times New Roman', serif;
  --font-mono:   ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
  overflow: hidden; /* prevent body scroll; editor manages its own overflow */
}

/* The hidden attribute must win over any explicit display rule. */
[hidden] { display: none !important; }

/* ---------- Edit view: full-screen layout ---------- */
#edit-view {
  position: fixed;
  inset: 0;
}

/* Top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
/* ---------- Brand logo (bottom-right, always visible) ---------- */
.brand-logo {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 50;
  opacity: 0.3;
  transition: opacity .2s;
}
.brand-logo:hover { opacity: 0.7; }
.brand-logo img { display: block; }
.topbar-spacer { flex: 1; }

#sidebar-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
#sidebar-toggle:hover { background: var(--panel); border-color: #3a4050; }
#sidebar-toggle .hamburger,
#sidebar-toggle .hamburger::before,
#sidebar-toggle .hamburger::after {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--fg);
  border-radius: 1px;
  position: relative;
}
#sidebar-toggle .hamburger::before,
#sidebar-toggle .hamburger::after {
  content: '';
  position: absolute;
  left: 0;
}
#sidebar-toggle .hamburger::before { top: -5px; }
#sidebar-toggle .hamburger::after  { top:  5px; }

/* Sidebar */
#sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: var(--bottombar-h);
  left: 0;
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform .22s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#edit-view.sidebar-open #sidebar {
  transform: translateX(0);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.sidebar-header h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 600;
  margin: 0;
}
#clear-saved {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
}
#clear-saved:hover { color: var(--accent); }

#saved-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#saved-list li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .15s;
  position: relative;
}
#saved-list li:hover { border-color: #3a4050; }
#saved-list .saved-preview {
  font-size: 13px;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 20px;
}
#saved-list .saved-meta {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#saved-list .saved-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
}
#saved-list .saved-delete:hover { color: var(--accent); }

.sidebar-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  margin: 20px 0 0;
}

/* Scrim that covers the main content when sidebar is open */
#edit-view.sidebar-open #editor-main::before {
  content: '';
  position: fixed;
  top: var(--topbar-h);
  bottom: var(--bottombar-h);
  left: var(--sidebar-w);
  right: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 15;
}

/* Editor main area */
#editor-main {
  position: fixed;
  top: var(--topbar-h);
  bottom: var(--bottombar-h);
  left: 0;
  right: 0;
  overflow-y: auto;
}

#text-input {
  min-height: 100%;
  padding: 48px max(40px, 10vw) 80px;
  font-family: var(--font-editor);
  font-size: 18px;
  line-height: 1.75;
  white-space: pre-wrap;
  outline: none;
  max-width: 720px;
  margin: 0 auto;
  color: var(--fg);
}
/* Intro overlay — shown when editor is empty */
#editor-intro {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  max-width: 520px;
  margin: 0 auto;
  padding: 0 40px;
  text-align: center;
  color: var(--muted);
  pointer-events: none; /* clicks pass through to the editor */
  opacity: 1;
  transition: opacity .2s;
}
#edit-view.has-content #editor-intro { opacity: 0; }
.intro-lead {
  font-size: 17px;
  margin: 0 0 16px;
  color: var(--muted);
}
.intro-lead strong { color: var(--fg); font-weight: 600; }
.intro-tip {
  font-size: 13px;
  margin: 0;
  color: var(--muted);
  opacity: 0.7;
}

#text-input .start-marker {
  background: rgba(255, 77, 77, 0.22);
  color: var(--fg);
  border-radius: 3px;
  padding: 0 2px;
  box-shadow: 0 0 0 1px var(--accent);
}

/* Bottom bar */
.bottombar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottombar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 30;
}

#settings {
  display: flex;
  align-items: center;
  gap: 20px;
}
#wpm-label {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wpm-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

/* Range slider — custom styling for cross-browser consistency */
#wpm {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
#wpm::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg);
  cursor: grab;
  border: none;
  transition: transform .1s;
}
#wpm::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.15); }
#wpm::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg);
  cursor: grab;
  border: none;
}
#wpm::-moz-range-track {
  background: var(--border);
  height: 4px;
  border-radius: 2px;
}

.wpm-value {
  min-width: 72px;
  font-size: 13px;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

#start-btn {
  padding: 10px 24px;
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
#start-btn:hover:not(:disabled) { transform: translateY(-1px); }
#start-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Reader view ---------- */
#reader-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
}
#countdown-number {
  font-family: var(--font-read);
  font-size: clamp(64px, 12vw, 160px);
  font-weight: 500;
  color: var(--fg);
  line-height: 1;
  letter-spacing: -0.02em;
}
#countdown-hints {
  list-style: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#countdown-hints kbd,
.done-hint kbd {
  display: inline-block;
  padding: 2px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg);
  margin: 0 2px;
}

#word-display {
  font-family: var(--font-read);
  font-size: clamp(40px, 7.5vw, 88px);
  font-weight: 500;
  letter-spacing: -0.01em;
  font-feature-settings: "ss01", "cv11"; /* Inter's disambiguated letterforms */
  display: flex;
  transform: translateX(-0.5ch);
}
#word-display .before { text-align: right; }
#word-display .pivot  { color: var(--accent); }
#word-display .after  { text-align: left; }

#status-bar {
  position: fixed;
  top: 16px;
  right: 20px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 12px;
}
#pause-indicator { color: var(--accent); }

#progress-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--border);
}
#progress-fill {
  height: 100%;
  width: 0;
  background: var(--fg);
  transition: width .1s linear;
}

/* Done screen */
#done-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--bg);
  padding: 20px;
}
#done-screen h2 {
  font-size: clamp(48px, 8vw, 96px);
  font-weight: 500;
  margin: 0;
  color: var(--fg);
  letter-spacing: 1px;
}
#done-stats {
  display: flex;
  gap: 48px;
  margin: 0;
  padding: 0;
}
#done-stats > div { text-align: center; }
#done-stats dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}
#done-stats dd {
  margin: 0;
  font-size: 28px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
#done-back-btn {
  margin-top: 8px;
  padding: 12px 28px;
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.done-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
#done-screen .wonderful-footer {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 0;
  padding: 0;
  border: none;
}
#done-screen .wonderful-footer a {
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
#done-screen .wonderful-footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Nav switcher (top-right of topbar) */
.nav-switcher {
  display: flex;
  gap: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.nav-link {
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
}
.nav-link:hover { color: var(--fg); }
.nav-link.nav-current { color: var(--fg); }
.nav-sep { color: var(--border); }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .bottombar { flex-direction: column; height: auto; padding: 12px 16px; gap: 8px; }
  :root { --bottombar-h: 112px; }
  #text-input { padding: 32px 20px 60px; font-size: 16px; }
  #sidebar { width: 85vw; }
}
