:root {
  color-scheme: light dark;

  --bg-light: #f6f3ee;
  --bg-dark: #121110;
  --surface-light: #fffdf9;
  --surface-dark: #1b1917;
  --inset-light: #f8f5ef;
  --inset-dark: #141311;
  --ink-light: #161513;
  --ink-dark: #f3efe8;
  --muted-light: #615c53;
  --muted-dark: #a69f94;
  --line-light: #dbd5ca;
  --line-dark: #2f2c28;
  --border-ctrl-light: #8a8378;
  --border-ctrl-dark: #6d675d;
  --accent-light: #c25c0e;
  --accent-dark: #f09540;
  --cta-bg-light: #181614;
  --cta-bg-dark: #f09540;
  --cta-fg-light: #fffdf9;
  --cta-fg-dark: #161310;
  --cta-hover-light: #b8530e;
  --cta-hover-dark: #f6a85c;

  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --inset: var(--inset-light);
  --ink: var(--ink-light);
  --muted: var(--muted-light);
  --line: var(--line-light);
  --border-ctrl: var(--border-ctrl-light);
  --accent: var(--accent-light);
  --cta-bg: var(--cta-bg-light);
  --cta-fg: var(--cta-fg-light);
  --cta-hover: var(--cta-hover-light);

  accent-color: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --inset: var(--inset-dark);
    --ink: var(--ink-dark);
    --muted: var(--muted-dark);
    --line: var(--line-dark);
    --border-ctrl: var(--border-ctrl-dark);
    --accent: var(--accent-dark);
    --cta-bg: var(--cta-bg-dark);
    --cta-fg: var(--cta-fg-dark);
    --cta-hover: var(--cta-hover-dark);
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) {
  color-scheme: dark;
  --bg: var(--bg-dark);
  --surface: var(--surface-dark);
  --inset: var(--inset-dark);
  --ink: var(--ink-dark);
  --muted: var(--muted-dark);
  --line: var(--line-dark);
  --border-ctrl: var(--border-ctrl-dark);
  --accent: var(--accent-dark);
  --cta-bg: var(--cta-bg-dark);
  --cta-fg: var(--cta-fg-dark);
  --cta-hover: var(--cta-hover-dark);
}

:root:has(> head > meta[name="color-scheme"][content="light"]) {
  color-scheme: light;
  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --inset: var(--inset-light);
  --ink: var(--ink-light);
  --muted: var(--muted-light);
  --line: var(--line-light);
  --border-ctrl: var(--border-ctrl-light);
  --accent: var(--accent-light);
  --cta-bg: var(--cta-bg-light);
  --cta-fg: var(--cta-fg-light);
  --cta-hover: var(--cta-hover-light);
}

@supports (color: light-dark(white, black)) {
  :root {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --inset: light-dark(var(--inset-light), var(--inset-dark));
    --ink: light-dark(var(--ink-light), var(--ink-dark));
    --muted: light-dark(var(--muted-light), var(--muted-dark));
    --line: light-dark(var(--line-light), var(--line-dark));
    --border-ctrl: light-dark(var(--border-ctrl-light), var(--border-ctrl-dark));
    --accent: light-dark(var(--accent-light), var(--accent-dark));
    --cta-bg: light-dark(var(--cta-bg-light), var(--cta-bg-dark));
    --cta-fg: light-dark(var(--cta-fg-light), var(--cta-fg-dark));
    --cta-hover: light-dark(var(--cta-hover-light), var(--cta-hover-dark));
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100dvh;
  padding: clamp(20px, 4vw, 48px);
}

.shell {
  max-width: 1180px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 2 * clamp(20px, 4vw, 48px));
}

.visually-hidden {
  position: absolute;
  clip-path: inset(50%);
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  white-space: nowrap;
}

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover {
  color: var(--accent);
}

.brand .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #e8892b;
  flex: none;
}

.crumbs .sep {
  color: var(--muted);
}

.crumbs .current {
  color: var(--muted);
  font-weight: 500;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 5px 11px;
  border-radius: 999px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  min-inline-size: 36px;
  min-block-size: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Theme icon visibility */
.icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .icon-sun { display: none; }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .icon-moon { display: block; }
}
:root:has(> head > meta[name="color-scheme"][content="dark"]) .icon-sun { display: none; }
:root:has(> head > meta[name="color-scheme"][content="dark"]) .icon-moon { display: block; }

/* Intro */
.intro {
  padding-block: clamp(28px, 4.5vh, 46px) clamp(20px, 3vh, 30px);
}

