:root {
  --bg: #eef7f2;
  --bg-strong: #dfeee8;
  --surface: rgba(255, 255, 252, 0.88);
  --surface-raised: rgba(255, 255, 255, 0.96);
  --soft: #eaf4ef;
  --ink: #10201b;
  --muted: #5c756d;
  --accent: #2f9b83;
  --accent-strong: #1f806d;
  --accent-glow: rgba(69, 194, 166, 0.24);
  --line: rgba(47, 155, 131, 0.22);
  --line-strong: rgba(31, 128, 109, 0.34);
  --danger: #b4533f;
  --warning-bg: rgba(244, 159, 67, 0.14);
  --warning-line: rgba(180, 83, 63, 0.28);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 24px 70px rgba(34, 70, 58, 0.13);
  --focus: 0 0 0 3px rgba(47, 155, 131, 0.24);
  --maxw: 1120px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1715;
    --bg-strong: #10211d;
    --surface: rgba(20, 35, 31, 0.9);
    --surface-raised: rgba(21, 39, 34, 0.96);
    --soft: #0d1916;
    --ink: #f4f7f5;
    --muted: #9db6ad;
    --accent: #4cc3a6;
    --accent-strong: #2e9d87;
    --accent-glow: rgba(76, 195, 166, 0.18);
    --line: rgba(76, 195, 166, 0.2);
    --line-strong: rgba(76, 195, 166, 0.34);
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 10% -8%, var(--accent-glow), transparent 32rem),
    radial-gradient(circle at 100% 0%, rgba(31, 128, 109, 0.12), transparent 34rem),
    linear-gradient(180deg, var(--bg), var(--bg-strong));
  color: var(--ink);
  font: 500 15px/1.55 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.34;
  background-image:
    linear-gradient(rgba(47, 155, 131, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47, 155, 131, 0.045) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button, input, select, textarea, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.wrap {
  width: min(100% - 32px, var(--maxw));
  margin: 0 auto;
  padding: 28px 0 34px;
  position: relative;
}
.wrap-narrow { width: min(100% - 32px, 860px); }

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.brand-row { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 50px !important;
  height: 50px !important;
  max-width: 50px;
  max-height: 50px;
  flex: 0 0 auto;
  display: block;
  overflow: hidden;
  line-height: 0;
  border-radius: 10px;
  align-self: flex-start;
  margin-top: 2px;
}
.brand-mark img {
  width: 50px !important;
  height: 50px !important;
  max-width: 50px;
  max-height: 50px;
  display: block;
  object-fit: cover;
}
.title {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.65rem);
  line-height: 0.95;
  letter-spacing: -0.055em;
}
.subtitle { margin: 8px 0 0; color: var(--muted); max-width: 620px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.pill, .engine-tab, .link-pill {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.44);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.engine-name { font-weight: 800; }
.engine-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 10px; }
.engine-tab { min-height: 44px; font-weight: 800; }
.engine-tab.active, .primary-action, .btn.primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  box-shadow: 0 12px 28px rgba(47, 155, 131, 0.22);
}

.notice {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--warning-line);
  border-radius: var(--radius-sm);
  background: var(--warning-bg);
  color: var(--ink);
}
.notice strong { display: block; margin-bottom: 2px; }

.form-stack { display: grid; gap: 12px; }
.language-card, .translation-card, .share-card, .settings-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}
.language-card { padding: 14px; }
.language-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}
.field { display: grid; gap: 7px; min-width: 0; }
.field-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
input, select, textarea {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--soft);
  color: var(--ink);
}
input, select { min-height: 50px; padding: 12px 14px; }
textarea {
  display: block;
  min-height: 196px;
  resize: vertical;
  border: 0;
  background: transparent;
  padding: 16px;
  line-height: 1.62;
}
textarea::placeholder, input::placeholder { color: color-mix(in srgb, var(--muted), transparent 10%); }

.swap-button {
  width: 52px;
  min-width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 255, 255, 0.45), transparent 42%),
    var(--soft);
  color: var(--accent-strong);
  font-size: 1.15rem;
  font-weight: 900;
}

