* {
  box-sizing: border-box;
}

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f0f3f6;
  --text: #202124;
  --muted: #5f6670;
  --border: #d8dde3;
  --border-strong: #bcc5cf;
  --accent: #ff5a5f;
  --accent-soft: rgba(255, 90, 95, 0.14);
  --focus: #1769d2;
  --positive: #237a49;
  --shadow: 0 18px 48px rgba(33, 43, 54, 0.1);
}

html {
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 15px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid #22252a;
  border-radius: 8px;
  padding: 0 14px;
  color: #ffffff;
  background: #22252a;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  opacity: 0.9;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  color: var(--text);
  background: #ffffff;
  border-color: var(--border-strong);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
}

input {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 300px;
  resize: vertical;
  padding: 12px;
  line-height: 1.65;
}

input:focus,
textarea:focus,
button:focus-visible,
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

label {
  display: block;
  color: var(--text);
  font-weight: 700;
}

.app-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 112px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 0 2px 18px;
}

.eyebrow,
.source-label,
.status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.eyebrow {
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 28px;
}

h2 {
  margin-top: 3px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.switch-track {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: #aeb7c2;
  transition: background 0.2s;
  flex-shrink: 0;
}

.switch input:checked + .switch-track {
  background: var(--positive);
}

.switch-track::before {
  content: "-";
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  color: #ffffff;
  font-size: 11px;
  line-height: 1;
}

.switch input:checked + .switch-track::before {
  content: "✓";
  right: auto;
  left: 6px;
}

.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 0.2s;
}

.switch input:checked + .switch-track .switch-knob {
  transform: translateX(18px);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.source-panel,
.reader-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.source-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 20px;
  padding: 18px;
}

.url-form,
.paste-panel {
  display: grid;
  gap: 9px;
}

.inline-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.status {
  min-height: 1.7em;
  overflow-wrap: anywhere;
}

.status.is-error {
  color: #b42318;
}

.status.is-success {
  color: var(--positive);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 8px;
}

.reader-panel {
  min-height: calc(100vh - 136px);
  overflow: hidden;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
}

.reader-stats {
  min-width: 78px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.reader {
  max-width: 760px;
  min-height: calc(100vh - 216px);
  margin: 0 auto;
  padding: 36px 36px 64px;
  font-size: 18px;
  line-height: 1.95;
  overflow-wrap: anywhere;
}

.reader h1,
.reader h2,
.reader h3 {
  margin: 1.9em 0 0.65em;
  line-height: 1.35;
}

.reader h1:first-child,
.reader h2:first-child,
.reader h3:first-child {
  margin-top: 0;
}

.reader h1 {
  font-size: 1.55em;
}

.reader h2 {
  font-size: 1.25em;
}

.reader h3 {
  font-size: 1.08em;
}

.reader p,
.reader ul,
.reader ol,
.reader blockquote,
.reader pre {
  margin: 0 0 1.2em;
}

.reader ul,
.reader ol {
  padding-left: 1.4em;
}

.reader blockquote {
  padding-left: 1em;
  border-left: 4px solid var(--border-strong);
  color: var(--muted);
}

.reader pre,
.reader code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.reader pre {
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: #111827;
  color: #f8fafc;
}

.reader a {
  color: #1459b8;
}

.empty-state {
  color: var(--muted);
}

.navigator {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  color: #ffffff;
  background: rgba(23, 25, 29, 0.94);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.26);
}

.navigator[hidden] {
  display: none;
}

.navigator button {
  min-height: 36px;
  border-color: #ffffff;
  color: #111111;
  background: #ffffff;
}

.navigator-counter {
  min-width: 74px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.sentence {
  cursor: pointer;
}

body.underline-off .sentence {
  cursor: auto;
}

.sentence.active {
  text-decoration-line: underline;
  text-decoration-thickness: 0.22em;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--accent);
  background-image: linear-gradient(to top, var(--accent-soft), var(--accent-soft));
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border-radius: 0.15em;
}

.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-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .source-panel {
    position: static;
  }

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

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 20px, 1280px);
    padding-top: 14px;
  }

  h1 {
    font-size: 24px;
  }

  .inline-action,
  .button-row {
    grid-template-columns: 1fr;
  }

  .reader-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .reader {
    padding: 24px 18px 80px;
    font-size: 16px;
  }

  .navigator {
    right: 10px;
    bottom: 10px;
    left: 10px;
    justify-content: center;
  }
}
