:root {
  --bg: #0d0f13;
  --bg-2: #13161c;
  --surface: #181c24;
  --surface-2: #1f2430;
  --line: rgba(255, 255, 255, .07);
  --text: #f3efe6;
  --text-2: #b9b4aa;
  --muted: #7c7a74;
  --accent: #8be3cf;
  --accent-ink: #0c2a24;
  --amber: #f2c46d;
  --red: #f0857a;
  --radius: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --caption-size: 30px;
  --dock-h: 76px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(139, 227, 207, .07), transparent 60%),
    var(--bg);
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

svg { display: block; }

/* ---------- App shell ---------- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-2);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
}

@media (max-width: 420px) {
  .topbar { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .status { font-size: 12px; padding: 0 10px 0 8px; gap: 6px; }
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-state="live"] { color: var(--accent); }
.status[data-state="live"] .dot { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.status[data-state="paused"] { color: var(--amber); }
.status[data-state="paused"] .dot { background: var(--amber); }
.status[data-state="connecting"] .dot,
.status[data-state="reconnecting"] .dot,
.status[data-state="stopping"] .dot { background: var(--amber); animation: pulse .8s ease-in-out infinite; }
.status[data-state="offline"] { color: var(--red); }
.status[data-state="offline"] .dot { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.75); }
}

.spacer { flex: 1; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--accent); }

.lang-toggle {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text-2);
  border: 1px solid var(--line);
}

.lang-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- Stream ---------- */

.stream-wrap {
  position: relative;
  min-height: 0;
}

.stream {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px max(16px, 4vw) calc(var(--dock-h) + 48px);
  scroll-behavior: smooth;
  scrollbar-width: none;
}

.stream::-webkit-scrollbar { display: none; }

.stream-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.block {
  position: relative;
  padding: 10px 14px;
  margin: 0 -14px;
  border-radius: var(--radius);
  font-size: var(--caption-size);
  line-height: 1.38;
  font-weight: 500;
  letter-spacing: -.005em;
  color: var(--text);
  transition: background .2s, opacity .4s, color .4s, box-shadow .2s;
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}

.block.old { color: var(--text-2); }

/* Blocks are only tappable in edit mode, so a finger can scroll freely. */
.block { cursor: default; }
.editing .block { cursor: pointer; box-shadow: inset 0 0 0 1px var(--line); }
.editing .block:hover { background: rgba(255, 255, 255, .03); }

.edit-banner {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  z-index: 5;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  animation: pop .2s ease-out;
}

.edit-banner[hidden] { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.block .ru { display: block; }
.block .bg { display: none; }
.block.degraded .ru { color: var(--muted); font-style: italic; }

.block.speaker-change { margin-top: 14px; }

.marker {
  align-self: center;
  margin: 14px 0;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
}

/* Bilingual: one row, two cells, aligned by construction. */
.bilingual .block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  font-size: calc(var(--caption-size) * .78);
}

.bilingual .block .bg {
  display: block;
  color: var(--muted);
  font-size: .82em;
  font-weight: 400;
  line-height: 1.45;
}

.bilingual .block .ru { order: 2; }
.bilingual .block .bg { order: 1; }

.bilingual .stream-head { display: grid; }

.stream-head {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 980px;
  margin: 0 auto 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  color: var(--muted);
}

/* Selected block: frozen view with tappable Bulgarian words. */
/* Room below so even the newest block can scroll up under the pill. */
.stream.frozen { padding-bottom: 75vh; }

.block { scroll-margin-top: 60px; }

.block.selected {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), 0 18px 40px -20px rgba(0, 0, 0, .7);
  cursor: default;
}

.block .words {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  grid-column: 1 / -1;
  order: 3;
}

.block.selected .words { display: flex; }

.word {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  transition: background .15s, color .15s;
}

.word:hover, .word:focus-visible { background: var(--accent); color: var(--accent-ink); outline: none; }

.words-hint {
  width: 100%;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .02em;
}

/* Live (composing) row */
.live {
  min-height: 48px;
  padding: 10px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: calc(var(--caption-size) * .6);
  font-style: italic;
}

.live .typing { display: inline-flex; gap: 5px; opacity: 0; transition: opacity .25s; }
.live.speaking .typing { opacity: 1; }
.live .typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing 1.2s infinite ease-in-out;
}
.live .typing i:nth-child(2) { animation-delay: .15s; }
.live .typing i:nth-child(3) { animation-delay: .3s; }

@keyframes typing {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}

