:root{
  --bg:#EDF1F5; --surface:#FFFFFF; --ink:#16233B; --muted:#5B677A; --rule:#D3DAE3;
  --hi:#FFD54A; --red:#C2362B; --focus:#2F6FEB; --shade:rgba(22,35,59,.10);
  --display:"Bricolage Grotesque","Avenir Next","Segoe UI","PingFang HK","Noto Sans HK","Microsoft JhengHei",system-ui,sans-serif;
  --body:"Instrument Sans","Helvetica Neue",Arial,"PingFang HK","Noto Sans HK","Microsoft JhengHei",system-ui,sans-serif;
}
@media (prefers-color-scheme:dark){:root{
  --bg:#121925; --surface:#1B2432; --ink:#E7ECF3; --muted:#98A3B4; --rule:#2B3647;
  --hi:#F2C640; --red:#E36A5E; --focus:#7AA7FF; --shade:rgba(0,0,0,.35);
}}
*,*::before,*::after{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.55 var(--body);min-height:100vh;display:flex;flex-direction:column}
img{max-width:100%;display:block}
a{color:inherit}
button,input,select,textarea{font:inherit;color:inherit}
:focus-visible{outline:3px solid var(--focus);outline-offset:2px}
.wrap{width:100%;max-width:1120px;margin:0 auto;padding:0 20px}
main{flex:1;padding-bottom:60px}
h1{font:800 clamp(1.9rem,4.5vw,2.8rem)/1.05 var(--display);letter-spacing:-.02em;margin:28px 0 8px}
h2{font:700 1.35rem/1.2 var(--display);margin:28px 0 10px}
h3{font:700 1.05rem/1.3 var(--display);margin:0}
.lead{color:var(--muted);max-width:62ch;margin:0 0 18px}
.muted{color:var(--muted)}
.small{font-size:.87rem}

/* Header */
.top{background:var(--surface);border-bottom:1px solid var(--rule);position:sticky;top:0;z-index:5}
.bar{display:flex;align-items:center;gap:18px;min-height:62px;flex-wrap:wrap}
.brand{font:800 1.45rem var(--display);text-decoration:none;letter-spacing:-.02em;display:flex;align-items:center;gap:9px}
.brand img{width:30px;height:30px}
nav{display:flex;gap:4px;flex-wrap:wrap}
nav a{text-decoration:none;padding:7px 11px;border-radius:8px;color:var(--muted);font-weight:500}
nav a[aria-current="page"]{color:var(--ink);background:var(--bg)}
.right{margin-left:auto;display:flex;gap:10px;align-items:center}
.lang{display:flex;border:1px solid var(--rule);border-radius:8px;overflow:hidden;font-size:.85rem}
.lang button{border:0;background:none;padding:5px 9px;cursor:pointer}
.lang button[aria-pressed="true"]{background:var(--ink);color:var(--bg)}
.lang button:disabled{cursor:not-allowed;opacity:.5}

/* The exchange slip: SwapSheet's signature element */
.slip{position:relative;border:1.5px dashed var(--ink);border-radius:6px;padding:4px 12px 4px 16px;display:flex;align-items:center;gap:8px;text-decoration:none;background:var(--surface)}
.slip::before{content:"";position:absolute;left:-7px;top:50%;margin-top:-6px;width:12px;height:12px;border-radius:50%;background:var(--surface);border:1.5px dashed var(--ink)}
.slip b{font:800 1.5rem/1 var(--display);color:var(--red)}
.slip span{font-size:.8rem;color:var(--muted);line-height:1.2}

