/* ============================================
   Robosobaka Voice Lab — Warm Editorial
   ============================================ */

:root {
  color-scheme: only light;

  /* Warm ivory base */
  --ivory: #faf7f2;
  --cream: #f3ede3;
  --linen: #ece5d8;
  --parchment: #e2d9ca;

  /* Ink & text */
  --ink: #2c2418;
  --ink-soft: #5c4f3d;
  --ink-faint: #9a8e7c;
  --ink-ghost: #c4baa8;

  /* Terracotta accent */
  --terra: #c4623a;
  --terra-light: #d98a6a;
  --terra-wash: rgba(196, 98, 58, 0.08);
  --terra-glow: rgba(196, 98, 58, 0.18);

  /* Sage for assistant */
  --sage: #6b8f71;
  --sage-wash: rgba(107, 143, 113, 0.09);
  --sage-border: rgba(107, 143, 113, 0.22);

  /* Utility */
  --shadow-sm: 0 1px 3px rgba(44, 36, 24, 0.06);
  --shadow-md: 0 4px 16px rgba(44, 36, 24, 0.08);
  --shadow-lg: 0 12px 40px rgba(44, 36, 24, 0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
}

/* ---------- Reset ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ---------- Body ---------- */

body {
  min-height: 100dvh;
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-weight: 400;
  color: var(--ink);
  background-color: var(--ivory);
  background-image:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(196, 98, 58, 0.05), transparent),
    radial-gradient(ellipse 60% 60% at 85% 100%, rgba(107, 143, 113, 0.05), transparent);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Subtle paper grain */
.grain {
  position: fixed;
  inset: 0;
  opacity: 0.3;
  pointer-events: none;
  z-index: 100;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* ---------- Shell ---------- */

.shell {
  display: flex;
  justify-content: center;
  padding: 28px 24px 40px;
  min-height: 100dvh;
}

/* ---------- Console ---------- */

.console {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 0;
}

/* Staggered entrance */
.console > * {
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.console > *:nth-child(1) { animation-delay: 0s; }
.console > *:nth-child(2) { animation-delay: 0.06s; }
.console > *:nth-child(3) { animation-delay: 0.12s; }
.console > *:nth-child(4) { animation-delay: 0.18s; }

/* ---------- Header ---------- */

.console-title {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: clamp(1.4rem, 3.5vw, 1.8rem);
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--ink);
}

/* ---------- Status + Play button row ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-ghost);
  transition: background 0.4s ease, box-shadow 0.4s ease;
  flex-shrink: 0;
}

.status-dot[data-state="idle"] {
  background: var(--ink-ghost);
  box-shadow: none;
}

.status-dot[data-state="connecting"] {
  background: var(--terra-light);
  box-shadow: 0 0 0 4px var(--terra-wash);
  animation: blink 1.4s ease-in-out infinite;
}

.status-dot[data-state="listening"] {
  background: var(--terra);
  box-shadow: 0 0 0 5px var(--terra-glow);
  animation: breathe 2.2s ease-in-out infinite;
}

/* ---------- Wake word indicator ---------- */

.wake-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-faint);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--cream);
  border: 1px solid var(--linen);
  transition: all 0.3s ease;
}

.wake-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-ghost);
  flex-shrink: 0;
  transition: all 0.3s ease;
}

body.wake-active .wake-indicator {
  background: var(--sage-wash);
  border-color: var(--sage-border);
  color: var(--sage);
}

body.wake-active .wake-dot {
  background: var(--sage);
  box-shadow: 0 0 0 4px rgba(107, 143, 113, 0.15);
  animation: breathe-sage 2.2s ease-in-out infinite;
}

@keyframes breathe-sage {
  0%, 100% { box-shadow: 0 0 0 4px rgba(107, 143, 113, 0.15); }
  50% { box-shadow: 0 0 0 7px rgba(107, 143, 113, 0.08); }
}

/* ---------- Controls row ---------- */

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* ---------- Mute button ---------- */

