:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #fff));
  --text: var(--tg-theme-text-color, #111);
  --hint: var(--tg-theme-hint-color, #8a8a8f);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --on-accent: var(--tg-theme-button-text-color, #fff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --line: var(--tg-theme-section-separator-color, rgba(128, 128, 128, .22));
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9f0a;
  --grey: #a0a0a8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #0f0f10);
    --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
    --text: var(--tg-theme-text-color, #fff);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
main { max-width: 560px; margin: 0 auto; padding: 12px 16px calc(84px + env(safe-area-inset-bottom, 0px)); }
main.solo { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }

h1 { font-size: 24px; font-weight: 700; margin: 6px 4px 14px; overflow-wrap: anywhere; }
.lead { color: var(--hint); margin: -12px 4px 14px; font-size: 15px; }
.lead b { color: var(--text); font-weight: 600; }
.back { display: inline-block; color: var(--link); padding: 4px; margin-bottom: 2px; cursor: pointer; }

section { margin: 0 0 18px; }
section > h3.path { text-transform: none; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
section > h3 { font-size: 13px; font-weight: 500; color: var(--hint); text-transform: uppercase; letter-spacing: .02em; margin: 0 12px 6px; }
.card { background: var(--card); border-radius: 12px; overflow: hidden; }

.row { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 9px 14px; position: relative; }
.row + .row::before { content: ""; position: absolute; left: 14px; right: 0; top: 0; border-top: 1px solid var(--line); }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--line); }
.row .l { flex: 1 1 auto; min-width: 0; }
.row .t { overflow-wrap: anywhere; }
.row .sub { color: var(--hint); font-size: 13px; margin-top: 1px; overflow-wrap: anywhere; }
.row .v { flex: 0 1 auto; color: var(--hint); text-align: right; max-width: 60%; overflow-wrap: anywhere; }
.row .chev { color: var(--hint); opacity: .6; font-size: 18px; margin-left: -4px; }
.row.action .t { color: var(--link); }
.row.danger .t { color: var(--danger); }
.row.mono .v { font: 13px ui-monospace, Menlo, monospace; color: var(--text); }

.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--grey); }
.dot.up { background: var(--green); }
.dot.down { background: var(--red); }
.dot.warn { background: var(--amber); }

.row select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; color: var(--link);
  font: inherit; text-align: right; text-align-last: right; max-width: 62%; padding: 4px 0; direction: rtl;
}
.row select option { direction: ltr; }