.intro-title-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.intro h1 {
  font-size: clamp(32px, 4.6vw, 48px);
  font-weight: 750;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.ipa-badge {
  font-family: "Charis SIL", "Gentium Plus", "Doulos SIL", "Noto Sans", "Lucida Grande", Georgia, serif;
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 400;
  color: var(--accent);
  letter-spacing: 0.01em;
}

.subtitle {
  margin-block-start: 8px;
  font-size: clamp(16px, 1.7vw, 18.5px);
  color: var(--muted);
  max-width: 72ch;
  text-wrap: balance;
}

/* Workspace Two-Column Grid */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.06fr);
  gap: clamp(18px, 2.4vw, 28px);
  align-items: start;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(20px, 2.6vw, 28px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-block-end: 18px;
}

.panel-head h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.engine-status {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.engine-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e8892b;
}

.engine-status[data-state="ready"]::before {
  background: #2c8a56;
}

.engine-status[data-state="error"] {
  color: #c93b2b;
}

.engine-status[data-state="error"]::before {
  background: #c93b2b;
}

/* Form Fields */
.field {
  margin-block-end: 18px;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-block-end: 8px;
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  inset-inline-end: 15px;
  inset-block-start: 50%;
  width: 8px;
  height: 8px;
  border-inline-end: 1.8px solid var(--muted);
  border-block-end: 1.8px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

select,
textarea {
  width: 100%;
  font: inherit;
  font-size: max(1rem, 15.5px);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-ctrl);
  border-radius: 11px;
  transition: border-color 0.15s ease;
}

select {
  appearance: none;
  min-block-size: 46px;
  padding: 10px 38px 10px 14px;
  cursor: pointer;
}

select:hover,
textarea:hover {
  border-color: var(--ink);
}

/* Input Mode Tabs (WCAG shape + aria-selected styling) */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 4px;
  margin-block-end: 18px;
}

.mode-tabs [role="tab"] {
  position: relative;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  min-block-size: 38px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.mode-tabs [role="tab"]:hover {
  color: var(--ink);
}

.mode-tabs [role="tab"][aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
}

.mode-tabs [role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-inline: 22%;
  inset-block-end: 3px;
  border-block-end: 2.5px solid var(--accent);
  border-radius: 2px;
}

.input-panels {
  display: grid;
}

.input-panels > [role="tabpanel"] {
  grid-area: 1 / 1;
}

[role="tabpanel"][hidden] {
  pointer-events: none;
}

[role="tabpanel"]:not([hidden]) {
  position: relative;
  z-index: 1;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-block-end: 8px;
}

.label-row .field-label {
  margin-block-end: 0;
}

.samples-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.sample-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--inset);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.sample-chip:hover {
  border-color: var(--accent);
  color: var(--ink);
}

textarea {
  padding: 13px 14px;
  resize: vertical;
  min-block-size: 178px;
  line-height: 1.55;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.input-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-block-start: 9px;
  font-size: 13px;
  color: var(--muted);
}

.live-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
}

.live-check input {
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.char-counter {
  font-variant-numeric: tabular-nums;
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  min-block-size: 215px;
  padding: 24px 18px;
  border: 1.5px dashed var(--border-ctrl);
  border-radius: 12px;
  background: var(--inset);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone[data-dragover] {
  border-color: var(--accent);
  color: var(--ink);
}

input#file-input:focus-visible + .dropzone {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

.dropzone-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.dropzone-hint {
  font-size: 13px;
  max-width: 38ch;
}

.dropzone-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.file-badge {
  margin-block-start: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
}

.divider {
  border: 0;
  border-block-start: 1px solid var(--line);
  margin-block: 20px 18px;
}

/* Action Buttons (Fixes Base44's invisible CTA!) */
.actions-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .actions-row {
    grid-template-columns: 1fr;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-block-size: 48px;
  padding-inline: 20px;
  border-radius: 11px;
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-ctrl);
}

.btn-secondary:hover {
  border-color: var(--ink);
  background: var(--inset);
}

.btn-primary {
  background: var(--cta-bg);
  color: var(--cta-fg);
  border: 1px solid transparent;
}

.btn-primary:hover {
  background: var(--cta-hover);
}

.shortcut-hint {
  font-family: ui-sans-serif, -apple-system, sans-serif;
  font-size: 11.5px;
  font-weight: 500;
  opacity: 0.78;
  border: 1px solid currentColor;
  border-radius: 5px;
  padding: 1px 5px;
}

@media (pointer: coarse) {
  .shortcut-hint {
    display: none;
  }
}

/* Output Panel */
.output-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-block-end: 16px;
}