.mute-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--linen);
  cursor: pointer;
  background: var(--cream);
  color: var(--ink-soft);
  padding: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.mute-icon {
  width: 18px;
  height: 18px;
  display: block;
  flex-shrink: 0;
}

/* По умолчанию: микрофон включён */
.mute-icon--on  { display: block; }
.mute-icon--off { display: none; }

.mute-btn:hover {
  border-color: var(--ink-ghost);
  background: var(--linen);
  box-shadow: var(--shadow-sm);
}

.mute-btn:active {
  box-shadow: none;
}

/* Состояние мьюта — перечёркнутый микрофон, терракотовый акцент */
body.muted .mute-btn {
  background: var(--terra-wash);
  border-color: rgba(196, 98, 58, 0.3);
  color: var(--terra);
  box-shadow: 0 0 0 3px rgba(196, 98, 58, 0.08);
}

body.muted .mute-btn:hover {
  background: rgba(196, 98, 58, 0.14);
  border-color: var(--terra-light);
}

body.muted .mute-icon--on  { display: none; }
body.muted .mute-icon--off { display: block; }

/* ---------- Play / Stop button ---------- */

.play-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--terra);
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease, background 0.3s ease;
  position: relative;

  /* Hide text set by JS */
  font-size: 0;
  color: transparent;
  overflow: hidden;
  line-height: 0;
}

/* Play triangle (idle state) */
.play-btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 54%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 9px 0 9px 16px;
  border-color: transparent transparent transparent #fff;
  transition: all 0.25s ease;
}

.play-btn:hover {
  box-shadow: var(--shadow-lg);
}

.play-btn:active {
  box-shadow: var(--shadow-sm);
}

.play-btn[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

/* Stop square (listening state) */
body.listening .play-btn {
  background: var(--ink-soft);
}

body.listening .play-btn::before {
  border-width: 0;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: #fff;
  left: 50%;
}

body.listening .play-btn:hover {
  background: var(--ink);
}

/* ---------- Chat ---------- */

.chat {
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--cream);
  border: 1px solid var(--linen);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--parchment) transparent;
}

.chat::-webkit-scrollbar {
  width: 5px;
}

.chat::-webkit-scrollbar-track {
  background: transparent;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--parchment);
  border-radius: 4px;
}

.chat-empty {
  color: var(--ink-faint);
  font-size: 0.88rem;
  line-height: 1.5;
  text-align: center;
  font-style: italic;
}

.chat-stream {
  display: grid;
  gap: 12px;
}

/* Messages */
.chat-message {
  display: grid;
  gap: 4px;
  animation: msg-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-message[data-role="user"] {
  justify-items: end;
}

.chat-message[data-role="assistant"] {
  justify-items: start;
}

.chat-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.55;
}

/* User bubble — terracotta tint */
.chat-message[data-role="user"] .chat-bubble {
  background: var(--terra-wash);
  border: 1px solid rgba(196, 98, 58, 0.15);
  border-radius: var(--radius-sm) var(--radius-sm) 4px var(--radius-sm);
  color: var(--ink);
}

/* Assistant bubble — sage tint */
.chat-message[data-role="assistant"] .chat-bubble {
  background: var(--sage-wash);
  border: 1px solid var(--sage-border);
  border-radius: var(--radius-sm) var(--radius-sm) var(--radius-sm) 4px;
  color: var(--ink);
}

.chat-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

/* Streaming */
.chat-message.is-streaming .chat-bubble {
  border-style: dashed;
}

/* ============================================
   Keyframes
   ============================================ */

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

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 5px var(--terra-glow); }
  50% { box-shadow: 0 0 0 8px var(--terra-wash); }
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 720px) {
  .shell {
    padding: 20px 16px 32px;
  }

  .play-btn {
    width: 48px;
    height: 48px;
  }

  .mute-btn {
    width: 38px;
    height: 38px;
  }

  .mute-icon {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 400px) {
  .console-title {
    font-size: 1.3rem;
  }

  .chat {
    padding: 16px;
  }
}
