:root {
  --bg: #0b1020;
  --bg2: #111833;
  --panel: rgba(18, 28, 58, .82);
  --line: rgba(110, 190, 255, .28);
  --line-strong: rgba(110, 190, 255, .6);
  --glow: 0 0 0 1px var(--line), 0 0 24px rgba(70, 160, 255, .12);
  --text: #e8f0ff;
  --muted: #8a9bc2;
  --accent: #5cc8ff;
  --red: #ff5d6c;
  --yellow: #ffc94d;
  --green: #4fe39a;
  --hp: #ff5d6c;
  --xp: #5cc8ff;
  --coin: #ffd166;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% -10%, #1a2a5c 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.45 'IBM Plex Sans Thai', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.boot { display: grid; place-items: center; height: 100vh; letter-spacing: .3em; color: var(--muted); font-weight: 600; }

#app { max-width: 480px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px); }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--glow); backdrop-filter: blur(6px); }
.panel-title { font-size: 11px; letter-spacing: .22em; color: var(--accent); font-weight: 600; text-transform: uppercase; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- status header ---------- */
.status { padding: 14px; display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: center; }
.pet { width: 72px; height: 72px; border-radius: 16px; background: rgba(92, 200, 255, .08); box-shadow: inset 0 0 0 1px var(--line); display: grid; place-items: center; position: relative; overflow: hidden; }
.pet img { width: 64px; height: 64px; }
.pet.tired img { filter: saturate(.4) brightness(.8); }
.pet .mood { position: absolute; right: 3px; bottom: 1px; font-size: 14px; }
.who { display: flex; align-items: baseline; gap: 8px; }
.who b { font-size: 17px; }
.lv { color: var(--accent); font-weight: 700; font-size: 13px; letter-spacing: .05em; }
.bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .07); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: inherit; transition: width .4s ease; }
.bar.xp > i { background: linear-gradient(90deg, #3a8dff, var(--xp)); box-shadow: 0 0 10px var(--xp); }
.bar.hp > i { background: linear-gradient(90deg, #d43a5a, var(--hp)); }
.bar-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 3px; }
.wallet { grid-column: 1 / -1; display: flex; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 99px; background: rgba(255, 255, 255, .05); font-size: 13px; font-weight: 600; }
.chip.coin { color: var(--coin); }
.chip.chest { color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.chip.chest.has { box-shadow: inset 0 0 0 1px var(--coin); color: var(--coin); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: inset 0 0 0 1px var(--coin), 0 0 14px rgba(255, 209, 102, .45); } }

/* ---------- banners ---------- */
.banner { margin-top: 12px; padding: 10px 12px; border-radius: 12px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.banner.trial { background: rgba(92, 200, 255, .1); box-shadow: inset 0 0 0 1px var(--line); }
.banner.locked { background: rgba(255, 93, 108, .12); box-shadow: inset 0 0 0 1px rgba(255, 93, 108, .5); }
.banner.dev { background: rgba(255, 201, 77, .1); color: var(--yellow); }
.banner .btn { margin-left: auto; flex: none; }

/* ---------- quests ---------- */
.week-head { display: flex; justify-content: space-between; align-items: end; margin: 18px 2px 8px; }
.week-head h2 { margin: 0; font-size: 18px; }
.group { margin-top: 14px; }
.group-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; letter-spacing: .08em; color: var(--muted); margin: 0 2px 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.red { background: var(--red); box-shadow: 0 0 8px var(--red); }
.dot.yellow { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.dot.green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.quest { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; margin-bottom: 8px; position: relative; overflow: hidden; }
.quest::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.quest.red::before { background: var(--red); }
.quest.yellow::before { background: var(--yellow); }
.quest.green::before { background: var(--green); }
.quest.complete { opacity: .62; }
.quest .title { font-weight: 600; overflow-wrap: anywhere; }
.quest .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.pips { display: flex; gap: 3px; }
.pips i { width: 10px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .14); }
.quest.red .pips i.on { background: var(--red); }
.quest.yellow .pips i.on { background: var(--yellow); }
.quest.green .pips i.on { background: var(--green); }
.more { width: 32px; height: 40px; color: var(--muted); font-size: 18px; flex: none; }
.tick { width: 44px; height: 44px; border-radius: 12px; flex: none; box-shadow: inset 0 0 0 2px var(--line-strong); display: grid; place-items: center; transition: transform .12s, background .2s; }
.tick:active { transform: scale(.9); }
.tick svg { width: 22px; height: 22px; opacity: 0; transition: opacity .15s; }
.tick.on { background: var(--accent); box-shadow: 0 0 14px rgba(92, 200, 255, .6); }
.tick.on svg { opacity: 1; }
.tick:disabled { opacity: .4; cursor: default; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.add-row { margin-top: 14px; }

/* ---------- buttons / forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 12px; font-weight: 600; background: rgba(255, 255, 255, .07); box-shadow: inset 0 0 0 1px var(--line); min-height: 42px; }
.btn.primary { background: var(--accent); color: #04121f; box-shadow: 0 0 18px rgba(92, 200, 255, .35); }
.btn.danger { color: var(--red); box-shadow: inset 0 0 0 1px rgba(255, 93, 108, .45); }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input { width: 100%; padding: 11px 12px; border-radius: 10px; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); outline: none; }
.input:focus { border-color: var(--accent); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 64px; padding: 9px 8px; border-radius: 10px; background: rgba(255, 255, 255, .05); box-shadow: inset 0 0 0 1px var(--line); font-size: 13px; font-weight: 600; }
.seg button.on { background: rgba(92, 200, 255, .18); box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); }
.seg button.c-red.on { background: rgba(255, 93, 108, .18); box-shadow: inset 0 0 0 1.5px var(--red); color: var(--red); }
.seg button.c-yellow.on { background: rgba(255, 201, 77, .16); box-shadow: inset 0 0 0 1.5px var(--yellow); color: var(--yellow); }
.seg button.c-green.on { background: rgba(79, 227, 154, .15); box-shadow: inset 0 0 0 1.5px var(--green); color: var(--green); }

/* ---------- stats ---------- */
.card { padding: 14px; margin-top: 12px; }
.stat-row { display: grid; grid-template-columns: 44px 1fr 40px; gap: 10px; align-items: center; margin-top: 10px; }
.stat-row b { color: var(--accent); font-size: 13px; letter-spacing: .05em; }
.stat-row .bar { margin: 0; }
.stat-row .bar > i { background: linear-gradient(90deg, #3a8dff, var(--accent)); }
.stat-row .num { text-align: right; font-weight: 600; }
.pet-big { display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: center; }
.pet-big img { width: 110px; height: 110px; }
.log { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.log li { padding: 7px 0; border-top: 1px solid rgba(255, 255, 255, .06); display: flex; gap: 10px; }
.log li span:first-child { color: var(--muted); flex: none; font-size: 12px; }

/* ---------- shop ---------- */
.reward { display: flex; align-items: center; gap: 10px; padding: 12px; margin-bottom: 8px; }
.reward.locked { opacity: .5; }
.price { color: var(--coin); font-weight: 700; font-size: 13px; }
.lock { font-size: 12px; color: var(--muted); }

/* ---------- nav ---------- */
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: rgba(9, 14, 30, .94); border-top: 1px solid var(--line); display: flex; justify-content: center; z-index: 10; backdrop-filter: blur(10px); }
.nav-inner { display: flex; width: 100%; max-width: 480px; }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); font-weight: 600; }
.nav button .ic { font-size: 20px; filter: grayscale(1) opacity(.7); }
.nav button.on { color: var(--accent); }
.nav button.on .ic { filter: none; }

/* ---------- sheets ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 30; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease; }
.sheet { width: 100%; max-width: 480px; max-height: 88vh; overflow: auto; background: var(--bg2); border-radius: 18px 18px 0 0; box-shadow: 0 -1px 0 var(--line-strong); padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .22s ease; }
.sheet h3 { margin: 0 0 14px; font-size: 17px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }

/* chest reveal */
.reveal { text-align: center; padding: 10px 0 4px; }
.reveal .big { font-size: 56px; animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
.reveal .gain { font-size: 22px; font-weight: 700; color: var(--coin); margin-top: 6px; }
@keyframes pop { from { transform: scale(.3) rotate(-12deg); opacity: 0; } }

/* toast */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 40; }
.toast { background: rgba(14, 24, 52, .96); box-shadow: 0 0 0 1px var(--line-strong), 0 6px 20px rgba(0, 0, 0, .4); padding: 9px 14px; border-radius: 12px; font-size: 13px; font-weight: 600; animation: up .2s ease; }
.toast.level { color: var(--coin); box-shadow: 0 0 0 1px var(--coin), 0 0 24px rgba(255, 209, 102, .35); }

/* ---------- onboarding / login ---------- */
.full { min-height: calc(100vh - 40px); display: flex; flex-direction: column; justify-content: center; padding-bottom: 20px; }
.ob-step { font-size: 12px; color: var(--accent); letter-spacing: .2em; font-weight: 600; }
.ob-q { font-size: 22px; font-weight: 700; margin: 8px 0 18px; line-height: 1.3; }
.choices { display: grid; gap: 10px; }
.choice { text-align: left; padding: 14px 16px; display: flex; gap: 12px; align-items: center; border-radius: 14px; background: var(--panel); box-shadow: var(--glow); }
.choice.on { box-shadow: 0 0 0 2px var(--accent), 0 0 20px rgba(92, 200, 255, .25); }
.choice .ic { font-size: 24px; }
.choice small { display: block; color: var(--muted); font-size: 12px; }
.pets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pets .choice { flex-direction: column; text-align: center; padding: 12px 6px; }
.pets img { width: 72px; height: 72px; }
.ob-nav { display: flex; gap: 10px; margin-top: 22px; }
.ob-nav .btn { flex: 1; }
.preview-list { list-style: none; padding: 0; margin: 0; }
.preview-list li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); font-size: 14px; }
.logo { font-size: 13px; letter-spacing: .35em; color: var(--accent); font-weight: 700; }
.hero-title { font-size: 28px; font-weight: 700; line-height: 1.25; margin: 10px 0 8px; }
#gbtn { display: flex; justify-content: center; margin-top: 22px; min-height: 44px; }
/* the page is color-scheme:dark; a cross-origin iframe with a different scheme gets an opaque white canvas */
#gbtn, #gbtn iframe { color-scheme: light; }

.adv-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.adv-grid label { font-size: 11px; color: var(--muted); }
.adv-grid .input { padding: 8px; margin-top: 3px; }
.adv-section { font-size: 12px; font-weight: 600; margin: 14px 0 6px; color: var(--accent); }
.hr { height: 1px; background: var(--line); margin: 16px 0; }
