:root {
  --bg: #F3F5F8; --surface: #FFFFFF; --text: #182230; --muted: #5B6575; --line: #C9D0DB;
  --accent: #245CDB; --accent-soft: #EAF0FF; --dark: #202B3B; --card: #172331; --toast-link: #BBD0FF;
  --warn-bg: #FDF0D0; --warn-text: #7A4F01; --warn-btn: #F4C95D; --ok-bg: #E3F6EA; --ok-text: #1B6B3A; --danger: #B42318;
  --vh: var(--tg-viewport-stable-height, 100vh);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; font-size: 14px; }
body { overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

#app { height: var(--vh); max-width: 520px; margin: 0 auto; position: relative; overflow: hidden; }
.scr { height: 100%; display: flex; flex-direction: column; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 16px; }

/* header */
.hdr { display: flex; align-items: center; gap: 12px; padding: 12px 16px 0 4px; flex-shrink: 0; }
.hdr.plain { padding-left: 16px; }
.back { width: 44px; height: 44px; border-radius: 16px; background: var(--surface); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.h-title { flex: 1; min-width: 0; }
.h1 { margin: 0; font-size: 24px; line-height: 30px; font-weight: 700; }
.h1.big { font-size: 27px; line-height: 36px; }
.h2 { margin: 0; font-size: 17px; line-height: 22px; font-weight: 600; }
.sub { font-size: 12px; line-height: 16px; color: var(--muted); }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--muted); }
.caps { font-size: 11px; line-height: 15px; font-weight: 600; color: var(--muted); }
.hint { font-size: 12px; line-height: 16px; color: var(--muted); margin: 0; }

