:root {
  --bg: #000000;
  --panel: #0b0e12;
  --panel-border: #232830;
  --line: #1f2226;
  --text: #f2f2f2;
  --muted: #969696;
  --pivot: #ff4d56;
  --frame-ch: 18;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}

@keyframes uiFadeIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drawerItemIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drawerSheen {
  from {
    transform: translateX(-12%);
  }
  to {
    transform: translateX(12%);
  }
}

.reader-screen {
  position: relative;
  min-height: 100vh;
  background: #000000;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.focus-frame {
  width: min(calc(var(--frame-ch) * 1ch), 88vw);
  min-width: 180px;
  padding: 1.65rem 0;
  position: relative;
  display: grid;
  place-items: center;
}

.focus-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--line);
}

.focus-line.top {
  top: 0;
}

.focus-line.bottom {
  bottom: 0;
}

.focus-notch {
  position: absolute;
  left: 50%;
  width: 2px;
  height: 1rem;
  background: var(--line);
  transform: translateX(-50%);
}

.focus-notch.top {
  top: 0;
}

.focus-notch.bottom {
  bottom: 0;
}

.word-display {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  width: 100%;
  font-family: "Libre Baskerville", serif;
  font-size: clamp(1rem, 1.7vw, 1.4rem);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.008em;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.42);
}

.word-left,
.word-right {
  color: #f8f8f8;
  white-space: pre;
}

.word-left {
  justify-self: end;
  text-align: right;
  padding-right: 0.02em;
}

.word-pivot {
  color: var(--pivot);
  white-space: pre;
  text-align: center;
}

.word-right {
  justify-self: start;
  text-align: left;
  padding-left: 0.02em;
}

.corner-btn {
  border: 0;
  background: transparent;
  color: #95a0ab;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  padding: 0;
  text-transform: uppercase;
  transition: color 130ms ease, opacity 130ms ease, text-shadow 130ms ease;
}

.corner-btn:hover {
  color: #f6f8fb;
  text-shadow: 0 0 9px rgba(176, 199, 230, 0.3);
}

.corner-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.top-left,
.top-right,
.bottom-left {
  position: absolute;
  z-index: 12;
}

.top-left {
  top: 0.9rem;
  left: 0.9rem;
  animation: uiFadeIn 320ms ease both;
  animation-delay: 80ms;
}

.top-right {
  top: 0.9rem;
  right: 0.9rem;
  animation: uiFadeIn 320ms ease both;
  animation-delay: 130ms;
}

.bottom-left {
  bottom: 0.9rem;
  left: 0.9rem;
  animation: uiFadeIn 320ms ease both;
  animation-delay: 180ms;
}

.wpm-control {
  position: fixed;
  top: 0.9rem;
  left: 50%;
  z-index: 12;
  transform: translateX(-50%);
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  animation: uiFadeIn 360ms ease both;
  animation-delay: 210ms;
}

.wpm-pill {
  color: #8a959e;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  cursor: ew-resize;
  user-select: none;
}

.wpm-pill:hover {
  color: #c2c9d0;
}

.wpm-control.dragging .wpm-pill {
  color: #d7dde4;
}

.wpm-scale {
  position: fixed;
  top: 2.1rem;
  left: 50%;
  width: min(320px, 72vw);
  height: 2px;
  border-radius: 999px;
  background: rgba(126, 136, 148, 0.78);
  box-shadow: 0 0 0 1px rgba(88, 98, 112, 0.2);
  opacity: 0;
  transform: translate(-50%, -4px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.wpm-scale.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(420px, 90vw);
  background:
    linear-gradient(180deg, rgba(20, 24, 29, 0.96), rgba(9, 11, 14, 0.97)),
    radial-gradient(circle at top left, rgba(112, 147, 198, 0.12), transparent 48%);
  border: 1px solid var(--panel-border);
  z-index: 20;
  padding: 1.15rem 1rem 1rem;
  overflow: auto;
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.58);
  opacity: 0;
  transition:
    transform 210ms cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 180ms ease;
}

.drawer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(118deg, transparent, rgba(152, 184, 221, 0.08), transparent);
  opacity: 0;
  pointer-events: none;
}

.drawer > * {
  position: relative;
  z-index: 1;
}

.left-drawer {
  left: 0;
  border-left: 0;
  transform: translateX(-105%);
}

.right-drawer {
  right: 0;
  border-right: 0;
  transform: translateX(105%);
}

.drawer.open.left-drawer,
.drawer.open.right-drawer {
  transform: translateX(0);
  opacity: 1;
}

