:root {
  --bg: #f4ede4;
  --card: #fffaf4;
  --text: #2b2520;
  --muted: #7a6e63;
  --line: #e7dccf;
  --soft: #efe5d8;
  --accent: #d97757;
  --accent-2: #c15f3c;
  --pet-ink: #2b2520;
  --pet-fill: #f6c9b4;
  --pet-bg-1: #fbe9df;
  --pet-bg-2: #f6dccd;
  --good: #4f8f55;
  --warn: #c9921f;
  --bad: #c24a36;
  --info: #3f6fb5;
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1915; --card: #26221d; --text: #f1e9df; --muted: #a99c8e; --line: #3a332b; --soft: #302a24;
    --pet-ink: #f1e9df; --pet-fill: #8a4a33; --pet-bg-1: #3a2a22; --pet-bg-2: #2e221c; --good: #6fb174; --warn: #e0ab3c; --bad: #e0624c; --info: #7ea6e6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1915; --card: #26221d; --text: #f1e9df; --muted: #a99c8e; --line: #3a332b; --soft: #302a24;
  --pet-ink: #f1e9df; --pet-fill: #8a4a33; --pet-bg-1: #3a2a22; --pet-bg-2: #2e221c; --good: #6fb174; --warn: #e0ab3c; --bad: #e0624c; --info: #7ea6e6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, sans-serif;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 560px; margin: 0 auto; display: grid; gap: 14px; }
h1, h2 { margin: 0 0 10px; }
h2 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px; }
h2 .hint { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12px; }
code, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12.5px; }
button { font: inherit; }