/* buttons */
.btn { height: 44px; border-radius: 12px; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 0 14px; background: var(--surface); color: var(--text); }
.btn.soft, .btn.on { background: var(--accent-soft); color: var(--accent); }
.btn.grey { background: var(--bg); }
.btn.primary { height: 52px; background: var(--accent); color: #fff; width: 100%; }
.btn.primary[disabled] { background: var(--accent-soft); color: var(--muted); }
.btn.dashed { border: 1px dashed var(--line); }
.btn.icon { width: 44px; padding: 0; }
.btn.wide { width: 100%; }
.btn:active { opacity: .8; }
.bottom { background: var(--surface); padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; }
.bottom.row { flex-direction: row; }
.bottom.row > * { flex: 1; }

.panel { background: var(--surface); border-radius: 16px; padding: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack > * { flex-shrink: 0; }
.h1.sm { font-size: 20px; line-height: 26px; }
.pills { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pills .btn { flex-shrink: 0; padding: 0 10px; font-size: 12px; }

/* posts list */
.post { background: var(--surface); border-radius: 16px; padding: 12px 12px 8px; }
.post-top { display: flex; gap: 12px; width: 100%; text-align: left; }
.post-actions { display: flex; gap: 2px; margin: -16px 0 0 64px; }
.post-actions .btn { width: 88px; }
.thumb { position: relative; flex-shrink: 0; overflow: hidden; background: var(--card); border-radius: 8px; }

/* card preview boxes (cards are drawn at full size and scaled) */
.cr-box { position: relative; overflow: hidden; background: var(--card); flex-shrink: 0; }
.cr-box > .cr-inner { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.strip { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip .cr-box { border-radius: 12px; }
.strip .sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.lockbadge { position: absolute; right: 3px; top: 3px; width: 16px; height: 18px; border-radius: 4px; background: var(--text); display: flex; align-items: center; justify-content: center; z-index: 2; }
.check { position: absolute; right: 6px; top: 6px; width: 20px; height: 20px; border-radius: 4px; background: rgba(24,34,48,.5); display: flex; align-items: center; justify-content: center; z-index: 2; }
.on > .check { background: var(--accent); }

/* tools */
.tools { background: var(--surface); border-radius: 16px; height: 78px; padding: 6px 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); flex-shrink: 0; }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-size: 10px; line-height: 13px; font-weight: 500; border-radius: 10px; }
.tool.on { background: var(--accent-soft); color: var(--accent); }
.tool.blue { color: var(--accent); }

/* materials */
.mat { display: flex; align-items: center; gap: 14px; min-height: 48px; }
.mat .ico { width: 20px; height: 20px; color: var(--muted); flex-shrink: 0; }
.mat .t { font-size: 14px; line-height: 18px; font-weight: 500; }
.mat .d { font-size: 11px; line-height: 15px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mat-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--bg); }

.fmt { height: 60px; border-radius: 12px; text-align: left; padding: 0 12px; background: var(--surface); border: 1.5px solid transparent; }
.fmt.on { border-color: var(--accent); background: var(--accent-soft); }
.fmt b { display: block; font-size: 16px; line-height: 20px; }
.fmt span { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }

.switch { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--line); flex-shrink: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 10px; background: #fff; transition: left .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { left: 21px; }
.cb { width: 22px; height: 22px; border-radius: 5px; border: 1.5px solid var(--muted); background: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cb.on { background: var(--accent); border-color: var(--accent); }

.field { height: 48px; border-radius: 12px; border: 0; background: var(--surface); padding: 0 14px; font-size: 15px; width: 100%; outline: none; }
.area { border-radius: 12px; border: 0; background: var(--bg); padding: 12px 14px; font-size: 15px; width: 100%; resize: none; outline: none; line-height: 1.4; }
.field:focus, .area:focus { box-shadow: 0 0 0 2px var(--accent-soft); }

/* sliders */
.slider { display: flex; flex-direction: column; padding: 2px 0; }
.slider .top { display: flex; font-size: 13px; line-height: 18px; }
.slider .top label { flex: 1; font-weight: 500; }
.slider .top span { color: var(--muted); }
input[type=range] { width: 100%; height: 28px; margin: 0; accent-color: var(--accent); }

.read { min-height: 60px; border-radius: 12px; padding: 8px 8px 8px 12px; display: flex; align-items: center; gap: 10px; font-size: 13px; line-height: 18px; }
.read.bad { background: var(--warn-bg); color: var(--warn-text); }
.read.good { background: var(--ok-bg); color: var(--ok-text); }
.read .btn { background: var(--warn-btn); color: var(--text); width: 104px; flex-shrink: 0; }

/* versions */
.ver { border-radius: 16px; background: var(--surface); }
.ver.cur { background: var(--accent-soft); outline: 1.5px solid var(--accent); }
.ver-head { width: 100%; padding: 12px; display: flex; gap: 10px; text-align: left; align-items: flex-start; }
.ver-name { font-size: 16px; line-height: 21px; font-weight: 600; }
.ver.cur .ver-name { color: var(--accent); }

/* overlays */
.toast { position: absolute; left: 16px; right: 16px; top: 72px; z-index: 50; background: var(--dark); color: #fff; border-radius: 14px; padding: 14px;
  font-size: 14px; line-height: 18px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.toast button { color: var(--toast-link); font-weight: 600; min-height: 32px; padding: 0 6px; }
.dim { position: absolute; inset: 0; background: rgba(243,245,248,.7); z-index: 30; }
.dim.dark { background: rgba(24,34,48,.35); }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 31; background: var(--surface); border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 24px rgba(24,34,48,.1); padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px;
  max-height: 88%; overflow-y: auto; }
.sheet .grip { width: 44px; height: 4px; border-radius: 2px; background: var(--line); align-self: center; flex-shrink: 0; }
.sheet-head { display: flex; align-items: center; }
.sheet-head .h1 { font-size: 22px; line-height: 28px; flex: 1; }
.dialog { position: absolute; left: 24px; right: 24px; top: 30%; z-index: 31; background: var(--surface); border-radius: 16px; padding: 18px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.busy { position: absolute; inset: 0; z-index: 60; background: rgba(243,245,248,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 32px; text-align: center; }
.spin { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.err { color: var(--danger); }
