:root {
  --page: #f4f4f4;
  --card: #ffffff;
  --ink: #111111;
  --mute: #6b6b6b;
  --line: #e4e4e4;
  --soft: #f2f2f2;
  --red: #e5251b;
  --red-hover: #c81d14;
  --on-red: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);

  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --r: 16px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0b0b0b; --card: #161616; --ink: #f5f5f5; --mute: #9c9c9c;
    --line: #2a2a2a; --soft: #202020; --red: #ff3d33; --red-hover: #ff5a51;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0b0b0b; --card: #161616; --ink: #f5f5f5; --mute: #9c9c9c;
  --line: #2a2a2a; --soft: #202020; --red: #ff3d33; --red-hover: #ff5a51;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--page); color: var(--ink);
  font: 400 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; text-underline-offset: 3px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.eyebrow { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--mute); margin: 0; }

/* ---------- Nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--page) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.nav__inner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1200px; margin: 0 auto; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  min-height: 60px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand__mark {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 10px;
  background: var(--red); color: #fff;
  box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--red) 70%, transparent);
  transition: transform 0.35s var(--ease);
}
.brand__mark svg { width: 20px; height: 20px; stroke-width: 2.2; }
.brand:hover .brand__mark { transform: rotate(-8deg); }
.brand__text { display: grid; line-height: 1.05; min-width: 0; }
.brand__kicker { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--mute); }
.brand__name { font-size: 1.06rem; font-weight: 800; letter-spacing: -0.015em; white-space: nowrap; }
.nav__badge {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--card);
  font-size: 0.78rem; font-weight: 600; color: var(--ink); white-space: nowrap;
}
.nav__badge i { position: relative; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.nav__badge i::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--red);
  animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@media (max-width: 419px) { .nav__badge { display: none; } }

/* ---------- Intro ---------- */
.intro { width: 100%; max-width: 1200px; margin: 0 auto; padding: 22px 16px 18px; }
.intro__title {
  margin: 0; font-size: clamp(1.7rem, 7.4vw, 2.75rem); font-weight: 800; line-height: 1.08;
  letter-spacing: -0.03em; text-wrap: balance; animation: fadeUp 0.5s var(--ease) both;
}
.intro__title span { color: var(--red); }
.intro__sub {
  margin: 6px 0 0; color: var(--mute); font-size: 1rem; line-height: 1.45; text-wrap: pretty;
  animation: fadeUp 0.5s 0.06s var(--ease) both;
}

/* ---------- App ---------- */
.app { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px 8px; flex: 1; }

.langbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--r) var(--r) 0 0; padding: 6px 8px;
}
.langbar__lang { padding: 8px 12px; font-weight: 700; font-size: 0.98rem; text-align: center; }
.langbar__lang:first-child { color: var(--red); }
.swap {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  transition: transform 0.4s var(--ease), background 0.2s, border-color 0.2s;
}
.swap:hover { background: var(--soft); border-color: var(--mute); }
.swap.is-spun { transform: rotate(180deg); }

.panes {
  display: grid; background: var(--card); border: 1px solid var(--line);
  border-radius: 0 0 var(--r) var(--r); box-shadow: var(--shadow); overflow: hidden;
}
.pane { position: relative; min-width: 0; display: flex; flex-direction: column; }
.pane--in { border-bottom: 1px solid var(--line); }
.pane--out { background: var(--soft); min-height: 160px; }

textarea {
  flex: 1; display: block; width: 100%; min-height: 168px; max-height: 60vh; resize: none;
  border: 0; background: transparent; padding: 18px 48px 10px 18px;
  font-size: 1.25rem; line-height: 1.45;
}
textarea:focus { outline: none; }
textarea::placeholder { color: var(--mute); opacity: 0.7; }
.pane__clear { position: absolute; top: 12px; right: 10px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: none; color: var(--mute); transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }

.styles { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 18px 12px; }
.style-btn {
  flex: none; min-height: 38px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: 0.88rem; font-weight: 500; white-space: nowrap;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.style-btn:hover { border-color: var(--mute); }
.style-btn[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--card); }

.pane__bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px 12px; border-top: 1px solid var(--line);
}
.count { margin-left: auto; color: var(--mute); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.text-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 10px; border-radius: 10px;
  border: 0; background: none; color: var(--mute); font-size: 0.9rem; font-weight: 500;
  transition: background 0.2s, color 0.2s;
}
.text-btn:hover { background: var(--soft); color: var(--ink); }
.pane--out .text-btn:hover { background: var(--card); }

.cta {
  flex: 1 0 100%; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 12px; padding: 14px 22px;
  background: var(--red); color: var(--on-red); font-size: 1.02rem; font-weight: 700;
  transition: background 0.2s, transform 0.15s var(--ease);
}
.cta:hover { background: var(--red-hover); }
.cta:active { transform: scale(0.98); }
.cta:disabled { cursor: progress; opacity: 0.85; }
.cta__kbd { display: none; font: 600 0.7rem/1 var(--font); opacity: 0.8; border: 1px solid currentColor; border-radius: 5px; padding: 3px 5px; }

