:root {
  --fondo: #000000;
  --card: #0d0d10;
  --bordo: rgba(255, 255, 255, 0.08);
  --testo: #f3f2f7;
  --tenue: #8d8b98;
  --debole: #5c5a66;
  --sys: #4a4853;
  --files: #7a7686;
  --accento: #b4a7ff;
  --accento-scuro: #6d5ce0;
  --ambra: #f2b25c;
  --metallo-1: #e9e7f2;
  --metallo-2: #8f8aa3;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: clamp(13px, min(1.75vw, 3vh), 21px); }
html, body { height: 100%; }
body {
  background: var(--fondo);
  color: var(--testo);
  font-family: 'Mona Sans Variable', 'Mona Sans', system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.stage { position: relative; height: 100vh; display: grid; place-items: center; padding: 3vh 4vw; }

.ctx {
  position: relative;
  width: min(31rem, 92vw);
  padding: 1rem 1.05rem 0.95rem;
  border-radius: 20px;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(180, 167, 255, 0.07), transparent 60%),
    var(--card);
  border: 1px solid var(--bordo);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 30px 60px -30px rgba(109, 92, 224, 0.35), 0 10px 30px -12px rgba(0, 0, 0, 0.9);
}

.ctx__top { display: flex; align-items: center; gap: 0.55rem; font-size: 0.72rem; }
.brand { display: inline-flex; align-items: center; gap: 0.32rem; font-weight: 640; letter-spacing: 0.01em; }
.brand svg { width: 0.95rem; height: 0.95rem; fill: var(--accento); }
.thread { color: var(--tenue); }
.model {
  margin-left: auto; font-size: 0.62rem; color: var(--tenue);
  padding: 0.2rem 0.5rem; border-radius: 999px; border: 1px solid var(--bordo); background: rgba(255, 255, 255, 0.02);
}

/* ---- the feed ---- */
.feed {
  position: relative;
  height: min(9.6rem, 26vh);
  margin: 0.8rem 0 0.85rem;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 0.38rem;
  /* the old messages fade out at the top instead of being cut */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 2.2rem);
  mask-image: linear-gradient(to bottom, transparent 0, #000 2.2rem);
}
.msgs { display: flex; flex-direction: column; gap: 0.38rem; }
.msg {
  max-width: 82%;
  padding: 0.42rem 0.62rem;
  border-radius: 12px;
  font-size: 0.7rem; line-height: 1.35;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: #d9d7e2;
}
.msg--me { align-self: flex-end; background: #1d1a2e; border-color: rgba(180, 167, 255, 0.16); color: #ebe8ff; }
.msg__meta { display: block; margin-top: 0.15rem; font-size: 0.56rem; color: var(--debole); }

.summary {
  align-self: center;
  display: inline-flex; align-items: center; gap: 0.38rem;
  padding: 0.3rem 0.65rem 0.3rem 0.45rem;
  border-radius: 999px;
  font-size: 0.64rem; color: #dcd8ee;
  background: linear-gradient(100deg, rgba(233, 231, 242, 0.1), rgba(180, 167, 255, 0.12));
  border: 1px solid rgba(233, 231, 242, 0.16);
  opacity: 0; visibility: hidden;
}
.summary b { font-weight: 640; }
.summary__ic { width: 0.9rem; height: 0.9rem; fill: none; stroke: var(--accento); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- the meter ---- */
.meter { position: relative; }
.meter__row { display: flex; align-items: baseline; justify-content: space-between; font-size: 0.66rem; margin-bottom: 0.42rem; }
.meter__label { color: var(--tenue); }
.meter__val b { font-weight: 640; color: var(--testo); display: inline-block; min-width: 2.6em; text-align: right; }
.meter__val .of { color: var(--debole); }

.bar {
  position: relative;
  display: flex; gap: 2px;
  height: 0.62rem;
  padding: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.seg { position: relative; height: 100%; border-radius: 999px; overflow: hidden; flex: none; cursor: default; }
.seg i { position: absolute; inset: 0; border-radius: inherit; }
.seg--sys i { background: var(--sys); }
.seg--files i { background: var(--files); }
.seg--sum i { background: linear-gradient(90deg, var(--metallo-2), var(--metallo-1)); }
.seg--chat i { background: linear-gradient(90deg, var(--accento-scuro), var(--accento)); }
.ctx.is-warn .seg--chat i { background: linear-gradient(90deg, #c9853a, var(--ambra)); }
.sheen {
  position: absolute; top: 0; bottom: 0; left: -40%; width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85), transparent);
  opacity: 0;
}
/* the 80% line: past it the bar warns */
.bar__mark { position: absolute; top: -3px; bottom: -3px; left: 80%; width: 1px; background: rgba(255, 255, 255, 0.18); }

.keys { display: flex; gap: 0.85rem; margin-top: 0.5rem; font-size: 0.58rem; color: var(--debole); }
.keys span { display: inline-flex; align-items: center; gap: 0.32rem; }
/* each key is a small piece of the bar itself */
.k { display: inline-block; width: 0.9rem; height: 0.32rem; border-radius: 999px; }
.k--sys { background: var(--sys); }
.k--files { background: var(--files); }
.k--chat { background: linear-gradient(90deg, var(--accento-scuro), var(--accento)); }

.tip {
  position: absolute; bottom: calc(100% + 7px); left: 0; z-index: 2;
  display: inline-flex; gap: 0.4rem; align-items: baseline;
  padding: 0.28rem 0.5rem; border-radius: 8px;
  font-size: 0.6rem; white-space: nowrap;
  background: #1b1a22; border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 18px -8px rgba(0, 0, 0, 0.8);
  opacity: 0; visibility: hidden; pointer-events: none;
}
.tip b { font-weight: 620; }
.tip span { color: var(--tenue); }

/* ---- the foot ---- */
.foot { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin-top: 0.8rem; }
.hint { font-size: 0.64rem; color: var(--tenue); min-height: 1.2em; }
.ctx.is-warn .hint { color: var(--ambra); }
.compact {
  appearance: none; border: 0; font: inherit; cursor: pointer;
  border-radius: 999px; padding: 1px;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.05) 40%, rgba(180, 167, 255, 0.4));
  color: var(--testo);
  box-shadow: 0 6px 16px -8px rgba(109, 92, 224, 0.7);
  transition: opacity 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.compact:disabled { opacity: 0.38; cursor: default; box-shadow: none; }
.compact__in {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.4rem 0.8rem; border-radius: 999px;
  font-size: 0.68rem; font-weight: 600;
  background: #15141b;
}
.compact svg { width: 0.85rem; height: 0.85rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.compact:focus-visible { outline: 2px solid var(--accento); outline-offset: 3px; }
@media (hover: hover) { .compact:not(:disabled):hover .compact__in { background: #1d1b27; } }

.pointer {
  position: absolute; left: 0; top: 0; width: 22px; height: 22px;
  fill: #fff; stroke: #000; stroke-width: 1.2; stroke-linejoin: round;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.6));
  pointer-events: none; opacity: 0;
}
