:root {
  --bg: #12101f;
  --bg2: #1b1830;
  --surface: #221f3b;
  --line: rgba(255, 255, 255, .09);
  --text: #f4f2ff;
  --muted: #a7a3c7;
  --like: #2fe08f;
  --nope: #ff5470;
  --brand1: #ff5e62;
  --brand2: #ff9966;
  --accent: #8b7bff;
  --radius: 26px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f4ff; --bg2: #ece9fb; --surface: #fff; --line: rgba(20, 16, 50, .1);
    --text: #1c1838; --muted: #66628a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg2), var(--bg));
  color: var(--text);
  font: 16px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

#app {
  max-width: 480px; margin: 0 auto; height: 100dvh;
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 6px; }
.logo { display: flex; align-items: center; gap: 6px; }
.flame { font-size: 26px; filter: drop-shadow(0 2px 8px rgba(255, 94, 98, .5)); }
.brand {
  font-weight: 800; font-size: 26px; letter-spacing: -.5px;
  background: linear-gradient(90deg, var(--brand1), var(--brand2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.top-right { display: flex; align-items: center; gap: 8px; }
.pill {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: 14px;
}
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center;
}
.icon-btn .dot { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand1); }

/* ---------- views ---------- */
main { flex: 1; min-height: 0; position: relative; }
.view { display: none; height: 100%; }
.view.active { display: flex; flex-direction: column; }
#view-saved, #view-me { overflow-y: auto; padding: 8px 16px 16px; }

/* ---------- deck ---------- */
.deck { position: relative; flex: 1; min-height: 0; margin: 6px 14px 0; }
.card {
  position: absolute; inset: 0 0 4px 0;
  border-radius: var(--radius);
  background: linear-gradient(155deg, var(--c1), var(--c2));
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .25);
  color: #fff; overflow: hidden;
  display: flex; flex-direction: column;
  padding: 22px 22px 18px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform .32s cubic-bezier(.2, .8, .2, 1), opacity .25s;
  will-change: transform;
}
.card.dragging { transition: none; cursor: grabbing; }
.card.behind { pointer-events: none; }
.card::before { /* hoa văn mờ */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(260px 260px at 90% 8%, rgba(255, 255, 255, .22), transparent 70%),
    radial-gradient(300px 300px at 0% 100%, rgba(0, 0, 0, .28), transparent 70%);
}
.card > * { position: relative; }
.c-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; opacity: .95; }
.c-head > span { white-space: nowrap; flex: none; }
.c-head .chip-top {
  background: rgba(0, 0, 0, .22); backdrop-filter: blur(6px);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto !important; min-width: 0;
}
.c-head .daily { background: #fff; color: #c2410c; padding: 4px 10px; border-radius: 999px; font-weight: 700; }
.c-head .grade { margin-left: auto; font-size: 12px; background: rgba(255, 255, 255, .22); padding: 4px 10px; border-radius: 999px; }
.c-emoji { font-size: 60px; line-height: 1; margin: 12px 0 6px; flex: none; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .3)); }
.c-title { font-size: 25px; line-height: 1.28; font-weight: 800; margin: 0 0 12px; letter-spacing: -.3px; text-wrap: balance; }
.c-body { flex: 1 1 auto; min-height: 0; overflow: hidden; -webkit-mask-image: linear-gradient(#000 88%, transparent); mask-image: linear-gradient(#000 88%, transparent); }
.c-title.sm { font-size: 20px; margin-bottom: 8px; }
.c-plain { font-size: 15px; line-height: 1.5; opacity: .95; margin: 0; }
.c-orig { font-size: 12.5px; opacity: .75; margin: 10px 0 0; }
.c-foot { margin-top: auto; padding-top: 12px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { background: rgba(0, 0, 0, .24); padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; }
.c-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 13px; opacity: .92; }
.c-meta .tr { background: rgba(255, 255, 255, .2); border-radius: 999px; padding: 4px 11px; font-weight: 600; }
.stamp {
  position: absolute !important; top: 34px; padding: 4px 14px; border: 4px solid; border-radius: 12px;
  font-weight: 800; font-size: 30px; letter-spacing: 2px; opacity: 0; pointer-events: none; background: rgba(0, 0, 0, .12);
}
.stamp.s-like { left: 20px; color: var(--like); border-color: var(--like); transform: rotate(-14deg); }
.stamp.s-nope { right: 20px; color: var(--nope); border-color: var(--nope); transform: rotate(14deg); }

.empty { margin: auto; text-align: center; padding: 32px; color: var(--muted); }
.empty .big { font-size: 64px; }
.empty h2 { color: var(--text); margin: 8px 0; }

/* ---------- action buttons ---------- */
.actions { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px 12px 12px; }
.act {
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
  transition: transform .15s, background .15s;
}
.act:active { transform: scale(.88); }
.act.small { width: 46px; height: 46px; color: var(--muted); }
.act.big { width: 68px; height: 68px; }
.act.nope { color: var(--nope); }
.act.like { color: var(--like); }
.act.big:hover { transform: scale(1.06); }
.act:disabled { opacity: .35; pointer-events: none; }

/* ---------- tab bar ---------- */
.tabs {
  display: flex; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); padding-bottom: var(--safe-b);
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.tabs button.on { color: var(--brand1); }

/* ---------- list / saved ---------- */
.seg { display: flex; background: var(--surface); border-radius: 12px; padding: 4px; gap: 4px; margin: 6px 0 12px; border: 1px solid var(--line); }
.seg button { flex: 1; padding: 8px 4px; border-radius: 9px; font-weight: 600; font-size: 13px; white-space: nowrap; color: var(--muted); }
.seg button.on { background: linear-gradient(90deg, var(--brand1), var(--brand2)); color: #fff; }
.list { display: grid; gap: 10px; }
.row {
  display: flex; gap: 12px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; align-items: flex-start;
}
.row .badge { flex: none; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 24px; background: linear-gradient(155deg, var(--c1), var(--c2)); }
.row b { display: block; font-size: 15px; line-height: 1.35; }
.row small { color: var(--muted); display: block; margin-top: 2px; font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.muted { color: var(--muted); }

/* ---------- profile ---------- */
.profile-head { text-align: center; padding: 18px 0 8px; }
.avatar-lg { font-size: 64px; width: 100px; height: 100px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 8px; background: linear-gradient(155deg, var(--brand1), var(--accent)); }
.stats3 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 6px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 12px 0; }
.box h3 { margin: 0 0 8px; font-size: 15px; }
.avatars { display: flex; flex-wrap: wrap; gap: 8px; }
.avatars button { width: 44px; height: 44px; border-radius: 12px; font-size: 24px; background: var(--bg2); border: 2px solid transparent; }
.avatars button.on { border-color: var(--brand1); }
.btn {
  display: inline-flex; justify-content: center; align-items: center; gap: 6px; width: 100%;
  padding: 13px 18px; border-radius: 14px; font-weight: 700;
  background: linear-gradient(90deg, var(--brand1), var(--brand2)); color: #fff;
}
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn:disabled { opacity: .6; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--brand1); }
.about { font-size: 13px; color: var(--muted); line-height: 1.55; }
.about a { color: var(--accent); }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(5, 3, 15, .6); backdrop-filter: blur(3px); z-index: 20; opacity: 0; transition: opacity .2s; }
.scrim.in { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; margin: 0 auto; max-width: 480px;
  max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 26px 26px 0 0; border: 1px solid var(--line); border-bottom: 0;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: var(--safe-b);
}
.sheet.in { transform: none; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 4px; flex: none; }
.sheet .s-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 18px 10px; flex: none; }
.sheet .s-head h2 { margin: 0; font-size: 18px; }
.sheet .s-body { overflow-y: auto; padding: 0 18px 18px; flex: 1; min-height: 0; }
.x { width: 34px; height: 34px; border-radius: 50%; background: var(--surface); font-size: 16px; }

