:root {
  color-scheme: light;
  --bg: #efe5d6;
  --panel: #faf3e8;
  --panel-strong: #1d1c1a;
  --text: #302923;
  --muted: #7e7063;
  --line: #d9cbb8;
  --line-soft: #eadfce;
  --accent: #f04a32;
  --accent-dark: #d83620;
  --stage: #e8ddcf;
  --shadow: 0 18px 50px rgba(77, 58, 39, 0.1);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141311;
  --panel: #1d1b18;
  --panel-strong: #f5f0e7;
  --text: #f1ede5;
  --muted: #aaa39a;
  --line: #39352f;
  --line-soft: #2d2a25;
  --stage: #24211d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 7% 2%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 26rem),
    var(--bg);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 7% 2%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 26rem),
    radial-gradient(circle at 92% 96%, rgba(155, 112, 71, 0.1), transparent 30rem),
    var(--bg);
}

button,
textarea,
input {
  font: inherit;
}

button {
  color: inherit;
}

button,
input[type="range"],
input[type="checkbox"] {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 40px 40px;
}

.topbar {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-weight: 850;
  font-size: 1rem;
  letter-spacing: 0.14em;
  text-decoration: none;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}

.top-actions,
.transport,
.progress-row,
.editor-footer,
.reader-topline,
.setting-label,
.range-labels {
  display: flex;
  align-items: center;
}

.top-actions {
  gap: 8px;
}

.button,
.icon-button,
.text-button,
.step-button,
.play-button {
  border: 0;
}

.button,
.icon-button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}

.button {
  padding: 0 16px;
  font-size: 0.84rem;
  font-weight: 700;
}

.button-clear {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
}

.button-clear:hover {
  background: var(--accent-dark);
}

.icon-button {
  width: 40px;
  display: grid;
  place-items: center;
}

.icon-button svg,
.step-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: calc(100vh - 128px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor-panel,
.reader-panel {
  padding: clamp(28px, 4vw, 56px);
}

.editor-panel {
  order: 2;
  display: flex;
  min-height: 540px;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.editor-panel.is-dragging {
  background: color-mix(in srgb, var(--accent) 5%, var(--panel));
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}

.editor-panel > * {
  width: min(900px, 100%);
  margin-right: auto;
  margin-left: auto;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.71rem;
  font-weight: 850;
  letter-spacing: 0.14em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  font-weight: 500;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.word-count,
.time-left {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

textarea {
  width: 100%;
  min-height: 360px;
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.02rem, 1.6vw, 1.2rem);
  line-height: 1.72;
}

textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 65%, transparent);
}

.editor-footer {
  justify-content: space-between;
  gap: 16px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}

.editor-footer p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.text-button {
  padding: 5px 0;
  color: var(--accent);
  background: none;
  font-size: 0.78rem;
  font-weight: 750;
}

.file-toolbar {
  width: min(900px, 100%);
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -6px auto 24px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: color-mix(in srgb, var(--stage) 45%, var(--panel));
}

.import-button,
.download-button {
  min-height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.74rem;
  font-weight: 800;
}

.import-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  color: var(--text);
  background: var(--panel);
}

.import-button svg {
  width: 17px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.import-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.file-status {
  min-width: 0;
  flex: 1;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-status.is-error {
  color: var(--accent-dark);
}

.download-button {
  padding: 0 12px;
  color: var(--accent);
  background: transparent;
}

.reader-panel {
  order: 1;
  display: flex;
  min-height: 760px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--panel) 94%, var(--stage));
}

.reader-panel > * {
  width: min(1100px, 100%);
}

.reader-topline {
  justify-content: space-between;
  margin-bottom: 20px;
}

.reader-stage {
  position: relative;
  min-height: 340px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  outline: 0;
  background:
    linear-gradient(90deg, transparent calc(50% - .5px), color-mix(in srgb, var(--line) 45%, transparent) 50%, transparent calc(50% + .5px)),
    var(--stage);
}

.reader-stage:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 32%, transparent);
}

.guide {
  position: absolute;
  left: 50%;
  width: 2px;
  height: 24px;
  transform: translateX(-50%);
  background: var(--accent);
}

.guide-top {
  top: 0;
}

.guide-bottom {
  bottom: 0;
}

.word-display {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: baseline;
  padding: 0 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(2rem, 6vw, 4.4rem);
  font-weight: 650;
  letter-spacing: -0.07em;
  line-height: 1;
}

.word-display.word-long {
  grid-template-columns: auto auto auto;
  justify-content: center;
  font-size: clamp(1.7rem, 4.4vw, 3.2rem);
}

