:root {
  --ink: #0E1013;
  --ink-2: #16191F;
  --ink-3: #1F232B;
  --on-ink: #ECEEF2;
  --on-ink-mute: rgba(236,238,242,.62);
  --rule: rgba(255,255,255,.10);
  --accent: #F5A93F;
  --accent-ink: #171003;
  --danger: #F2686B;
  --f-sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-display: "Instrument Serif", Georgia, serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0; background: var(--ink); color: var(--on-ink);
  font-family: var(--f-sans); font-size: 16px; line-height: 1.5;
  display: flex; flex-direction: column;
  /* dvh tracks the visual viewport, so the layout shrinks around the on-screen
     keyboard instead of the header scrolling off the top. */
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ---- header ---- */
header {
  display: flex; align-items: center; gap: .7rem;
  padding: calc(env(safe-area-inset-top, 0px) + .8rem) 1rem .8rem;
  border-bottom: 1px solid var(--rule); background: var(--ink-2);
  flex: none;   /* a flex child, not sticky -- it can never scroll away */
  z-index: 5;
}
.mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-family: var(--f-display); font-size: 1.15rem;
}
.title { font-weight: 600; letter-spacing: -.01em; }
.title em { font-family: var(--f-display); font-style: italic; font-weight: 400; }
.sub { font-size: .74rem; color: var(--on-ink-mute); }
header .spacer { flex: 1; }
.icon-btn {
  background: var(--ink-3); border: 1px solid var(--rule); color: var(--on-ink);
  border-radius: 10px; padding: .45rem .6rem; font-size: .8rem; cursor: pointer;
}
.icon-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* ---- thread ---- */
#thread {
  flex: 1 1 auto; min-height: 0;   /* min-height:0 lets it actually shrink */
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.msg {
  max-width: 82%; padding: .6rem .85rem; border-radius: 14px;
  font-size: .95rem; white-space: pre-wrap; word-wrap: break-word; animation: rise .22s ease-out;
}
.in  { background: var(--ink-3); align-self: flex-start; border-bottom-left-radius: 4px; }
.out { background: var(--accent); color: var(--accent-ink); align-self: flex-end; border-bottom-right-radius: 4px; font-weight: 500; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.meta { font-size: .68rem; color: var(--on-ink-mute); align-self: center; padding: .15rem 0; }
.billtag {
  font-size: .62rem; color: var(--accent); border: 1px solid var(--rule);
  border-radius: 6px; padding: .05rem .3rem; margin-left: .4rem; vertical-align: middle;
}
.chips { display: flex; gap: .4rem; align-self: flex-start; flex-wrap: wrap; margin-top: -.15rem; }
.chip {
  background: var(--ink-2); border: 1px solid var(--rule); color: var(--accent);
  border-radius: 10px; padding: .35rem .75rem; font-size: .82rem; font-weight: 600; cursor: pointer;
}
.chip:active { background: var(--ink-3); }

/* ---- composer ---- */
form {
  flex: none;
  display: flex; gap: .5rem; align-items: center;
  padding: .7rem 1rem calc(env(safe-area-inset-bottom, 0px) + .7rem);
  border-top: 1px solid var(--rule); background: var(--ink-2);
}
input[type=text] {
  flex: 1; background: var(--ink-3); border: 1px solid var(--rule); color: var(--on-ink);
  border-radius: 999px; padding: .7rem 1rem; font-size: 1rem; font-family: inherit; min-width: 0;
}
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button.send, button.mic {
  border: none; border-radius: 999px; width: 44px; height: 44px; flex: none;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
button.send svg, button.mic svg { width: 20px; height: 20px; display: block; }
button.mic { background: var(--ink-3); color: var(--on-ink); border: 1px solid var(--rule); }
button.mic.rec { background: var(--danger); color: #fff; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
button:disabled { opacity: .45; }

/* ---- panel ---- */
#panel {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; z-index: 10;
}
#panel.open { display: block; }
.sheet {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(88%, 380px);
  background: var(--ink-2); border-left: 1px solid var(--rule); padding: 1.2rem; overflow-y: auto;
}
.sheet h2 { font-family: var(--f-display); font-weight: 400; font-size: 1.4rem; margin: 0 0 .2rem; }
.sheet h3 { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--on-ink-mute); margin: 1.4rem 0 .5rem; }
.row { border-bottom: 1px solid var(--rule); padding: .6rem 0; font-size: .9rem; }
.row small { display: block; color: var(--on-ink-mute); font-size: .78rem; }
.empty { color: var(--on-ink-mute); font-size: .88rem; }
