:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --border-strong: #c4cad2;
  --text: #12161c;
  --text-dim: #5d6673;
  --text-faint: #8a929e;
  --accent: #2f6df0;
  --accent-soft: #e8effd;
  --accent-text: #ffffff;
  --ok: #17845a;
  --ok-soft: #e3f5ec;
  --warn: #a8600a;
  --warn-soft: #fdf1df;
  --err: #c23b34;
  --err-soft: #fdeceb;
  --rec: #d93a34;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1c222b;
    --border: #2a313c;
    --border-strong: #3a434f;
    --text: #e8ecf1;
    --text-dim: #9aa4b2;
    --text-faint: #6e7884;
    --accent: #5b8dff;
    --accent-soft: #18233c;
    --accent-text: #0b1020;
    --ok: #4ed09a;
    --ok-soft: #10291f;
    --warn: #e0a45c;
    --warn-soft: #2b2113;
    --err: #f08a84;
    --err-soft: #2e1917;
    --rec: #ff6b63;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto,
        "Noto Sans", "Noto Sans Devanagari", "Noto Sans Tamil", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.logo {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--accent), #8a5cf6);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 18px;
}
h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.sub { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }
.edition-note { font-size: 10.5px; color: var(--text-faint); margin-top: 2px; }
.head-text { flex: 1 1 200px; min-width: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.pill.tier-LOCAL     { background: var(--ok-soft);     color: var(--ok);     border-color: transparent; }
.pill.tier-LOCAL .dot{ background: var(--ok); }
.pill.tier-FREE_WEB  { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.tier-FREE_WEB .dot { background: var(--accent); }
.pill.tier-FREE_API  { background: var(--warn-soft);   color: var(--warn);   border-color: transparent; }
.pill.tier-FREE_API .dot { background: var(--warn); }
.pill.err            { background: var(--err-soft);    color: var(--err);    border-color: transparent; }
.pill.err .dot       { background: var(--err); }

/* ---------- panels ---------- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
}
@media (max-width: 780px) {
  .grid { grid-template-columns: 1fr; }
  .swap-col { justify-self: center; }
}

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 260px;
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
select {
  font: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--text); background: transparent;
  border: 1px solid transparent; border-radius: 8px;
  padding: 5px 7px; cursor: pointer; max-width: 100%;
  appearance: none; background-image: none;
}
select:hover { background: var(--surface-2); }
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
option { background: var(--surface); color: var(--text); }

textarea, .output {
  flex: 1; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 17px; line-height: 1.55;
  padding: 14px; resize: none; min-height: 150px; width: 100%;
}
textarea:focus { outline: none; }
textarea::placeholder { color: var(--text-faint); }
.output { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.output.empty { color: var(--text-faint); }

.panel-foot {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-top: 1px solid var(--border);
  min-height: 42px; flex-wrap: wrap;
}
.spacer { flex: 1; }
.count { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* ---------- the romanization hint ---------- */
.hint {
  margin: 0 12px 10px; padding: 9px 11px;
  background: var(--accent-soft); border-radius: 9px;
  font-size: 14px; line-height: 1.45;
  display: none; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.hint.show { display: flex; }
.hint .tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--accent); flex: none;
}
.hint .native { font-size: 16px; color: var(--text); }
.hint .approx { font-size: 11px; color: var(--warn); }

/* ---------- buttons ---------- */
button {
  font: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); border-radius: 8px;
  padding: 6px 11px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, color .12s, border-color .12s;
}
button:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--accent-text); }
button.icon { padding: 6px 8px; }
button.rec { background: var(--rec); border-color: var(--rec); color: #fff; }
button.rec:hover:not(:disabled) { color: #fff; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .55 } }
button.rec .dot { width: 8px; height: 8px; border-radius: 50%; background: #fff;
                  animation: pulse 1s ease-in-out infinite; }

.swap-col { display: flex; align-items: center; justify-content: center; padding-top: 90px; }
@media (max-width: 780px) { .swap-col { padding-top: 0; } }
#swap { border-radius: 50%; width: 36px; height: 36px; padding: 0; justify-content: center; }

/* ---------- status strip ---------- */
.status {
  margin-top: 14px; display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap; min-height: 26px; font-size: 12.5px; color: var(--text-dim);
}
.status .mono { font-family: var(--mono); font-size: 11.5px; }
.status .note { color: var(--text-faint); }

/* ---------- settings ---------- */
details.settings {
  margin-top: 18px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
details.settings > summary {
  cursor: pointer; padding: 11px 14px; font-size: 13px;
  font-weight: 600; color: var(--text-dim); list-style: none;
}
details.settings > summary::-webkit-details-marker { display: none; }
details.settings > summary::before { content: "\25B8  "; color: var(--text-faint); }
details.settings[open] > summary::before { content: "\25BE  "; }
.settings-body {
  padding: 4px 14px 16px; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  border-top: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; font-weight: 700; letter-spacing: .03em;
               text-transform: uppercase; color: var(--text-faint); }
.field select {
  border: 1px solid var(--border); background: var(--surface-2);
  padding: 7px 9px; font-weight: 500; font-size: 13.5px;
}
.field .help { font-size: 11.5px; color: var(--text-faint); line-height: 1.4; }

table.providers { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 4px; }
table.providers th {
  text-align: left; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-faint); font-weight: 700;
  padding: 5px 8px 5px 0; border-bottom: 1px solid var(--border);
}
table.providers td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border);
                     vertical-align: top; color: var(--text-dim); }
table.providers td.name { font-family: var(--mono); color: var(--text); font-size: 12px; }
.yes { color: var(--ok); font-weight: 700; }
.no  { color: var(--text-faint); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(8px);
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- quality badge ---------- */
.quality { font-weight: 700; }
.quality.high     { color: var(--ok); }
.quality.moderate { color: var(--warn); }
.quality.low,
.quality.very     { color: var(--err); }

.back-translation {
  font-size: 12.5px; color: var(--text-dim);
  border-left: 2px solid var(--border-strong);
  padding-left: 9px; margin-top: 2px;
}

/* ---------- document panel ---------- */
input[type="file"] {
  font: inherit; font-size: 13px; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input[type="file"]::file-selector-button {
  font: inherit; font-size: 12.5px; font-weight: 600;
  margin-right: 10px; padding: 5px 10px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
.doc-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alts { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.alts .alt { font-size: 12px; color: var(--text-dim); }
.alts .alt b { color: var(--text); font-weight: 600; }

/* keyboard hint in the input footer -- hidden when the panel gets narrow */
.kbd-hint { margin-left: 10px; color: var(--text-faint); }
@media (max-width: 900px) { .kbd-hint { display: none; } }