.word-display.word-very-long {
  grid-template-columns: auto auto auto;
  justify-content: center;
  font-size: clamp(1.25rem, 3.3vw, 2.4rem);
  letter-spacing: -0.08em;
}

.word-display.word-extra-long {
  grid-template-columns: auto auto auto;
  justify-content: center;
  font-size: clamp(0.85rem, 2.6vw, 1.8rem);
  letter-spacing: -0.09em;
}

.word-before {
  min-width: 0;
  justify-self: end;
}

.word-focus {
  color: var(--accent);
}

.word-after {
  min-width: 0;
  justify-self: start;
}

.empty-message {
  position: absolute;
  inset: auto 20px 28px;
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}

.has-text .empty-message {
  display: none;
}

.progress-row {
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 5px;
  appearance: none;
  border-radius: 999px;
  outline: none;
  background: linear-gradient(to right, var(--accent) 0 var(--range-progress, 0%), var(--line) var(--range-progress, 0%) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  appearance: none;
  border: 3px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 3px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.transport {
  justify-content: center;
  gap: 28px;
  margin: 26px 0;
}

.step-button {
  min-width: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px;
  color: var(--muted);
  background: none;
  font-size: 0.7rem;
  font-weight: 800;
}

.play-button {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  box-shadow: 0 10px 25px color-mix(in srgb, var(--accent) 28%, transparent);
  transition: transform 150ms ease, background 150ms ease;
}

.play-button:hover {
  transform: scale(1.04);
  background: var(--accent-dark);
}

.play-button:active {
  transform: scale(0.97);
}

.play-button svg {
  width: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.play-button .play-icon {
  fill: currentColor;
  stroke: none;
  transform: translateX(2px);
}

.pause-icon,
.is-playing .play-icon {
  display: none;
}

.is-playing .pause-icon {
  display: block;
}

.settings {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.setting-label {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 0.8rem;
  font-weight: 750;
}

.setting-label output {
  color: var(--accent);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.range-labels {
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.62rem;
}

.toggle-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-left: 28px;
  border-left: 1px solid var(--line-soft);
}

.toggle-setting > span:first-child {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toggle-setting strong {
  font-size: 0.78rem;
}

.toggle-setting small {
  color: var(--muted);
  font-size: 0.67rem;
}

.toggle-setting input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--line);
  transition: background 160ms ease;
}

.toggle::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  content: "";
  background: white;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform 160ms ease;
}

.toggle-setting input:checked + .toggle {
  background: var(--accent);
}

.toggle-setting input:checked + .toggle::after {
  transform: translateX(18px);
}

.toggle-setting input:focus-visible + .toggle {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 32%, transparent);
}

.shortcut-hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.67rem;
  text-align: center;
}

kbd {
  margin-right: 3px;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
  font-family: inherit;
  font-size: 0.62rem;
}

.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;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 0 20px 24px;
  }

  .editor-panel {
    min-height: 440px;
  }

  .reader-panel {
    min-height: 720px;
  }
}

@media (max-width: 600px) {
  .app-shell {
    padding: 0;
  }

  .topbar {
    height: 68px;
    padding: 0 18px;
  }

  .button-clear {
    padding: 0 12px;
  }

  .workspace {
    min-height: calc(100vh - 68px);
    border-width: 1px 0 0;
    border-radius: 0;
  }

  .editor-panel,
  .reader-panel {
    padding: 28px 20px;
  }

  .editor-panel {
    min-height: 410px;
  }

  .section-heading {
    align-items: flex-start;
  }

  textarea {
    min-height: 235px;
  }

  .editor-footer p {
    display: none;
  }

  .file-toolbar {
    flex-wrap: wrap;
  }

  .file-status {
    min-width: 100%;
    order: 3;
    white-space: normal;
  }

  .reader-panel {
    min-height: max(860px, calc(100svh - 24px));
    justify-content: flex-start;
  }

  .reader-stage {
    min-height: 280px;
  }

  .word-display {
    padding: 0 8px;
    font-size: clamp(1.8rem, 11vw, 3.3rem);
  }

  .word-display.word-long {
    font-size: clamp(1.25rem, 6.5vw, 2rem);
  }

  .word-display.word-very-long {
    font-size: clamp(0.9rem, 4.8vw, 1.4rem);
  }

  .word-display.word-extra-long {
    font-size: clamp(0.68rem, 3.5vw, 1rem);
  }

  .settings {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .toggle-setting {
    padding: 20px 0 0;
    border-top: 1px solid var(--line-soft);
    border-left: 0;
  }

  .shortcut-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
