:root {
  --bg: #fff9fd;
  --bg-2: #f2fbff;
  --surface: #ffffff;
  --surface-soft: #fff3fb;
  --surface-blue: #eef8ff;
  --text: #25283c;
  --muted: #667086;
  --line: #e7dff1;
  --primary: #8f8cf8;
  --primary-strong: #6661d9;
  --primary-soft: #ecebff;
  --pink: #f3a7c8;
  --pink-soft: #ffeaf4;
  --sky: #75d8ee;
  --sky-soft: #e4f9ff;
  --mint: #75dcb7;
  --mint-soft: #e9fff7;
  --sun: #ffe58a;
  --danger: #c93b55;
  --danger-soft: #ffe8ee;
  --shadow: 0 22px 60px rgba(112, 98, 160, 0.18);
  --shadow-soft: 0 12px 30px rgba(112, 98, 160, 0.12);
  --reader-font: 1.08rem;
  --reader-line: 1.65;
  --reader-para: 1.2;
  --reader-width: 68ch;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #111326;
  --bg-2: #171a33;
  --surface: #20233f;
  --surface-soft: #28223d;
  --surface-blue: #1b2b42;
  --text: #f7f3ff;
  --muted: #c3bfd5;
  --line: #3d3a5c;
  --primary: #aaa8ff;
  --primary-strong: #d8d5ff;
  --primary-soft: #33305f;
  --pink: #ffafd4;
  --pink-soft: #44263b;
  --sky: #8ceaff;
  --sky-soft: #173748;
  --mint: #96efce;
  --mint-soft: #173a32;
  --sun: #6d5c25;
  --danger: #ff8ba0;
  --danger-soft: #45212b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --shadow-soft: 0 12px 34px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 0;
  scroll-behavior: smooth;
}

body {
  min-width: 0;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 10% 8%, var(--pink-soft), transparent 34rem),
    radial-gradient(circle at 90% 4%, var(--sky-soft), transparent 32rem),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: 0.55;
  background-image:
    radial-gradient(circle, var(--primary) 0 1.5px, transparent 1.6px),
    radial-gradient(circle, var(--pink) 0 1px, transparent 1.1px);
  background-position: 22px 38px, 112px 96px;
  background-size: 180px 180px, 240px 240px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea,
.file-btn {
  -webkit-tap-highlight-color: transparent;
}

button,
.file-btn,
.main-nav a,
.primary-btn,
.secondary-btn,
.sparkle-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1rem;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover,
.file-btn:hover,
.main-nav a:hover,
.primary-btn:hover,
.secondary-btn:hover,
.sparkle-btn:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--primary) 60%, var(--line));
  box-shadow: var(--shadow-soft);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 50%, transparent);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
  gap: 1rem;
  min-height: 76px;
  padding: 0.8rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-logo {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--sky) 35%, var(--line));
  background: #fff;
  object-fit: cover;
  box-shadow: 0 10px 24px rgba(117, 216, 238, 0.25);
}

.brand strong {
  display: block;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.main-nav,
.header-actions,
.action-row,
.playback-dock,
.mobile-playbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.main-nav {
  justify-content: center;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 78%, var(--primary-soft));
}

.main-nav a,
.main-nav button {
  min-height: 38px;
  border: 0;
  padding: 0 1rem;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.main-nav a:hover,
.main-nav button:hover {
  color: var(--primary-strong);
  background: var(--surface);
}

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

.save-badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 0.85rem;
  border-radius: 999px;
  background: var(--mint-soft);
  color: color-mix(in srgb, var(--mint) 45%, var(--text));
  font-size: 0.85rem;
  font-weight: 800;
}

.status-pill {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.icon-btn {
  width: 46px;
  min-width: 46px;
  padding: 0;
  border-radius: 15px;
}

svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.app-main {
  width: min(100% - 2rem, 1440px);
  margin: 0 auto;
  padding: clamp(1rem, 2vw, 2rem) 0 9rem;
}

.hero-card,
.app-card,
.drawer,
.bottom-sheet,
.dialog,
.playback-dock {
  border: 1px solid color-mix(in srgb, var(--line) 86%, transparent);
  border-radius: 28px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
}

.hero-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.5rem;
  min-height: 230px;
  padding: clamp(1.4rem, 4vw, 3rem);
  overflow: hidden;
}