/* Buttons and fields */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;border:0;border-radius:10px;padding:10px 16px;font-weight:600;cursor:pointer;background:var(--ink);color:var(--bg);text-decoration:none}
.btn.hi{background:var(--hi);color:#16233B}
.btn.ghost{background:transparent;color:var(--ink);border:1px solid var(--rule)}
.btn.danger{background:var(--red);color:#fff}
.btn.sm{padding:7px 12px;font-size:.88rem}
.btn:disabled{opacity:.45;cursor:not-allowed}
.link{background:none;border:0;padding:0;color:var(--muted);text-decoration:underline;text-underline-offset:3px;cursor:pointer}
label.f{display:grid;gap:5px;font-weight:600;font-size:.92rem}
input[type=text],input[type=email],input[type=number],input[type=search],select,textarea{width:100%;border:1px solid var(--rule);border-radius:9px;padding:10px 12px;background:var(--surface);font-weight:400}
textarea{min-height:100px;resize:vertical}
.check{display:flex;gap:10px;align-items:flex-start;font-size:.9rem;color:var(--muted)}
.check input{margin-top:4px}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.stack{display:grid;gap:14px}
.err{color:var(--red);font-size:.92rem;min-height:1.3em}
.ok{color:#2E7D4F}
.note{background:var(--surface);border:1px solid var(--rule);border-left:5px solid var(--hi);border-radius:8px;padding:12px 14px}
.warn{border-left-color:var(--red)}

/* Filters */
.filters{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin:8px 0 6px}
.filters input{flex:1 1 260px}
.filters select{width:auto}
.chips{display:flex;gap:8px;overflow-x:auto;padding:6px 2px 12px}
.chip{flex:none;border:1px solid var(--rule);background:var(--surface);border-radius:999px;padding:6px 13px;cursor:pointer;font-size:.88rem;display:flex;gap:7px;align-items:center}
.chip i{width:9px;height:9px;border-radius:50%;background:var(--c,var(--muted))}
.chip[aria-pressed="true"]{background:var(--ink);color:var(--bg);border-color:var(--ink)}

/* Document cards: sheets of paper */
.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:18px}
.sheet{position:relative;background:var(--surface);border:1px solid var(--rule);border-radius:4px;text-decoration:none;display:flex;flex-direction:column;overflow:hidden}
.sheet::before{content:"";position:absolute;left:0;top:0;bottom:0;width:5px;background:var(--c,var(--muted));z-index:1}
.thumb{aspect-ratio:4/3;background:var(--bg);overflow:hidden;border-bottom:1px solid var(--rule)}
.thumb img{width:100%;height:100%;object-fit:cover;object-position:top}
.thumb.blank{background-image:repeating-linear-gradient(to bottom,transparent 0 17px,var(--rule) 17px 18px)}
.sheet .body{padding:12px 14px 14px 18px;display:grid;gap:6px}
.meta{font-size:.82rem;color:var(--muted);display:flex;flex-wrap:wrap;gap:3px 10px}
.tag{font-size:.76rem;padding:2px 8px;border-radius:5px;background:var(--bg);color:var(--muted);justify-self:start}
.tag.free{color:#2E7D4F}.tag.own{color:var(--red)}
.empty{text-align:center;padding:50px 20px;border:1.5px dashed var(--rule);border-radius:10px;color:var(--muted)}
.empty strong{display:block;color:var(--ink);font:700 1.25rem var(--display);margin-bottom:6px}

/* Document page */
.docpage{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(280px,1fr);gap:28px;align-items:start;margin-top:22px}
.pages{display:grid;gap:14px}
.page{background:#fff;border:1px solid var(--rule);border-radius:4px;box-shadow:0 6px 20px var(--shade);overflow:hidden}
.lockband{position:relative;border:1.5px dashed var(--rule);border-radius:6px;padding:26px 18px;text-align:center;color:var(--muted);background:repeating-linear-gradient(to bottom,var(--surface) 0 17px,var(--rule) 17px 18px)}
.lockband strong{display:block;color:var(--ink);font:700 1.1rem var(--display);background:var(--surface);padding:2px 0}
.fade{position:relative}
.fade::after{content:"";position:absolute;left:0;right:0;bottom:0;height:40%;background:linear-gradient(to bottom,transparent,var(--surface))}
.panel{background:var(--surface);border:1px solid var(--rule);border-radius:10px;padding:20px;display:grid;gap:12px;position:sticky;top:80px}
.panel dl{display:grid;grid-template-columns:auto 1fr;gap:4px 12px;margin:0;font-size:.92rem}
.panel dt{color:var(--muted)}
.panel dd{margin:0}

/* Sponsors */
.sponsor{background:var(--surface);border:1px solid var(--rule);border-radius:10px;padding:18px;display:grid;gap:12px;margin-bottom:18px}
.sponsor .head{display:flex;gap:14px;align-items:center;flex-wrap:wrap}
.sponsor .logo{width:56px;height:56px;border-radius:10px;object-fit:contain;background:#fff;border:1px solid var(--rule)}

/* Tables and lists */
.list{display:grid;gap:10px}
.row{background:var(--surface);border:1px solid var(--rule);border-radius:9px;padding:12px 14px;display:grid;gap:6px}
.row .acts{display:flex;gap:8px;flex-wrap:wrap}

/* Dialog */
dialog{border:0;border-radius:14px;padding:0;background:var(--surface);color:var(--ink);width:min(560px,94vw);max-height:92vh;box-shadow:0 20px 60px var(--shade)}
dialog.wide{width:min(960px,96vw)}
dialog::backdrop{background:rgba(10,16,28,.55)}
.dlg{padding:22px;display:grid;gap:14px}
.viewer{width:100%;height:75vh;border:1px solid var(--rule);border-radius:8px;background:#fff}

.foot{display:flex;flex-wrap:wrap;gap:8px 20px;padding:22px 20px 30px;border-top:1px solid var(--rule);font-size:.87rem;color:var(--muted)}
.foot a{color:inherit}
.prose{max-width:70ch}
.prose h2{font-size:1.1rem;margin:22px 0 6px}
.prose p,.prose li{margin:.35rem 0}

@media (max-width:760px){
  .docpage{grid-template-columns:1fr}
  .panel{position:static}
  .grid2{grid-template-columns:1fr}
  nav{order:3;width:100%;overflow-x:auto;flex-wrap:nowrap}
}

/* Account button (top right) */
.acct{display:flex;align-items:center;gap:9px;text-decoration:none;padding:4px 10px 4px 4px;border:1px solid var(--rule);border-radius:999px;background:var(--surface)}
.acct[aria-current="page"]{border-color:var(--ink)}
.av{width:30px;height:30px;border-radius:50%;background:var(--ink);color:var(--bg);display:grid;place-items:center;font:700 .95rem var(--display)}
.acct-t{display:grid;line-height:1.15}
.acct-t b{font-size:.88rem}
.acct-t small{font-size:.76rem;color:var(--red);font-weight:600}

/* Folders: the tab on top makes each tile read as a file folder */
.folders{display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:22px 16px;margin:18px 0 8px}
.folder{position:relative;display:grid;gap:4px;text-decoration:none;background:var(--surface);border:1px solid var(--rule);border-top:4px solid var(--c,var(--muted));border-radius:0 8px 8px 8px;padding:14px 14px 12px;min-height:84px}
.folder::before{content:"";position:absolute;top:-14px;left:-1px;width:44%;height:12px;background:var(--c,var(--muted));border-radius:6px 6px 0 0}
.folder:hover{border-color:var(--c,var(--ink))}
.fname{font:700 1rem/1.25 var(--display)}
.fcount{font-size:.82rem;color:var(--muted)}
.crumbs{display:flex;flex-wrap:wrap;gap:6px;align-items:center;font-size:.9rem;color:var(--muted);margin:-2px 0 10px}
.crumbs a{color:var(--muted)}
a.chip{text-decoration:none;color:var(--ink)}

/* Account page */
.acctgrid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:18px}
.box{background:var(--surface);border:1px solid var(--rule);border-radius:10px;padding:18px;display:grid;gap:10px;align-content:start}
.box h2{margin:0}
.kv{display:grid;grid-template-columns:auto 1fr;gap:4px 14px;margin:0;font-size:.95rem}
.kv dt{color:var(--muted)}.kv dd{margin:0;overflow-wrap:anywhere}
.bignum{font:800 3rem/1 var(--display);color:var(--red)}

/* Moderator tools */
.adminbox{border:1.5px dashed var(--red);border-radius:8px;padding:10px 12px;display:grid;gap:8px}
.subgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:6px 12px;max-height:240px;overflow:auto;border:1px solid var(--rule);border-radius:8px;padding:10px}

/* AI features */
.ico{width:18px;height:18px;flex:none}
.docacts{display:flex;gap:8px;flex-wrap:wrap}
.btn.ai{background:var(--ink);color:var(--bg)}
.btn.ai .ico{color:var(--hi)}
.btn.ai-ghost .ico{color:var(--red)}
.chatlog{display:grid;gap:10px;max-height:52vh;min-height:160px;overflow:auto;padding:12px;background:var(--bg);border:1px solid var(--rule);border-radius:10px}
.msg{max-width:88%;padding:10px 13px;border-radius:12px;white-space:pre-wrap;overflow-wrap:anywhere;line-height:1.5}
.msg.user{justify-self:end;background:var(--ink);color:var(--bg);border-bottom-right-radius:4px}
.msg.assistant{justify-self:start;background:var(--surface);border:1px solid var(--rule);border-bottom-left-radius:4px}
.msg.err{border-color:var(--red);color:var(--red)}
.chatform{display:flex;gap:10px;align-items:flex-end}
.chatform textarea{min-height:48px;flex:1}
.aitext{white-space:pre-wrap;overflow-wrap:anywhere;line-height:1.6;background:var(--bg);border:1px solid var(--rule);border-radius:10px;padding:14px 16px;max-height:60vh;overflow:auto}

/* AI Tutor */
nav a.nav-ai{display:inline-flex;align-items:center;gap:5px;color:var(--ink);font-weight:600}
nav a.nav-ai .ico{color:var(--red);width:16px;height:16px}
.tutor{max-width:860px;width:100%;display:flex;flex-direction:column;min-height:calc(100vh - 200px)}
.tutor-top{display:flex;justify-content:space-between;align-items:center;gap:12px}
.tutor-h{display:flex;align-items:center;gap:10px;font-size:clamp(1.5rem,3.5vw,2.1rem)}
.tutor-h .ico{width:28px;height:28px;color:var(--red)}
.tutor-log{flex:1;display:grid;align-content:start;gap:12px;padding:8px 0 16px}
.tutor-empty{padding:30px 0}
.tutor-bar{position:sticky;bottom:0;background:var(--bg);padding:10px 0 12px;border-top:1px solid var(--rule)}
.tutor-form{display:flex;gap:8px;align-items:flex-end;background:var(--surface);border:1px solid var(--rule);border-radius:14px;padding:8px}
.tutor-form:focus-within{outline:3px solid var(--focus);outline-offset:1px}
.tutor-form textarea{border:0;background:transparent;min-height:40px;max-height:180px;resize:none;padding:8px 6px;outline:none}
.tattach{padding:8px 10px;cursor:pointer}
.tinfo{margin:8px 2px 0}
.tprev{display:flex;align-items:center;gap:10px;margin-bottom:8px}
.tprev img{width:56px;height:56px;object-fit:cover;border-radius:8px;border:1px solid var(--rule)}
.msgimg{display:block;max-width:240px;max-height:240px;border-radius:8px;margin-bottom:6px}
.tutor .msg{max-width:92%}

/* =====================================================================
   Motion: page transitions, card entrances, hover lift, thinking animation
   ===================================================================== */
@keyframes rise   { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop    { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-5px); opacity: 1; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes blink  { 50% { opacity: 0; } }
@keyframes swapIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Every page slides in gently when you move between pages */
#view > * { animation: rise .42s cubic-bezier(.2,.7,.2,1) both; }
#view > *:nth-child(2) { animation-delay: .04s; }
#view > *:nth-child(3) { animation-delay: .08s; }
#view > *:nth-child(4) { animation-delay: .12s; }
#view > *:nth-child(n+5) { animation-delay: .16s; }

/* Cards and folders arrive one after another */
.cards > *, .folders > * { animation: rise .45s cubic-bezier(.2,.7,.2,1) both; }
.cards > *:nth-child(1), .folders > *:nth-child(1) { animation-delay: .05s; }
.cards > *:nth-child(2), .folders > *:nth-child(2) { animation-delay: .09s; }
.cards > *:nth-child(3), .folders > *:nth-child(3) { animation-delay: .13s; }
.cards > *:nth-child(4), .folders > *:nth-child(4) { animation-delay: .17s; }
.cards > *:nth-child(5), .folders > *:nth-child(5) { animation-delay: .21s; }
.cards > *:nth-child(6), .folders > *:nth-child(6) { animation-delay: .25s; }
.cards > *:nth-child(7), .folders > *:nth-child(7) { animation-delay: .29s; }
.cards > *:nth-child(8), .folders > *:nth-child(8) { animation-delay: .33s; }
.cards > *:nth-child(n+9), .folders > *:nth-child(n+9) { animation-delay: .36s; }

/* Hover and press feedback */
.sheet, .folder { transition: transform .22s cubic-bezier(.2,.7,.2,1), box-shadow .22s, border-color .22s; }
.sheet:hover, .folder:hover { transform: translateY(-4px); box-shadow: 0 12px 26px var(--shade); }
.sheet .thumb img { transition: transform .5s cubic-bezier(.2,.7,.2,1); }
.sheet:hover .thumb img { transform: scale(1.04); }
.btn { transition: transform .12s, filter .2s, background-color .2s; }
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: scale(.97); }
.chip { transition: background-color .2s, color .2s, border-color .2s, transform .12s; }
.chip:active { transform: scale(.96); }
nav a { position: relative; transition: color .2s, background-color .2s; }
nav a[aria-current="page"]::after { content: ""; position: absolute; left: 11px; right: 11px; bottom: 2px; height: 2px; border-radius: 2px; background: var(--red); animation: fadeIn .3s both; }

/* Pop-up windows */
dialog[open] .dlg { animation: pop .28s cubic-bezier(.2,.7,.2,1) both; }
dialog[open]::backdrop { animation: fadeIn .25s both; }

/* Chat bubbles */
.msg { animation: rise .3s cubic-bezier(.2,.7,.2,1) both; }

/* "Thinking" indicator: bouncing dots + shimmering label */
.thinking { display: inline-flex; align-items: center; gap: 10px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; background: var(--hi); }
.dots i:nth-child(3) { animation-delay: .3s; background: var(--ink); }
.tlabel { font-weight: 600; color: var(--muted);
  background: linear-gradient(90deg, var(--muted) 0%, var(--muted) 40%, var(--ink) 50%, var(--muted) 60%, var(--muted) 100%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  animation: shimmer 1.8s linear infinite; }
.tlabel.swap { animation: shimmer 1.8s linear infinite, swapIn .3s both; }
.caret { display: inline-block; width: 7px; height: 1em; vertical-align: -2px; margin-left: 2px; background: var(--red); animation: blink .8s steps(1) infinite; }

/* AI Tutor: history sidebar + chat */
.tutor-wrap { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 24px; align-items: start; }
.tside { position: sticky; top: 80px; display: grid; gap: 8px; max-height: calc(100vh - 110px); overflow: auto; padding: 22px 0 10px; }
.tnewbtn { justify-self: start; }
.tside-h { margin: 10px 0 0; font-family: var(--body); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.tlist { display: grid; gap: 2px; }
.titem { display: flex; align-items: center; border-radius: 8px; transition: background-color .15s; }
.titem:hover, .titem.on { background: var(--surface); }
.titem.on { box-shadow: inset 3px 0 0 var(--red); }
.topen { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 8px 10px; cursor: pointer; display: grid; }
.topen span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .92rem; }
.topen small { color: var(--muted); font-size: .76rem; }
.tdel { background: none; border: 0; color: var(--muted); font-size: 1.2rem; padding: 4px 10px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.titem:hover .tdel, .tdel:focus-visible { opacity: 1; }
.tside-toggle { display: none; }
.tattach.disabled { opacity: .4; pointer-events: none; }
.fchips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.fchip { display: inline-flex; align-items: center; gap: 4px; font-size: .82rem; padding: 3px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--rule); color: var(--ink); }
.msg.user .fchip { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: inherit; }
@media (max-width: 860px) {
  .tutor-wrap { grid-template-columns: 1fr; }
  .tside { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); max-height: none; background: var(--surface);
    border-right: 1px solid var(--rule); padding: calc(20px + env(safe-area-inset-top, 0px)) 14px 20px; transform: translateX(-102%);
    transition: transform .28s cubic-bezier(.2,.7,.2,1); box-shadow: 0 0 40px var(--shade); }
  .tside.open { transform: none; }
  .tside-toggle { display: inline-flex; }
}

/* Respect students who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Several attached files before sending */
.tprev { flex-wrap: wrap; gap: 6px; }
.tprev .fchip img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }
.fx { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0 0 4px; }
.fx:hover { color: var(--red); }

/* Language filter, empty subjects, topic folders */
.langbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 6px; }
a.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.folder.is-empty { opacity: .55; }
.folder.is-empty:hover { opacity: .85; }
.folder.topic::before { width: 30%; }

/* Manage documents */
.mbar { position: sticky; top: 62px; z-index: 3; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--rule); margin-bottom: 10px; }
.mtable-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); }
.mtable { width: 100%; border-collapse: collapse; font-size: .88rem; }
.mtable th, .mtable td { padding: 8px 10px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.mtable th { position: sticky; top: 0; background: var(--surface); font-weight: 600; color: var(--muted); }
.mtable tr:hover td { background: var(--bg); }
.mtable td:nth-child(2) { min-width: 260px; }

/* Search box with suggestions */
.searchbox { position: relative; flex-wrap: nowrap; }
.searchbox input { flex: 1; }
.suggest { position: absolute; z-index: 8; top: calc(100% + 4px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--rule);
  border-radius: 12px; box-shadow: 0 14px 34px var(--shade); padding: 6px; max-height: 360px; overflow: auto; animation: pop .18s both; }
.sg-h { font-size: .78rem; font-weight: 600; color: var(--muted); padding: 8px 10px 4px; letter-spacing: .03em; }
.sg-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 8px 8px; }
.sg-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.sg-item:hover, .sg-item.on, .sg-chips .chip.on { background: var(--bg); }
.sg-item b { color: var(--red); }
.sg-item small { margin-left: 6px; }

