:root {
  --bg: #000;
  --fg: #fff;
  --muted: #888;
  --accent: #ff5252;
  --panel: #0d0d0d;
  --border: #222;
  --focus: #4ea1ff;
  --reader-font: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--reader-font);
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
}

button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* ---------- Library ---------- */

#library-view {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 28px;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.12em;
}

.app-header .tagline {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

#drop-zone {
  width: 100%;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease;
}

#drop-zone:hover,
#drop-zone.drag-active {
  border-color: var(--fg);
  background: var(--panel);
}

#drop-zone .primary {
  font-size: 18px;
}

#drop-zone .secondary {
  color: var(--muted);
  font-size: 13px;
}

#status {
  min-height: 20px;
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: 13px;
}

#doc-list {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty {
  color: var(--muted);
  text-align: center;
  margin: 24px 0;
}

.doc-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.doc-open {
  flex: 1;
  text-align: left;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--panel);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  border: 1px solid var(--border);
}

.doc-open:hover { border-color: var(--fg); }

.doc-title {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  justify-self: end;
}

.doc-type {
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.08em;
}

.doc-bar {
  grid-column: 1 / -1;
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}

.doc-bar-fill {
  display: block;
  height: 100%;
  background: var(--fg);
  width: 0%;
  transition: width 200ms ease;
}

.doc-delete {
  width: 44px;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
}

.doc-delete:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Reader ---------- */

#reader-view {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #000;
}

#reader-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

#reader-title {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#btn-exit {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 18px;
  color: var(--muted);
}

#btn-exit:hover { color: var(--fg); border-color: var(--fg); }

#word-tap {
  position: relative;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: grid;
  grid-template-rows: 1fr auto auto 1fr;
  align-items: center;
  justify-items: center;
}

#word-stage {
  grid-row: 2;
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* The reader uses a fixed pivot column so the ORP letter stays at
   the same x position from word to word, eliminating eye drift. */
#word {
  font-family: var(--reader-font);
  font-size: clamp(40px, 9vw, 88px);
  letter-spacing: 0;
  line-height: 1;
  position: relative;
  display: flex;
  align-items: baseline;
  white-space: pre;
}

#word-left {
  text-align: right;
  flex: 1 1 0;
  min-width: 0;
}

#word-right {
  text-align: left;
  flex: 1 1 0;
  min-width: 0;
}

#word-orp {
  color: var(--accent);
  text-align: center;
  flex: 0 0 auto;
  min-width: 1ch;
}

/* Visual guide marks above and below the ORP column. */
#word-stage::before,
#word-stage::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 1px;
  height: 14px;
  background: var(--border);
  transform: translateX(-0.5px);
}

#word-stage::before { top: -28px; }
#word-stage::after { bottom: -28px; }

#progress {
  grid-row: 3;
  width: min(60%, 520px);
  margin-top: 56px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

#progress-track {
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0%;
  background: var(--fg);
  transition: width 120ms linear;
}

#progress-labels {
  display: flex;
  justify-content: space-between;
}

#controls {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.control-row.transport button {
  width: 56px;
  height: 44px;
  border-radius: 10px;
  font-size: 16px;
}

#btn-play {
  width: 64px !important;
  height: 48px !important;
  font-size: 20px;
}

.control-row.speed {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
}

.control-row.speed button {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 20px;
}

#wpm-slider {
  width: 100%;
  accent-color: var(--fg);
}

#wpm-label {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
}

#wpm-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- Responsive ---------- */

@media (max-width: 600px) {
  #library-view { padding: 20px 14px 48px; }
  .app-header h1 { font-size: 22px; }
  #word { font-size: clamp(38px, 11vw, 72px); }
  #progress { width: 86%; margin-top: 36px; }
  #word-stage::before { top: -22px; }
  #word-stage::after { bottom: -22px; }
  .control-row.transport button { width: 48px; height: 44px; }
}

@media (min-height: 800px) {
  #word { font-size: clamp(48px, 8vw, 104px); }
}
