:root {
  --bg: #f4f3f1;
  --card: #ffffff;
  --text: #1d1d1b;
  --muted: #8c8a85;
  --accent: #c96442;
  --accent-soft: #f3e7e2;
  --border: #e7e6e3;
  --user: #ecebe8;
  --green: #2e7d52;
  --icon-bg: #ece9f7;
  --shadow: 0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
html { background: var(--bg); } /* fill any edge so no white can ever show */
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  position: fixed; inset: 0; overflow: hidden;
}
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--bg);
}
.topbar .title { flex: 1; text-align: center; font-weight: 600; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-wrap { flex: 1; text-align: center; overflow: hidden; }
.title-wrap .title { font-size: 16px; }
.title-wrap .subtitle { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  border: none; background: #fff; color: var(--text); font-size: 18px;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; position: relative;
}
.iconbtn.plus { background: var(--accent); color: #fff; font-size: 24px; line-height: 1; }
#backBtn { font-size: 26px; }
.iconbtn .count { position: absolute; top: -2px; right: -2px; background: var(--accent); color: #fff; font-size: 10px; min-width: 15px; height: 15px; border-radius: 999px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }
.iconbtn .count:empty, .iconbtn .count[data-zero="1"] { display: none; }

.ram-strip { font-size: 12px; color: var(--muted); text-align: center; padding: 0 0 6px; }

/* ---------- list screen ---------- */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 14px calc(env(safe-area-inset-bottom) + 20px); }
.sec { color: var(--muted); font-size: 13px; font-weight: 500; margin: 16px 4px 8px; }
.card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 13px 14px; margin-bottom: 10px; display: flex; gap: 12px; align-items: flex-start;
}
.card .ic {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 11px; background: var(--icon-bg);
  display: flex; align-items: center; justify-content: center; color: #6b5bd1; font-size: 17px;
}
.card .ic.live { background: #e6f4ec; color: var(--green); }
.card .body { flex: 1; min-width: 0; }
.card .top { display: flex; align-items: baseline; gap: 8px; }
.card .name { font-weight: 600; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .time { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.card .sub { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub.connected { color: var(--green); }
.card .res { font-size: 12px; color: var(--accent); margin-top: 4px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 12px; }

/* ---------- conversation screen ---------- */
#messages { flex: 1; overflow-y: auto; padding: 8px 16px 10px; -webkit-overflow-scrolling: touch; }
.msg { margin: 12px 0; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { background: var(--user); border-radius: 16px; padding: 10px 14px; margin-left: 40px; }
.msg.asst { color: var(--text); }
.msg.asst .text { font-size: 16px; }
.msg.streaming { opacity: .75; }
.msg .att { font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg.asst .row { margin-top: 6px; }
.msg .play { font-size: 13px; color: var(--muted); background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; }
.hint { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 16px; }

#status { text-align: center; font-size: 13px; color: var(--muted); padding: 5px; }
#status.live { color: var(--accent); }

#playerBar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; }
.pp { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: none; font-size: 16px; color: #fff; background: var(--accent); }
.pp.note { background: #fff; color: var(--text); box-shadow: var(--shadow); }
#scrub { -webkit-appearance: none; appearance: none; flex: 1; height: 30px; background: transparent; }
#scrub::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: var(--border); }
#scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: var(--accent); }
.time { font-size: 12px; color: var(--muted); min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }

#attachBar { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 16px 0; }
.chip { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 5px 10px; font-size: 13px; }
.chip .x { background: none; border: none; color: var(--muted); font-size: 14px; }

/* ---------- composer ---------- */
#composer { padding: 6px 12px calc(env(safe-area-inset-bottom) + 8px); background: var(--bg); }
.composer-field { background: #fff; border: 1px solid var(--border); border-radius: 20px; padding: 6px 14px; box-shadow: var(--shadow); }
#input { width: 100%; resize: none; max-height: 140px; border: none; outline: none; background: transparent; color: var(--text); font: inherit; padding: 4px 0; }
.composer-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px 0; }
.composer-row .spacer { flex: 1; }
.round { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: none; font-size: 17px; color: var(--text); background: #fff; box-shadow: var(--shadow); }
.round.send { background: var(--accent); color: #fff; font-size: 19px; }
.round.rec-on { background: #e5484d; color: #fff; animation: pulse 1.1s infinite; }
#audioModeBtn[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.55} }

/* ---------- sheets ---------- */
#sheetBackdrop { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 20; }
.sheet { position: fixed; left: 8px; right: 8px; bottom: calc(env(safe-area-inset-bottom) + 8px); z-index: 21; background: #fff; border-radius: 18px; box-shadow: 0 8px 40px rgba(0,0,0,.18); padding: 8px; max-height: 80dvh; overflow-y: auto; }
.sheet-title { color: var(--muted); font-size: 13px; text-align: center; padding: 10px; }
.sheet-btn { width: 100%; border: none; background: #fff; color: var(--text); font-size: 17px; padding: 15px; border-top: 1px solid var(--border); }
.sheet-btn:first-of-type { border-top: none; }
.sheet-btn.danger { color: #e5484d; }
.sheet-btn.cancel { margin-top: 6px; border-top: none; font-weight: 600; }
.sheet-head { display: flex; align-items: baseline; gap: 8px; padding: 10px 8px; }
.sheet-head .sub { color: var(--muted); font-size: 12px; flex: 1; }
.sheet-head .x { background: none; border: none; color: var(--muted); font-size: 18px; }
.noteRec { width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--border); background: #faf9f7; color: var(--text); font-size: 15px; margin-bottom: 8px; }
.noteRec.rec-on { background: #e5484d; color: #fff; border-color: #e5484d; }
#notesList { display: flex; flex-direction: column; gap: 8px; padding-bottom: 6px; }
.note-item { background: #faf9f7; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; }
.note-item .nt { flex: 1; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; }
.note-item .copy { flex: 0 0 auto; font-size: 12px; color: var(--accent); background: none; border: 1px solid var(--accent-soft); border-radius: 999px; padding: 4px 10px; }
.note-item .copy.done { color: #fff; background: var(--green); border-color: var(--green); }
.note-item .del { flex: 0 0 auto; background: none; border: none; color: var(--muted); font-size: 14px; }
