:root {
  --bg-1: #f0ebe1;
  --bg-2: #d9e8e1;
  --card: #fffdf8;
  --ink: #1f2a2a;
  --muted: #5a6666;
  --accent: #0f766e;
  --accent-2: #155e75;
  --border: #d7d9d1;
  --chunk-font-size: 27px;
  --chunk-font-family: "Alegreya", "Palatino Linotype", "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, var(--bg-1), var(--bg-2));
  min-height: 100vh;
  position: relative;
}

.app-shell {
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.card {
  position: relative;
  overflow: hidden;
  width: min(760px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.12);
  padding: 1.25rem;
}

body.focus-mode::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(1, 6, 17, 0.9);
  z-index: 900;
  pointer-events: none;
}

body.focus-mode .focus-target {
  position: relative;
  z-index: 901;
}

h1,
.subtitle {
  margin: 0;
}

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.95rem;
}

h1 {
  font-family: var(--chunk-font-family);
  font-size: clamp(1.75rem, 2.8vw, 2.35rem);
  font-weight: 1000;
  display: block;
  text-align: left;
  white-space: nowrap;
}

.reset-session-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.reset-session-link:hover {
  color: rgba(31, 42, 42, 0.9);
}

.reset-session-link:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.58);
  outline-offset: 0.14em;
  border-radius: 0.1em;
}

.title-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.title-logo {
  width: 2.4rem;
  height: 2.4rem;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  margin-top: 0.05rem;
}

.title-logo svg {
  width: 100%;
  height: 100%;
}

.title-logo .book-left-page,
.title-logo .book-right-page {
  fill: rgba(15, 118, 110, 0.14);
  stroke: rgba(15, 118, 110, 0.86);
  stroke-width: 2.1;
  stroke-linejoin: round;
}

.title-logo .book-top-edge {
  fill: none;
  stroke: rgba(15, 118, 110, 0.86);
  stroke-width: 2.1;
  stroke-linecap: round;
}

.title-logo .book-center-fold {
  stroke: rgba(15, 118, 110, 0.92);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.title-logo .book-text-line {
  fill: none;
  stroke: rgba(15, 118, 110, 0.62);
  stroke-width: 1.35;
  stroke-linecap: round;
}

.subtitle {
  margin: 0.16rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  text-align: left;
}

.browser-note {
  margin: -0.4rem 0 0.95rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid rgba(21, 94, 117, 0.24);
  background: linear-gradient(180deg, rgba(232, 244, 241, 0.95), rgba(226, 238, 246, 0.88));
  color: #415050;
  font-size: 0.86rem;
  line-height: 1.38;
}

.browser-note strong {
  color: #0f766e;
}

.legal-footer {
  width: min(760px, 100%);
  margin: 0.4rem 0 0;
  padding: 0.45rem 0.55rem 0.1rem;
  color: rgba(65, 80, 80, 0.56);
  font-size: 0.62rem;
  line-height: 1.35;
  text-align: center;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 700;
}

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

textarea,
input[type="text"],
input[type="number"],
select {
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
  padding: 0.75rem;
  background: #fff;
}

textarea {
  resize: vertical;
  margin-bottom: 0.35rem;
}

#manualInputPanel {
  margin-bottom: 0.2rem;
}

#loadedPanel {
  margin-top: 0.15rem;
}

.controls-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.chunk-editor-wrap {
  margin: 0.85rem 0 0.4rem;
  position: relative;
  padding-bottom: 0;
}

.chunk-editor-head {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.chunk-tools {
  display: inline-flex;
  gap: 0.28rem;
  flex-wrap: wrap;
}

.mode-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.inline-choice {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0;
  font-weight: 600;
}

.inline-choice input {
  accent-color: var(--accent-2);
}

.hint {
  margin: 0.2rem 0 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.chunk-editor {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 0.7rem 2.55rem 1.15rem 0.7rem;
  min-height: 3rem;
  line-height: 1.35;
  text-align: center;
}

.chunk-editor.align-left {
  text-align: left;
}

.chunk-editor.align-center {
  text-align: center;
}

.chunk-editor-shell {
  position: relative;
}

.chunks-progress {
  position: absolute;
  left: 0.64rem;
  right: 0.64rem;
  bottom: 0.08rem;
  height: 0.48rem;
  border-radius: 999px;
  background: rgba(21, 94, 117, 0.16);
  overflow: hidden;
  z-index: 905;
}

.chunks-progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, rgba(15, 118, 110, 0.95), rgba(21, 94, 117, 1));
  transition: width 130ms ease;
}

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