/* ---------- Output ---------- */
.empty { padding: 18px; }
.empty__ph { margin: 0; font-size: 1.25rem; color: var(--mute); opacity: 0.7; }
.empty__fact { margin: 14px 0 0; font-size: 0.88rem; color: var(--mute); transition: opacity 0.4s; }

.result { padding: 18px; display: grid; gap: 16px; scroll-margin-top: 12px; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--mute); }
#loadingText { transition: opacity 0.25s; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--red); animation: bounce 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

.translation {
  margin: 0; font-size: 1.3rem; line-height: 1.45; font-weight: 500;
  white-space: pre-line; text-wrap: pretty; animation: fadeUp 0.4s var(--ease) both;
}
.translation:empty { display: none; }
.error { margin: 0; color: var(--red); font-weight: 600; }

.caret::after {
  content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 2px;
  vertical-align: -0.2em; background: var(--red); animation: blink 0.9s steps(2) infinite;
}
.result__actions { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 -10px -6px; }

/* ---------- Buzzword cloud ---------- */
.cloud { margin-top: 32px; text-align: center; }
.cloud__words {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: 0 10px; max-width: 920px; margin: 10px auto 0; padding: 8px 0 12px;
}
.word {
  --s: 1rem; --w: 500; --d: 6s; --delay: 0s; --dx: 0px; --dy: -5px; --rot: 0deg;
  border: 0; background: none; padding: 9px 7px; border-radius: 8px;
  font-size: var(--s); font-weight: var(--w); line-height: 1.1; color: var(--ink);
  white-space: nowrap;
  animation: drift var(--d) ease-in-out var(--delay) infinite, cloudIn 0.6s var(--in, 0s) var(--ease) both;
  transition: color 0.2s, scale 0.25s var(--ease), opacity 0.45s, filter 0.45s;
}
.word--red { color: var(--red); }
.word--mute { color: var(--mute); }
.word:hover { color: var(--red); scale: 1.08; }
.word__txt { display: inline-block; }

/* ---------- Footer & toast ---------- */
.colophon {
  width: 100%; max-width: 1200px; margin: 0 auto; text-align: center;
  padding: 28px 16px max(28px, calc(env(safe-area-inset-bottom) + 16px));
  color: var(--mute); font-size: 0.8rem;
}
.colophon__by { margin: 0 0 10px; font-size: 0.92rem; color: var(--ink); }
.colophon__by a {
  display: inline-flex; align-items: center; gap: 7px; margin-left: 4px;
  font-weight: 700; text-decoration: none; padding: 10px 2px;
  background-image: linear-gradient(var(--red), var(--red)); background-repeat: no-repeat;
  background-size: 0 2px; background-position: 100% 85%;
  transition: background-size 0.35s var(--ease);
}
.colophon__by a:hover { background-size: 100% 2px; background-position: 0 85%; }
.colophon__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none; }
.colophon__note { margin: 0 auto; max-width: 44em; line-height: 1.5; }
.toast {
  position: fixed; left: 50%; bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px)); z-index: 20;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 10px;
  font-size: 0.9rem; font-weight: 500; transition: opacity 0.25s, transform 0.35s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Desktop ---------- */
@media (min-width: 860px) {
  .nav__inner { padding-inline: 24px; min-height: 68px; }
  .intro { padding: 40px 24px 26px; }
  .intro__sub { font-size: 1.08rem; }
  textarea { max-height: none; }
  .app { padding: 0 24px 32px; }
  .langbar { padding: 6px; }
  .langbar__lang { text-align: left; padding-left: 14px; }
  .langbar__lang:last-child { padding-left: 24px; }
  .panes { grid-template-columns: 1fr 1fr; min-height: 440px; }
  .pane--in { border-bottom: 0; border-right: 1px solid var(--line); }
  textarea { font-size: 1.4rem; padding: 22px 52px 12px 22px; }
  .styles { padding: 4px 22px 12px; }
  .pane__bar { flex-wrap: nowrap; padding: 12px 14px; }
  .cta { flex: none; }
  .cta__kbd { display: inline-block; }
  .empty, .result { padding: 22px; }
  .empty__ph, .translation { font-size: 1.45rem; }
  .cloud { margin-top: 36px; }
  .colophon { padding: 40px 24px 36px; }
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-4px); opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes ping { 75%, 100% { transform: scale(2.6); opacity: 0; } }
@keyframes drift {
  0%, 100% { transform: translate(0, 0) rotate(var(--rot)); }
  50% { transform: translate(var(--dx), var(--dy)) rotate(calc(var(--rot) * -1)); }
}
@keyframes cloudIn { from { opacity: 0; filter: blur(6px); } to { opacity: 1; filter: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