.live .live-bg { display: none; }
.bilingual .live .live-bg {
  display: block;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Empty state */
.empty {
  position: absolute;
  inset: 0 0 var(--dock-h);
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  padding: 24px;
}

.empty .big {
  font-size: 26px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.empty[hidden] { display: none; }

/* Floating pills over the stream */
.float-pill {
  position: absolute;
  left: 50%;
  top: 8px;
  z-index: 5;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 30px -8px rgba(0, 0, 0, .7);
  animation: pop .2s ease-out;
}

.float-pill[hidden] { display: none; }

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

/* ---------- Dock ---------- */

.dock {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  height: var(--dock-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 999px;
  background: rgba(24, 28, 36, .92);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px -18px rgba(0, 0, 0, .8);
}

.main-btn {
  height: 56px;
  min-width: 56px;
  padding: 0 22px 0 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 700;
  transition: transform .12s, background .2s;
}

.main-btn:active { transform: scale(.96); }
.main-btn.pause { background: var(--surface-2); color: var(--text); }
.main-btn.resume { background: var(--amber); color: #3a2a06; }
.main-btn:disabled { opacity: .6; cursor: default; }

.stop-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--red);
  transition: transform .12s, opacity .2s;
}

.stop-btn:active { transform: scale(.94); }
.stop-btn[hidden] { display: none; }

.vu {
  display: block;
  width: 168px;
  height: 56px;
  margin: 0 4px;
}

.vu[hidden] { display: none; }

/* ---------- Sheets ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, .6);
  z-index: 20;
  animation: fade .2s ease-out;
}

.scrim[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Anchored to the top so the on-screen keyboard never covers it. */
.sheet {
  position: fixed;
  left: 50%;
  top: max(12px, env(safe-area-inset-top));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 18px 20px 20px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .8);
  z-index: 21;
  animation: slide .25s cubic-bezier(.2, .8, .2, 1);
}

.sheet[hidden] { display: none; }
.sheet .grip { display: none; }

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

.sheet .grip {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  margin: 0 auto 14px;
}

.sheet h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
}

.sheet .sub {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--muted);
}

.field { display: block; margin-bottom: 12px; }

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--muted);
}

.field input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 20px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 227, 207, .15);
}

.arrow {
  display: grid;
  place-items: center;
  color: var(--muted);
  margin: -4px 0 8px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  flex: 1;
  height: 50px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  background: var(--surface-2);
}

.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .5; }

/* ---------- Dictionary drawer ---------- */

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  box-shadow: 30px 0 60px -30px rgba(0, 0, 0, .8);
  padding: max(10px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  z-index: 21;
  animation: drawer-in .28s cubic-bezier(.2, .8, .2, 1);
}

.drawer[hidden] { display: none; }

@keyframes drawer-in {
  from { transform: translateX(-24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 10px;
}

.drawer-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.drawer-head .count { color: var(--muted); font-weight: 500; font-size: 15px; margin-left: 4px; }

.dict-cols,
.dict-add,
.dict-list li {
  display: grid;
  grid-template-columns: 1fr 1fr 36px;
  gap: 8px;
  align-items: center;
}

.dict-cols {
  padding: 0 10px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  color: var(--muted);
}

.dict-add {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.dict-add input,
.dict-edit {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.dict-add input:focus,
.dict-edit:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 227, 207, .15);
}

.dict-add .add { background: var(--accent); color: var(--accent-ink); }
.dict-add .add:hover { background: var(--accent); color: var(--accent-ink); }

.dict-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
}

.dict-list li {
  min-height: 46px;
  border-bottom: 1px solid var(--line);
  animation: rise .25s ease-out;
}

.dict-list .cell {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 17px;
  line-height: 1.3;
  overflow-wrap: anywhere;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
  transition: background .15s;
}

.dict-list .cell:hover { background: var(--surface); }
.dict-list .src { color: var(--text-2); }
.dict-list .dst { color: var(--text); font-weight: 600; }
.dict-list .src.pressing { background: var(--surface-2); }
.dict-list .del { color: var(--muted); }
.dict-list .del:hover { color: var(--red); }
.dict-list li.saved .cell { animation: flash .8s ease-out; }

@keyframes flash {
  from { background: rgba(139, 227, 207, .22); }
  to { background: transparent; }
}

.glossary-empty {
  display: block !important;
  border: 0 !important;
  color: var(--muted);
  padding: 32px 0;
  text-align: center;
}

.dict-hint {
  margin: 10px 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.drawer-logout {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, color .15s;
}

.drawer-logout:hover { background: var(--surface); color: var(--red); }

.toast {
  position: fixed;
  top: max(56px, calc(env(safe-area-inset-top) + 48px));
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 14px;
  z-index: 30;
  animation: pop .2s ease-out;
}

.toast[hidden] { display: none; }
.toast.error { color: var(--red); }

/* ---------- Login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(380px, 100%);
  text-align: center;
}

.login-card img { width: 64px; height: 64px; margin: 0 auto 18px; }
.login-card h1 { margin: 0 0 6px; font-size: 26px; }
.login-card p { margin: 0 0 24px; color: var(--muted); }
.login-card .field input { text-align: center; letter-spacing: .1em; }
.login-card .btn { width: 100%; margin-top: 4px; }
.login-error { min-height: 22px; margin-top: 12px; color: var(--red); font-size: 14px; }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  :root { --dock-h: 68px; }
  .main-btn, .stop-btn, .vu { height: 48px; }
  .vu { width: 120px; }
  .stop-btn { width: 48px; }
  .bilingual .block { grid-template-columns: 1fr; gap: 4px; }
  .bilingual .block .ru { order: 2; }
  .bilingual .stream-head { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .stream { scroll-behavior: auto; }
}