/* ---------- pet compacto ---------- */
.pet-card {
  display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.avatar {
  position: relative;
  width: 132px; aspect-ratio: 3 / 4; border-radius: 20px;
  background: linear-gradient(160deg, var(--pet-bg-1), var(--pet-bg-2));
  display: grid; place-items: center; overflow: hidden;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}
.avatar canvas { width: 96%; height: auto; display: block; image-rendering: pixelated; }
/* Kevin: imagem ocupa o quadrado todo; canvas vira só a camada de efeitos */
.avatar.has-kevin { background: transparent; box-shadow: none; border-radius: 0; overflow: visible; }
/* Kevin "apoiado" na borda de baixo do card: o moletom encosta na borda, sem flutuar */
.pet-card { overflow: hidden; }
.pet-card .avatar.has-kevin { align-self: end; margin-bottom: -15px; }
.avatar.has-kevin canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.kevin { width: 136%; height: 136%; max-width: none; margin-top: 14%; object-fit: cover; transform-origin: 50% 80%; }
.kevin.sheet { position: relative; width: 100%; height: 100%; margin: 0; }
/* duas camadas: o quadro novo aparece por cima com fade (crossfade suave) */
.kevin.sheet .layer { position: absolute; inset: 0; background-repeat: no-repeat; opacity: 0; transition: opacity var(--fade, 400ms) ease-in-out; }
.kevin.breathe { animation: breathe 3.2s ease-in-out infinite; }
.kevin.bounce { animation: bounce .9s ease-in-out infinite; }
.kevin.hop { animation: hop .6s ease-in-out infinite; }
.kevin.sway { animation: sway 4s ease-in-out infinite; }
.kevin.shiver { animation: shiver .25s linear infinite; }
.kevin.sleep { animation: breathe 5s ease-in-out infinite; filter: brightness(.82) saturate(.85); }
.kevin.dim { filter: saturate(.7); }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.025, 1.035); } }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3%); } }
@keyframes hop { 0%,100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-7%) scale(.98,1.03); } }
@keyframes sway { 0%,100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }
@keyframes shiver { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-1.5%); } 75% { transform: translateX(1.5%); } }
.pet-info { min-width: 0; display: grid; gap: 6px; }
.pet-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pet-head strong { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--accent); color: #fff; font-weight: 600; }
.chip.ghost { background: var(--soft); color: var(--muted); }
.pet-says { margin: 0; font-size: 14px; font-weight: 500; text-wrap: pretty; }
.pet-says.thinking { color: var(--muted); }
.mini-bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; font-size: 11px; }
.mini-bars span { display: flex; align-items: center; gap: 4px; }
.mini-bars i { flex: 1; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.mini-bars b { display: block; height: 100%; width: 0; background: var(--good); border-radius: inherit; transition: width .6s; }
.mini-bars span:last-child b { background: var(--accent); }
.pet-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.pet-actions button { border: 1px solid var(--line); background: var(--soft); color: var(--text); border-radius: 99px; padding: 4px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.pet-actions button:active { transform: translateY(1px); }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.meta { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- aprovações ---------- */
.approvals { border-color: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.approvals h2 { color: var(--text); }
.count { background: var(--warn); color: #fff; border-radius: 99px; padding: 0 8px; font-size: 12px; letter-spacing: 0; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.approval-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.approval { display: grid; gap: 8px; padding: 12px; border-radius: 14px; background: var(--soft); }
.approval .top { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.approval .tool { font-weight: 700; }
.approval .proj { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.approval .age { margin-left: auto; color: var(--muted); white-space: nowrap; font-size: 12px; }
.approval pre {
  margin: 0; padding: 10px; border-radius: 10px; background: var(--card); border: 1px solid var(--line);
  white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto;
  font: 12.5px/1.45 "JetBrains Mono", ui-monospace, monospace;
}
.approval .actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.approval .actions.two { grid-template-columns: 1fr 1fr; }
.approval button { border: 0; border-radius: 12px; padding: 12px 8px; font-weight: 700; font-size: 14px; cursor: pointer; }
.approval button:disabled { opacity: .5; }
.btn-allow { background: var(--good); color: #fff; }
.btn-always { background: var(--card); color: var(--good); border: 1px solid var(--good) !important; }
.btn-deny { background: var(--card); color: var(--bad); border: 1px solid var(--bad) !important; }

/* ---------- sessões ---------- */
.sessions { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.session { display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.session:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--line); }
.dot.pensando, .dot.executando { background: var(--info); animation: pulse 1.2s infinite; }
.dot.aprovacao, .dot.pergunta { background: var(--warn); animation: pulse 1s infinite; }
.dot.sua_vez { background: var(--good); }
.session .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.session .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.session .status { grid-column: 2 / -1; font-size: 13px; display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; min-width: 0; }
.session .label { font-weight: 600; }
.session .label.aprovacao, .session .label.pergunta { color: var(--warn); }
.session .label.sua_vez { color: var(--good); }
.session .label.executando, .session .label.pensando { color: var(--info); }
.session .detail { grid-column: 2 / -1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.session .meta-line { grid-column: 2 / -1; font-size: 12px; color: var(--muted); }
.older summary { cursor: pointer; color: var(--muted); font-size: 13px; padding-top: 8px; }

/* ---------- uso ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpis div { background: var(--soft); border-radius: 12px; padding: 10px; }
.kpis b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.kpis span { font-size: 12px; color: var(--muted); }
.hours, .days { display: flex; align-items: flex-end; gap: 2px; height: 64px; }
.hours i, .days i { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .9; }
.hours i.zero, .days i.zero { background: var(--line); }
.hours i.now { outline: 2px solid var(--text); outline-offset: 1px; }
.hours-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin: 4px 0 10px; }
.days { height: 80px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list li { display: grid; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--line); min-width: 0; }
.list li:last-child { border-bottom: 0; padding-bottom: 0; }
.list .row { display: flex; justify-content: space-between; gap: 10px; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.list .num { font-size: 12.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.list.compact li { grid-template-columns: 1fr auto; padding-bottom: 6px; }
.list.compact .bar { height: 6px; grid-column: 1 / -1; background: var(--line); border-radius: 99px; overflow: hidden; }
.list.compact .bar i { display: block; height: 100%; background: var(--accent); }
.compact-log li { grid-template-columns: auto 1fr auto; gap: 8px; align-items: baseline; padding-bottom: 6px; }
.compact-log .res { font-size: 12px; font-weight: 700; }
.res.allow { color: var(--good); } .res.deny { color: var(--bad); } .res.local, .res.expired { color: var(--muted); }
.compact-log .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-size: 13px; }
.diary li p { margin: 0; }
.empty { color: var(--muted); font-size: 13px; }

footer { text-align: center; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 13px; cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

/* ---------- setup ---------- */
.setup { max-width: 380px; margin: 15vh auto 0; text-align: center; }
.setup h1 { font: 22px Silkscreen, monospace; color: var(--accent-2); }
.setup form { display: flex; gap: 8px; margin-top: 16px; }
.setup input { flex: 1; min-width: 0; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; }
.setup button { padding: 12px 16px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font-weight: 600; }
.error { color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
  .kevin { animation: none !important; }
  .pulse, .dot { animation: none !important; }
  .mini-bars b { transition: none; }
}

/* ---------- perguntas e planos ---------- */
.question { display: grid; gap: 8px; }
.question + .question { border-top: 1px solid var(--line); padding-top: 10px; }
.question .chip { justify-self: start; }
.q-text { margin: 0; font-weight: 600; font-size: 15px; text-wrap: pretty; }
.options { display: grid; gap: 6px; }
.approval button.option {
  text-align: left; display: grid; gap: 2px; padding: 10px 12px; border-radius: 12px;
  background: var(--card); color: var(--text); border: 1.5px solid var(--line) !important; font-weight: 500;
}
.approval button.option b { font-size: 14px; }
.approval button.option small { font-size: 12.5px; color: var(--muted); font-weight: 400; line-height: 1.35; }
.approval button.option.on { border-color: var(--good) !important; background: color-mix(in srgb, var(--good) 12%, var(--card)); }
.approval button.option.other b { color: var(--muted); font-weight: 600; }
.approval pre.plan { max-height: 340px; font-family: Inter, system-ui, sans-serif; font-size: 13.5px; }

/* origem da sessão */
.src { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; padding: 1px 6px; border-radius: 6px; margin-right: 6px; vertical-align: 1px; }
.src-code { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-2); }
.src-cowork { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }
.src-desktop { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.src-chat { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }

/* limites de uso e contexto */
.limits { display: grid; gap: 4px; }
.limit { display: grid; gap: 6px; padding: 6px 0; }
.limit-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 14px; }
.limit-label { font-weight: 500; }
.limit-meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.limit-meta b { color: var(--text); font-weight: 600; margin-left: 4px; }
.limit-bar { display: block; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.limit-bar i { display: block; height: 100%; border-radius: inherit; background: var(--info); transition: width .6s; }
.limit-bar i.warn { background: var(--warn); }
.limit-bar i.bad { background: var(--bad); }
.limits-org { margin: 8px 0 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.ctx { grid-column: 2 / -1; display: grid; gap: 4px; margin-top: 2px; }
.ctx-label { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctx .limit-bar { height: 4px; }