/* Payment choices */
.paybtns { display: grid; gap: 8px; }
.paybtns .btn { justify-content: flex-start; text-align: left; }
.alipay-mark { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: #1677FF; color: #fff; font-weight: 700; font-size: .8rem; margin-right: 4px; flex: none; }

/* Help desk bubble */
.helpfab { position: fixed; z-index: 30; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); display: inline-flex; align-items: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 12px 18px 12px 14px; background: var(--ink); color: var(--bg); font-weight: 600; cursor: pointer;
  box-shadow: 0 10px 26px var(--shade); transition: transform .15s; animation: pop .35s .3s both; }
.helpfab:hover { transform: translateY(-2px); }
.helpfab .ico { width: 22px; height: 22px; }
.helpfab[hidden], .helppanel[hidden] { display: none; }
.helppanel { position: fixed; z-index: 31; right: 20px; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); width: min(380px, calc(100vw - 24px));
  max-height: min(620px, calc(100vh - 110px)); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--rule);
  border-radius: 16px; box-shadow: 0 24px 60px var(--shade); overflow: hidden; animation: pop .22s both; }
.helppanel header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; background: var(--ink); color: var(--bg); }
.hx { background: none; border: 0; color: inherit; font-size: 1.4rem; line-height: 1; cursor: pointer; }
.hlog { flex: 1; overflow: auto; display: grid; align-content: start; gap: 8px; padding: 12px; background: var(--bg); min-height: 180px; }
.hlog .msg { max-width: 92%; font-size: .92rem; }
.hquick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px 0; }
.hquick .chip { flex: none; font-size: .8rem; }
.hform { display: flex; gap: 8px; padding: 10px; }
.hform input { flex: 1; }
.hnote { margin: 0; padding: 0 12px 10px; font-size: .75rem; }
.hres { display: grid; gap: 6px; margin-top: 8px; white-space: normal; }
.hres a { display: grid; text-decoration: none; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
.hres a:hover { border-color: var(--ink); }
.hres small { color: var(--muted); }
.hmore { margin-top: 8px; }
@media (max-width: 700px) {
  .helppanel { right: 12px; left: 12px; width: auto; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .helpfab span { display: none; }
  .helpfab { padding: 14px; right: 14px; }
}

/* Search suggestions sit above everything below the search box */
.searchbox { z-index: 25; }
#view > form.searchbox { animation: none; }

/* Back button */
.backbtn { display: inline-flex; align-items: center; gap: 4px; margin: 18px 0 -8px; padding: 6px 12px 6px 8px; border: 1px solid var(--rule);
  border-radius: 999px; background: var(--surface); color: var(--ink); font-weight: 600; font-size: .9rem; cursor: pointer; transition: transform .12s, border-color .15s; }
.backbtn:hover { border-color: var(--ink); }
.backbtn:active { transform: scale(.97); }

/* AI help desk icon */
.helpfab .helpico { width: 26px; height: 26px; }
.hhead { display: flex; align-items: center; gap: 8px; }
.hhead .ico { width: 22px; height: 22px; }
.hrow { display: flex; gap: 8px; align-items: flex-start; }
.havatar { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--bg); display: grid; place-items: center; }
.havatar .ico { width: 18px; height: 18px; }
.hlog .hrow .msg { max-width: calc(100% - 40px); }

/* Buttons under help desk answers */
.hbtns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; white-space: normal; }
.hbtns .btn { font-size: .82rem; }