.translation-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.translation-card { overflow: hidden; }
.card-header, .settings-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 13px 16px;
  border-bottom: 1px dashed var(--line);
}
.card-title { font-weight: 900; }
.card-meta { color: var(--muted); font-size: 0.86rem; }
.output-empty {
  color: var(--muted);
}
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px dashed var(--line);
}

.primary-action {
  min-height: 54px;
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 13px 18px;
  font-weight: 900;
}
.primary-action:hover, .btn.primary:hover, .engine-tab.active:hover { filter: brightness(1.02); }

.share-card { padding: 14px; }
.share-card.disabled { opacity: 0.82; }
.share-title { margin: 0; font-weight: 900; }
.share-help { margin: 4px 0 0; color: var(--muted); }
.share-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 10px;
}
.share-input { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.btn, .btn-copy {
  min-height: 46px;
  min-width: 72px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--soft);
  color: var(--ink);
  font-weight: 800;
}
.btn-copy { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--accent-strong), var(--accent)); }

.defsgrid { display: grid; gap: 12px; }
.def-card { padding: 16px; }
.def_type { color: var(--accent-strong); text-transform: capitalize; font-weight: 800; }
.syn, .muted { color: var(--muted); }
.syn_type, .use_in_sentence { color: var(--accent-strong); }

.footer-links {
  min-height: 52px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  color: var(--muted);
}
.footer-links a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--accent-strong);
  font-weight: 800;
}

.toasts {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 420px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow);
  transform: translateY(8px);
  opacity: 0;
  animation: toast-in 0.18s ease forwards;
}
.toast.success { border-left: 6px solid var(--accent); }
.toast.warn { border-left: 6px solid #f59e0b; }
.toast.error { border-left: 6px solid #ef4444; }
.toast .close {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}
@keyframes toast-in { to { transform: translateY(0); opacity: 1; } }
@keyframes toast-out { to { transform: translateY(8px); opacity: 0; } }

.settings-card .content { padding: 8px 16px 16px; }
.settings-form { display: grid; gap: 14px; }
.setting-row {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0;
  border-bottom: 1px dashed var(--line);
  cursor: pointer;
}
.setting-row:last-of-type { border-bottom: 0; }
.setting-title { font-weight: 900; }
.setting-description { color: var(--muted); }
.switch-control {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 44px;
}
.switch-control input {
  appearance: none;
  -webkit-appearance: none;
  width: 64px;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--soft);
  cursor: pointer;
}
.switch-control input::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 5px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-raised);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s ease;
}
.switch-control input:checked { background: linear-gradient(135deg, var(--accent-strong), var(--accent)); border-color: transparent; }
.switch-control input:checked::after { transform: translateX(20px); }
.settings-actions { display: flex; justify-content: flex-end; padding-top: 4px; }

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

@media (max-width: 760px) {
  .wrap { width: min(100% - 28px, var(--maxw)); padding-top: 24px; }
  .site-header { align-items: flex-start; }
  .brand-row { align-items: flex-start; }
  .brand-mark {
    width: 42px !important;
    height: 42px !important;
    max-width: 42px;
    max-height: 42px;
  }
  .brand-mark img {
    width: 42px !important;
    height: 42px !important;
    max-width: 42px;
    max-height: 42px;
  }
  .header-actions { max-width: 44%; }
  .pill { min-height: 38px; padding: 7px 10px; }
  .engine-tabs { margin-top: 14px; }
  .language-row { grid-template-columns: 1fr; }
  .swap-button { justify-self: center; transform: rotate(90deg); }
  .translation-grid { grid-template-columns: 1fr; }
  textarea { min-height: 180px; }
  .share-controls { grid-template-columns: 1fr auto; }
  .setting-row { align-items: flex-start; }
}

@media (max-width: 430px) {
  .site-header { display: grid; grid-template-columns: 1fr; }
  .header-actions { max-width: none; justify-content: flex-start; }
  .share-controls { grid-template-columns: minmax(0, 1fr) auto; }
  .btn-copy { min-width: 70px; }
}