.hero-card::after {
  position: absolute;
  inset: auto 5% -80px auto;
  width: 280px;
  height: 280px;
  border-radius: 999px;
  background: radial-gradient(circle, color-mix(in srgb, var(--sky) 35%, transparent), transparent 68%);
  content: "";
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.hero-card h1 {
  max-width: 780px;
  margin-bottom: 0.8rem;
  font-size: clamp(2.25rem, 5vw, 5.2rem);
  line-height: 0.98;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.hero-card p:not(.eyebrow) {
  max-width: 68ch;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.65;
}

.hero-logo {
  position: relative;
  z-index: 1;
  width: clamp(112px, 14vw, 180px);
  height: auto;
  border-radius: 34px;
  background: #fff;
  box-shadow: 0 24px 48px rgba(117, 216, 238, 0.28);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.96fr) minmax(0, 1.04fr);
  gap: 1rem;
  margin-top: 1rem;
}

.app-card {
  min-width: 0;
  padding: clamp(1rem, 2.2vw, 1.5rem);
}

.card-top,
.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card-top h2,
.drawer-header h2 {
  margin-bottom: 0.25rem;
  font-size: clamp(1.35rem, 2vw, 1.8rem);
}

.meta-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.field {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 90%, var(--surface-blue));
  color: var(--text);
  font-weight: 400;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

input[type="text"],
input[type="search"],
select {
  min-height: 46px;
  padding: 0 1rem;
}

textarea {
  min-height: clamp(220px, 28vh, 360px);
  max-height: 54vh;
  resize: vertical;
  padding: 1rem;
  line-height: 1.7;
}

input[type="range"] {
  accent-color: var(--primary);
}

.primary-btn,
.play-btn {
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--sky));
  color: #fff;
  font-weight: 900;
  box-shadow: 0 14px 30px color-mix(in srgb, var(--primary) 35%, transparent);
}

.secondary-btn {
  background: color-mix(in srgb, var(--surface) 90%, var(--primary-soft));
  font-weight: 800;
}

.sparkle-btn {
  border-color: color-mix(in srgb, var(--pink) 60%, var(--line));
  background: linear-gradient(135deg, var(--pink-soft), var(--primary-soft));
  color: var(--primary-strong);
  font-weight: 900;
}

.danger-btn {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 900;
}

.compact {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.reader {
  min-height: clamp(310px, 44vh, 560px);
  max-height: 64vh;
  overflow-y: auto;
  padding: clamp(1rem, 3vw, 2rem) max(1rem, calc((100% - var(--reader-width)) / 2));
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 96%, var(--sun)), var(--surface)),
    var(--surface);
  font-size: var(--reader-font);
  line-height: var(--reader-line);
}

.reader p {
  margin: 0 0 calc(var(--reader-para) * 1rem);
}

.sentence,
.word {
  border-radius: 0.35em;
  transition: background 120ms ease, color 120ms ease;
}

.sentence {
  cursor: pointer;
  padding: 0.05em 0.1em;
}

.sentence:hover {
  outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
}

.read {
  color: color-mix(in srgb, var(--muted) 72%, var(--surface));
}

.current-sentence {
  background: color-mix(in srgb, var(--sun) 76%, transparent);
  color: var(--text);
}

.current-word {
  background: linear-gradient(135deg, var(--primary), var(--sky));
  color: #fff;
}

.current-paragraph {
  background: var(--sky-soft);
}

.search-hit {
  box-shadow: inset 0 -0.48em color-mix(in srgb, var(--pink) 45%, transparent);
}

.selected-search {
  outline: 2px solid var(--pink);
}

.playback-dock {
  position: sticky;
  bottom: 1rem;
  z-index: 20;
  flex-wrap: wrap;
  margin: 1rem auto 0;
  padding: 0.8rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
}

.play-btn {
  min-width: 124px;
  min-height: 56px;
  border-radius: 999px;
  font-size: 1.05rem;
}

.progress-wrap {
  flex: 1 1 220px;
  min-width: 170px;
}

progress {
  width: 100%;
  height: 13px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--primary-soft);
}

progress::-webkit-progress-bar {
  background: var(--primary-soft);
}

progress::-webkit-progress-value,
progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--primary), var(--sky), var(--mint));
}

.dock-field {
  display: grid;
  gap: 0.25rem;
  min-width: 170px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.speed-dock {
  min-width: 200px;
}

.drawer {
  position: fixed;
  top: 88px;
  right: clamp(0.75rem, 2vw, 1.5rem);
  bottom: 1rem;
  z-index: 45;
  width: min(430px, calc(100vw - 1.5rem));
  padding: 1.25rem;
  overflow-y: auto;
  transform: translateX(calc(100% + 2rem));
  transition: transform 180ms ease;
}

body.history-open #historyPanel,
body.settings-open #settingsPanel {
  transform: translateX(0);
}

.notice {
  padding: 0.85rem 1rem;
  border: 1px solid color-mix(in srgb, var(--sun) 55%, var(--line));
  border-radius: 20px;
  background: color-mix(in srgb, var(--sun) 24%, var(--surface));
  color: var(--muted);
  line-height: 1.5;
}

.history-tools,
.settings-section,
.history-list {
  display: grid;
  gap: 0.85rem;
}

.settings-section {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 88%, var(--primary-soft));
}

.settings-section h3 {
  margin-bottom: 0.4rem;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  font-weight: 700;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.preset-grid button {
  min-height: 40px;
  padding: 0 0.5rem;
  border-radius: 16px;
}

.preset-grid button.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 900;
}

