:root {
  --bg: #12151c;
  --panel: #1a1f2a;
  --panel2: #202636;
  --text: #d8dde8;
  --dim: #7f8aa3;
  --accent: #7fb8a4;
  --warn: #d4a45f;
  --user: #8fa8d4;
  --danger: #c96f6f;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
}
.brand { font-size: 15px; letter-spacing: 0.25em; text-transform: uppercase; color: var(--dim); }
header button {
  background: none; border: none; color: var(--dim); font-size: 22px; cursor: pointer; padding: 4px 8px;
}

main {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 22px; padding: 0 24px; min-height: 0;
}

#orbWrap { text-align: center; }
#orb {
  width: 150px; height: 150px; border-radius: 50%;
  margin: 0 auto 26px;
  background: radial-gradient(circle at 38% 32%, #3d6b5c, #1d2b26 70%);
  box-shadow: 0 0 60px rgba(127, 184, 164, 0.12);
  transition: transform 1.2s ease, box-shadow 1.2s ease, background 1.2s ease;
}
body.s-ai #orb {
  animation: breathe 5s ease-in-out infinite;
  box-shadow: 0 0 90px rgba(127, 184, 164, 0.35);
}
body.s-listening #orb {
  background: radial-gradient(circle at 38% 32%, #37476b, #1c2130 70%);
  box-shadow: 0 0 70px rgba(143, 168, 212, 0.25);
}
body.s-user #orb {
  background: radial-gradient(circle at 38% 32%, #46598a, #1c2130 70%);
  box-shadow: 0 0 100px rgba(143, 168, 212, 0.45);
  transform: scale(1.06);
}
body.s-paused #orb {
  background: radial-gradient(circle at 38% 32%, #6b5a37, #2b2519 70%);
  box-shadow: 0 0 70px rgba(212, 164, 95, 0.3);
}
body.s-thinking #orb { animation: slowspin 3s linear infinite; opacity: 0.85; }
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}
@keyframes slowspin {
  0%, 100% { transform: scale(0.97); }
  50% { transform: scale(1.02); }
}

#stateName { font-size: 19px; font-weight: 600; letter-spacing: 0.02em; }
#stateDetail { color: var(--dim); font-size: 13.5px; margin-top: 6px; min-height: 20px; max-width: 300px; margin-left: auto; margin-right: auto; }

#silenceWrap { width: min(300px, 80vw); visibility: hidden; }
#silenceTrack { height: 5px; background: #0d1017; border-radius: 3px; overflow: hidden; }
#silenceFill { height: 100%; width: 0%; background: var(--warn); border-radius: 3px; }
#silenceLabel { font-size: 11.5px; color: var(--dim); text-align: center; margin-top: 6px; }

#exchange { min-height: 74px; text-align: center; max-width: 340px; }
#youSaid { color: var(--user); font-size: 13.5px; font-style: italic; opacity: 0.8; }
#aiSaid { color: #b9c6bd; font-size: 14.5px; font-style: italic; margin-top: 8px; }

footer { padding: 18px 24px calc(18px + env(safe-area-inset-bottom)); display: flex; gap: 12px; }
footer button {
  flex: 1; padding: 16px; border-radius: 14px; font-size: 17px; cursor: pointer; border: none;
}
#btnStart { background: var(--accent); color: #0e1310; font-weight: 600; }
#btnStart.ending { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
#btnDone { background: var(--panel2); color: var(--text); border: 1px solid #333c52; display: none; }
body.s-listening #btnDone, body.s-user #btnDone, body.s-paused #btnDone { display: block; }

/* Settings sheet */
#settingsSheet {
  position: fixed; inset: 0; background: rgba(10, 12, 17, 0.72);
  display: flex; align-items: flex-end; z-index: 10;
}
#settingsSheet.hidden { display: none; }
.sheetInner {
  background: var(--panel); width: 100%; max-height: 86vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px 22px calc(28px + env(safe-area-inset-bottom));
}
.sheetHeader { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sheetHeader h2 { font-size: 17px; }
.sheetHeader button { background: none; border: none; color: var(--accent); font-size: 16px; font-weight: 600; cursor: pointer; }
#modeBadge { font-size: 12px; color: var(--dim); margin-bottom: 14px; }
#modeBadge b { color: var(--accent); }

.slider { margin-top: 18px; }
.slider label { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.slider label b { color: var(--accent); font-variant-numeric: tabular-nums; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); }
.slider select {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid #333c52; border-radius: 10px; padding: 10px; font-size: 15px;
}
.hint { font-size: 12px; color: var(--dim); margin-top: 4px; }

.meterLine { margin-top: 8px; }
#meterTrack { position: relative; height: 14px; background: #0d1017; border-radius: 7px; overflow: hidden; }
#meterFill { height: 100%; width: 0%; background: linear-gradient(90deg, #3d6b5c, var(--accent)); transition: width 0.06s linear; }
#thresholdMark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--warn); }

#log {
  margin-top: 22px; background: #0d1017; border-radius: 10px; padding: 12px;
  font: 11px/1.7 ui-monospace, Menlo, monospace; color: var(--dim);
  max-height: 160px; overflow-y: auto; white-space: pre-wrap;
}