/* Phones: only draw cards that are on screen, and animate just the first few */
/* (content-visibility removed: it causes repeated redraws / flicker in some iOS versions) */
.cards > *:nth-child(n+13) { animation: none; }
.loadmore { display: block; margin: 18px auto 6px; min-width: 220px; }
@media (max-width: 700px) {
  .cards > * { animation: none; }            /* no card animations on phones at all */
  .sheet:hover { transform: none; }
  .sheet:hover .thumb img { transform: none; }
}

/* Lite mode (in-app browsers such as Threads/Instagram, and low-memory devices): no animations or hover effects */
html.lite *, html.lite *::before, html.lite *::after { animation: none !important; transition: none !important; }
html.lite .sheet:hover, html.lite .folder:hover { transform: none; box-shadow: none; }
html.lite .helppanel, html.lite .suggest { box-shadow: none; }
.iab { position: sticky; top: 0; z-index: 40; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--hi); color: #16233B; font-size: .88rem; font-weight: 600; }
.iab button { background: none; border: 0; font-size: 1.3rem; line-height: 1; color: inherit; cursor: pointer; }
.ver { opacity: .6; }
.thumb.blank { background-image: repeating-linear-gradient(to bottom, transparent 0 17px, var(--rule) 17px 18px); }

/* Toolbars and panels stay hidden when marked hidden (display:flex otherwise overrides it) */
.mbar[hidden], .tprev[hidden], .suggest[hidden], .loadmore[hidden] { display: none !important; }
