:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e4e8ef;
  --border-strong: #d4dae3;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eef3fe;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.12);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #171b22;
    --border: #262c36;
    --border-strong: #323a46;
    --text: #e7eaf0;
    --muted: #9aa4b2;
    --accent: #4f8cff;
    --accent-dark: #6ea0ff;
    --accent-soft: #1a2436;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 19px;
  box-shadow: var(--shadow-sm);
}

.brand h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ghost-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.ghost-btn.small {
  padding: 4px 10px;
  font-size: 12px;
}

.ghost-btn .icon {
  font-size: 14px;
}

/* ---------- Layout ---------- */
.layout {
  max-width: 1080px;
  margin: 28px auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

.layout.with-history {
  grid-template-columns: 1fr 300px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- Language bar ---------- */
.lang-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.lang-select,
.voice-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--card);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s;
}

.lang-select:focus,
.voice-select:focus {
  outline: none;
  border-color: var(--accent);
}

.swap-btn {
  border: 1px solid var(--border-strong);
  background: var(--card);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--accent);
  transition: background 0.15s, transform 0.2s;
}

.swap-btn:hover {
  background: var(--accent-soft);
}

.swap-btn:active {
  transform: rotate(180deg);
}

/* ---------- Panes ---------- */
.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 260px;
  border-right: 1px solid var(--border);
}

.pane.output {
  border-right: none;
  background: color-mix(in srgb, var(--card) 96%, var(--accent));
}

.text-area {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 20px;
  font-size: 18px;
  line-height: 1.55;
  font-family: inherit;
  background: transparent;
  color: var(--text);
}

.output-text {
  white-space: pre-wrap;
  overflow-y: auto;
}

.output-text:empty::before {
  content: "Translation";
  color: var(--muted);
}

.output-text.loading {
  opacity: 0.5;
}

.pane-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  min-height: 46px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 7px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.counter {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.status {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.voice-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 28px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.primary-btn:active {
  transform: translateY(1px);
}

.primary-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ---------- History ---------- */
.history-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  max-height: 70vh;
  overflow-y: auto;
  position: sticky;
  top: 92px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.history-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.history-item .hi-langs {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-item .hi-src {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .hi-tgt {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.history-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
}

/* ---------- Login ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 50;
}

.login-overlay[hidden] {
  display: none;
}

.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 40px 34px;
  width: min(370px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.logo.big {
  width: 52px;
  height: 52px;
  font-size: 28px;
  border-radius: 14px;
  margin-bottom: 8px;
}

.login-box h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 650;
}

.login-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.login-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 8px;
  background: var(--card);
  color: var(--text);
}

.login-input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-btn {
  width: 100%;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 4px 0 0;
}

/* ---------- Misc ---------- */
.hint {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 32px;
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 860px) {
  .layout.with-history {
    grid-template-columns: 1fr;
  }

  .history-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 560px) {
  .panes {
    grid-template-columns: 1fr;
  }

  .pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}