:root {
  /* Same brand palette as the extension popup. */
  --brand-500: #1f9d63;
  --brand-600: #16633d;
  --brand-700: #0f5234;
  --teal-500: #0f8a78;
  --grad-brand: linear-gradient(135deg, #1f9d63 0%, #0f8a78 100%);

  --bg: #ffffff;
  --page: #f4f7f5;
  --surface: #f6faf8;
  --surface-2: #eef5f1;
  --border: rgba(15, 31, 26, 0.10);
  --border-strong: rgba(15, 31, 26, 0.16);
  --text: #0f1f1a;
  --text-muted: #5a7064;
  --text-faint: #7d9489;

  --warn: #c9711d;
  --warn-grad: linear-gradient(135deg, #f0a738 0%, #e0772f 100%);
  --danger: #c0392b;
  --focus-ring: rgba(31, 157, 99, 0.22);

  --radius: 14px;
  --radius-sm: 8px;
  --shadow-md: 0 8px 28px rgba(15, 31, 26, 0.07);
}

* { box-sizing: border-box; }
/* Our own `display` rules outrank the UA sheet's [hidden], so make it explicit. */
[hidden] { display: none !important; }

html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--grad-brand);
  box-shadow: 0 2px 8px rgba(15, 102, 73, 0.28);
}
.brand-mark svg { width: 17px; height: 17px; color: #fff; }

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-600);
  background: var(--surface-2);
  border-radius: 99px;
  white-space: nowrap;
}
.chip-icon { width: 13px; height: 13px; }
.chip.low { color: var(--warn); background: rgba(240, 167, 56, 0.16); }

/* ---- Select (custom dropdown over a hidden native <select>) ----
   The native element stays in the DOM as the single source of truth — the
   dropdown just drives it — so it keeps working if this script-built UI
   never renders. */
.ft-native {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.select { position: relative; display: inline-flex; }

.select-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 99px;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.select-trigger:hover { background: var(--surface-2); }
.select-trigger:focus-visible { outline: 2px solid var(--teal-500); outline-offset: 1px; }
.select-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-caret {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: var(--text-muted);
  transition: transform 0.16s ease;
}
.select[data-open="true"] .select-trigger { background: var(--surface-2); }
.select[data-open="true"] .select-caret { transform: rotate(180deg); }

/* The header language picker is a small outlined pill. */
.select.is-ui .select-trigger {
  padding: 6px 10px 6px 12px;
  font-size: 13px;
  border: 1px solid var(--border-strong);
}
.select.is-ui .select-trigger:hover { border-color: var(--brand-500); }

.select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 20;
  min-width: 176px;
  max-width: min(280px, calc(100vw - 32px));
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 31, 26, 0.14), 0 2px 6px rgba(15, 31, 26, 0.06);
  transform: translateX(-50%) translateY(-4px);
  opacity: 0;
  visibility: hidden;
  /* Visibility flips instantly on open (an option gets focused right away) and
     only waits for the fade on close. */
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s 0.14s;
}
.select[data-open="true"] .select-menu {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s;
}
/* Right-aligned in the header so the menu can't hang off the viewport. */
.select.is-ui .select-menu { left: auto; right: 0; transform: translateY(-4px); }
.select.is-ui[data-open="true"] .select-menu { transform: translateY(0); }

.select-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.1s ease;
}
.select-option:hover, .select-option.is-active { background: var(--surface-2); }
.select-option:focus-visible { outline: 2px solid var(--teal-500); outline-offset: -2px; }
.select-option.is-selected { font-weight: 700; color: var(--brand-600); }
.select-check { width: 16px; height: 16px; flex: 0 0 auto; opacity: 0; }
.select-option.is-selected .select-check { opacity: 1; }

.account { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: cover;
}
.account-text { display: flex; flex-direction: column; min-width: 0; max-width: 190px; line-height: 1.25; }
.name { font-size: 12.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email { font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link {
  padding: 5px 8px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-600);
  background: none;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.link:hover { background: var(--surface-2); color: var(--brand-700); }

/* ---- Layout ---- */
.wrap {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 22px 20px 40px;
}

/* ---- Mode tabs ---- */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 99px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab svg { width: 16px; height: 16px; }
.tab:hover:not([disabled]) { background: var(--surface-2); color: var(--text); }
.tab.is-active { color: var(--brand-600); background: var(--bg); border-color: var(--border); }
.tab[disabled] { color: var(--text-faint); cursor: default; }
.tab:focus-visible { outline: 2px solid var(--teal-500); outline-offset: 2px; }
.soon {
  padding: 1px 6px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-2);
  border-radius: 99px;
}

/* ---- Translator card ---- */
.card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  /* Not `overflow: hidden` — the language dropdown has to escape the card.
     The panes round their own outer corners instead (see below). */
}

.langbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
/* Each language picker hugs its own label; the swap button stays centred. */
.langbar .select { justify-self: center; max-width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--teal-500); outline-offset: 1px; }
.icon-btn.is-on { color: var(--brand-600); background: var(--surface-2); }
.icon-btn[disabled] { opacity: 0.45; cursor: default; }
.icon-btn[disabled]:hover { background: transparent; color: var(--text-muted); }

.text-btn {
  padding: 5px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.text-btn:hover { background: var(--surface-2); color: var(--text); }
.text-btn.primary-text { color: var(--brand-600); }

/* Two panes side by side on desktop, stacked on narrow screens. */
.panes { display: grid; grid-template-columns: 1fr 1fr; }
.pane { padding: 16px 18px 10px; min-width: 0; }
.pane + .pane { border-left: 1px solid var(--border); }
.pane.result { background: var(--surface); }
/* The card can't clip (the dropdown escapes it), so the panes round the card's
   bottom corners themselves. */
.panes > .pane:first-child { border-bottom-left-radius: var(--radius); }
.panes > .pane:last-child { border-bottom-right-radius: var(--radius); }

.text-area {
  display: block;
  width: 100%;
  min-height: 148px;
  max-height: 420px;
  padding: 0;
  overflow-y: auto;
  font-family: inherit;
  font-size: 19px;
  line-height: 1.45;
  color: var(--text);
  background: transparent;
  border: 0;
  resize: none;
  overflow-wrap: anywhere;
}
.text-area:focus { outline: none; }
.text-area::placeholder { color: var(--text-faint); }
.output { white-space: pre-wrap; }
.output.is-placeholder, .output.is-loading { color: var(--text-faint); }
.output.is-error { color: var(--danger); font-size: 15px; }

.pane-foot {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 34px;
  margin-top: 6px;
}
.foot-spacer { flex: 1; }
.counter {
  margin-left: auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}
.counter.near-limit { color: var(--warn); }
.status {
  margin-left: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-600);
}

/* ---- Sign-in gate ---- */
.gate {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px 20px;
  text-align: center;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(3px);
  border-radius: var(--radius);
}
.gate-close { position: absolute; top: 10px; right: 10px; }
.gate-text { margin: 0; max-width: 440px; font-size: 15px; color: var(--text-muted); }
.gate-error { margin: 0; font-size: 13px; font-weight: 600; color: var(--danger); }

/* ---- Footer ---- */
.sitefoot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  padding: 18px 20px 26px;
  font-size: 12.5px;
  color: var(--text-faint);
}
.sitefoot a { color: var(--text-muted); font-weight: 600; text-decoration: none; }
.sitefoot a:hover { color: var(--brand-600); text-decoration: underline; }
.dot { margin: 0 8px; color: var(--text-faint); }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .account-text { display: none; }
  .panes { grid-template-columns: 1fr; }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
  .panes > .pane:first-child { border-bottom-left-radius: 0; }
  .panes > .pane:last-child { border-radius: 0 0 var(--radius) var(--radius); }
  .text-area { min-height: 108px; font-size: 17px; }
  /* Centring a wide menu under a pill near the edge would overflow the screen. */
  .langbar .select:first-child .select-menu { left: 0; transform: translateY(-4px); }
  .langbar .select:first-child[data-open="true"] .select-menu { transform: translateY(0); }
  .langbar .select:last-child .select-menu { left: auto; right: 0; transform: translateY(-4px); }
  .langbar .select:last-child[data-open="true"] .select-menu { transform: translateY(0); }
}

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

/* ---- Dark mode ---- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a17;
    --page: #0e1310;
    --surface: #1b231f;
    --surface-2: #232e29;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #e9f3ee;
    --text-muted: #9bb8ac;
    --text-faint: #7d978c;
    --brand-600: #8be3b6;
    --brand-700: #a7eccb;
    --danger: #ff9b8f;
    --focus-ring: rgba(37, 176, 115, 0.28);
    --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.35);
  }
  .chip.low { color: #f0a738; background: rgba(240, 167, 56, 0.14); }
  .gate { background: rgba(20, 26, 23, 0.86); }
  .select-menu { box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3); }
}
