/* ==========================================================================
   Translate — tool styling
   Dense, keyboard-first, monochrome with one accent. Light and dark parity.
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-sunken: #f7f8fa;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --text: #14161a;
  --text-muted: #6b7280;
  --text-faint: #9aa1a9;
  --accent: #1a56db;
  --accent-hover: #1544b0;
  --accent-soft: #eef3ff;
  --danger: #b42318;
  --ok: #067647;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 12px rgb(16 24 40 / 6%);
  --radius: 10px;
  --bar-h: 48px;
  --status-h: 32px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #14161a;
  --bg-sunken: #0e1013;
  --surface: #191c21;
  --border: #2a2e35;
  --border-strong: #3a404a;
  --text: #e8eaed;
  --text-muted: #9aa1a9;
  --text-faint: #6b7280;
  --accent: #6f9bff;
  --accent-hover: #8db0ff;
  --accent-soft: #1b2438;
  --danger: #ff8a80;
  --ok: #5bd6a0;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 30%);
}

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

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.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;
}

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

/* ---------------------------------------------------------------- top bar */

.bar {
  height: var(--bar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.bar-left, .bar-right { display: flex; align-items: center; gap: 8px; }

.brand {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.engine {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-sunken);
  white-space: nowrap;
}

.engine[data-state="live"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.engine[data-state="error"] { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

/* ------------------------------------------------------------ icon buttons */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px; height: 30px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}

.icon-btn:hover:not(:disabled) {
  background: var(--bg-sunken);
  border-color: var(--border);
  color: var(--text);
}

.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.text-btn {
  border: 0; background: transparent; cursor: pointer;
  color: var(--text-muted); font: inherit; font-size: 12px;
  padding: 4px 6px; border-radius: 5px;
}
.text-btn:hover { color: var(--text); background: var(--bg-sunken); }

/* Theme icon swap */
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* -------------------------------------------------------------- workspace */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  padding: 12px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel:focus-within { border-color: var(--border-strong); }

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px 7px 10px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, var(--bg-sunken));
}

.head-actions { display: flex; align-items: center; gap: 2px; }

/* ------------------------------------------------------------- lang select */

.select-wrap { position: relative; display: flex; min-width: 0; }

.select-wrap::after {
  content: "";
  position: absolute; right: 10px; top: 50%;
  width: 5px; height: 5px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 4px 26px 4px 4px;
  border-radius: 6px;
  cursor: pointer;
  max-width: 100%;
  text-overflow: ellipsis;
}

select:hover { background: var(--bg-sunken); }
select option { background: var(--surface); color: var(--text); }

/* ----------------------------------------------------------------- editors */

.editor {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding: 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.65;
  resize: none;
  overflow-y: auto;
  overflow-wrap: anywhere;
}

.editor:focus { outline: none; }
.editor::placeholder { color: var(--text-faint); }

.output {
  white-space: pre-wrap;
  cursor: text;
}

.output:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
}

.output mark {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  margin-bottom: -2px;
  border: 1.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- panel foot */

.panel-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, var(--bg-sunken));
}

.meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta.warn { color: var(--danger); }
.meta.ok { color: var(--ok); }

/* -------------------------------------------------------------- swap column */

.swap-col {
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.swap {
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text-muted);
}
.icon-btn.swap:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn.swap.spin svg { animation: flip .45s ease; }

@keyframes flip {
  0% { transform: rotate(0); }
  50% { transform: rotate(180deg); }
  100% { transform: rotate(360deg); }
}

/* -------------------------------------------------------------- status bar */

.statusbar {
  flex: 0 0 auto;
  height: var(--status-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.statusbar .spacer { flex: 1; }
.statusbar kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 4px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-sunken);
}

.statusbar .footer-link {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
  text-decoration: none;
}
.statusbar .footer-link:hover { color: var(--accent); }

#status-text[data-tone="error"] { color: var(--danger); }
#status-text[data-tone="busy"] { color: var(--accent); }

/* ----------------------------------------------------------------- history */

.history {
  position: fixed;
  top: calc(var(--bar-h) + 8px);
  right: 8px;
  width: min(380px, calc(100vw - 16px));
  max-height: min(60vh, 520px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgb(0 0 0 / 18%);
  z-index: 40;
  overflow: hidden;
}

.history-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.history-head > div { display: flex; align-items: center; gap: 2px; }

.history-list { list-style: none; overflow-y: auto; }

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.history-item:hover { background: var(--bg-sunken); }
.history-item:last-child { border-bottom: 0; }

.history-item .pair {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.history-item .snippet {
  font-size: 13px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-empty { padding: 22px 12px; text-align: center; font-size: 13px; color: var(--text-faint); }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--status-h) + 14px);
  transform: translateX(-50%);
  padding: 8px 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  border-radius: 7px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 24%);
  z-index: 60;
  animation: rise .16s ease;
}

.toast[data-tone="error"] { background: var(--danger); color: #fff; }

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto 1fr;
  }
  .swap-col { padding: 2px 0; }
  .icon-btn.swap svg { transform: rotate(90deg); }
  .statusbar kbd { display: none; }
  .statusbar { justify-content: center; }
  .statusbar .spacer { display: none; }
  .editor { font-size: 16px; padding: 13px; }
}

@media (max-width: 420px) {
  .brand { font-size: 13px; }
  .engine { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
}

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