.drawer.open::before {
  opacity: 1;
  animation: drawerSheen 7s ease-in-out infinite alternate;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid rgba(143, 162, 189, 0.2);
  padding-bottom: 0.65rem;
}

.drawer.open .drawer-head,
.drawer.open .hint,
.drawer.open .input-group,
.drawer.open .input-actions,
.drawer.open #status,
.drawer.open .transcript {
  opacity: 0;
  animation: drawerItemIn 260ms ease forwards;
}

.drawer.open .hint {
  animation-delay: 40ms;
}

.drawer.open .input-group:nth-of-type(1) {
  animation-delay: 75ms;
}

.drawer.open .input-group:nth-of-type(2) {
  animation-delay: 110ms;
}

.drawer.open .input-group:nth-of-type(3) {
  animation-delay: 145ms;
}

.drawer.open .input-actions {
  animation-delay: 180ms;
}

.drawer.open #status,
.drawer.open .transcript {
  animation-delay: 210ms;
}

.drawer-head h1,
.drawer-head h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #e5ebf3;
}

.ghost-btn {
  padding: 0.3rem 0.62rem;
}

.hint {
  margin: 0 0 1rem;
  color: #98a4b1;
  font-size: 0.84rem;
  line-height: 1.45;
}

.input-group {
  display: grid;
  gap: 0.48rem;
  margin-bottom: 0.85rem;
}

label {
  color: #b8c4d0;
  font-size: 0.79rem;
  text-transform: uppercase;
  letter-spacing: 0.035em;
}

input[type="file"],
textarea,
input[type="number"],
input[type="range"] {
  width: 100%;
}

input[type="file"],
textarea,
input[type="number"] {
  border: 1px solid #2f3742;
  border-radius: 12px;
  background: #090d11;
  color: #eff3f7;
  padding: 0.6rem 0.72rem;
  font: inherit;
  transition: border-color 130ms ease, box-shadow 130ms ease, background-color 130ms ease;
}

input[type="file"]:focus,
textarea:focus,
input[type="number"]:focus {
  outline: none;
  border-color: #5f7ea0;
  box-shadow: 0 0 0 2px rgba(95, 126, 160, 0.16);
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-trigger {
  border: 1px solid #3f556f;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(50, 65, 83, 0.62), rgba(22, 30, 41, 0.92));
  color: #deebf8;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-start;
  width: 100%;
  padding: 0.62rem 0.76rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: border-color 130ms ease, box-shadow 130ms ease, background 130ms ease;
}

.file-trigger:hover {
  border-color: #6f8eb1;
  background: linear-gradient(180deg, rgba(62, 80, 102, 0.74), rgba(27, 37, 50, 0.96));
}

.file-trigger:focus-visible {
  outline: none;
  border-color: #85a3c8;
  box-shadow: 0 0 0 2px rgba(120, 159, 201, 0.22);
}

.file-icon {
  width: 1rem;
  height: 1rem;
  color: #b8d0ea;
  flex: 0 0 auto;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.input-actions {
  display: flex;
  gap: 0.55rem;
  margin-bottom: 0.65rem;
}

#loadTextBtn,
#restartBtn {
  border: 1px solid #465364;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(46, 56, 70, 0.65), rgba(22, 27, 34, 0.85));
  color: #e4ebf3;
  padding: 0.43rem 0.88rem;
  font: inherit;
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  cursor: pointer;
}

#loadTextBtn:hover,
#restartBtn:hover {
  border-color: #6e89a8;
}

#restartBtn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#status {
  margin: 0;
  font-size: 0.84rem;
  color: #9fadbb;
  min-height: 1.25rem;
}

.transcript {
  border: 1px solid #2f3945;
  border-radius: 12px;
  padding: 0.86rem;
  background: #080c11;
  min-height: 180px;
  line-height: 1.78;
  font-size: 0.95rem;
}

.word-token {
  color: #d5dce4;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 110ms ease, color 110ms ease;
}

.word-token:hover {
  color: #ffffff;
  background: #223143;
}

.word-token.active {
  color: #f6fbff;
  background: #3a4d64;
}

body.is-playing .corner-btn,
body.is-playing .wpm-control,
body.is-playing .wpm-control *,
body.is-playing .drawer,
body.is-playing .drawer::before,
body.is-playing .drawer *,
body.is-playing .focus-frame {
  animation: none !important;
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 700px) {
  .focus-frame {
    width: min(calc(var(--frame-ch) * 1ch), 94vw);
    padding: 1.35rem 0;
  }
}
