:root {
  --bg: #14111f;
  --panel: #1f1a30;
  --panel-2: #2a2340;
  --line: #3a3156;
  --text: #ece8f6;
  --muted: #9d94b8;
  --accent: #ffb547;
  --hp: #ff4d6d;
  --exp: #7c5cff;
  --water: #3ec5ff;
  --ok: #3ddc97;
  --radius: 14px;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(circle at 50% -20%, #2c2150 0, var(--bg) 60%) fixed; color: var(--text); }
.app { max-width: 520px; margin: 0 auto; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0 0 8px; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.tiny { font-size: .78rem; }
.accent { color: var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 14px; }

/* 進度條 */
.bar { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; transition: width .6s cubic-bezier(.2,.9,.3,1.2); }
.exp-bar > span { background: linear-gradient(90deg, #5b3dff, var(--exp)); }
.hp-bar { height: 16px; border: 1px solid #00000055; }
.hp-bar > span { background: linear-gradient(90deg, #c9184a, var(--hp)); }
.water-bar > span { background: linear-gradient(90deg, #0077b6, var(--water)); }
.deficit-bar { height: 14px; margin: 8px 0 4px; }
.deficit-bar > span { background: linear-gradient(90deg, #f77f00, var(--accent)); }

/* 頂部狀態列 */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center; padding: 12px 0; background: linear-gradient(var(--bg) 75%, transparent); }
.lv { font-weight: 800; font-size: 1.1rem; color: var(--accent); background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.exp { flex: 1; min-width: 0; }
.exp .name { font-weight: 700; font-size: .9rem; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; flex-direction: column; gap: 4px; }
.chip { display: inline-block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: .82rem; white-space: nowrap; }

/* Boss */
.boss { text-align: center; position: relative; overflow: hidden; }
.boss .stage { font-size: .75rem; letter-spacing: .12em; color: var(--muted); display: flex; justify-content: center; gap: 8px; align-items: center; }
.badge { font-size: .72rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; letter-spacing: 0; white-space: nowrap; }
.boss-icon { font-size: 72px; line-height: 1.2; margin: 6px 0; position: relative; display: inline-block; animation: bob 3s ease-in-out infinite; }
.boss.hit .boss-icon { animation: shake .45s; }
.boss.shielded .boss-icon { filter: drop-shadow(0 0 12px var(--water)); }
.boss.cleared .boss-icon { animation: none; }
.hp-text { font-size: .8rem; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.boss-meta, .stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.boss-meta div, .stats-grid div { background: var(--panel-2); border-radius: 10px; padding: 8px 4px; text-align: center; }
.boss-meta small, .stats-grid small { display: block; color: var(--muted); font-size: .7rem; }
.boss-meta b, .stats-grid b { font-size: .92rem; }
.shield-note { font-size: .82rem; color: var(--water); margin: 12px 0 0; }
.float-dmg { position: absolute; left: 50%; top: 0; transform: translateX(-50%); font-size: 1.4rem; font-weight: 900; color: var(--hp); text-shadow: 0 2px 0 #000; white-space: nowrap; animation: float 1.4s ease-out forwards; pointer-events: none; }
.float-dmg.crit { color: var(--accent); font-size: 1.8rem; }

@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes shake { 20% { transform: translateX(-8px) rotate(-4deg); } 40% { transform: translateX(8px) rotate(4deg); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
@keyframes float { from { opacity: 1; top: 0; } to { opacity: 0; top: -60px; } }

/* 表單 */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: .8rem; color: var(--muted); }
input, select { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 16px; font-family: inherit; }
input:focus, select:focus { outline: 2px solid var(--exp); outline-offset: 1px; }
.date-pick { width: auto; padding: 6px 8px; font-size: .85rem; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 8px; }
legend { padding: 0 6px; font-weight: 700; font-size: .9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
.grid-reward { grid-template-columns: 1fr 90px auto; }
.toggle { display: block !important; position: relative; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { display: block; text-align: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--text); font-size: .85rem; cursor: pointer; user-select: none; }
.toggle input:checked + span { background: #1d4d3b; border-color: var(--ok); color: #fff; }
.toggle input:focus-visible + span { outline: 2px solid var(--exp); }
.grid2 .toggle { align-self: end; }

/* 按鈕 */
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 12px; padding: 12px 16px; font-size: .95rem; font-weight: 700; cursor: pointer; text-align: center; font-family: inherit; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #ffc566, #f59e0b); color: #2a1600; border-color: #f59e0b; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--hp); }
.btn.small { padding: 7px 12px; font-size: .82rem; border-radius: 9px; }
.btn.file { display: inline-block; }
.divider { text-align: center; color: var(--muted); margin: 14px 0; font-size: .8rem; }
.setup { margin-top: 48px; }
.setup .btn.file { width: 100%; }

/* 戰鬥結果 */
.result { margin-top: 14px; padding: 12px; border-radius: 12px; background: #2b1d2f; border: 1px solid #5c2a44; display: grid; gap: 6px; }
.result-dmg b { color: var(--hp); font-size: 1.2rem; }

/* 圖表 */
.weight-chart { width: 100%; height: auto; display: block; }
.weight-chart .grid { stroke: var(--line); stroke-width: .5; }
.weight-chart .tick { fill: var(--muted); font-size: 10px; }
.weight-chart .corridor { fill: #3ddc9722; stroke: #3ddc9766; stroke-dasharray: 3 3; }
.weight-chart .raw-line { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; opacity: .7; }
.weight-chart .raw-dot { fill: var(--muted); }
.weight-chart .ema-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .75rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; }
.lg-raw { border-top: 1px dashed var(--muted); }
.lg-ema { background: var(--accent); }
.lg-corridor { background: #3ddc9766; height: 8px !important; }

.radar { width: 240px; max-width: 100%; }
.radar .ring { fill: none; stroke: var(--line); }
.radar .shape { fill: #7c5cff55; stroke: var(--exp); stroke-width: 2; }
.radar text { fill: var(--text); font-size: 11px; font-weight: 700; }

.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge-tile { background: var(--panel-2); border-radius: 10px; padding: 10px 4px; text-align: center; opacity: .35; filter: grayscale(1); }
.badge-tile.on { opacity: 1; filter: none; border: 1px solid var(--accent); }
.badge-tile span { font-size: 1.6rem; display: block; }
.badge-tile small { font-size: .7rem; }

.stages, .rewards { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.stage-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; background: var(--panel-2); border-radius: 10px; padding: 10px; }
.stage-row .tiny { grid-column: 1; }
.stage-row .badge { grid-row: 1 / 3; grid-column: 2; align-self: center; }
.stage-row.locked { opacity: .5; }
.stage-row.defeated { border-left: 3px solid var(--ok); }
.stage-row.active, .stage-row.shielded { border-left: 3px solid var(--hp); }
.reward { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.reward.redeemed { opacity: .55; }

/* 底部導覽 */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: center; background: #110e1bf2; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); backdrop-filter: blur(8px); z-index: 10; }
.tabbar button { flex: 1; max-width: 130px; background: none; border: 0; color: var(--muted); padding: 8px 0 10px; font-size: .75rem; display: grid; gap: 2px; cursor: pointer; font-family: inherit; }
.tabbar button span { font-size: 1.3rem; }
.tabbar button.active { color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #000d; color: #fff; padding: 10px 16px; border-radius: 99px; font-size: .88rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .grid3 label:first-child { grid-column: 1 / -1; }
}
