/* ============================================================ tokens */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --surface-3: #e8eaed;
  --text: #1f1f1f;
  --muted: #5f6368;
  --border: #dadce0;
  --border-soft: #e8eaed;
  --primary: #1a73e8;
  --primary-hover: #1b66c9;
  --primary-soft: #e8f0fe;
  --danger: #d93025;
  --success: #188038;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, .12), 0 1px 3px rgba(60, 64, 67, .08);
  --shadow-2: 0 4px 12px rgba(60, 64, 67, .15), 0 1px 3px rgba(60, 64, 67, .1);
  --shadow-3: 0 12px 32px rgba(60, 64, 67, .22);
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 40px;
  --topbar-h: 60px;
  --font: "Google Sans", "Segoe UI Variable", "Segoe UI", Roboto, -apple-system,
          BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131314;
    --bg-soft: #1b1c1e;
    --surface: #1e1f20;
    --surface-2: #2a2b2d;
    --surface-3: #35363a;
    --text: #e3e3e3;
    --muted: #9aa0a6;
    --border: #3c4043;
    --border-soft: #2f3033;
    --primary: #8ab4f8;
    --primary-hover: #a8c7fa;
    --primary-soft: #1f3049;
    --danger: #f28b82;
    --success: #81c995;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-2: 0 4px 14px rgba(0, 0, 0, .55);
    --shadow-3: 0 16px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #131314;
  --bg-soft: #1b1c1e;
  --surface: #1e1f20;
  --surface-2: #2a2b2d;
  --surface-3: #35363a;
  --text: #e3e3e3;
  --muted: #9aa0a6;
  --border: #3c4043;
  --border-soft: #2f3033;
  --primary: #8ab4f8;
  --primary-hover: #a8c7fa;
  --primary-soft: #1f3049;
  --danger: #f28b82;
  --success: #81c995;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, .55);
  --shadow-3: 0 16px 40px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ============================================================= base */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; display: block; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace; font-size: 13.5px; }

::selection { background: var(--primary-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ========================================================== topbar */
.topbar {
  flex: none;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 max(12px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1a73e8, #4285f4 45%, #34a853);
  color: #fff;
  box-shadow: var(--shadow-1);
}
.brand-mark svg { width: 20px; height: 20px; }

.brand-name {
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.pill {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 5px 12px;
}
.pill:empty { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: var(--tap); height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn.active { color: var(--primary); background: var(--primary-soft); }
.icon-btn[disabled] { opacity: .4; pointer-events: none; }

#uiLangBtn { font-size: 12px; font-weight: 600; letter-spacing: .04em; }

.ico-moon { display: none; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="dark"] .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-sun { display: none; }
  :root:not([data-theme="light"]) .ico-moon { display: block; }
}

/* ============================================================ tabs */
.tabs {
  flex: none;
  position: sticky;
  top: var(--topbar-h);
  z-index: 35;
  display: flex;
  gap: 8px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.tab svg { width: 18px; height: 18px; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
  font-weight: 500;
}

/* =========================================================== shell */
.shell {
  flex: 1;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-left)) 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

/* ========================================================= langbar */
.langbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.lang-side { display: flex; align-items: center; gap: 6px; min-width: 0; }
.lang-side[data-side="target"] { justify-content: flex-start; }

.quick { display: flex; gap: 6px; min-width: 0; overflow: hidden; }

.lang-chip, .lang-more {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.lang-chip:hover, .lang-more:hover { background: var(--surface-2); color: var(--text); }
.lang-chip.active {
  color: var(--primary);
  font-weight: 500;
  background: var(--primary-soft);
}
.lang-more { max-width: 100%; }
.lang-more svg { width: 18px; height: 18px; flex: none; }
.lang-more-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.swap-btn {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: transform .3s cubic-bezier(.2, .8, .3, 1), background .15s ease, color .15s ease;
}
.swap-btn:hover { background: var(--surface-2); color: var(--text); }
.swap-btn.spin { transform: rotate(180deg); }

/* ========================================================== panels */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  min-height: 260px;
}

.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 10px;
  min-width: 0;
}
.source-panel { border-right: 1px solid var(--border-soft); }
.target-panel { background: var(--bg-soft); }

#sourceText {
  flex: 1;
  width: 100%;
  min-height: 168px;
  padding: 0 34px 0 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 24px;
  line-height: 1.45;
  letter-spacing: -.005em;
  overflow: hidden;
}
#sourceText::placeholder { color: var(--muted); }
#sourceText.dense { font-size: 17px; line-height: 1.6; }

.clear-btn {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.clear-btn:hover { background: var(--surface-2); color: var(--text); }
.clear-btn svg { width: 18px; height: 18px; }

.output {
  flex: 1;
  min-height: 168px;
  font-size: 24px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}
.output.dense { font-size: 17px; line-height: 1.6; }
.output:empty + .output-placeholder { display: block; }

.output-placeholder {
  display: none;
  position: absolute;
  top: 18px; left: 20px;
  font-size: 24px;
  color: var(--muted);
  pointer-events: none;
}

.detected {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 6px;
  margin-bottom: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
}

.panel-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  min-height: 40px;
}
.foot-actions { display: flex; align-items: center; gap: 2px; }
.counter { margin-left: auto; font-size: 12px; color: var(--muted); }
.counter.over { color: var(--danger); font-weight: 600; }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.text-btn:hover { background: var(--primary-soft); }

.btn.translate-btn { flex: 0 0 auto; }
.btn.translate-btn[disabled] { box-shadow: none; }

/* loader */
.loader { display: flex; gap: 5px; padding: 4px 0; }
.loader span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--primary);
  opacity: .35;
  animation: bounce 1.2s infinite ease-in-out;
}
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .3; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* ======================================================== insights */
.insights { padding: 16px 20px; display: grid; gap: 14px; }
.insight-row { display: grid; gap: 6px; }
.insight-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.insight-values { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13.5px;
  cursor: pointer;
  border: 0;
  color: var(--text);
  transition: background .15s ease;
}
.chip:hover { background: var(--surface-3); }
.definition { display: grid; gap: 2px; padding: 8px 0; border-top: 1px solid var(--border-soft); }
.definition:first-of-type { border-top: 0; }
.definition-pos { font-size: 12px; font-style: italic; color: var(--muted); }
.definition-example { font-size: 13px; color: var(--muted); }
.romanization { font-size: 14px; color: var(--muted); }