.d-hero { border-radius: 20px; padding: 18px; color: #fff; background: linear-gradient(155deg, var(--c1), var(--c2)); margin-bottom: 14px; }
.d-hero .e { font-size: 44px; }
.d-hero h3 { margin: 6px 0 0; font-size: 21px; line-height: 1.3; }
.d-sec { margin: 14px 0; }
.d-sec h4 { margin: 0 0 4px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.d-sec p { margin: 0; font-size: 15px; word-break: break-word; }
.d-srcs a { display: inline-block; margin: 2px 8px 2px 0; color: var(--accent); font-size: 14px; word-break: break-all; }
.chips.dark span { background: var(--surface); border: 1px solid var(--line); }

/* comments */
.cm { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cm .av { flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 20px; }
.cm .who { font-size: 13px; font-weight: 700; }
.cm .who small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.cm p { margin: 2px 0 0; font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.cm .del { color: var(--muted); font-size: 12px; margin-top: 2px; }
.composer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex: none; }
.composer textarea, .field input {
  flex: 1; width: 100%; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 11px 14px; font: inherit; resize: none;
}
.composer .send { flex: none; width: 46px; border-radius: 14px; background: linear-gradient(90deg, var(--brand1), var(--brand2)); color: #fff; font-size: 18px; }

/* forms */
.field { margin: 10px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.err { color: var(--nope); font-size: 14px; min-height: 20px; margin: 6px 0; }
.topics { display: flex; flex-wrap: wrap; gap: 8px; }
.topics button { padding: 8px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.topics button.on { background: linear-gradient(90deg, var(--brand1), var(--brand2)); color: #fff; border-color: transparent; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0;
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 40;
  transition: .25s; pointer-events: none; max-width: 90vw; text-align: center; backdrop-filter: blur(8px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 640px) {
  .c-emoji { font-size: 52px; margin: 8px 0 2px; }
  .c-title { font-size: 21px; }
  .act.big { width: 58px; height: 58px; }
  .actions { padding: 8px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- thử thách 7 ngày ---------- */
.nudge {
  display: flex; align-items: center; gap: 10px; margin: 4px 14px 0; padding: 10px 12px;
  background: linear-gradient(90deg, rgba(255, 94, 98, .18), rgba(255, 153, 102, .18));
  border: 1px solid rgba(255, 153, 102, .35); border-radius: 16px;
}
.nudge .nudge-text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.35; }
.nudge .nudge-text b { display: block; }
.nudge .nudge-text span { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nudge button { flex: none; padding: 7px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; background: linear-gradient(90deg, var(--brand1), var(--brand2)); color: #fff; }
.nudge button.later { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.chcard { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: grid; gap: 10px; }
.chcard.done { border-color: rgba(47, 224, 143, .45); }
.chcard.expired { opacity: .75; }
.chcard .row-top { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; }
.chcard .badge { flex: none; width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 22px; background: linear-gradient(155deg, var(--c1), var(--c2)); }
.chcard b { font-size: 15px; line-height: 1.35; display: block; }
.chcard small { color: var(--muted); }
.dots { display: flex; gap: 6px; }
.dots i { flex: 1; height: 10px; border-radius: 6px; background: var(--bg2); border: 1px solid var(--line); }
.dots i.on { background: linear-gradient(90deg, var(--brand1), var(--brand2)); border-color: transparent; }
.dots i.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.dots i.past { opacity: .55; }
.chbtns { display: flex; gap: 8px; }
.chbtns .btn { padding: 10px 14px; font-size: 14px; }
.chbtns .btn.small { width: auto; flex: none; }
.composer.wrap { flex-wrap: wrap; }
.composer.wrap .btn { flex: 1 1 140px; width: auto; padding: 11px 14px; font-size: 14px; }
.vn-note { font-size: 13px; color: var(--muted); }

/* ---------- cộng đồng ---------- */
.sel { width: 100%; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 11px 14px; font: inherit; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badges span { font-size: 12.5px; padding: 5px 10px; border-radius: 999px; background: var(--bg2); color: var(--muted); border: 1px dashed var(--line); filter: grayscale(1); opacity: .6; }
.badges span.on { filter: none; opacity: 1; color: var(--text); border: 1px solid rgba(255, 153, 102, .5); background: linear-gradient(90deg, rgba(255, 94, 98, .16), rgba(255, 153, 102, .16)); }
.lb { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.lb:last-child { border-bottom: 0; }
.lb .who { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb small { color: var(--muted); flex: none; }
