:root {
  color-scheme: light;
  --bg: #f4f5f0;
  --surface: #fffefa;
  --surface-strong: #eef1ed;
  --text: #111820;
  --reader-text: #111820;
  --muted: #59616c;
  --line: #cfd6dc;
  --accent: #006f6d;
  --accent-strong: #004f4d;
  --accent-soft: #d8f0ed;
  --danger: #9f2d39;
  --shadow: 0 18px 50px rgba(33, 38, 48, 0.12);
  --reader-size: 20px;
  --reader-line: 1.78;
  --reader-font: var(--ui-font);
  --reader-weight: 400;
  --heading-weight: 680;
  --strong-weight: 650;
  --ui-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Arial, sans-serif;
  --mono-font: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: var(--ui-font);
}

:root[data-theme="soft"] {
  color-scheme: light;
  --bg: #f4f5f0;
  --surface: #fffefa;
  --surface-strong: #eef1ed;
  --text: #111820;
  --reader-text: #111820;
  --muted: #59616c;
  --line: #cfd6dc;
  --accent: #006f6d;
  --accent-strong: #004f4d;
  --accent-soft: #d8f0ed;
  --shadow: 0 18px 50px rgba(33, 38, 48, 0.12);
}

:root[data-theme="contrast"] {
  --bg: #f7f7f2;
  --surface: #ffffff;
  --surface-strong: #e9ece8;
  --text: #05080c;
  --reader-text: #05080c;
  --muted: #3f4650;
  --line: #9ea7b1;
  --accent: #005c59;
  --accent-strong: #003e3c;
  --accent-soft: #cae6e2;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121313;
  --surface: #1c1d1c;
  --surface-strong: #292b29;
  --text: #f5f2e9;
  --reader-text: #f8f4ea;
  --muted: #c3c0b8;
  --line: #454741;
  --accent: #56d1c6;
  --accent-strong: #9df1ea;
  --accent-soft: #173c38;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

:root[data-reader-font="system"] {
  --reader-font: var(--ui-font);
  --reader-line: 1.78;
}

:root[data-reader-font="serif"] {
  --reader-font: Georgia, "Times New Roman", serif;
  --reader-line: 1.72;
}

:root[data-reader-font="mono"] {
  --reader-font: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --reader-line: 1.68;
}

:root[data-reader-weight="regular"] {
  --reader-weight: 400;
  --heading-weight: 680;
  --strong-weight: 650;
}

:root[data-reader-weight="medium"] {
  --reader-weight: 450;
  --heading-weight: 740;
  --strong-weight: 720;
}

:root[data-reader-weight="bold"] {
  --reader-weight: 520;
  --heading-weight: 850;
  --strong-weight: 800;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: auto;
  text-rendering: optimizeLegibility;
}

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

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 78px;
  padding: 16px clamp(16px, 4vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 4;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.15;
  font-weight: 800;
}

.brand p {
  max-width: min(62vw, 700px);
  margin: 5px 0 0;
  color: var(--muted);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease, opacity 140ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button.compact {
  min-height: 38px;
  padding: 0 12px;
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button.secondary {
  background: var(--surface-strong);
  color: var(--text);
}

.workbench {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
}

.sidebar {
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.dropzone {
  min-height: 142px;
  border: 1.5px dashed #a8b1bc;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border 160ms ease, background 160ms ease, transform 160ms ease;
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.dropzone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-title,
.drop-subtitle {
  display: block;
}

.drop-title {
  font-size: 1.03rem;
  font-weight: 800;
}

.drop-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.control-group {
  display: grid;
  gap: 10px;
}

.share-box {
  display: grid;
  gap: 8px;
}

.share-result {
  display: grid;
  gap: 8px;
}

.share-result[hidden] {
  display: none;
}

.share-result label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
}

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

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

.share-row input {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

.share-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 550;
}

.share-status[data-tone="success"] {
  color: var(--accent-strong);
}

.share-status[data-tone="error"] {
  color: var(--danger);
}

.control-group > label:not(.switch) {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-weight: 550;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--text);
  font-weight: 550;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.stats {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats div {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.stats span {
  display: block;
  font-size: 1.32rem;
  font-weight: 850;
}

.stats small {
  color: var(--muted);
}

.content-area {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.tabs {
  display: flex;
  align-items: center;
  min-height: 58px;
  gap: 8px;
  padding: 10px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.tab {
  min-width: 104px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.panel {
  min-height: 0;
  display: none;
  overflow: auto;
}

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

.reader {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 56px);
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-line);
  color: var(--reader-text);
  font-weight: var(--reader-weight);
}

.reader.empty {
  min-height: calc(100vh - 138px);
  display: grid;
  align-content: center;
  justify-items: start;
  color: var(--reader-text);
}

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

.reader h1,
.reader h2,
.reader h3,
.reader h4 {
  font-family: var(--ui-font);
  line-height: 1.2;
  margin: 1.42em 0 0.46em;
  font-weight: var(--heading-weight);
}

.reader h1 {
  font-size: clamp(2rem, 4.2vw, 2.7rem);
}

.reader h2 {
  font-size: 1.5rem;
}

.reader h3 {
  font-size: 1.22rem;
}

.reader p,
.reader ul,
.reader ol,
.reader pre,
.reader table {
  margin: 0.8em 0;
}

.reader strong {
  font-weight: var(--strong-weight);
}

.reader code {
  font-family: var(--mono-font);
  font-size: 0.94em;
  background: #eef2f6;
  border-radius: 5px;
  padding: 0.14em 0.34em;
}

.reader pre {
  overflow: auto;
  padding: 16px;
  border-radius: 8px;
  background: #202631;
  color: #edf3f8;
}

.reader pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.reader blockquote {
  margin: 1em 0;
  padding: 0.2em 0 0.2em 1em;
  border-left: 4px solid var(--accent);
  color: #374151;
}

.reader table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--ui-font);
  font-size: 0.94rem;
}

.reader th,
.reader td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
}

.reader a {
  color: var(--accent-strong);
  text-decoration-thickness: 0.08em;
}

#whatsappOutput {
  display: block;
  width: min(100%, 760px);
  min-height: calc(100vh - 138px);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 34px);
  border: 0;
  outline: 0;
  resize: none;
  background: var(--surface);
  color: var(--reader-text);
  font: var(--reader-size)/1.68 var(--reader-font);
  font-weight: var(--reader-weight);
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand p {
    max-width: 88vw;
  }

  .top-actions {
    width: 100%;
  }

  .button {
    flex: 1;
  }

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats {
    margin-top: 0;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121313;
    --surface: #1c1d1c;
    --surface-strong: #292b29;
    --text: #f5f2e9;
    --reader-text: #f8f4ea;
    --muted: #c3c0b8;
    --line: #454741;
    --accent: #56d1c6;
    --accent-strong: #9df1ea;
    --accent-soft: #173c38;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  }

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

  .topbar {
    background: rgba(32, 36, 43, 0.88);
  }

  .sidebar {
    background: #1c2026;
  }

  .reader code {
    background: #313844;
  }

  .reader blockquote {
    color: #cad1da;
  }

  #whatsappOutput {
    color: var(--text);
  }
}

:root[data-theme="soft"] body,
:root[data-theme="contrast"] body,
:root[data-theme="dark"] body {
  background: var(--bg);
}
