:root {
  --bg: #0f1118;
  --surface: #191d29;
  --surface-2: #232838;
  --text: #f5f7fb;
  --muted: #9ea7ba;
  --line: #30384c;
  --accent: #66e3c4;
  --accent-2: #ffcc66;
  --danger: #ff7085;
  --good: #74e38f;
  --radius: 20px;
  --shadow: 0 18px 45px rgba(0,0,0,.28);
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top, #1b2130 0, var(--bg) 44%); color: var(--text); }
body { min-height: 100dvh; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(102,227,196,.45); outline-offset: 2px; }
#app { width: min(100%, 560px); min-height: 100dvh; margin: 0 auto; position: relative; padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 78px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; background: linear-gradient(to bottom, rgba(15,17,24,.98), rgba(15,17,24,.86)); backdrop-filter: blur(14px); border-bottom: 1px solid rgba(255,255,255,.06); }
.topbar h1 { margin: 2px 0 0; font-size: 22px; letter-spacing: .03em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.icon-button { width: 42px; height: 42px; border: 0; border-radius: 14px; background: var(--surface); cursor: pointer; }
.view { padding: 18px 16px 30px; }
.bottom-nav { position: fixed; left: 50%; bottom: 0; z-index: 25; transform: translateX(-50%); width: min(100%, 560px); display: grid; grid-template-columns: repeat(5, 1fr); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: rgba(18,21,30,.94); border-top: 1px solid rgba(255,255,255,.08); backdrop-filter: blur(18px); }
.nav-item { border: 0; background: transparent; color: var(--muted); display: grid; gap: 3px; justify-items: center; padding: 7px 2px; border-radius: 14px; cursor: pointer; }
.nav-item span { font-size: 21px; line-height: 1; }
.nav-item small { font-size: 11px; }
.nav-item.active { color: var(--accent); background: rgba(102,227,196,.08); }
.hero { padding: 22px; border-radius: 28px; background: linear-gradient(145deg, #273147, #171b27 70%); box-shadow: var(--shadow); overflow: hidden; position: relative; }
.hero::after { content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%; right: -65px; top: -85px; background: rgba(102,227,196,.17); filter: blur(2px); }
.hero h2 { font-size: 29px; line-height: 1.15; margin: 6px 0 10px; max-width: 320px; }
.hero p { margin: 0 0 20px; color: #c2c9d8; line-height: 1.65; max-width: 410px; }
.primary, .secondary, .danger-button { min-height: 48px; padding: 0 18px; border-radius: 15px; font-weight: 800; cursor: pointer; }
.primary { border: 0; background: var(--accent); color: #07130f; box-shadow: 0 10px 24px rgba(102,227,196,.18); }
.secondary { border: 1px solid var(--line); background: var(--surface-2); }
.danger-button { border: 1px solid rgba(255,112,133,.4); background: rgba(255,112,133,.12); color: #ffacb8; }
.full { width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row > * { flex: 1; }
.section { margin-top: 22px; }
.section-head { display: flex; justify-content: space-between; align-items: end; margin-bottom: 12px; gap: 16px; }
.section-head h2, .section-head h3 { margin: 0; font-size: 18px; }
.section-head p, .section-head small { margin: 0; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-top: 14px; }
.stat-card { padding: 14px; border-radius: 17px; background: var(--surface); border: 1px solid rgba(255,255,255,.05); }
.stat-card strong { display: block; font-size: 24px; margin-top: 5px; }
.stat-card small { color: var(--muted); }
.notice { padding: 14px 15px; background: rgba(255,204,102,.09); border: 1px solid rgba(255,204,102,.22); color: #f3ddb0; border-radius: 16px; line-height: 1.55; font-size: 14px; }
.card-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.monster-card { border: 1px solid var(--line); border-radius: 20px; background: linear-gradient(180deg, #222838, #171b26); overflow: hidden; cursor: pointer; text-align: left; padding: 0; position: relative; }
.monster-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(102,227,196,.22); }
.monster-visual { aspect-ratio: 1.2; display: grid; place-items: center; padding: 14px; background: radial-gradient(circle at 50% 35%, var(--monster-glow, rgba(102,227,196,.28)), transparent 60%); }
.monster-visual svg { width: 100%; height: 100%; filter: drop-shadow(0 15px 16px rgba(0,0,0,.32)); }
.monster-visual .monster-image { width: 100%; height: 100%; object-fit: contain; display: block; filter: drop-shadow(0 15px 16px rgba(0,0,0,.32)); }
.monster-visual.battle-art .monster-image { image-rendering: pixelated; image-rendering: crisp-edges; filter: drop-shadow(0 10px 10px rgba(0,0,0,.4)); }
.dex-entry img { width: 100%; height: 100%; object-fit: contain; display: block; }
.monster-info { padding: 12px; }
.monster-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.monster-title strong { font-size: 16px; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; min-height: 24px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 900; background: rgba(255,255,255,.08); }
.quality-S { color: #ffd86b; background: rgba(255,216,107,.14); }
.quality-A { color: #cc9cff; background: rgba(204,156,255,.14); }
.quality-B { color: #7bd7ff; background: rgba(123,215,255,.14); }
.quality-C { color: #b7c0d0; }
.mini-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 5px; margin-top: 10px; }
.mini-stats span { font-size: 11px; color: var(--muted); }
.mini-stats b { display: block; color: var(--text); font-size: 15px; }
.empty-card { min-height: 190px; border-radius: 20px; border: 1px dashed #414a60; display: grid; place-items: center; color: var(--muted); background: rgba(255,255,255,.018); }
.scanner-shell { border-radius: 24px; overflow: hidden; background: #06070a; border: 1px solid var(--line); min-height: 290px; position: relative; }
#scanVideo { width: 100%; min-height: 290px; height: 46vh; max-height: 430px; display: block; object-fit: cover; background: #050609; }
.camera-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 700; z-index: 1; }
.camera-placeholder[hidden] { display: none; }
.scan-guide { pointer-events: none; position: absolute; inset: 50% auto auto 50%; transform: translate(-50%,-50%); width: 90%; height: 54%; border: 2px solid rgba(102,227,196,.9); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0,0,0,.28); z-index: 2; }
.scan-line { position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: var(--accent); box-shadow: 0 0 14px var(--accent); animation: scan 1.8s ease-in-out infinite alternate; }
@keyframes scan { from { transform: translateY(-55px); } to { transform: translateY(55px); } }
.form-group { display: grid; gap: 8px; margin-top: 12px; }
.form-group label { color: var(--muted); font-size: 13px; }
.input { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 14px; background: #11141d; color: var(--text); padding: 0 14px; font-size: 16px; }
.split { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.result-stage { text-align: center; padding: 10px 0; }
.result-stage .monster-visual { width: min(85%, 360px); margin: 0 auto; aspect-ratio: 1; border-radius: 28px; }
.result-stage h2 { font-size: 30px; margin: 12px 0 4px; }
.result-stage p { color: var(--muted); }
.large-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin: 16px 0; }
.large-stats div { background: var(--surface); border-radius: 16px; padding: 14px 7px; }
.large-stats small { color: var(--muted); display: block; }
.large-stats strong { display: block; font-size: 25px; margin-top: 3px; }
.detail-list { display: grid; gap: 10px; margin: 16px 0; }
.detail-row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 14px; border-radius: 14px; background: var(--surface); }
.detail-row span { color: var(--muted); }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare-card { padding: 12px; border-radius: 17px; background: var(--surface); }
.compare-card h4 { margin: 0 0 10px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--danger); }
.bestiary-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.dex-entry { aspect-ratio: .78; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); padding: 5px; display: grid; grid-template-rows: 1fr auto; text-align: center; overflow: hidden; }
.dex-entry.unknown { filter: grayscale(1); opacity: .42; }
.dex-entry svg { width: 100%; height: 100%; }
.dex-entry small { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.battle-arena { border-radius: 28px; padding: 18px 14px; min-height: 390px; background: linear-gradient(#202a3b 0 45%, #30333a 45% 48%, #161922 48%); position: relative; overflow: hidden; }
.battle-arena::before { content:""; position:absolute; inset:0; background: repeating-linear-gradient(90deg,transparent 0 50px,rgba(255,255,255,.025) 51px 52px); }
.fighters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; position: relative; z-index: 1; align-items: end; height: 280px; }
.fighter { text-align: center; transition: transform .16s ease, filter .16s ease; }
.fighter.enemy .monster-visual { transform: scaleX(-1); }
.fighter.attack-left { transform: translateX(22px) scale(1.04); }
.fighter.attack-right { transform: translateX(-22px) scale(1.04); }
.fighter.hit { filter: brightness(2) saturate(.4); transform: translateX(-8px); }
.fighter.enemy.hit { transform: translateX(8px); }
.fighter .monster-visual { padding: 0; background: none; }
.hp-wrap { margin-top: 5px; }
.hp-label { display: flex; justify-content: space-between; font-size: 11px; color: #d8deea; }
.hp-bar { height: 9px; border-radius: 99px; background: #0c0e13; overflow: hidden; margin-top: 4px; }
.hp-fill { height: 100%; background: linear-gradient(90deg, #4adf79, #b7ee65); transition: width .25s ease; }
.battle-log { position: relative; z-index: 2; min-height: 62px; margin-top: 10px; padding: 12px; border-radius: 15px; background: rgba(5,7,10,.72); color: #dae0ec; font-size: 13px; line-height: 1.5; }
.modal { width: min(calc(100% - 24px), 520px); max-height: 88dvh; overflow: auto; border: 1px solid var(--line); border-radius: 24px; background: #171b26; color: var(--text); padding: 20px; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(3px); }
.modal h2 { margin-top: 0; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #f4f7fa; color: #111620; padding: 11px 16px; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); transition: .25s ease; white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.onboarding { min-height: 70dvh; display: grid; align-content: center; gap: 16px; }
.onboarding-logo { width: 116px; height: 116px; border-radius: 32px; display: grid; place-items: center; margin: 0 auto 8px; background: linear-gradient(145deg, var(--accent), #2a9e8b); color: #0a1714; font-size: 54px; box-shadow: 0 20px 50px rgba(102,227,196,.22); }
.onboarding h2 { text-align: center; font-size: 30px; margin: 0; }
.onboarding p { text-align: center; color: var(--muted); line-height: 1.65; margin: 0 14px; }
.small-note { color: var(--muted); font-size: 12px; line-height: 1.55; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
@media (min-width: 520px) {
  .card-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .bestiary-grid { grid-template-columns: repeat(5,1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
#backButton { grid-column: 1; grid-row: 1; }
.topbar > div { grid-column: 2; grid-row: 1; min-width: 0; }
#settingsButton { grid-column: 3; grid-row: 1; }

.scan-tip { margin-top: 12px; line-height: 1.65; }

.camera-debug { margin-top: 10px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.025); padding: 10px 12px; color: var(--muted); font-size: 12px; }
.camera-debug summary { cursor: pointer; font-weight: 700; }
.camera-debug pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 10px 0 0; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: #cad1df; }
