:root {
  --bg: #0f0d0b;
  --bg-raised: #191510;
  --bg-input: #221c16;
  --line: #2f271f;
  --text: #ece4d8;
  --muted: #9a8e7e;
  --accent: #d39a55;
  --accent-strong: #f0c27f;
  --danger: #e07a62;
  --ok: #8fbf7a;
  --radius: 14px;
  --serif: "PT Serif", "Georgia", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--accent);
  color: #1a120a;
  font-weight: 600;
}
button:disabled { opacity: .5; cursor: default; }
button.quiet { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; }

/* Orb: the stand-in for the character, driven by the conversation state. */

.orb {
  --size: 132px;
  --level: 0;
  position: relative;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: default;
}
button.orb:focus-visible { outline-offset: 6px; border-radius: 50%; }
button.orb { cursor: pointer; }
.orb::before {
  content: "";
  position: absolute;
  inset: -18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(211, 154, 85, .28), transparent 65%);
  transform: scale(calc(.9 + var(--level) * .5));
  transition: transform .12s ease-out, opacity .4s;
  opacity: .6;
}
.orb__core {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #f6dcae 0%, #c98445 42%, #4a2b17 100%);
  box-shadow: 0 0 0 1px rgba(240, 194, 127, .2), 0 18px 50px rgba(0, 0, 0, .55);
  transform: scale(calc(1 + var(--level) * .12));
  transition: transform .12s ease-out;
}
.orb--idle .orb__core { animation: breathe 5s ease-in-out infinite; }
.orb--thinking .orb__core { animation: think 1.4s ease-in-out infinite; }
.orb--thinking::before { opacity: .9; animation: halo 1.4s ease-in-out infinite; }
.orb--speaking::before { opacity: 1; }
.orb--listening::before {
  opacity: 1;
  background: radial-gradient(circle, rgba(224, 122, 98, .4), transparent 65%);
}
.orb--listening .orb__core {
  animation: none;
  box-shadow: 0 0 0 3px rgba(224, 122, 98, .75), 0 18px 50px rgba(0, 0, 0, .55);
}
.orb--speaking .orb__core { animation: none; }

@keyframes breathe { 50% { transform: scale(1.03); } }
@keyframes think { 50% { transform: scale(.95); filter: brightness(1.15); } }
@keyframes halo { 50% { transform: scale(1.15); } }

@media (prefers-reduced-motion: reduce) {
  .orb__core, .orb::before { animation: none !important; transition: none; }
}

/* Login */

.login-page { display: grid; place-items: center; padding: 16px; }
.login {
  width: min(360px, 100%);
  display: grid;
  justify-items: center;
  gap: 20px;
  text-align: center;
}
.login h1 { font: 600 1.6rem/1.2 var(--serif); margin: 0; letter-spacing: .01em; }
.login form { width: 100%; display: grid; gap: 12px; }
.login input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-input);
}
.login__error { color: var(--danger); min-height: 1.5em; margin: 0; font-size: .95rem; }

/* Main layout */

.app {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  max-width: 760px;
  margin: 0 auto;
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
}
.bar__title { font: 600 1.05rem var(--serif); flex: 1; }
.link { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.link--on { background: var(--ok); }
.link--off { background: var(--danger); }

.icon-button {
  background: transparent;
  color: var(--muted);
  padding: 8px;
  display: grid;
  place-items: center;
}
.icon-button:hover { color: var(--text); }

.stage {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 8px 16px 16px;
}
.status { margin: 0; color: var(--muted); font-size: .92rem; min-height: 1.4em; }

.transcript {
  overflow-y: auto;
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--line);
  scroll-behavior: smooth;
}
.transcript:empty::before {
  content: "Разговор пуст. Начните первым.";
  color: var(--muted);
  text-align: center;
  margin-top: 24px;
  font-size: .95rem;
}

.turn { max-width: 88%; white-space: pre-wrap; overflow-wrap: anywhere; }
.turn--user {
  align-self: flex-end;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  color: var(--text);
}
.turn--assistant {
  align-self: flex-start;
  font: 1.08rem/1.6 var(--serif);
  padding-left: 12px;
  border-left: 2px solid var(--accent);
}
.turn--pending::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}
.turn--error { align-self: center; color: var(--danger); font-size: .92rem; }
@keyframes blink { 50% { opacity: 0; } }

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  overflow-y: hidden;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  line-height: 1.4;
}
.composer button { padding: 10px; border-radius: 12px; display: grid; place-items: center; }

/* Settings */

.settings {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  justify-content: flex-end;
}
.settings[hidden] { display: none; }
.settings__panel {
  width: min(380px, 100%);
  height: 100%;
  overflow-y: auto;
  background: var(--bg-raised);
  border-left: 1px solid var(--line);
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings__head { display: flex; align-items: center; justify-content: space-between; }
.settings__head h2 { margin: 0; font: 600 1.2rem var(--serif); }
.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.field small { color: var(--muted); font-size: .85rem; }
.field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-input);
}
.spending { margin: 0; font-variant-numeric: tabular-nums; }
.settings__actions { display: grid; gap: 10px; margin-top: auto; }