.chunk-segment {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
}

.chunk-break {
  display: block;
  height: 0;
  line-height: 0;
}

.chunk-break.double {
  margin-top: 1.24em;
}

.word-chip {
  display: inline;
  font-family: var(--chunk-font-family);
  font-size: var(--chunk-font-size);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #2b3636;
  transition: color 120ms ease, background-color 120ms ease;
  border-radius: 5px;
  padding: 0;
}

.chunk-editor.playback .active-chunk-word {
  color: #0f766e;
}

.chunk-editor.playback .unread-chunk-word {
  color: #9aa2a6;
}

.divider-btn {
  border: 0;
  background: transparent;
  cursor: col-resize;
  width: 0.34em;
  height: 1em;
  margin: 0;
  padding: 0;
  vertical-align: baseline;
  line-height: 1;
  font-size: var(--chunk-font-size);
  opacity: 1;
  border-radius: 3px;
  transition: background-color 120ms ease;
}

.divider-btn.on {
  background: rgba(220, 38, 38, 0.24);
}

.chunk-editor.playback .divider-btn,
.chunk-editor.playback .divider-btn.on,
.chunk-editor.playback .divider-btn:hover,
.chunk-editor.playback .active-gap,
.chunk-editor.playback .unread-gap {
  background: transparent !important;
}

.divider-btn:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}

.divider-btn:hover {
  background: rgba(15, 118, 110, 0.2);
}

.field output {
  display: inline-block;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.button-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.button-row.centered {
  justify-content: center;
}

#playbackControls {
  margin-top: 0.65rem;
  margin-bottom: 0.65rem;
}

.button-row.compact {
  margin-top: 0.25rem;
  margin-bottom: 0.15rem;
  justify-content: center;
}

.button-row.subtle-row {
  margin-top: -0.35rem;
  margin-bottom: 0.2rem;
}

.button-row.subtle-row.right {
  justify-content: flex-end;
}

#prevChunkBtn,
#nextChunkBtn,
#closePlayerBtn {
  display: none !important;
}

body.focus-mode.audio-player-active #prevChunkBtn,
body.focus-mode.audio-player-active #nextChunkBtn {
  display: inline-grid !important;
}

body.focus-mode.audio-player-active #closePlayerBtn {
  display: inline-grid !important;
}

.player-close-btn {
  position: absolute;
  top: -0.72rem;
  right: -0.72rem;
  width: 1.92rem;
  height: 1.92rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(241, 245, 249, 0.52);
  background: rgba(15, 23, 42, 0.86);
  color: #f8fafc;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  place-items: center;
  z-index: 905;
}

.player-close-btn:hover {
  background: rgba(15, 23, 42, 0.96);
  border-color: rgba(248, 250, 252, 0.74);
}

.edit-corner-btn {
  position: absolute;
  right: 0.58rem;
  bottom: 0.52rem;
  width: 1.72rem;
  height: 1.72rem;
  padding: 0;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
  color: #334155;
  background: rgba(148, 163, 184, 0.2);
  border: 1px solid rgba(100, 116, 139, 0.34);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease, background-color 120ms ease;
}

.chunk-editor-shell:hover .edit-corner-btn,
.chunk-editor-wrap:focus-within .edit-corner-btn {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

body.audio-player-active .edit-corner-btn {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(4px) !important;
}

.edit-corner-btn:hover {
  background: rgba(148, 163, 184, 0.34);
}

.edit-corner-btn:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.72rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: white;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
}

button.secondary {
  background: #4b5563;
}

.playback-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.08rem;
  line-height: 1;
}

.playback-icon-btn svg {
  width: 1.18rem;
  height: 1.18rem;
  display: block;
  pointer-events: none;
}

#playBtn.playback-icon-btn {
  width: 2.95rem;
  height: 2.95rem;
  font-size: 1.22rem;
}

#playBtn.playback-icon-btn svg {
  width: 1.28rem;
  height: 1.28rem;
}