/* ===== screens ===== */
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 0 24px; min-height: 0; overflow-y: auto; }
.hidden { display: none !important; }

/* ===== auth ===== */
.authBox { width: min(340px, 90vw); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.authBox h1 { font-size: 22px; font-weight: 500; line-height: 1.4; color: var(--text); margin-bottom: 18px; }
.authBox input {
  background: var(--panel); border: 1px solid #333c52; border-radius: 12px;
  padding: 14px 16px; color: var(--text); font-size: 16px;
}
.authBox input:focus { outline: none; border-color: var(--accent); }
button.primary { background: var(--accent); color: #0e1310; font-weight: 600; border: none; border-radius: 12px; padding: 14px; font-size: 16px; cursor: pointer; }
button.ghost { background: none; border: none; color: var(--dim); font-size: 14px; cursor: pointer; padding: 8px; }
button.link { background: none; border: none; color: var(--dim); font-size: 13px; cursor: pointer; padding: 4px; text-decoration: underline; opacity: 0.75; }
#authMsg { font-size: 13px; color: var(--warn); min-height: 18px; }

/* ===== mode picker ===== */
#greeting { font-size: 20px; color: var(--text); text-align: center; }
#modeCards { display: flex; flex-direction: column; gap: 12px; width: min(400px, 92vw); }
.modeCard {
  background: var(--panel); border: 1px solid transparent; border-radius: 16px;
  padding: 16px 18px; cursor: pointer; text-align: left; transition: border-color .2s;
}
.modeCard:active { border-color: var(--accent); }
.modeCard h3 { font-size: 16px; font-weight: 600; }
.modeCard p { font-size: 13px; color: var(--dim); margin-top: 3px; }
.modeCard .len { font-size: 11px; color: var(--accent); margin-top: 6px; letter-spacing: .05em; }
.lenRow { width: min(400px, 92vw); }
.lenRow label { display: flex; justify-content: space-between; font-size: 13px; color: var(--dim); margin-bottom: 4px; }
.lenRow label b { color: var(--accent); }
.lenRow input { width: 100%; accent-color: var(--accent); }
#capMsg { background: var(--panel); border-radius: 14px; padding: 16px 20px; color: var(--warn); font-size: 14px; text-align: center; max-width: 340px; }

/* ===== hypnosis transcript feed ===== */
#feed {
  width: min(420px, 92vw); max-height: 32vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px; padding: 4px;
  mask-image: linear-gradient(to bottom, transparent, black 12%);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 12%);
}
.bubble { font-size: 14px; line-height: 1.5; padding: 8px 12px; border-radius: 12px; max-width: 88%; }
.bubble.ai { background: rgba(127,184,164,.09); color: #b9c6bd; align-self: flex-start; font-style: italic; }
.bubble.user { background: rgba(143,168,212,.10); color: var(--user); align-self: flex-end; }

/* ===== done screen ===== */
.doneBox { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
#doneOrb { width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(circle at 38% 32%, #3d6b5c, #1d2b26 70%); box-shadow: 0 0 70px rgba(127,184,164,.25); }
#doneStats { color: var(--dim); font-size: 14px; }
#screenDone .primary { min-width: 180px; margin-top: 8px; }

/* ===== settings extras ===== */
.textInput {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid #333c52; border-radius: 10px; padding: 10px 12px; font-size: 15px;
}
.toggleRow label { align-items: center; }
.toggleRow input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }

footer#sessionFooter { display: flex; }
footer#sessionFooter.hidden { display: none; }
#btnEnd { flex: 0 0 92px; background: transparent; border: 1px solid var(--danger); color: var(--danger); border-radius: 14px; font-size: 16px; cursor: pointer; }
