:root {
  --bg: #07090f; --panel: #0f1420; --panel-2: #151c2c; --line: #222b40;
  --text: #e8eefc; --muted: #8590ab; --accent: #5ef2d6; --pink: #ff5ea8;
  --gold: #ffc857; --violet: #7a5cff; --danger: #ff5e6c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
#app { max-width: 560px; margin: 0 auto; padding: 12px 16px 48px; }
[hidden] { display: none !important; }
h2 { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 26px 0 10px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); font-weight: 400; letter-spacing: 0; text-transform: none; }
.fine { color: var(--muted); font-size: 12px; margin-top: 28px; }
.error { color: var(--danger); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.primary { background: var(--accent); color: #031a16; font-weight: 700; border-radius: 12px; padding: 12px 18px; }
.secondary { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: inline-block; }
.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); border-radius: 12px; padding: 10px 14px; }
.icon-btn { background: var(--panel-2); width: 40px; height: 40px; border-radius: 12px; font-size: 18px; }
input { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* pairing */
.pair-card { margin-top: 12vh; text-align: center; display: grid; gap: 12px; }
.logo { font-size: 56px; font-weight: 900; letter-spacing: .08em; background: linear-gradient(90deg, var(--accent), var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { margin: -10px 0 0; color: var(--muted); letter-spacing: .3em; text-transform: uppercase; font-size: 12px; }
#pair-form { display: grid; gap: 10px; }
#pair-code { text-align: center; font-size: 26px; letter-spacing: .2em; text-transform: uppercase; }

/* header */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.twin-name { font-size: 22px; font-weight: 800; }
.tier { color: var(--accent); font-size: 13px; font-weight: 600; }
.xpbar { position: relative; height: 10px; background: var(--panel-2); border-radius: 6px; margin: 10px 0 4px; overflow: hidden; }
#xp-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--violet)); transition: width .6s; }
#xp-text { position: absolute; right: 0; top: 12px; font-size: 11px; color: var(--muted); }

/* stage */
.stage { display: grid; grid-template-columns: 1fr 120px; gap: 12px; margin-top: 22px; align-items: center; }
.twin-wrap { position: relative; display: grid; justify-items: center; }
#twin { width: 100%; max-width: 240px; height: auto; filter: drop-shadow(0 0 18px rgba(94, 242, 214, .15)); }
#twin [id^="p-"] { transition: opacity .8s; }
#heart { animation: beat 1.2s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes beat { 0%, 60%, 100% { transform: translate(112px, 146px) scale(1); } 30% { transform: translate(112px, 146px) scale(1.18); } }
.nosig { fill: var(--accent); font: 700 9px ui-monospace, monospace; letter-spacing: .15em; animation: flicker 2.4s infinite; }
@keyframes flicker { 0%, 100% { opacity: .9; } 50% { opacity: .35; } }
#no-signal { animation: flicker 1.1s infinite; }
.scan-btn { position: absolute; bottom: 4px; background: rgba(94, 242, 214, .12); border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 13px; }
.sync { display: grid; gap: 14px; justify-items: center; }
.sync-ring { position: relative; width: 104px; height: 104px; display: grid; place-items: center; text-align: center; }
.sync-ring svg { position: absolute; inset: 0; transform: rotate(0deg); }
.sync-ring path { fill: none; stroke-width: 3; }
.ring-bg { stroke: var(--panel-2); }
.ring { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray .8s; }
.sync-ring b { font-size: 28px; display: block; line-height: 1; }
.sync-ring small, .chain small { color: var(--muted); font-size: 11px; display: block; }
.chain { text-align: center; }
.chain b { font-size: 22px; margin-left: 4px; }

/* systems */
.systems { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
.sys { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.sys b { font-size: 12px; display: block; }
.sys .bar { height: 5px; background: var(--panel-2); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.sys .bar div { height: 100%; background: var(--accent); transition: width .6s; }
.sys span { font-size: 11px; color: var(--muted); }

/* quests */
.pill { background: var(--panel-2); color: var(--text); border-radius: 999px; padding: 2px 9px; font-size: 12px; letter-spacing: 0; }
.pill.perfect { background: var(--gold); color: #2a1c00; }
.quests { display: grid; gap: 8px; }
.quest { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; transition: border-color .3s, background .3s; }
.quest.done { border-color: rgba(94, 242, 214, .55); background: linear-gradient(90deg, rgba(94, 242, 214, .08), var(--panel)); }
.quest.na { opacity: .7; }
.q-row { display: flex; align-items: center; gap: 12px; }
.check { flex: none; width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel-2); font-size: 18px; display: grid; place-items: center; }
.quest.done .check { background: var(--accent); border-color: var(--accent); color: #031a16; }
.q-text { flex: 1; min-width: 0; }
.q-text b { display: block; }
.q-text small { color: var(--muted); }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; margin-left: 6px; vertical-align: 2px; }
.na-btn { background: transparent; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; flex: none; }
.q-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.q-form .wide { grid-column: 1 / -1; }
.q-form label { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip.on { background: rgba(94, 242, 214, .15); border-color: var(--accent); color: var(--accent); }
.toggle { display: flex !important; grid-auto-flow: column; align-items: center; gap: 8px !important; grid-column: 1 / -1; }
.toggle input { width: auto; }
.warn { grid-column: 1 / -1; background: rgba(255, 94, 108, .12); border: 1px solid var(--danger); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.q-value { color: var(--accent); font-size: 13px; font-weight: 600; }

/* bosses */
.bosses { display: grid; gap: 8px; }
.boss { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.boss.down { border-color: var(--gold); }
.boss-head { display: flex; justify-content: space-between; }
.boss-hp { color: var(--muted); font-size: 13px; }
.boss.down .boss-hp { color: var(--gold); font-weight: 700; }
.hp { height: 10px; background: var(--panel-2); border-radius: 6px; margin: 8px 0 6px; overflow: hidden; }
.hp div { height: 100%; background: linear-gradient(90deg, var(--danger), var(--pink)); transition: width .6s; }
.boss small { color: var(--muted); }

/* mirror + achievements */
.mirror { display: grid; gap: 10px; }
.strip { display: flex; gap: 8px; overflow-x: auto; }
.strip img { width: 72px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); flex: none; }
.achievements { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ach { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; opacity: .45; }
.ach.on { opacity: 1; border-color: var(--gold); }
.ach b { display: block; font-size: 13px; }
.ach small { color: var(--muted); font-size: 11px; }

/* sheets */
.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); display: grid; align-items: end; z-index: 10; }
.sheet-card, .cam-card { background: var(--panel); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 12px; max-width: 560px; width: 100%; margin: 0 auto; max-height: 92vh; overflow-y: auto; }
.sheet label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
hr { border: 0; border-top: 1px solid var(--line); width: 100%; }
.device { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.device small { color: var(--muted); display: block; }
.code { font: 700 30px ui-monospace, monospace; letter-spacing: .15em; text-align: center; color: var(--accent); background: var(--panel-2); border-radius: 12px; padding: 14px; }
.viewfinder { position: relative; aspect-ratio: 3 / 4; background: #000; border-radius: 16px; overflow: hidden; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.viewfinder.rear video { transform: none; }
.guide { position: absolute; inset: 0; pointer-events: none; }
.guide.face::after { content: ""; position: absolute; left: 22%; right: 22%; top: 14%; bottom: 26%; border: 3px dashed var(--accent); border-radius: 50%; box-shadow: 0 0 0 999px rgba(7, 9, 15, .45); }
.guide.body::after { content: ""; position: absolute; left: 18%; right: 18%; top: 4%; bottom: 4%; border: 3px dashed var(--accent); border-radius: 40px; }
.cam-actions { display: flex; gap: 10px; justify-content: center; }
.file-btn { cursor: pointer; }

/* toast + level up */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--accent); color: var(--text); border-radius: 999px; padding: 10px 18px; font-weight: 600; z-index: 20; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); animation: pop .3s; }
.toast.big { border-color: var(--gold); background: #231b05; color: var(--gold); font-size: 17px; }
@keyframes pop { from { transform: translate(-50%, 20px); opacity: 0; } }

@media (min-width: 900px) {
  #app { max-width: 1060px; }
  #game:not([hidden]) { display: grid; grid-template-columns: 400px 1fr; column-gap: 36px; }
  #game > .top, #game > .xpbar { grid-column: 1 / -1; }
  .col-left { position: sticky; top: 12px; align-self: start; }
  .col-right > h2:first-child { margin-top: 22px; }
}
