:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --surface: #ffffff;
  --surface-soft: #eef6f3;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d7ded8;
  --teal: #006d77;
  --teal-dark: #064f55;
  --coral: #d85c44;
  --amber: #f2c14e;
  --shadow: 0 18px 48px rgba(31, 41, 51, 0.11);
  --radius: 8px;
  --player-height: 92px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(0, 109, 119, 0.07) 0, rgba(245, 246, 241, 0) 260px),
    var(--bg);
  color: var(--ink);
}

body.settings-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.primary-action:focus-within {
  outline: 3px solid rgba(0, 109, 119, 0.28);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 16px 16px 36px;
}

body.reader-mode .app-shell {
  padding-bottom: calc(var(--player-height) + 28px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}

body.reader-mode .topbar {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 0.84rem;
}

.brand .brand-mark {
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.05rem;
}

.status-pill {
  flex: 0 0 auto;
  max-width: 44%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--teal-dark);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-view {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.home-intro {
  display: grid;
  gap: 6px;
  padding: 6px 0 2px;
}

.home-intro h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(2rem, 9vw, 3.6rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.home-tabs {
  position: sticky;
  top: 8px;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: rgba(238, 246, 243, 0.94);
  backdrop-filter: blur(14px);
}

.home-tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.home-tab-button span {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  padding: 0 7px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--teal-dark);
  font-size: 0.75rem;
}

.home-tab-button.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(31, 41, 51, 0.08);
}

.home-tab-button:disabled {
  cursor: default;
  opacity: 0.52;
}

.home-panel {
  display: grid;
  gap: 14px;
}

.step-panel,
.library-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.upload-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.upload-panel.is-dragging {
  border-color: var(--teal);
  background: var(--surface-soft);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--coral);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  max-width: 680px;
  font-size: clamp(1.7rem, 7vw, 3.2rem);
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.primary-action,
.ghost-button,
.icon-button,
.control-button,
.play-button,
.settings-button,
.library-open,
.library-delete,
.home-tab-button,
.voice-choice-button {
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background-color 0.16s ease,
    color 0.16s ease,
    border-color 0.16s ease;
}

.primary-action:active,
.ghost-button:active,
.icon-button:active,
.control-button:active,
.play-button:active,
.settings-button:active,
.library-open:active,
.library-delete:active,
.home-tab-button:active,
.voice-choice-button:active {
  transform: translateY(1px);
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  width: 100%;
  border-radius: var(--radius);
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.primary-action span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1.35rem;
  line-height: 1;
}

#fileInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.library-section,
.voice-lab-section {
  padding: 18px;
}

.step-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.step-heading h2 {
  font-size: 1.25rem;
}

.step-number {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.ghost-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.mini-status {
  flex: 0 0 auto;
  border: 1px solid #b9d9d5;
  border-radius: 999px;
  padding: 7px 10px;
  background: #edf8f6;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

.sample-text {
  margin: 14px 0 0;
  border-left: 4px solid var(--teal);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 12px 12px 14px;
  background: var(--surface-soft);
  color: var(--ink);
  line-height: 1.55;
}

.voice-cards {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.voice-choice-button {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.voice-choice-button h3 {
  margin: 0;
  font-size: 1rem;
}

.voice-choice-button p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.voice-choice-button.is-active {
  border-color: #88cbc5;
  background: #edf8f6;
  box-shadow: 0 10px 22px rgba(0, 109, 119, 0.1);
}

.voice-option-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.voice-play-label {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 6px 9px;
  background: var(--ink);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
}

.voice-choice-button.is-active .voice-play-label {
  background: var(--teal);
}

.voice-choice-button:disabled {
  cursor: progress;
  opacity: 0.78;
}

.library-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.library-item {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}

.library-item-main {
  min-width: 0;
}

.library-item h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.library-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.library-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.library-open,
.library-delete {
  min-height: 44px;
  border-radius: var(--radius);
  font-weight: 800;
}

.library-open {
  background: var(--ink);
  color: #fff;
}

.library-delete {
  min-width: 44px;
  border: 1px solid #efc5bd;
  background: #fff6f4;
  color: #9b2c1f;
}

.reader-view {
  margin-top: 4px;
}

.reader-header {
  position: sticky;
  top: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 8px;
  padding: 8px 0 10px;
  background: linear-gradient(180deg, var(--bg) 86%, rgba(245, 246, 241, 0));
}

.icon-button {
  display: grid;
  place-items: center;
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1;
}

.icon-button.solid {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  font-size: 0.78rem;
}

.reader-title-wrap {
  min-width: 0;
}

#readerKicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

#readerTitle {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  position: sticky;
  top: 60px;
  z-index: 4;
  overflow: hidden;
  height: 5px;
  border-radius: 999px;
  background: #dde5df;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--amber));
  transition: width 0.2s ease;
}

.reader-text {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.segment {
  position: relative;
  display: block;
  width: 100%;
  border: 1px solid transparent;
  border-left: 4px solid transparent;
  border-radius: var(--radius);
  padding: 12px 12px 12px 11px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 8px 22px rgba(31, 41, 51, 0.05);
}

.segment:hover {
  border-color: var(--line);
}

.segment.is-active {
  border-color: #a8d8d3;
  border-left-color: var(--teal);
  background: #e9f7f4;
}

.segment.is-loading {
  border-left-color: var(--teal);
}

.segment.is-loading::after {
  content: "Preparando audio";
  position: absolute;
  top: 8px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--teal-dark);
  background: #d1ece9;
  padding: 4px 12px;
  border-radius: 999px;
  animation: segmentLoadingPulse 1.2s ease-in-out infinite;
}

@keyframes segmentLoadingPulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

.segment-page {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-bottom: 7px;
  border-radius: 999px;
  padding: 0 8px;
  background: #f7e6df;
  color: #8f3526;
  font-size: 0.75rem;
  font-weight: 800;
}

.segment-text {
  display: block;
  font-size: 1rem;
  line-height: 1.62;
}

.player-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -14px 34px rgba(31, 41, 51, 0.14);
  backdrop-filter: blur(16px);
}

.player-meta {
  display: grid;
  gap: 1px;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.player-meta span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.player-meta strong {
  display: none;
}

.player-controls {
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.player-controls {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px 42px;
  gap: 7px;
}

.control-button,
.play-button,
.settings-button {
  min-height: 44px;
  border-radius: var(--radius);
  font-weight: 900;
}

.control-button,
.settings-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.8rem;
  line-height: 1;
}

.settings-button {
  font-size: 1.12rem;
}

.settings-button[aria-expanded="true"] {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.play-button {
  background: var(--teal);
  color: #fff;
}

.settings-scrim {
  position: fixed;
  inset: 0;
  z-index: 18;
  background: rgba(31, 41, 51, 0.32);
}

.settings-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 19;
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 -22px 56px rgba(31, 41, 51, 0.2);
}

.settings-grip {
  justify-self: center;
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: #cbd5d1;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-section {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-soft);
}

.settings-section-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.settings-help {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.page-jump-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
}

.page-jump-form input {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.page-jump-form .ghost-button {
  min-height: 44px;
  background: var(--ink);
  color: #fff;
}

.reader-voice-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.reader-voice-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 800;
}

.reader-voice-button.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.rate-setting,
.voice-setting {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.voice-setting {
  grid-template-columns: auto minmax(0, 1fr);
}

body.has-neural-voices .voice-setting {
  display: none;
}

.rate-setting span,
.voice-setting span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.rate-setting strong {
  color: var(--teal-dark);
  font-size: 0.82rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

select {
  min-width: 0;
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(var(--player-height) + 18px);
  left: 16px;
  z-index: 20;
  max-width: 560px;
  margin: 0 auto;
  border-radius: var(--radius);
  padding: 13px 14px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  line-height: 1.45;
}

.login-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.login-main {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px 0 36px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 26px 22px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-intro {
  margin-bottom: 22px;
}

.login-intro .eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.login-intro h1 {
  margin: 0 0 8px;
  font-size: 1.55rem;
  letter-spacing: -0.01em;
}

.login-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field > span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.login-field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
}

.login-field input:focus {
  outline: 3px solid rgba(0, 109, 119, 0.28);
  outline-offset: 1px;
  border-color: var(--teal);
}

.login-submit {
  margin-top: 6px;
}

.login-foot {
  margin: 6px 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.login-error {
  margin-bottom: 4px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(216, 92, 68, 0.1);
  color: var(--coral);
  font-size: 0.88rem;
  border: 1px solid rgba(216, 92, 68, 0.25);
}

@media (min-width: 760px) {
  :root {
    --player-height: 112px;
  }

  .app-shell {
    padding: 24px 24px 44px;
  }

  body.reader-mode .app-shell {
    padding-bottom: calc(var(--player-height) + 34px);
  }

  body.reader-mode .topbar {
    display: flex;
  }

  .home-view {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .home-tabs {
    top: 12px;
    width: min(100%, 520px);
  }

  .start-panel {
    grid-template-columns: minmax(0, 1.18fr) minmax(300px, 0.82fr);
    align-items: start;
  }

  .upload-panel,
  .library-section,
  .voice-lab-section {
    padding: 24px;
  }

  .voice-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .primary-action {
    width: fit-content;
    min-width: 220px;
    padding: 0 22px;
  }

  .library-item {
    grid-template-columns: minmax(0, 1fr) 210px;
    align-items: center;
  }

  .library-list {
    width: min(100%, 880px);
  }

  .reader-view {
    margin-top: 14px;
  }

  .reader-header {
    grid-template-columns: 68px minmax(0, 1fr) 58px;
    gap: 10px;
    padding: 10px 0 12px;
  }

  .progress-track {
    top: 66px;
    height: 7px;
  }

  .player-meta {
    gap: 3px;
  }

  .player-meta strong {
    display: block;
    overflow: hidden;
    font-size: 0.94rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .player-controls {
    grid-template-columns: 52px minmax(0, 1fr) 52px 52px;
    gap: 10px;
  }

  .control-button,
  .play-button,
  .settings-button {
    min-height: 48px;
  }

  .player-bar {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }

  .settings-sheet {
    right: 50%;
    left: auto;
    width: min(100% - 32px, 520px);
    transform: translateX(50%);
    border-radius: 16px 16px 0 0;
  }

  .reader-text {
    width: min(100%, 820px);
    margin-inline: auto;
  }

  .reader-header,
  .progress-track {
    width: min(100%, 920px);
    margin-inline: auto;
  }
}

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