/* ========================================================= history */
.history { padding: 6px 8px 8px; }
.history-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
}
.history-tabs { display: flex; gap: 4px; }
.hist-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.hist-tab.active { background: var(--surface-2); color: var(--text); font-weight: 500; }
.history-head .text-btn { margin-left: auto; }

.history-list { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.history-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s ease;
}
.history-item:hover { background: var(--surface-2); }
.history-text { min-width: 0; flex: 1; }
.history-src { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-dst { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-langs { font-size: 11px; color: var(--muted); white-space: nowrap; padding-top: 2px; }
.history-empty { padding: 22px 12px; text-align: center; color: var(--muted); font-size: 14px; }

/* ========================================================== drop UI */
.drop-card {
  padding: 44px 24px;
  border: 2px dashed var(--border);
  box-shadow: none;
  background: var(--bg-soft);
  transition: border-color .2s ease, background .2s ease;
}
.drop-card.dragover { border-color: var(--primary); background: var(--primary-soft); }
.drop-inner { display: grid; justify-items: center; gap: 8px; text-align: center; }
.drop-icon {
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  border-radius: 18px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 6px;
}
.drop-icon svg { width: 28px; height: 28px; }
.drop-title { margin: 0; font-size: 17px; font-weight: 500; }
.drop-inner .muted { margin: 0; font-size: 13.5px; max-width: 46ch; }
.drop-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }

.btn {
  height: 40px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-1);
}
:root[data-theme="dark"] .btn.primary { color: #08213f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn.primary { color: #08213f; }
}
.btn.primary:hover { background: var(--primary-hover); }
.btn.small { height: 36px; padding: 0 14px; font-size: 13px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* ===================================================== result cards */
.image-result, .doc-result { padding: 16px 18px; display: grid; gap: 16px; }

.image-preview {
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-radius: 12px;
  overflow: hidden;
  max-height: 320px;
}
.image-preview img { max-width: 100%; max-height: 320px; object-fit: contain; display: block; }

.image-texts, .doc-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.result-block {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bg-soft);
  min-width: 0;
}
.result-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.result-head .foot-actions { margin-left: auto; }
.result-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.6;
  min-height: 60px;
}
.result-body.scroll { max-height: 52vh; overflow-y: auto; }

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}