.output-meta h3 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.detection-summary {
  font-size: 13.5px;
  color: var(--muted);
  margin-block-start: 2px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-inline-size: 38px;
  min-block-size: 38px;
  padding-inline: 10px;
  border-radius: 9px;
  border: 1px solid var(--border-ctrl);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.tool-btn-labeled {
  padding-inline: 13px;
}

.tool-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.tool-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.slow-btn {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--muted);
}

.slow-btn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--inset);
}

#speak-btn .icon-stop { display: none; }
#speak-btn[data-speaking] {
  border-color: var(--accent);
  color: var(--accent);
}
#speak-btn[data-speaking] .icon-volume { display: none; }
#speak-btn[data-speaking] .icon-stop { display: block; }

/* Copy button + accessible status bubble */
.copy-wrap {
  position: relative;
  display: inline-flex;
}

#copy-btn .icon-check { display: none; }
#copy-btn[data-copied] {
  border-color: #2c8a56;
  color: #2c8a56;
}
#copy-btn[data-copied] .icon-copy { display: none; }
#copy-btn[data-copied] .icon-check { display: block; }

.copy-tip {
  position: absolute;
  inset-block-end: calc(100% + 6px);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

#copy-btn[data-copied] + .copy-tip,
#copy-btn[data-failed] + .copy-tip {
  opacity: 1;
}

/* Output View Tabs + Sub-options */
.view-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-block-end: 1px solid var(--line);
  margin-block-end: 16px;
}

.view-tabs {
  display: flex;
  align-items: center;
  gap: 18px;
  overflow-x: auto;
}

.view-tabs [role="tab"] {
  position: relative;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding-block: 6px 11px;
  white-space: nowrap;
  cursor: pointer;
}

.view-tabs [role="tab"]:hover {
  color: var(--ink);
}

.view-tabs [role="tab"][aria-selected="true"] {
  color: var(--ink);
}

.view-tabs [role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 2.5px solid var(--accent);
}

.sub-options {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sub-options[hidden] {
  display: none;
}

.pill-opt {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--inset);
  color: var(--muted);
  font-family: "Charis SIL", "Gentium Plus", "Noto Sans", ui-sans-serif, sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 7px;
  cursor: pointer;
}

.pill-opt[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--surface);
}

/* Specimen Frame (mirrors screenshot's double-bordered output box) */
.specimen-shell {
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.specimen-box {
  background: var(--surface);
  border: 1.25px solid var(--border-ctrl);
  border-radius: 10px;
  min-block-size: 215px;
  padding: 16px 18px;
  display: grid;
}

.specimen-box > [role="tabpanel"],
.specimen-box > .empty-state {
  grid-area: 1 / 1;
}

.transcription-text {
  font-family: "Charis SIL", "Gentium Plus", "Doulos SIL", "Noto Sans", "Lucida Grande", "Segoe UI", sans-serif;
  font-size: clamp(19px, 2.1vw, 23px);
  line-height: 1.65;
  letter-spacing: 0.01em;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
}

.respell-text {
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(17.5px, 1.9vw, 20.5px);
  letter-spacing: 0.015em;
}

/* Word-by-Word Interlinear Grid */
.words-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

.word-tile {
  appearance: none;
  text-align: start;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--inset);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.14s ease, transform 0.12s ease;
}

.word-tile:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.word-tile .w-src {
  font-size: 13px;
  color: var(--muted);
}

.word-tile .w-ipa {
  font-family: "Charis SIL", "Gentium Plus", "Doulos SIL", "Noto Sans", "Lucida Grande", sans-serif;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.word-tile .w-respell {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
}

.empty-state[hidden] {
  display: none;
}

.empty-lead {
  font-size: 14.5px;
}

.empty-specimen {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 9px;
  background: var(--inset);
  border: 1px solid var(--line);
  max-width: 44ch;
}

.empty-specimen .ex-src {
  font-size: 13px;
  color: var(--muted);
}

.empty-specimen .ex-arrow {
  display: none;
}

.empty-specimen .ex-ipa {
  font-family: "Charis SIL", "Gentium Plus", "Noto Sans", "Lucida Grande", sans-serif;
  font-size: 18px;
  color: var(--ink);
}

.empty-specimen .ex-respell {
  font-size: 12.5px;
  color: var(--accent);
}

.note-banner {
  margin-block-start: 12px;
  font-size: 13px;
  color: var(--muted);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
}

/* Footer */
.foot {
  margin-block-start: auto;
  padding-block-start: clamp(36px, 5vh, 56px);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13.5px;
  color: var(--muted);
}

.foot a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.foot a:hover {
  color: var(--accent);
}

@media (forced-colors: active) {
  .panel,
  .specimen-box,
  .btn,
  .tool-btn,
  select,
  textarea {
    border: 1px solid ButtonText;
  }
}

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