:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #fff));
  --text: var(--tg-theme-text-color, #000);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, .2));
  --soft: rgba(128, 128, 128, .12);
  --red: #e5484d;
  --green: #30a46c;
  --r: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
body.reviewing { padding-bottom: 0; }
body.reviewing #tabs { display: none; }
main { max-width: 640px; margin: 0 auto; padding: 14px 16px 24px; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 0; }
button:disabled { opacity: .4; cursor: default; }
h2 { font-size: 22px; margin: 4px 0 14px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 22px 4px 8px; }
mark { background: none; color: var(--accent); }
.hint { color: var(--hint); font-size: 13px; margin: 8px 4px; }
.hint code { background: var(--soft); border-radius: 5px; padding: 1px 5px; }
.empty { color: var(--hint); text-align: center; padding: 28px 12px; margin: 0; }
.grow { flex: 1; min-width: 0; }

/* buttons */
.primary, .secondary, .danger { border-radius: 12px; padding: 12px 16px; font-weight: 600; transition: transform .08s; }
.primary { background: var(--btn); color: var(--btn-text); }
.secondary { background: var(--soft); color: var(--link); }
.danger { background: rgba(229, 72, 77, .12); color: var(--danger); }
.primary:active, .secondary:active, .danger:active, .pill:active, .rate button:active { transform: scale(.97); }
.wide { width: 100%; margin-top: 14px; }
.btns { display: flex; gap: 8px; }
.btns > * { flex: 1; }
.link { color: var(--hint); font-size: 14px; padding: 8px 12px; }

/* chips and segmented control */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; border-radius: 999px; padding: 6px 12px; background: var(--card); font-size: 14px; font-weight: 500; white-space: nowrap; }
.chip span { color: var(--hint); font-weight: 400; margin-left: 2px; }
.chip.on { background: var(--btn); color: var(--btn-text); }
.chip.on span { color: inherit; opacity: .75; }
.langin { width: 130px; border: 0; outline: 0; border-radius: 999px; padding: 6px 12px; background: var(--card); font-size: 14px; }
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; margin: 14px 0 0; }
h3 + .seg { margin-top: 0; }
.seg button { flex: 1; border-radius: 9px; padding: 7px 4px; font-size: 13px; font-weight: 500; color: var(--hint); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* home */
.hero { background: var(--card); border-radius: var(--r); padding: 20px 18px 18px; margin-top: 14px; text-align: center; }
.hero .big { font-size: 54px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.hero .sub { color: var(--hint); margin: 6px 0 18px; }
.list { background: var(--card); border-radius: var(--r); overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--sep); }
.row b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { display: block; color: var(--hint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { flex: none; border-radius: 10px; padding: 7px 10px; background: var(--soft); font-size: 13px; font-weight: 600; min-width: 54px; }
.pill.hot { background: var(--btn); color: var(--btn-text); }
.stats { display: flex; justify-content: center; gap: 16px; color: var(--hint); font-size: 14px; margin: 18px 0 0; }

/* review */
.review { display: flex; flex-direction: column; min-height: calc(var(--tg-viewport-stable-height, 100vh) - 28px); }
.rv-top { display: flex; justify-content: space-between; color: var(--hint); font-size: 13px; font-weight: 500; }
.bar { height: 4px; border-radius: 2px; background: var(--soft); margin: 8px 0 14px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--btn); border-radius: 2px; transition: width .25s; }
.card { flex: 1; background: var(--card); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 14px; min-height: 240px; position: relative; }
.card .tag { position: absolute; top: 14px; left: 16px; font-size: 12px; color: var(--hint); }
.card .q { font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.card .a { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; animation: rise .2s ease-out; }
.card .note { color: var(--hint); font-style: italic; font-size: 15px; overflow-wrap: anywhere; }
.reveal { border: 1.5px dashed var(--sep); border-radius: 12px; padding: 12px 18px; color: var(--hint); width: 100%; max-width: 360px; }
.verdict { border-radius: 10px; padding: 5px 12px; font-size: 14px; background: rgba(48, 164, 108, .15); }
.verdict.no { background: rgba(229, 72, 77, .14); }
.answer { display: flex; gap: 8px; margin-top: 12px; }
.answer input { flex: 1; min-width: 0; border: 0; outline: 0; border-radius: 12px; padding: 12px 14px; background: var(--card); }
.answer button { border-radius: 12px; padding: 0 16px; background: var(--soft); color: var(--link); font-weight: 600; }
.rate { display: flex; gap: 8px; margin-top: 12px; }
.rate button { flex: 1; border-radius: 14px; padding: 11px 4px; font-weight: 600; line-height: 1.2; transition: transform .08s; }
.rate small { display: block; font-size: 12px; font-weight: 500; margin-top: 3px; opacity: .8; }
.rate .r { background: rgba(229, 72, 77, .15); color: var(--red); }
.rate .g { background: rgba(51, 144, 236, .15); color: var(--link); }
.rate .f { background: rgba(48, 164, 108, .17); color: var(--green); }
.rv-sub { display: flex; justify-content: space-between; margin-top: 4px; padding-bottom: env(safe-area-inset-bottom); }
.done { text-align: center; padding: 40px 8px; }
.done .emoji { font-size: 56px; }
.done h2 { justify-content: center; margin: 8px 0 4px; }
.done .stats { margin: 12px 0 26px; font-size: 16px; color: var(--text); }
.done .btns { flex-direction: column; max-width: 320px; margin: 0 auto; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* forms */
.form label, .form .label { display: block; font-size: 13px; color: var(--hint); margin: 14px 4px 6px; }
.form label i { font-style: normal; opacity: .7; }
.form input, .form textarea { display: block; width: 100%; margin-top: 6px; border: 0; outline: 0; border-radius: 12px; padding: 12px 14px; background: var(--card); color: var(--text); font-size: 16px; }
.form textarea { resize: vertical; line-height: 1.45; }
.form input:focus, .form textarea:focus, .answer input:focus, .search input:focus { box-shadow: 0 0 0 2px var(--btn); }
.form .chips { margin: 0 0 8px; }
.form .newtopic { margin-top: 0; padding: 9px 12px; font-size: 14px; border-radius: 999px; background: var(--soft); }
.lang { font-size: 12px; font-weight: 600; background: var(--soft); color: var(--hint); border-radius: 6px; padding: 3px 7px; }
.result { background: var(--card); border-radius: 12px; padding: 12px 14px; margin-top: 14px; font-size: 14px; }
.result .bad { color: var(--danger); }
.search input { width: 100%; border: 0; outline: 0; border-radius: 12px; padding: 11px 14px; background: var(--card); }
.search + .chips { margin-top: 10px; margin-bottom: 12px; }
.word .st { flex: none; width: 22px; text-align: center; }
.word .tags { flex: none; max-width: 30%; color: var(--hint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* tabs */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--sep); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 5; }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 500; color: var(--hint); padding: 4px 0; }
#tabs button span { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
#tabs button.on { color: var(--link); }
#tabs button.on span { filter: none; opacity: 1; }

/* sheet */
#sheet { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#sheet .bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); opacity: 0; transition: opacity .2s; }
#sheet .body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92%; overflow-y: auto; background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .25s ease-out; max-width: 640px; margin: 0 auto; }
#sheet.open { pointer-events: auto; }
#sheet.open .bg { opacity: 1; }
#sheet.open .body { transform: none; }
.grab { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 6px; }
#sheet h3 { margin-top: 10px; }
#sheet .btns { margin-top: 18px; }

/* toast and loading */
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: rgba(30, 30, 30, .92); color: #fff; border-radius: 12px; padding: 10px 16px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 20; max-width: 90%; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: rgba(200, 50, 55, .95); }
.loading { text-align: center; color: var(--hint); padding: 60px 0; }
