:root {
  --ink: #1f2a1c;
  --ink-soft: #4c5a47;
  --glass: rgba(255, 253, 246, 0.82);
  --glass-strong: rgba(255, 253, 246, 0.94);
  --line: rgba(60, 80, 50, 0.16);
  --accent: #3f7d3a;
  --accent-ink: #ffffff;
  --sun: #e9a23b;
  --notice-bg: #fff3d6;
  --notice-ink: #6b4a00;
  --problem-bg: #fde7e3;
  --problem-ink: #8a2a1b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(30, 50, 20, 0.16), 0 2px 6px rgba(30, 50, 20, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  /* Sky, then a meadow under her feet: the canvas is transparent */
  background:
    radial-gradient(120% 60% at 50% 105%, #b8cf8f 0%, #cfdeac 38%, rgba(220, 232, 196, 0) 70%),
    linear-gradient(180deg, #bcd8ee 0%, #dcebf2 45%, #eef1df 70%, #d6e2b8 100%);
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; font-size: 1.35rem; letter-spacing: 0.01em; }
.chip {
  font-size: 0.78rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.info { flex: 1; min-width: 0; font-size: 0.85rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; margin-left: auto; }

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--glass);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.icon-button:hover { background: var(--glass-strong); }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- status panel */
.panel {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(720px, calc(100% - 32px));
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  padding: 14px 16px 12px;
}
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.status { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.95rem; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: #9aa596; transition: background 0.2s; }
.status[data-state="listening"] .dot { background: #3f9d48; box-shadow: 0 0 0 4px rgba(63, 157, 72, 0.18); }
.status[data-state="hearing"] .dot { background: #3f9d48; animation: pulse 0.9s ease-in-out infinite; }
.status[data-state="thinking"] .dot, .status[data-state="connecting"] .dot { background: var(--sun); animation: pulse 1.2s ease-in-out infinite; }
.status[data-state="speaking"] .dot { background: #4a77c9; animation: pulse 0.7s ease-in-out infinite; }
.status[data-state="disconnected"] .dot { background: #c4513b; }
.status[data-state="paused"] .dot { background: #8a8f86; }
@keyframes pulse { 50% { transform: scale(1.35); opacity: 0.7; } }

.mic-meter { width: 72px; height: 6px; border-radius: 3px; background: rgba(60, 80, 50, 0.12); overflow: hidden; }
.mic-meter span { display: block; height: 100%; width: 0; background: #3f9d48; transition: width 0.08s linear; }

.captions { margin-top: 8px; }
.captions.hidden { display: none; }
.greta-line { margin: 0; font-size: 1.08rem; line-height: 1.45; max-height: 7.3em; overflow-y: auto; }
.greta-line:empty { display: none; }
.user-line { margin: 6px 0 0; font-size: 0.92rem; color: var(--ink-soft); font-style: italic; }
.user-line:empty { display: none; }
.user-line::before { content: "Vous : "; font-style: normal; font-weight: 600; }

.notice, .problem { margin: 8px 0 0; font-size: 0.88rem; padding: 6px 10px; border-radius: 10px; }
.notice { background: var(--notice-bg); color: var(--notice-ink); }
.problem { background: var(--problem-bg); color: var(--problem-ink); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.control {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-size: 0.9rem;
}
.control:hover:not(:disabled) { background: #fff; }
.control:disabled { opacity: 0.45; cursor: default; }
.control[aria-pressed="true"] { background: var(--ink); color: #fff; }
.say-form { flex: 1 1 220px; display: flex; gap: 6px; min-width: 0; }
.say-form input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
}
.control.send { width: 42px; padding: 0; background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.control.send:hover:not(:disabled) { background: #356c31; }

/* ---------------------------------------------------------------- start overlay */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(230, 238, 222, 0.35);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
body:has(.overlay:not([hidden])) .panel { display: none; }
.card {
  width: min(480px, 100%);
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.welcome h1 { margin: 0; font-size: 1.6rem; }
.lead { margin: 4px 0 16px; color: var(--ink-soft); }
.modes { display: grid; gap: 8px; }
.mode { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: rgba(255, 255, 255, 0.6); }
.mode:has(input:checked) { border-color: var(--accent); background: #f1f7ec; }
.mode input { margin-top: 4px; accent-color: var(--accent); }
.mode b { display: block; }
.mode small { color: var(--ink-soft); }
.welcome-account { font-size: 0.88rem; color: var(--ink-soft); min-height: 1.2em; margin: 12px 0 4px; }
.welcome-account button { margin-left: 4px; }
.progress { height: 4px; background: rgba(60, 80, 50, 0.12); border-radius: 2px; overflow: hidden; margin: 8px 0 14px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.progress.done { visibility: hidden; }
.primary {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 1.02rem;
  cursor: pointer;
}
.primary:disabled { opacity: 0.6; cursor: default; }
.hint { font-size: 0.8rem; color: var(--ink-soft); margin: 12px 0 0; }

/* ---------------------------------------------------------------- settings drawer */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100%);
  background: var(--glass-strong);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overflow-y: auto;
  padding: max(14px, env(safe-area-inset-top)) 18px 24px;
  z-index: 10;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer h2 { margin: 0; font-size: 1.2rem; }
.group { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.group[data-hidden="true"] { display: none; }
.group h3 { margin: 0 0 10px; font-size: 0.95rem; }
.group label { display: block; font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 10px; }
.group label small { color: var(--ink-soft); opacity: 0.85; }
.group input[type="text"], .group input[type="url"], .group input[type="email"], .group input[type="password"], .group input[type="number"], .group select, .group textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 0.92rem;
}
.group textarea { resize: vertical; line-height: 1.4; }
.group .check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 0.92rem; }
.group .check input { accent-color: var(--accent); width: 16px; height: 16px; }
.help { font-size: 0.8rem; color: var(--ink-soft); margin: -4px 0 10px; line-height: 1.4; }
.row { display: flex; gap: 10px; }
.row > label { flex: 1; }
.secondary {
  display: inline-block;
  height: 38px;
  line-height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.file-button { position: relative; overflow: hidden; color: var(--accent) !important; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0; font-size: 0.88rem; }
.account-line { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 0.92rem; margin: 0 0 10px; }
.form-error { color: var(--problem-ink); font-size: 0.85rem; margin: 8px 0 0; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.segmented label { flex: 1; margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 8px 4px; font-size: 0.88rem; color: var(--ink); cursor: pointer; }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -3px; }
code { font-size: 0.85em; background: rgba(60, 80, 50, 0.08); padding: 1px 4px; border-radius: 4px; }

@media (max-width: 600px) {
  .panel { padding: 12px; }
  .greta-line { font-size: 1rem; max-height: 5.8em; }
  .control { padding: 0 10px; font-size: 0.85rem; }
  .info { display: none; }
}
