:root {
  --bg: #0b1020;
  --panel: rgba(16, 24, 48, .78);
  --panel-solid: #121a33;
  --line: rgba(140, 170, 255, .18);
  --gold: #e8c26a;
  --gold-dim: #a8884a;
  --text: #e6ecff;
  --muted: #8f9bc0;
  --str: #ff5d5d;
  --agi: #3ee39a;
  --end: #ff9d3f;
  --vit: #b9e85c;
  --danger: #ff6b6b;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 'Nunito Sans', system-ui, sans-serif;
  background-image: radial-gradient(ellipse at 50% -10%, #1d2b5c 0%, transparent 60%);
  min-height: 100vh;
}
h1, h2 { font-family: Cinzel, Georgia, serif; letter-spacing: .04em; margin: 0; }
h2 { font-size: 15px; color: var(--gold); text-transform: uppercase; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select {
  font: inherit; color: var(--text); background: rgba(5, 9, 22, .7); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--gold-dim); outline-offset: 0; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); }

.view { max-width: 560px; margin: 0 auto; padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 8px 24px rgba(0, 0, 0, .3);
}

/* hero */
.hero {
  position: relative; display: flex; align-items: flex-end; gap: 4px; min-height: 230px;
  border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; border: 1px solid rgba(232, 194, 106, .35);
  background: linear-gradient(180deg, rgba(11, 16, 32, .1) 20%, rgba(11, 16, 32, .95) 100%), var(--art) center/cover;
}
.portrait { height: 230px; width: auto; align-self: flex-end; margin-left: -6px; mask-image: linear-gradient(180deg, #000 70%, transparent); -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); }
.hero-text { padding: 0 12px 16px 0; min-width: 0; }
.hero h1 { font-size: 26px; line-height: 1.1; text-shadow: 0 2px 8px #000; overflow-wrap: anywhere; }
.lvl { display: inline-block; font-family: Cinzel, serif; font-size: 12px; color: var(--bg); background: var(--gold); border-radius: 6px; padding: 1px 8px; margin-bottom: 6px; }
.lvl b { font-size: 15px; }
.title { color: var(--gold); font-family: Cinzel, serif; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: rgba(5, 9, 22, .6); border: 1px solid var(--line); font-size: 18px; flex: none; }
.icon-btn.small { width: 30px; height: 30px; font-size: 16px; }
.hero > .icon-btn { position: absolute; top: 10px; right: 10px; }

/* buffs */
.buffs { display: flex; flex-wrap: wrap; gap: 10px; }
.buff { position: relative; width: 66px; display: grid; justify-items: center; gap: 2px; }
.buff img { width: 56px; height: 56px; border-radius: 10px; border: 2px solid var(--gold-dim); box-shadow: 0 0 12px rgba(232, 194, 106, .25); }
.buff.debuff img { border-color: #a33; box-shadow: 0 0 12px rgba(255, 60, 60, .3); }
.buff .time { position: absolute; top: 40px; right: 2px; font-size: 11px; font-weight: 800; background: rgba(0, 0, 0, .8); border-radius: 6px; padding: 0 4px; }
.buff .bname { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.2; }

/* stats */
.stat { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 8px 0; border-top: 1px solid var(--line); }
.stat:first-of-type { border-top: 0; }
.stat img { width: 44px; height: 44px; border-radius: 10px; flex: none; }
.stat-main { flex: 1; min-width: 0; }
.stat-top { display: flex; align-items: baseline; gap: 8px; }
.stat-top b { font-family: Cinzel, serif; font-size: 15px; width: 36px; }
.stat-name { color: var(--muted); font-size: 13px; flex: 1; }
.stat-val { font-family: Cinzel, serif; font-weight: 800; font-size: 24px; line-height: 1; }
.gain { font-size: 11px; color: var(--vit); font-weight: 800; }
.stat-xp { font-size: 11px; color: var(--muted); margin-top: 3px; }
.bar { height: 6px; background: rgba(255, 255, 255, .07); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: currentColor; box-shadow: 0 0 8px currentColor; }
.c-str, .b-str { color: var(--str); } .c-agi, .b-agi { color: var(--agi); }
.c-end, .b-end { color: var(--end); } .c-vit, .b-vit { color: var(--vit); }

/* quest */
.quest-line { display: grid; grid-template-columns: 1fr auto 36px; gap: 10px; align-items: center; padding: 4px 0; }
.quest-line > span:last-child { text-align: right; color: var(--muted); }
.pips { display: flex; gap: 5px; }
.pips i { width: 12px; height: 12px; transform: rotate(45deg); border: 1px solid var(--gold-dim); }
.pips i.on { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.reward { color: var(--gold); font-size: 13px; margin: 8px 0 12px; }
.streak { margin-left: auto; font-size: 11px; color: var(--end); text-transform: none; font-family: 'Nunito Sans', sans-serif; font-weight: 800; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.muscles { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.muscle { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid; }
.muscle.ready { color: var(--agi); border-color: rgba(62, 227, 154, .35); }
.muscle.sore { color: var(--str); border-color: rgba(255, 93, 93, .45); background: rgba(255, 93, 93, .08); }
.rec { display: flex; justify-content: space-between; padding: 5px 0; border-top: 1px solid var(--line); }
.rec:first-of-type { border-top: 0; }

/* buttons */
.btn { display: block; width: 100%; text-align: center; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .04); font-weight: 800; }
.btn.primary { background: linear-gradient(180deg, #f0cf80, #c99a3e); color: #1a1406; border-color: #f3d792; }
.btn.ghost { border-color: transparent; color: var(--muted); margin-top: 6px; }
.btn.big { padding: 14px; font-size: 16px; margin-top: 12px; font-family: Cinzel, serif; letter-spacing: .05em; }
.btn:disabled { opacity: .5; }
.link { font-size: 12px; text-decoration: underline; }
.danger { color: var(--danger); }

/* train */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { display: grid; justify-items: center; gap: 4px; padding: 14px 8px; border-radius: 12px; border: 1px solid var(--line); background: rgba(5, 9, 22, .5); text-align: center; }
.card img { width: 64px; height: 64px; border-radius: 12px; }
.card span { font-size: 12px; color: var(--muted); }
.card.resume { width: 100%; margin-bottom: 10px; border-color: var(--gold-dim); }
.form-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.form-head h2 { margin: 0; }
.seg { display: flex; gap: 6px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; }
.seg button.on { background: var(--gold); color: #1a1406; border-color: var(--gold); font-weight: 800; }
.ex { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: rgba(5, 9, 22, .4); }
.ex-head { display: flex; align-items: center; gap: 8px; }
.ex-head b { flex: 1; }
.target { font-size: 12px; color: var(--gold); }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.ex-row { display: flex; gap: 10px; align-items: flex-end; }
.load { width: 78px; flex: none; margin: 0; }
.sets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1; }
.set { width: 52px; text-align: center; padding: 10px 4px; }
.kinds { display: grid; gap: 8px; margin-bottom: 12px; }
.kind { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin: 0; color: var(--text); font-size: 14px; }
.kind input { width: auto; accent-color: var(--gold); }
.kind span { display: grid; }
.kind small { color: var(--muted); }
.kind:has(input:checked) { border-color: var(--gold-dim); background: rgba(232, 194, 106, .07); }

/* plan */
.plan { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 12px; }
.plan td, .plan th { padding: 6px 4px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.plan th { color: var(--muted); font-weight: 600; border-top: 0; }
.k-strength { color: var(--str); } .k-cardio { color: var(--agi); } .k-recovery { color: var(--vit); } .k-rest { color: var(--muted); }
.rules { padding-left: 18px; margin: 0; display: grid; gap: 8px; font-size: 14px; }

/* chronicle */
.entry { padding: 10px 0; border-top: 1px solid var(--line); }
.entry:first-of-type { border-top: 0; }
.entry-top { display: flex; justify-content: space-between; gap: 10px; }
.entry-top small { color: var(--muted); white-space: nowrap; }
.entry-sub { font-size: 12px; color: var(--muted); margin: 2px 0 6px; overflow-wrap: anywhere; }
.entry-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.entry-ev { font-size: 12px; color: var(--gold); margin-top: 6px; }
.chip { display: inline-block; font-size: 11px; font-weight: 800; border: 1px solid currentColor; border-radius: 999px; padding: 0 8px; margin: 0 4px 4px 0; }

/* nav */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: rgba(8, 12, 26, .94); border-top: 1px solid rgba(232, 194, 106, .3);
  padding-bottom: env(safe-area-inset-bottom); backdrop-filter: blur(10px);
}
.tabs button { flex: 1; max-width: 140px; padding: 14px 0; font-family: Cinzel, serif; font-size: 13px; color: var(--muted); }
.tabs button.on { color: var(--gold); box-shadow: inset 0 2px 0 var(--gold); }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); display: grid; align-items: end; justify-items: center; z-index: 10; }
#modal[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 560px; background: var(--panel-solid); border: 1px solid rgba(232, 194, 106, .4);
  border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out; max-height: 90vh; overflow: auto;
}
.sheet h2 { font-size: 20px; justify-content: center; }
.sheet .btn { margin-top: 10px; }
.sheet .buffs { justify-content: center; margin: 12px 0; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.levelup { color: var(--gold); text-shadow: 0 0 18px var(--gold); animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { to { text-shadow: 0 0 4px var(--gold); } }
.results { display: grid; gap: 8px; }
.res { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 10px; background: rgba(255, 255, 255, .04); }
.res img { width: 34px; height: 34px; border-radius: 8px; }
.res b { font-family: Cinzel, serif; width: 40px; }
.res span { flex: 1; }
.res .up { flex: none; color: var(--gold); font-weight: 800; font-family: Cinzel, serif; }
.events { color: var(--gold); font-size: 13px; padding-left: 18px; }
.buff-detail { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.buff-detail img { width: 72px; height: 72px; border-radius: 12px; border: 2px solid var(--gold-dim); }
.buff-detail h2 { justify-content: flex-start; margin: 0; }

/* key gate */
.keygate { max-width: 360px; margin: 12vh auto 0; text-align: center; display: grid; gap: 12px; }
.keygate img { width: 140px; margin: 0 auto; border-radius: 12px; }

#toasts { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 16px; right: 16px; display: grid; gap: 8px; z-index: 20; justify-items: center; }
.toast { max-width: 520px; padding: 10px 14px; border-radius: 10px; background: #1e2950; border: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.toast.error { background: #4a1420; border-color: var(--danger); }
