:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14181f);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --ok: #1f9d55;
  --ok-bg: #e3f6ea;
  --note: #b7791f;
  --note-bg: #fdf1d6;
  --bad: #d64545;
  --bad-bg: #fde4e4;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.07);
  --line: rgba(127,127,127,.22);
  --tabh: 64px;
}
.dark {
  --ok-bg: #12351f;
  --note-bg: #3a2c0c;
  --bad-bg: #3d1616;
  --ok: #4ade80;
  --note: #fbbf24;
  --bad: #f87171;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
#app { max-width: 560px; margin: 0 auto; min-height: 100%; padding-bottom: calc(var(--tabh) + 16px + env(safe-area-inset-bottom, 0px)); }

/* screenshot frame: headless Chrome has a ~500px minimum window, so emulate a 390px phone */
html.frame body { width: 390px; height: 100vh; overflow: hidden; transform: translateZ(0); }
html.frame #app { height: 100%; overflow-y: auto; }

/* hero */
.hero {
  display: flex; align-items: center; gap: 14px;
  margin: 12px 14px 4px; padding: 18px 16px; border-radius: 22px;
  box-shadow: var(--shadow); transition: background .3s, color .3s;
}
.hero-ok { background: var(--ok-bg); color: var(--ok); }
.hero-note { background: var(--note-bg); color: var(--note); }
.hero-problem { background: var(--bad-bg); color: var(--bad); }
.hero-icon { width: 56px; height: 56px; border-radius: 50%; background: currentColor; display: grid; place-items: center; flex: none; }
.hero-icon svg { width: 32px; height: 32px; stroke: var(--bg); stroke-width: 3; }
.hero-title { font-size: 26px; font-weight: 700; line-height: 1.15; }
.hero-sub { font-size: 14px; color: var(--hint); margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.hero-sub.stale { color: var(--bad); font-weight: 600; }
.hero-sub svg { width: 16px; height: 16px; }

/* screens */
#screens { position: relative; }
.screen { display: none; padding: 10px 14px 0; }
.screen.active { display: block; animation: enter .28s ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen.active { animation: none; } }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--hint); margin: 18px 4px 8px; font-weight: 600; }

.card { background: var(--card); border-radius: 18px; padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 10px; overflow-wrap: anywhere; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 6px; }
.tile { background: var(--card); border-radius: 18px; padding: 12px 8px 10px; box-shadow: var(--shadow); text-align: center; min-height: 84px; display: flex; flex-direction: column; justify-content: center; }
.tile-num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.tile-label { font-size: 12px; color: var(--hint); margin-top: 2px; }
.tile.good .tile-num { color: var(--ok); }
.tile.warn .tile-num { color: var(--note); }
.tile.bad .tile-num { color: var(--bad); }

/* items */
.item { display: flex; gap: 12px; align-items: flex-start; }
.item .ic { margin-top: 1px; }
.item.note .ic { color: var(--note); }
.item.problem .ic { color: var(--bad); }
.item-title { font-weight: 600; }
.item-detail { color: var(--hint); font-size: 14px; margin-top: 2px; }
.empty { text-align: center; color: var(--hint); padding: 26px 12px; }
.empty svg { width: 40px; height: 40px; color: var(--ok); display: block; margin: 0 auto 8px; }

/* needs */
.task-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ident { font-weight: 700; font-size: 13px; color: var(--btn); letter-spacing: .02em; text-decoration: none; }
.age { font-size: 12px; color: var(--hint); white-space: nowrap; }
.age.old { color: var(--note); font-weight: 600; }
.task-title { font-weight: 600; font-size: 17px; margin: 4px 0 8px; }
.quote { border-left: 3px solid var(--btn); padding: 2px 0 2px 10px; font-size: 14px; color: var(--text); opacity: .88; margin-bottom: 12px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.btn { min-height: 46px; border-radius: 14px; border: 0; font: inherit; font-weight: 600; cursor: pointer; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: transform .1s, opacity .2s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--btn); color: var(--btn-text); }
.btn-no { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); }
.btn-ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn svg { width: 18px; height: 18px; stroke-width: 2.6; }
.answered { display: flex; align-items: center; gap: 8px; color: var(--ok); font-weight: 600; min-height: 46px; }

/* digest */
.cat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.cat-name { font-weight: 700; font-size: 17px; }
.badge-count { background: var(--btn); color: var(--btn-text); border-radius: 999px; min-width: 26px; height: 26px; padding: 0 8px; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.link { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 6px 0; color: var(--text); text-decoration: none; border-top: 1px solid var(--line); }
.link:first-of-type { border-top: 0; }
.link span { min-width: 0; }
.link svg { color: var(--hint); width: 18px; height: 18px; }
.more { color: var(--hint); font-size: 13px; padding-top: 6px; }

/* ask */
textarea { width: 100%; min-height: 150px; resize: none; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; padding: 14px; outline: none; }
textarea:focus { border-color: var(--btn); }
.ask-actions { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.ask-actions .btn { flex: 0 0 auto; min-width: 130px; }
.hint { color: var(--hint); font-size: 13px; }
.sent { text-align: center; padding: 30px 16px; }
.sent .big { width: 64px; height: 64px; border-radius: 50%; background: var(--ok); display: grid; place-items: center; margin: 0 auto 12px; }
.sent .big svg { stroke: var(--bg); width: 34px; height: 34px; stroke-width: 3; }
.sent h3 { margin: 0 0 6px; font-size: 20px; }
.sent p { margin: 0 0 16px; color: var(--hint); }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar-inner { display: flex; width: 100%; max-width: 560px; }
.tab { flex: 1; min-height: var(--tabh); background: none; border: 0; color: var(--hint); font: inherit; font-size: 12px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; position: relative; }
.tab.active { color: var(--btn); }
.tab .tab-ic { position: relative; display: grid; }
.tab .count { position: absolute; top: -6px; left: 14px; background: var(--bad); color: #fff; font-size: 11px; line-height: 1; font-weight: 700; border-radius: 999px; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px; border: 2px solid var(--bg); box-sizing: content-box; }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; opacity: 0; transition: opacity .25s; }
.sheet-backdrop.show { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-width: 560px; margin: 0 auto; background: var(--bg); border-radius: 24px 24px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateY(105%); transition: transform .28s cubic-bezier(.2,.8,.2,1); box-shadow: 0 -8px 30px rgba(0,0,0,.3); }
.sheet.show { transform: none; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet-title { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.sheet-body { color: var(--hint); font-size: 14px; margin-bottom: 16px; }
.sheet-actions { display: grid; gap: 8px; }
.sheet-actions .btn { min-height: 50px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + 18px); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 40; max-width: 90%; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