button.tertiary {
  padding: 0.34rem 0.56rem;
  border-radius: 10px;
  background: #e5e7eb;
  color: #1f2937;
  font-size: 0.82rem;
  font-weight: 600;
}

.icon-btn {
  border: 0;
  border-radius: 8px;
  padding: 0.2rem 0.4rem;
  min-width: 1.8rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: #334155;
  background: rgba(148, 163, 184, 0.25);
  cursor: pointer;
}

.icon-btn svg {
  width: 0.92rem;
  height: 0.92rem;
  display: block;
}

.icon-btn:hover {
  background: rgba(148, 163, 184, 0.38);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 1.25rem;
  padding: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(21, 94, 117, 0.26);
  background: linear-gradient(90deg, rgba(15, 118, 110, 0.28), rgba(21, 94, 117, 0.38));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 999px;
  border: 2px solid rgba(21, 94, 117, 0.9);
  background: #f8faf9;
  margin-top: -0.29rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
}

input[type="range"]::-moz-range-track {
  height: 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(21, 94, 117, 0.26);
  background: linear-gradient(90deg, rgba(15, 118, 110, 0.28), rgba(21, 94, 117, 0.38));
}

input[type="range"]::-moz-range-thumb {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 999px;
  border: 2px solid rgba(21, 94, 117, 0.9);
  background: #f8faf9;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
}

.subtle-btn {
  border: 0;
  background: transparent;
  color: #64748b;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 0.2rem 0.1rem;
  cursor: pointer;
  border-radius: 6px;
}

.subtle-btn:hover {
  color: #334155;
  background: rgba(148, 163, 184, 0.16);
}

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

.status {
  margin: 1rem 0 0.4rem;
  color: var(--muted);
}

.status.centered {
  text-align: center;
  margin-top: 0.5rem;
}

.settings-panel {
  margin-top: 0.55rem;
  border-top: 1px solid rgba(31, 42, 42, 0.12);
  padding-top: 0.45rem;
}

.settings-panel.settings-locked {
  opacity: 0.62;
  pointer-events: none;
}

.settings-panel > summary {
  list-style: none;
  cursor: pointer;
  font-weight: 700;
  color: #334155;
  user-select: none;
}

.settings-panel > summary::-webkit-details-marker {
  display: none;
}

.settings-panel > summary::after {
  content: "▾";
  margin-left: 0.4rem;
  color: #64748b;
  font-size: 1.06rem;
}

.settings-panel:not([open]) > summary::after {
  content: "▸";
}

.settings-panel[open] .controls-grid {
  margin-top: 0.55rem;
  gap: 0.55rem;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.settings-panel .field label {
  margin-bottom: 0.22rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.settings-panel .field output {
  margin-top: 0.16rem;
  font-size: 0.82rem;
}

.settings-panel input[type="number"],
.settings-panel select {
  padding: 0.58rem 0.65rem;
}

.settings-panel .mode-row {
  gap: 0.52rem;
}

.settings-panel .inline-choice {
  font-weight: 500;
  font-size: 0.9rem;
}

.seo-content {
  margin-top: 1.05rem;
  padding-top: 0.9rem;
  border-top: 1px solid rgba(21, 94, 117, 0.18);
  color: #344242;
}

.seo-content h2,
.seo-content h3 {
  font-family: "Alegreya", "Palatino Linotype", "Times New Roman", serif;
  margin: 0;
  color: #1f2a2a;
}

.seo-content h2 {
  font-size: 1.2rem;
  margin-bottom: 0.45rem;
}

.seo-content h3 {
  font-size: 1.02rem;
  margin-top: 0.72rem;
  margin-bottom: 0.32rem;
}

.seo-content p,
.seo-content li {
  font-size: 0.92rem;
  line-height: 1.5;
}

.seo-content p {
  margin: 0.26rem 0;
}

.seo-content ol {
  margin: 0.2rem 0 0.3rem 1.15rem;
  padding: 0;
}

.seo-content strong {
  color: #1f2a2a;
}

@media (hover: none) {
  .edit-corner-btn {
    opacity: 0.9;
    transform: translateY(0);
    pointer-events: auto;
  }
}

@media (max-width: 520px) {
  .card {
    padding: 1rem;
    border-radius: 14px;
  }
}