.doc-head { display: flex; align-items: center; gap: 12px; }
.doc-file { display: flex; align-items: center; gap: 12px; min-width: 0; }
.doc-file-ico { width: 34px; height: 34px; color: var(--primary); flex: none; }
.doc-name { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-head .foot-actions { margin-left: auto; }

.progress { height: 3px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .3s ease; }

/* ========================================================== footer */
.footer {
  flex: none;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.footer .dot { opacity: .5; }

/* =========================================================== modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(32, 33, 36, .45);
  backdrop-filter: blur(2px);
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal-card {
  width: min(640px, 100%);
  max-height: min(88dvh, 820px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-3);
  overflow: hidden;
  animation: pop .18s cubic-bezier(.2, .8, .3, 1);
}
@keyframes pop { from { transform: translateY(10px) scale(.985); opacity: 0; } }

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 12px 12px 22px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 500; }
.modal-head .icon-btn { margin-left: auto; }

.modal-body { padding: 18px 22px; overflow-y: auto; display: grid; gap: 18px; }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-soft);
}

.field { display: grid; gap: 7px; }
.field-label { font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); }

.field input[type="text"],
.field input[type="password"],
.field textarea,
.lock-card input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  outline: none;
  font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field textarea:focus, .lock-card input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; line-height: 1.5; }

.input-row { display: flex; gap: 8px; align-items: center; }
.input-row input { flex: 1; min-width: 0; }

/* [hidden] must beat the display rules above it */
[hidden] { display: none !important; }

/* searchable model picker */
.combo { position: relative; }

.combo-panel {
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
}

.combo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.combo-item:hover, .combo-item.cursor { background: var(--surface-2); }
.combo-item.selected { background: var(--primary-soft); }
.combo-main { min-width: 0; flex: 1; }
.combo-name {
  font-size: 13.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.combo-id {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.combo-tags { display: flex; gap: 4px; flex: none; }
.tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}
.tag.free { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.tag.vision { background: var(--primary-soft); color: var(--primary); }
.combo-note {
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.combo-vendor {
  padding: 10px 10px 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 999px;
}
.segmented button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 9px 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 500;
  box-shadow: var(--shadow-1);
}

.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }

.form-status { margin: 0; padding: 0 22px 16px; font-size: 13px; }
.form-status.ok { color: var(--success); }
.form-status.err { color: var(--danger); }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }

/* language picker */
.lang-modal-card { width: min(880px, 100%); }
.lang-search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--muted);
}
.lang-search input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 15px;
  padding: 6px 0;
}
.lang-grid {
  padding: 12px 14px 20px;
  overflow-y: auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 2px;
  align-content: start;
}
.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.lang-option:hover { background: var(--surface-2); }
.lang-option.selected { color: var(--primary); font-weight: 500; background: var(--primary-soft); }
.lang-option .native { color: var(--muted); font-size: 12px; }
.lang-group-title {
  grid-column: 1 / -1;
  padding: 14px 12px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}

/* =========================================================== toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 460px);
  padding: 12px 18px;
  border-radius: 10px;
  background: #202124;
  color: #e8eaed;
  font-size: 14px;
  box-shadow: var(--shadow-3);
  animation: toastIn .2s ease;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ============================================================ lock */
.lock {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}
.lock-card {
  width: min(380px, 100%);
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
  padding: 34px 28px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
}
.lock-icon {
  display: grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
}
.lock-icon svg { width: 26px; height: 26px; }
.lock-card h1 { margin: 0; font-size: 19px; font-weight: 500; }
.lock-card p { margin: 0; font-size: 13.5px; }
.lock-card input, .lock-card .btn { width: 100%; }

/* ===================================================== responsive */
@media (max-width: 900px) {
  .image-texts, .doc-columns { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --topbar-h: 56px; --radius: 14px; }

  .brand-name { font-size: 17px; }
  .pill { display: none; }
  .shell { padding: 14px 12px 32px; gap: 12px; }
  .tabs { padding: 10px 12px; }

  .langbar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    box-shadow: var(--shadow-1);
    gap: 2px;
  }
  .quick { display: none; }
  .lang-side { min-width: 0; }
  .lang-more {
    width: 100%;
    justify-content: center;
    height: 40px;
    font-weight: 500;
    color: var(--text);
    padding: 0 6px;
  }
  .swap-btn { width: 38px; height: 38px; border: 0; background: var(--surface-2); }

  .panels { grid-template-columns: 1fr; min-height: 0; }
  .source-panel { border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .panel { padding: 14px 16px 8px; }
  #sourceText { font-size: 20px; min-height: 118px; }
  .output, .output-placeholder { font-size: 20px; }
  .output { min-height: 96px; }
  .output-placeholder { top: 14px; left: 16px; }
  #sourceText.dense, .output.dense { font-size: 16px; }

  .combo-panel { max-height: 46vh; }

  /* comfortable touch targets */
  .icon-btn.small { width: 38px; height: 38px; }
  .clear-btn { width: 34px; height: 34px; top: 10px; right: 10px; }
  .chip { padding: 8px 14px; }
  .hist-tab, .text-btn { padding: 10px 14px; }
  .btn.translate-btn { height: var(--tap); padding: 0 22px; font-size: 14px; }

  .drop-card { padding: 32px 18px; }
  .image-result, .doc-result { padding: 14px; }
  .result-body.scroll { max-height: 40vh; }

  .modal { padding: 0; place-items: end stretch; }
  .modal-card {
    width: 100%;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    animation: sheet .22s cubic-bezier(.2, .8, .3, 1);
  }
  @keyframes sheet { from { transform: translateY(24px); opacity: .6; } }
  .modal-body { padding: 16px; }
  .lang-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .segmented { grid-auto-flow: row; border-radius: 14px; }
  .segmented button { border-radius: 10px; }
  .modal-foot { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .history-list { max-height: 300px; }
}

@media (max-width: 380px) {
  .lang-more { font-size: 13px; }
  #sourceText, .output, .output-placeholder { font-size: 18px; }
}

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