.switch { flex: none; position: relative; width: 50px; height: 30px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 15px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:disabled + i { opacity: .5; }

.status { background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 18px; }
.status .head { font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.status ul { margin: 8px 0 0; padding-left: 18px; color: var(--hint); font-size: 14px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.tile { background: var(--card); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile b { display: block; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile span { color: var(--hint); font-size: 12px; }

.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.full i { background: var(--red); }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 110px; padding: 14px 14px 0; }
.bars div { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.barlabels { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 4px 14px 12px; font-size: 11px; color: var(--hint); text-align: center; }
.barlabels b { display: block; color: var(--text); font-weight: 500; font-size: 11px; white-space: nowrap; }

pre { margin: 0; padding: 12px 14px; font: 12px/1.45 ui-monospace, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { color: var(--hint); padding: 14px; text-align: center; }
.seg { display: flex; background: var(--line); border-radius: 9px; padding: 2px; margin: 0 0 14px; }
.seg div { flex: 1; text-align: center; padding: 6px; border-radius: 7px; font-size: 14px; cursor: pointer; }
.seg .on { background: var(--card); font-weight: 600; }

nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 5;
}
nav div { flex: 1; max-width: 140px; text-align: center; padding: 9px 4px 8px; font-size: 12px; color: var(--hint); cursor: pointer; }
nav div b { display: block; font-size: 20px; font-weight: 400; line-height: 1.1; filter: grayscale(1); opacity: .7; }
nav div.on { color: var(--link); }
nav div.on b { filter: none; opacity: 1; }

.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.sheet h2 { font-size: 18px; margin: 0 4px 12px; overflow-wrap: anywhere; }
.sheet p { margin: 0 4px 14px; color: var(--hint); font-size: 15px; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 13px; color: var(--hint); margin: 0 12px 4px; }
.field input, .field select {
  width: 100%; border: 0; border-radius: 12px; background: var(--card); color: var(--text);
  font: inherit; padding: 12px 14px; outline: none; appearance: none; -webkit-appearance: none;
}
.err { color: var(--danger); font-size: 14px; margin: 4px 4px 10px; white-space: pre-line; }
.btns { display: flex; gap: 8px; margin-top: 14px; }
button {
  flex: 1; border: 0; border-radius: 12px; padding: 13px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
}
button.plain { background: var(--card); color: var(--text); font-weight: 500; }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: .5; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: rgba(30, 30, 32, .94); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: 88vw; z-index: 20; white-space: pre-line; text-align: center;
}
#toast.bad { background: var(--red); }
.center { min-height: 70vh; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--hint); padding: 24px; }

@keyframes from-right { from { opacity: 0; transform: translateX(28px); } }
@keyframes from-left { from { opacity: 0; transform: translateX(-28px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-down { to { transform: translateY(100%); } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes bar-grow { from { transform: scaleY(0); } }
@keyframes meter-fill { from { transform: scaleX(0); } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px) scale(.96); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52, 199, 89, .55); } 100% { box-shadow: 0 0 0 9px rgba(52, 199, 89, 0); } }

main.push > *, main.pop > *, main.tab > * { animation: from-right .32s cubic-bezier(.2, .8, .2, 1) both; }
main.pop > * { animation-name: from-left; }
main.tab > * { animation-name: rise; }
main > :nth-child(2) { animation-delay: .03s; }
main > :nth-child(3) { animation-delay: .06s; }
main > :nth-child(4) { animation-delay: .09s; }
main > :nth-child(5) { animation-delay: .12s; }
main > :nth-child(6) { animation-delay: .15s; }
main > :nth-child(n+7) { animation-delay: .18s; }

.bars div { transform-origin: bottom; }
.meter i { transform-origin: left; }
main.push .bars div, main.pop .bars div, main.tab .bars div, .grow.fresh .bars div { animation: bar-grow .55s cubic-bezier(.2, .8, .2, 1) .12s both; }
main.push .meter i, main.pop .meter i, main.tab .meter i { animation: meter-fill .7s cubic-bezier(.2, .8, .2, 1) .15s both; }
.grow.fresh { animation: rise .3s ease both; }
.bars div:nth-child(2) { animation-delay: .16s !important; }
.bars div:nth-child(3) { animation-delay: .20s !important; }
.bars div:nth-child(4) { animation-delay: .24s !important; }
.bars div:nth-child(5) { animation-delay: .28s !important; }
.bars div:nth-child(6) { animation-delay: .32s !important; }
.bars div:nth-child(7) { animation-delay: .36s !important; }

.status .dot.up { animation: pulse 2.2s ease-out infinite; }

.overlay { animation: fade .2s ease both; }
.sheet { animation: sheet-up .32s cubic-bezier(.2, .9, .2, 1) both; }
.overlay.closing { animation: fade-out .2s ease both; pointer-events: none; }
.overlay.closing .sheet { animation: sheet-down .2s ease-in both; }

#toast { animation: toast-in .25s cubic-bezier(.2, .9, .2, 1) both; }
#toast.out { animation: fade-out .2s ease both; }

nav div b { transition: transform .15s; }
nav div:active b { transform: scale(.85); }
nav div.picked b { animation: pop .35s ease both; }
.row.tap, .seg div, nav div { transition: background-color .15s; }
button { transition: transform .12s, opacity .15s; }
button:active { transform: scale(.97); }
.tile { transition: transform .12s; }
.seg .on { transition: background-color .2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
