:root {
  --bg: #10261a;
  --bg-soft: #163623;
  --ink: #f4f1e4;
  --ink-dim: #b9c8b3;
  --accent: #f4a11f;
  --accent-ink: #2a1a04;
  --ring: rgba(244, 161, 31, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-soft), var(--bg));
  color: var(--ink);
  font-family: "Noto Sans Devanagari", "Segoe UI", system-ui, -apple-system, sans-serif;
}

.app {
  min-height: 100dvh;
  margin: 0 auto;
  padding: 16px 16px 28px;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.header { text-align: center; }

.title {
  margin: 0;
  font-size: clamp(26px, 6vw, 36px);
  letter-spacing: 0.5px;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--ink-dim);
  font-size: 15px;
}

/* ---------- Character ---------- */

.stage-wrap {
  position: relative;
  /* Dominant visual: fill most of the width and a solid chunk of the viewport height. */
  width: min(620px, 94vw, 68dvh);
  aspect-ratio: 320 / 340;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  margin: 4px 0;
}

.stage {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* Scales with the user's mic level so they can see they are being heard. */
.mic-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 88%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid var(--ring);
  transform: translate(-50%, -50%) scale(var(--level, 1));
  opacity: var(--ring-opacity, 0);
  transition: transform 90ms linear, opacity 220ms ease;
  z-index: 0;
}

/* Idle life: a slow breathing bob and an occasional blink. */
#farmer {
  animation: breathe 3.8s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2.5px); }
}

.eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 5.4s infinite;
}

.eye:nth-of-type(2) { animation-delay: 40ms; }

@keyframes blink {
  0%, 93%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(0.08); }
}

/* Mouth frames: exactly one visible, chosen by the audio level. */
.mouth { opacity: 0; }
.stage[data-mouth="0"] .mouth-closed,
.stage[data-mouth="1"] .mouth-mid,
.stage[data-mouth="2"] .mouth-open { opacity: 1; }

/* The character leans in slightly while listening. */
.stage[data-state="listening"] #farmer { animation-duration: 2.6s; }

@media (prefers-reduced-motion: reduce) {
  #farmer, .eye { animation: none; }
  .mic-ring { transition: opacity 220ms ease; transform: translate(-50%, -50%); }
}

/* ---------- Status + captions ---------- */

.status {
  margin: 0;
  min-height: 24px;
  font-size: 16px;
  color: var(--accent);
  text-align: center;
}

.caption {
  margin: 0;
  min-height: 44px;
  max-width: 42ch;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-dim);
  text-align: center;
}

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

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
}

.btn {
  font: inherit;
  font-size: 16px;
  padding: 13px 22px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 80ms ease, background 160ms ease, opacity 160ms ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.btn-primary:hover { background: #ffb43e; }

.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border-color: rgba(244, 241, 228, 0.25);
}

.btn-ghost:hover { color: var(--ink); border-color: rgba(244, 241, 228, 0.5); }

.btn[hidden] { display: none; }

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

.login-app {
  justify-content: center;
  max-width: 420px;
  gap: 28px;
}

.login-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 22px;
  border: 1px solid rgba(244, 241, 228, 0.14);
  border-radius: 18px;
  background: rgba(16, 38, 26, 0.55);
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-dim);
}

.login-field input {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(244, 241, 228, 0.22);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-error {
  margin: 0;
  color: #ffb4a2;
  font-size: 14px;
  text-align: center;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}