.history-item {
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
}

.history-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
}

.history-name {
  min-height: 40px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-weight: 900;
}

.history-name:focus {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.history-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}

.history-actions button {
  min-height: 38px;
  padding: 0 0.45rem;
  border-radius: 14px;
  font-size: 0.82rem;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 0.75rem;
  padding: 2rem 1rem;
  border: 1px dashed var(--line);
  border-radius: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state img {
  border-radius: 16px;
}

.file-btn {
  position: relative;
  overflow: hidden;
  font-weight: 800;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.bottom-sheet {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 50;
  width: min(760px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1.25rem;
  transform: translate(-50%, calc(100% + 2rem));
  transition: transform 180ms ease;
}

body.mp3-open #mp3Sheet {
  transform: translate(-50%, 0);
}

.sheet-grid,
.audio-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.85rem;
}

.audio-panel {
  grid-template-columns: minmax(0, 1fr) auto;
  margin: 1rem 0;
}

audio {
  width: 100%;
}

.context-menu {
  position: fixed;
  z-index: 60;
  display: grid;
  gap: 0.35rem;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(24, 22, 48, 0.45);
}

.dialog {
  width: min(460px, 100%);
  padding: 1.25rem;
}

.mobile-tabs,
.mobile-playbar,
.mobile-header-btn {
  display: none;
}

body.fullscreen-reader .app-header,
body.fullscreen-reader .hero-card,
body.fullscreen-reader .editor-card,
body.fullscreen-reader .playback-dock,
body.fullscreen-reader .mobile-tabs {
  display: none;
}

body.fullscreen-reader .app-main {
  width: 100%;
  padding: 0;
}

body.fullscreen-reader .workspace-grid {
  display: block;
  margin: 0;
}

body.fullscreen-reader .reader-card {
  min-height: 100vh;
  border-radius: 0;
}

body.fullscreen-reader .reader {
  max-height: none;
  min-height: calc(100vh - 110px);
}

.page-shell {
  width: min(100% - 2rem, 1120px);
  margin: 0 auto;
  padding: 1rem 0 4rem;
}

.page-header {
  margin-bottom: 1rem;
}

.page-back {
  color: var(--primary-strong);
  font-weight: 900;
  text-decoration: none;
}

.page-hero {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
}

.page-hero img {
  width: 92px;
  height: 92px;
  border-radius: 24px;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.page-card {
  padding: 1.25rem;
}

@media (max-width: 1100px) {
  .app-header {
    grid-template-columns: 1fr auto;
  }

  .main-nav {
    display: none;
  }

  .mobile-header-btn {
    display: inline-flex;
  }

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

@media (max-width: 760px) {
  .app-header {
    min-height: 68px;
    padding: 0.65rem 0.85rem;
    width: min(100vw, 390px);
  }

  .brand small,
  .save-badge {
    display: none;
  }

  .brand-logo {
    width: 42px;
    height: 42px;
  }

  .app-main {
    width: min(calc(100vw - 3rem), 340px);
    margin-left: 0.75rem;
    margin-right: auto;
    padding-bottom: 7rem;
  }

  .hero-card {
    grid-template-columns: 1fr;
    min-height: 0;
    padding: 1.25rem;
  }

  .hero-logo {
    display: none;
  }

  .hero-card h1 {
    font-size: clamp(1.65rem, 8vw, 2.25rem);
    line-height: 1.08;
  }

  #themeQuickBtn {
    display: none;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin: 0.8rem 0;
    padding: 0.35rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
  }

  .tab-btn {
    min-height: 42px;
    border: 0;
    background: transparent;
    font-weight: 900;
  }

  .tab-btn.active {
    background: var(--primary-soft);
    color: var(--primary-strong);
  }

  .mobile-panel {
    display: none;
  }

  .mobile-panel.active {
    display: block;
  }

  .playback-dock {
    display: none;
  }

  .mobile-playbar {
    position: fixed;
    left: max(0.75rem, env(safe-area-inset-left));
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    z-index: 35;
    justify-content: center;
    padding: 0.6rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
  }

  .drawer {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(100vw, 430px);
    border-radius: 0;
    padding: 1rem;
  }

  .bottom-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: 28px 28px 0 0;
    transform: translateY(calc(100% + 2rem));
  }

  body.mp3-open #mp3Sheet {
    transform: translateY(0);
  }

  .sheet-grid,
  .audio-panel,
  .page-grid {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 250px;
    max-height: 46vh;
  }

  .reader {
    min-height: 56vh;
    max-height: none;
  }
}

@media (max-width: 380px) {
  .app-main {
    width: min(calc(100vw - 1.25rem), 340px);
  }

  .action-row {
    flex-wrap: wrap;
  }

  .action-row > * {
    flex: 1 1 auto;
  }
}

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