/* ---------- Fonts ---------- */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('fonts/OpenDyslexic-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('fonts/OpenDyslexic-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Reset / shell ---------- */
* { box-sizing: border-box; }

/* Visually hidden but still focusable/clickable - safer than [hidden] for file inputs */
.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;
  opacity: 0;
}
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: #f5f5f5;
  font-family: -apple-system, system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: #0a0a0a;
  border-bottom: 1px solid #1a1a1a;
  font-size: 13px;
  color: #888;
}

#status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70vw;
}

#wpm-wrap {
  display: inline-flex;
  align-items: center;
}

#wpm-display {
  font-variant-numeric: tabular-nums;
  color: #ccc;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
}
#wpm-display:hover {
  background: #181818;
  border-color: #2a2a2a;
}

#wpm-input {
  font: inherit;
  font-variant-numeric: tabular-nums;
  width: 90px;
  padding: 2px 6px;
  background: #0a0a0a;
  color: #f5f5f5;
  border: 1px solid #ff3344;
  border-radius: 4px;
  text-align: right;
  outline: none;
  /* hide native spin buttons */
  -moz-appearance: textfield;
  appearance: textfield;
}
#wpm-input::-webkit-outer-spin-button,
#wpm-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------- Stage ---------- */
#stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

/* Spritz-style tick guides: short horizontal marks above and below the ORP letter,
   centered on the anchor x. Sized relative to the word so they stay proportional
   when font size changes. Reference: Spritz patent US 20140016867 A1 (FIG. 2). */
.tick {
  position: absolute;
  left: var(--anchor-x);
  width: calc(var(--word-size) * 0.55);
  height: 2px;
  background: #4a4a4a;
  transform: translateX(-50%);
  pointer-events: none;
}
.tick-top { top: calc(50% - var(--word-size) * 0.9); }
.tick-bot { top: calc(50% + var(--word-size) * 0.9); }

#word-frame {
  position: relative;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The ORP letter is anchored at horizontal viewport position --anchor-x (42% from left,
   matching the original Instagram reels measured at ~41.8%). The red letter's visual
   center sits exactly on that line. before/after spans flank it, set in JS after
   measuring the anchor's pixel width. The anchor never moves between words. */
:root {
  --anchor-x: 42%;
  --word-size: 96px;  /* tunable via + / - keys; clamped 32-240 in JS */
}

#word-before, #word-orp, #word-after {
  position: absolute;
  top: 50%;
  font-size: var(--word-size);
  font-weight: 400;
  line-height: 1;
  white-space: pre;
}

#word-before {
  /* `right` is set in JS after measuring the anchor */
  right: calc(100% - var(--anchor-x));
  text-align: right;
  color: #f5f5f5;
  transform: translateY(-50%);
}

#word-orp {
  left: var(--anchor-x);
  color: #ff3344;
  transform: translate(-50%, -50%);
}

#word-after {
  /* `left` is set in JS after measuring the anchor */
  left: var(--anchor-x);
  color: #f5f5f5;
  transform: translateY(-50%);
}

#hint {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: #555;
  letter-spacing: 0.5px;
}
#hint.hidden { display: none; }

/* ---------- Font modes ---------- */
body[data-font="dyslexic"] #word-before,
body[data-font="dyslexic"] #word-orp,
body[data-font="dyslexic"] #word-after {
  font-family: 'OpenDyslexic', sans-serif;
}

body[data-font="serif"] #word-before,
body[data-font="serif"] #word-orp,
body[data-font="serif"] #word-after {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-weight: 400;
}

body[data-font="mono"] #word-before,
body[data-font="mono"] #word-orp,
body[data-font="mono"] #word-after {
  font-family: ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace;
}

/* ---------- Action bar ---------- */
#actionbar {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  background: #0a0a0a;
  border-top: 1px solid #1a1a1a;
}

#actionbar button,
#actionbar .actbtn {
  background: #1a1a1a;
  color: #ddd;
  border: 1px solid #2a2a2a;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  display: inline-block;
  line-height: normal;
  user-select: none;
}
#actionbar button:hover,
#actionbar .actbtn:hover {
  background: #232323;
  border-color: #3a3a3a;
}
#btn-help {
  margin-left: auto;
  width: 36px;
  padding: 8px 0;
  text-align: center;
}

/* ---------- Dialogs ---------- */
dialog {
  background: #111;
  color: #f5f5f5;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 22px;
  max-width: 600px;
  width: 92vw;
  font-family: inherit;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

dialog h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 600;
  color: #ccc;
}

dialog textarea, dialog input[type="url"] {
  width: 100%;
  background: #0a0a0a;
  color: #f5f5f5;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

dialog menu button {
  background: #1a1a1a;
  color: #ddd;
  border: 1px solid #2a2a2a;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
dialog menu button[value="ok"] {
  background: #ff3344;
  border-color: #ff3344;
  color: #fff;
}

dialog .muted {
  color: #777;
  font-size: 12px;
  margin: 8px 0 0;
}

dialog code {
  background: #0a0a0a;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}

table.keys {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.keys td {
  padding: 6px 0;
  border-bottom: 1px solid #1a1a1a;
}
table.keys td:first-child {
  width: 180px;
  color: #888;
}

kbd {
  display: inline-block;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #ddd;
}

/* ---------- Chapter panel ---------- */
#chapter-panel[hidden] { display: none; }
#chapter-panel {
  position: fixed;
  top: 41px;
  left: 0;
  bottom: 53px;
  width: 320px;
  background: #0a0a0a;
  border-right: 1px solid #1a1a1a;
  display: flex;
  flex-direction: column;
  z-index: 5;
}
#chapter-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #1a1a1a;
  font-size: 13px;
  color: #888;
}
#chapter-close {
  background: transparent;
  border: none;
  color: #888;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
#chapter-list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 8px 0;
  list-style: none;
}
#chapter-list li {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  color: #ccc;
  border-left: 2px solid transparent;
}
#chapter-list li:hover {
  background: #141414;
  border-left-color: #2a2a2a;
}
#chapter-list li.active {
  border-left-color: #ff3344;
  color: #fff;
  background: #141414;
}
