/* Babelfish SPA — responsive, dark/light from the device preference. */

:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-inset: #f0f2f5;
  --fg: #14161a;
  --fg-muted: #5c636e;
  --fg-faint: #868d99;
  --line: #dfe3e9;
  --line-strong: #c8ced8;
  --accent: #3b5bdb;
  --accent-fg: #ffffff;
  --accent-soft: rgba(59, 91, 219, 0.10);
  --ok: #1f8b4c;
  --err: #c0392b;
  --warn: #a8620a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 28, .06), 0 8px 24px rgba(16, 20, 28, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --bg-elev: #16191e;
    --bg-inset: #1c2027;
    --fg: #e8eaee;
    --fg-muted: #a2a9b5;
    --fg-faint: #78808d;
    --line: #2a2f38;
    --line-strong: #3a414c;
    --accent: #7b94ff;
    --accent-fg: #0b0d10;
    --accent-soft: rgba(123, 148, 255, 0.14);
    --ok: #57c98a;
    --err: #ff7b6b;
    --warn: #e0a45a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 520px at 12% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: max(12px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
}

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
.slash { color: var(--fg-faint); font-weight: 400; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  max-width: 1180px;
  margin: 4px auto 14px;
  padding: 0 2px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { min-width: 0; }
.brand .mark {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 17px;
}
.sub { margin: 1px 0 0; font-size: 12px; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.top-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* Language switch: shows the current language and the one a click moves to. */
.lang-btn {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.lang-from { font-weight: 600; color: var(--fg); }
.lang-arrow { color: var(--fg-faint); font-size: 12px; line-height: 1; }
.lang-to { font-weight: 600; color: var(--accent); }
.lang-btn:hover:not(:disabled) .lang-arrow { color: var(--accent); }

.grid {
  display: grid;
  gap: 14px;
  max-width: 1180px;
  margin: 0 auto;
  grid-template-columns: 1fr;
  align-items: start;
}

@media (min-width: 1000px) {
  .grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); }
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.pill {
  font-size: 11px;
  color: var(--fg-muted);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pill[data-tone="warn"] { color: var(--warn); border-color: var(--warn); }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

label { display: block; font-size: 12.5px; color: var(--fg-muted); margin-bottom: 6px; }

.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.counter { font-size: 11.5px; color: var(--fg-faint); font-variant-numeric: tabular-nums; }
.counter[data-tone="warn"] { color: var(--warn); }
.counter[data-tone="err"] { color: var(--err); }

textarea, input, select {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}

textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
textarea#system-prompt { font-size: 13px; }

textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%),
                    linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

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

.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

button {
  font: inherit;
  font-size: 13.5px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s, transform .04s;
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.secondary { background: var(--bg-inset); color: var(--fg); border-color: var(--line-strong); }
.secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.ghost { background: transparent; color: var(--fg-muted); border-color: var(--line); }
.ghost:hover:not(:disabled) { color: var(--fg); border-color: var(--line-strong); }
.small { font-size: 12px; padding: 5px 9px; }

.status { font-size: 12.5px; color: var(--fg-muted); min-height: 1.2em; }
.status[data-tone="err"] { color: var(--err); }
.status[data-tone="ok"] { color: var(--ok); }

.detect { margin-left: auto; font-size: 11.5px; color: var(--fg-faint); }

.hint, .hint-line {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--fg-muted);
  line-height: 1.5;
}
.hint { background: var(--bg-inset); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; }
.hint p { margin: 0 0 4px; }
.hint p:last-child { margin-bottom: 0; }
.hint-line { margin-top: 6px; }
code { font-family: var(--mono); font-size: 11.5px; background: var(--bg-inset); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; word-break: break-all; }
.hint code { background: transparent; border: 0; padding: 0; }

/* Tabs: mobile only */
.tabs {
  display: flex;
  gap: 6px;
  max-width: 1180px;
  margin: 0 auto 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.tab {
  flex: 1 1 50%;
  background: transparent;
  color: var(--fg-muted);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
}
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  padding: 0;
  width: min(560px, calc(100vw - 28px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(8, 10, 14, .45); backdrop-filter: blur(2px); }
.dialog-inner { padding: 16px; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; font-size: 13.5px; }
.stats dt, .stats .k { color: var(--fg-muted); }
.stats .v { text-align: right; font-variant-numeric: tabular-nums; }
.stats .sep { grid-column: 1 / -1; border-top: 1px solid var(--line); margin: 4px 0; }
.stats .langs { grid-column: 1 / -1; color: var(--fg-muted); font-size: 12.5px; }
.stats .empty { grid-column: 1 / -1; color: var(--fg-faint); text-align: center; padding: 10px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 28px));
  background: var(--fg);
  color: var(--bg-elev);
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 430px) {
  body { padding-left: 10px; padding-right: 10px; }
  h1 { font-size: 14.5px; }
  .brand .mark { width: 28px; height: 28px; flex-basis: 28px; font-size: 15px; }
  .brand-text { min-width: 0; }
  .brand { flex: 1 1 auto; }
  .top-actions { gap: 6px; }
  .lang-btn { padding: 6px 9px; font-size: 12px; gap: 4px; }
  #lang-btn .lang-arrow { font-size: 11px; }
  .card { padding: 13px; }
  .detect { margin-left: 0; flex-basis: 100%; }
  #stats-btn { padding: 7px 10px; font-size: 12px; }
}

/* Desktop / wide tablet: both cards side by side, tab switcher redundant.
   These rules come last on purpose — .tabs is declared above as flex. */
@media (min-width: 1000px) {
  .tabs { display: none; }
  .card[hidden] { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
