/* Mostić: light, earthy, green. Serbian = sage, English = wheat. */
:root {
  --paper: #f7faf3;
  --white: #ffffff;
  --mint: #e2eeda;
  --mint-deep: #cfe3c2;
  --sage: #b5d2a6;
  --fern: #4f7d4b;
  --fern-bright: #6a9b64;
  --moss: #24392b;
  --muted: #667b69;
  --line: #d9e6d1;
  --wheat-soft: #fbf4dc;
  --wheat: #f2e6bf;
  --wheat-deep: #e6cf8c;
  --ochre: #8c6b24;
  --rust: #9b4f37;
  --shadow: 0 10px 30px -14px rgba(36, 57, 43, 0.35);
  --serif: 'Alegreya', 'Iowan Old Style', Georgia, serif;
  --sans: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  background: var(--paper);
}
html.is-large { font-size: 20px; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--moss);
  font-family: var(--sans);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.55; cursor: default; }
:focus-visible { outline: 3px solid var(--fern-bright); outline-offset: 2px; border-radius: 12px; }

.app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
}
.top, .pairbar, .banner, .dock { flex: none; }

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-top) + 12px) 16px 8px;
}
.top__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top__mark { flex: none; width: 40px; height: 40px; }
.top__greeting {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.5rem;
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
html.is-large .top__greeting { font-size: 1.3rem; }
.top__actions { display: flex; gap: 8px; flex: none; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--fern);
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.is-active { background: var(--fern); border-color: var(--fern); color: var(--white); }
.icon-btn--sm { width: 38px; height: 38px; background: transparent; border-color: transparent; color: var(--muted); }
.icon-btn--sm svg { width: 21px; height: 21px; }
.icon-btn.is-saved { color: #c39a2e; }
.icon-btn.is-playing { color: var(--fern); animation: throb 0.9s ease-in-out infinite; }

/* ---------- two-phone bar ---------- */
.pairbar {
  margin: 0 16px 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
}
.pairbar__main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 6px 12px;
  text-align: left;
}
.pairbar__text { font-weight: 700; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pairbar__code {
  margin-left: auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.14em;
  background: var(--mint);
  border-radius: 999px;
  padding: 2px 10px;
}
.pairbar__end { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.pairbar__end svg { width: 20px; height: 20px; }

.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot--ok { background: var(--fern-bright); box-shadow: 0 0 0 0 rgba(106, 155, 100, 0.5); animation: beacon 2.2s infinite; }
.dot--wait { background: #d2ad4f; animation: blink 1.4s ease-in-out infinite; }

.banner {
  margin: 0 16px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--wheat-soft);
  color: var(--ochre);
  font-weight: 700;
  font-size: 0.92rem;
}
.banner svg { width: 20px; height: 20px; flex: none; }

/* ---------- conversation ---------- */
.feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 16px 20px;
}

.msg {
  max-width: 88%;
  padding: 12px 16px 8px;
  border-radius: 24px;
  position: relative;
}
.msg.is-new { animation: rise 0.32s cubic-bezier(0.2, 0.8, 0.3, 1); }
.msg--mine { align-self: flex-end; border-bottom-right-radius: 8px; }
.msg--theirs { align-self: flex-start; border-bottom-left-radius: 8px; }
.msg--sr { background: var(--mint); }
.msg--en { background: var(--wheat-soft); }
.msg__sub { margin: 0 0 3px; font-size: 0.92rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.msg--en .msg__sub { color: #84723f; }
.msg__main {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.55rem;
  line-height: 1.26;
  overflow-wrap: anywhere;
}
.msg__main--pending { color: var(--muted); font-family: var(--sans); font-size: 1rem; animation: blink 1.4s ease-in-out infinite; }
.msg__actions { display: flex; justify-content: flex-end; gap: 2px; margin: 0 -8px -2px 0; }
.msg__error { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 4px 0 8px; color: var(--rust); font-weight: 700; }

.msg--live { background: var(--white); border: 2px dashed var(--sage); }
.msg--live.msg--en { border-color: var(--wheat-deep); }
.msg--live .msg__main { min-height: 1.3em; }

.bars { display: inline-flex; align-items: center; gap: 3px; height: 16px; }
.bars i { width: 3px; height: 100%; border-radius: 2px; background: var(--fern-bright); animation: bar 0.9s ease-in-out infinite; }
.msg--en .bars i { background: #c39a2e; }
.bars i:nth-child(2) { animation-delay: 0.15s; }
.bars i:nth-child(3) { animation-delay: 0.3s; }
.bars i:nth-child(4) { animation-delay: 0.45s; }

.empty {
  margin: auto 0;
  padding: 8px 4px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.empty__art { width: 100%; max-width: 300px; }
.empty__art svg { display: block; }
.empty__title { margin: 14px 0 4px; font-family: var(--serif); font-weight: 700; font-size: 1.7rem; line-height: 1.15; }
.empty__body { margin: 0 0 16px; color: var(--muted); max-width: 32ch; }
.empty__chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--white);
  border: 1px solid var(--line);
  font-weight: 700;
  transition: transform 0.1s, background 0.15s;
}
.chip:active { transform: scale(0.96); background: var(--mint); }
.chip svg { width: 18px; height: 18px; }
.chip--retry { min-height: 38px; padding: 6px 12px; color: var(--moss); }

/* ---------- dock with the talk buttons ---------- */
.dock {
  background: var(--white);
  border-radius: 30px 30px 0 0;
  box-shadow: 0 -10px 30px -18px rgba(36, 57, 43, 0.4);
  padding: 16px 16px calc(var(--safe-bottom) + 8px);
}

.pebbles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pebbles--single { grid-template-columns: 1fr; justify-items: center; }

.pebble {
  position: relative;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 14px 8px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.12s ease, opacity 0.25s ease, filter 0.25s ease, box-shadow 0.2s ease;
}
.pebble--a { border-radius: 46% 54% 42% 58% / 56% 46% 54% 44%; }
.pebble--b { border-radius: 55% 45% 58% 42% / 46% 56% 44% 54%; }
.pebbles--single .pebble { width: min(100%, 300px); min-height: 156px; }

.pebble--sr {
  background: radial-gradient(120% 95% at 28% 18%, #e4f0da 0%, #c3dbb4 55%, #a8c897 100%);
  color: var(--moss);
  box-shadow: inset 0 -7px 0 rgba(79, 125, 75, 0.16), 0 12px 22px -14px rgba(79, 125, 75, 0.75);
}
.pebble--en {
  background: radial-gradient(120% 95% at 28% 18%, #fcf5de 0%, #f2e2b0 55%, #e8d293 100%);
  color: #4a3b12;
  box-shadow: inset 0 -7px 0 rgba(140, 107, 36, 0.15), 0 12px 22px -14px rgba(140, 107, 36, 0.7);
}
.pebble:active { transform: translateY(2px) scale(0.985); }

.pebble__seed {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  color: var(--fern);
  margin-bottom: 4px;
  transition: background 0.2s, color 0.2s;
}
.pebble--en .pebble__seed { color: var(--ochre); }
.pebble__name { font-family: var(--serif); font-weight: 700; font-size: 1.5rem; line-height: 1.1; }
.pebble__hint { font-weight: 700; font-size: 0.85rem; opacity: 0.8; }
.pebble__ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 3px solid var(--fern-bright);
  opacity: 0;
  pointer-events: none;
}
.pebble--en .pebble__ring { border-color: #c9a43f; }

.pebble.is-listening { animation: breathe 2.6s ease-in-out infinite alternate; }
.pebble.is-listening .pebble__seed { background: var(--fern); color: var(--white); }
.pebble--en.is-listening .pebble__seed { background: var(--ochre); }
.pebble.is-listening .pebble__ring { animation: ripple 1.5s ease-out infinite; }
.pebble.is-listening .pebble__hint { opacity: 1; }
.pebble.is-dimmed { opacity: 0.38; filter: saturate(0.5); pointer-events: none; }

.dock__tools { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 16px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 700;
}
.tool:active { background: var(--mint); }
.tool svg { width: 20px; height: 20px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 64px);
  transform: translate(-50%, -8px);
  max-width: min(92vw, 480px);
  padding: 10px 18px;
  border-radius: 18px;
  background: var(--moss);
  color: var(--white);
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  box-shadow: var(--shadow);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- bottom sheets ---------- */
.sheet {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}
.sheet[open] { display: flex; align-items: flex-end; justify-content: center; }
.sheet::backdrop { background: rgba(36, 57, 43, 0.3); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.sheet__panel {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--white);
  border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideup 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet__panel::before {
  content: '';
  align-self: center;
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--line);
  margin-bottom: 2px;
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet__title { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 1.55rem; }
.sheet__title:focus { outline: none; }
.sheet__lead { margin: -6px 0 0; color: var(--muted); }
.sheet__section { margin: 6px 0 -4px; font-size: 0.95rem; color: var(--muted); font-weight: 800; }
.sheet__row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet__footer { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
.sheet__footer .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field__label { font-weight: 800; font-size: 0.95rem; }
.field__hint { margin: 0; color: var(--muted); font-size: 0.88rem; }
.field__error { margin: -4px 0 0; min-height: 1.2em; color: var(--rust); font-weight: 700; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg__opt {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  font-weight: 700;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.seg__opt.is-on { background: var(--fern); border-color: var(--fern); color: var(--white); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 800; font-size: 0.95rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { flex: none; width: 54px; height: 32px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.2s; }
.switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}
.switch input:checked + .switch__track { background: var(--fern); }
.switch input:checked + .switch__track::after { transform: translateX(22px); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--fern-bright); outline-offset: 2px; }

.input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--paper);
  font-size: 1.1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--fern-bright); box-shadow: 0 0 0 4px rgba(106, 155, 100, 0.18); }
.input--area { resize: none; font-family: var(--serif); font-size: 1.35rem; line-height: 1.3; }
.input--code { text-align: center; font-size: 2rem; font-weight: 800; letter-spacing: 0.45em; font-variant-numeric: tabular-nums; padding-left: 0.45em; }

.btn {
  min-height: 52px;
  padding: 12px 18px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  transition: transform 0.1s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 22px; height: 22px; }
.btn--primary { background: var(--fern); color: var(--white); }
.btn--secondary { background: var(--mint); color: var(--moss); }
.btn--quiet { background: var(--paper); border: 1.5px solid var(--line); color: var(--moss); }

/* two phones */
.pair { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pair__qr { width: min(240px, 70vw); aspect-ratio: 1; padding: 10px; background: var(--white); border: 1px solid var(--line); border-radius: 24px; }
.pair__code { display: flex; gap: 8px; }
.pair__code span {
  width: 52px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--mint);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 2.1rem;
}
.pair__status { margin: 0; display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; }
.pair__intro { display: flex; justify-content: center; align-items: center; gap: 10px; color: var(--fern); padding: 4px 0; }
.pair__intro svg { width: 34px; height: 34px; }
.pair__intro span:nth-child(2) svg { width: 24px; height: 24px; color: var(--sage); }

/* phrases */
.phrases { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.phrase { display: flex; align-items: center; gap: 4px; }
.phrase__say {
  flex: 1;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  transition: background 0.15s;
}
.phrase__say:active { background: var(--mint); }
.phrase__main { font-family: var(--serif); font-weight: 500; font-size: 1.25rem; line-height: 1.2; }
.phrase__sub { color: var(--muted); font-size: 0.9rem; }

/* ---------- family code screen ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--paper);
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 20px) 20px calc(var(--safe-bottom) + 20px);
  overflow-y: auto;
}
.gate__card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.gate__art { width: 100%; max-width: 280px; align-self: center; }
.gate__title { margin: 4px 0 0; font-family: var(--serif); font-weight: 700; font-size: 2rem; line-height: 1.1; text-align: center; }
.gate__body { margin: 0; color: var(--muted); text-align: center; }

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes slideup { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes breathe {
  0% { border-radius: 46% 54% 42% 58% / 56% 46% 54% 44%; transform: scale(1.02); }
  50% { border-radius: 58% 42% 52% 48% / 44% 58% 42% 56%; transform: scale(1.045); }
  100% { border-radius: 42% 58% 56% 44% / 52% 42% 58% 48%; transform: scale(1.03); }
}
@keyframes ripple { 0% { opacity: 0.7; transform: scale(1); } 100% { opacity: 0; transform: scale(1.14); } }
@keyframes bar { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes throb { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes beacon {
  0% { box-shadow: 0 0 0 0 rgba(106, 155, 100, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(106, 155, 100, 0); }
  100% { box-shadow: 0 0 0 0 rgba(106, 155, 100, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .pebble.is-listening { outline: 4px solid var(--fern-bright); outline-offset: 3px; }
}

@media (min-width: 600px) {
  body { background: linear-gradient(180deg, var(--paper), var(--mint) 140%); }
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); background: var(--paper); }
}

@media (max-height: 640px) {
  .pebble { min-height: 112px; }
  .pebble__seed { width: 38px; height: 38px; }
}

/* ---------- flags ---------- */
.flag { display: inline-flex; width: 28px; height: 19px; border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 1px rgba(36, 57, 43, 0.14); flex: none; }
.flag svg { width: 100%; height: 100%; display: block; }
.lang-opt { display: inline-flex; align-items: center; gap: 8px; }
.seg__opt.is-on .flag { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.85); }
.flags { display: flex; justify-content: center; gap: 10px; }
.flag-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 18px 8px 12px;
  border-radius: 999px;
  background: var(--white);
  border: 1.5px solid var(--line);
  font-weight: 800;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.flag-btn:active { transform: scale(0.97); }
.flag-btn.is-on { border-color: var(--fern); background: var(--mint); }
.flag-btn .flag { width: 32px; height: 22px; }

/* ---------- admin ---------- */
.admin { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 20px; background: var(--paper); border: 1px solid var(--line); }
.admin__title { margin: 0; font-family: var(--serif); font-size: 1.3rem; }
.admin__sub { margin: 6px 0 0; font-size: 0.95rem; font-weight: 800; color: var(--muted); }
.admin__body { display: flex; flex-direction: column; gap: 10px; }
.admin__list { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 0.95rem; }
.admin__list dt { font-weight: 800; }
.admin__list dd { margin: 0; color: var(--moss); overflow-wrap: anywhere; }
.admin__line { margin: 0; font-size: 0.92rem; color: var(--moss); }
.admin__links { display: flex; flex-wrap: wrap; gap: 8px; }
.admin__links .chip { text-decoration: none; color: var(--moss); font-size: 0.92rem; }
.meter { display: flex; flex-direction: column; gap: 6px; }
.meter__top { display: flex; justify-content: space-between; gap: 10px; font-size: 0.95rem; font-weight: 800; }
.meter__val { font-weight: 600; color: var(--muted); text-align: right; }
.meter__bar { height: 10px; border-radius: 999px; background: var(--mint); overflow: hidden; }
.meter__bar i { display: block; height: 100%; min-width: 4px; border-radius: inherit; background: var(--fern-bright); }
.meter--near .meter__bar i { background: #d2ad4f; }
.meter--over .meter__bar i { background: var(--rust); }
.meter__warn { margin: 0; font-size: 0.85rem; font-weight: 800; color: var(--ochre); }
.meter--over .meter__warn { color: var(--rust); }
.sheet__meta { margin: 0; display: flex; justify-content: space-between; gap: 12px; font-size: 0.85rem; color: var(--muted); }
.sheet__meta a { color: var(--fern); font-weight: 700; }
.meter__top > span:first-child { white-space: nowrap; }
