:root {
  color-scheme: light;
  --paper: #f5f3f8;
  --ink: #1d1d1b;
  --muted: #726e79;
  --line: #252521;
  --white: #fffdf7;
  --card-green: #00d16f;
  --card-green-dark: #00a957;
  --card-yellow: #f2c500;
  --card-violet: #9468d7;
  --purple: #8f70d6;
  --purple-dark: #654a9e;
  --lavender: #d9d3e5;
  --violet: #b9a7e5;
  --shadow: 5px 5px 0 var(--ink);
  --soft-shadow: 0 12px 32px rgb(29 29 27 / 9%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; min-height: 100%; background: var(--paper); scroll-behavior: smooth; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--paper); color: var(--ink); touch-action: manipulation; }
button, input, select { font: inherit; }
button, a, select { touch-action: manipulation; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; }
::selection { color: var(--ink); background: var(--purple); }

.app-shell { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
.topbar { min-height: 116px; max-width: 1450px; margin: 0 auto; padding: 8px 46px; display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 16px; min-width: 0; color: inherit; text-decoration: none; }
.brand-logo { display: block; width: 152px; height: 107px; object-fit: cover; object-position: center; }
.topbar-actions { display: flex; align-items: center; gap: 22px; }
.save-indicator { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; font-weight: 700; }
.save-indicator i { width: 9px; height: 9px; border-radius: 50%; background: var(--purple-dark); box-shadow: 0 0 0 4px rgb(143 112 214 / 15%); }
.avatar-shortcut { width: 48px; height: 48px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 50%; background: var(--purple); font-size: 18px; font-weight: 950; cursor: pointer; box-shadow: 3px 3px 0 var(--ink); }

.app-nav { width: min(1250px, calc(100% - 92px)); margin: 0 auto; min-height: 64px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgb(29 29 27 / 15%); }
.nav-item { position: relative; display: inline-flex; align-items: center; gap: 9px; padding: 10px 16px; border: 0; border-radius: 4px; background: transparent; color: #62615d; font-size: 13px; font-weight: 800; cursor: pointer; transition: color .16s ease, background .16s ease; }
.nav-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { color: var(--ink); background: rgb(0 0 0 / 4%); }
.nav-item.is-current { color: var(--ink); background: var(--purple); }

.main-content { width: min(1250px, calc(100% - 92px)); min-height: calc(100vh - 260px); margin: 0 auto; padding: 42px 0 54px; }
.screen { display: none; animation: screen-in .22s ease-out both; }
.screen.is-active { display: block; }
@keyframes screen-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
.screen.login-screen { min-height: min(68vh, 720px); display: grid; place-items: center; }
.login-form { width: min(480px, 100%); padding: 32px; display: flex; flex-direction: column; }
.login-form .eyebrow { margin-bottom: 10px; color: var(--purple-dark); }
.login-form h1 { margin-bottom: 0; font-size: clamp(38px, 5vw, 54px); }
.login-form .page-subtitle { margin: 12px 0 22px; }
.login-form .field-label:not(:first-child) { margin-top: 14px; }
.login-error { min-height: 18px; margin: 8px 0 0; color: #8b3048; font-size: 12px; font-weight: 750; }
.login-form .button { margin-top: 8px; }
.eyebrow { display: inline-block; color: var(--ink); font-size: 10px; font-weight: 950; line-height: 1.3; letter-spacing: .19em; text-transform: uppercase; }
.eyebrow-light { color: rgb(255 253 247 / 66%); }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-weight: 900; letter-spacing: -.025em; text-transform: uppercase; }
h1 { margin-bottom: 0; font-size: clamp(42px, 5vw, 68px); line-height: .97; }
h2 { margin-bottom: 0; font-size: clamp(25px, 3vw, 36px); line-height: 1.02; }
.page-subtitle { margin: 11px 0 0; color: var(--muted); font-size: 16px; }
.page-heading { margin-bottom: 25px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.page-heading .eyebrow { margin-bottom: 10px; }
.page-heading h1 { font-size: clamp(36px, 4.6vw, 56px); }

.card { position: relative; min-width: 0; border: 2px solid var(--line); border-radius: 8px; background: var(--white); box-shadow: var(--shadow); }
.card-dark { background: var(--ink); color: var(--white); }
.card-green { background: var(--card-green); }
.card-yellow { background: var(--card-yellow); }
.card-violet { background: var(--card-violet); }
.card-index { position: absolute; right: 18px; bottom: 14px; color: rgb(255 253 247 / 38%); font-size: 9px; font-weight: 900; letter-spacing: .15em; }
.button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 0 18px; border: 2px solid var(--ink); border-radius: 5px; font-size: 14px; font-weight: 900; cursor: pointer; box-shadow: 3px 3px 0 var(--ink); transition: transform .12s ease, box-shadow .12s ease, filter .12s ease; }
.button:hover { filter: brightness(1.04); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.button-primary { background: var(--purple); }
.button-dark { background: var(--ink); color: var(--white); }
.button-outline { background: transparent; }
.button-wide { width: 100%; min-height: 54px; }
.button:disabled { opacity: .55; cursor: default; transform: none; box-shadow: 3px 3px 0 var(--ink); }
.text-link { display: inline-flex; align-items: center; gap: 10px; padding: 0; border: 0; background: transparent; font-size: 13px; font-weight: 950; cursor: pointer; }
.text-link span { font-size: 18px; transition: transform .15s ease; }
.text-link:hover span { transform: translateX(4px); }

/* Character setup */
.setup-screen { max-width: 1100px; margin: 0 auto; }
.setup-intro { margin: 0 0 30px; }
.setup-intro .eyebrow { margin-bottom: 12px; padding: 7px 10px; background: var(--lavender); }
.setup-intro h1 { font-size: clamp(48px, 7vw, 82px); }
.setup-intro p { margin: 14px 0 0; color: var(--muted); font-size: 17px; }
.setup-layout { display: grid; grid-template-columns: .78fr 1.22fr; align-items: stretch; gap: 24px; }
.setup-preview { min-height: 550px; padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.setup-preview::after { position: absolute; top: 91px; left: -48px; width: 95px; height: 15px; background: var(--purple); content: ""; transform: rotate(-37deg); }
.preview-meta { position: absolute; top: 21px; right: 22px; left: 22px; display: flex; justify-content: space-between; color: rgb(255 253 247 / 70%); font-size: 10px; font-weight: 900; letter-spacing: .15em; }
.level-chip { padding: 5px 8px; border: 1px solid rgb(255 255 255 / 25%); border-radius: 3px; color: var(--purple); }
.avatar-stage { width: 210px; height: 228px; display: grid; place-items: center; }
.avatar-stage svg { width: 100%; height: 100%; overflow: visible; }
.preview-name { margin-top: 5px; font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: 30px; text-align: center; text-transform: uppercase; }
.preview-caption { margin-top: 5px; color: rgb(255 253 247 / 55%); font-size: 12px; }
.sticker { position: absolute; bottom: 24px; left: 24px; padding: 7px 9px; color: var(--ink); font-size: 9px; font-weight: 950; letter-spacing: .15em; transform: rotate(-4deg); }
.sticker-purple { background: var(--purple); }
.setup-form { padding: 28px; display: flex; flex-direction: column; }
.form-heading { margin-bottom: 20px; }
.form-heading .eyebrow { margin-bottom: 8px; }
.form-heading h2 { font-size: 32px; }
.field-label { display: block; margin: 0 0 8px; color: var(--ink); font-size: 12px; font-weight: 900; }
.text-input { width: 100%; min-width: 0; min-height: 46px; padding: 11px 13px; border: 1.5px solid #aaa69c; border-radius: 4px; background: #fffefb; color: var(--ink); font-size: 14px; }
.text-input::placeholder { color: #9a978e; }
.text-input:focus { border-color: var(--ink); outline: 2px solid rgb(143 112 214 / 38%); outline-offset: 1px; }
.setup-form > .text-input { margin-bottom: 18px; }
.setup-ai-trigger { align-self: flex-start; margin: -7px 0 19px; color: var(--purple-dark); }
.ai-card { padding: 20px; display: grid; gap: 17px; }
.ai-card h2 { max-width: 260px; margin-top: 9px; font-size: 27px; }
.ai-plan-form { max-height: min(90vh, 850px); overflow-y: auto; }
.ai-plan-form .field-label { margin-top: 14px; }
.ai-textarea { min-height: 76px; resize: vertical; }
.ai-plan-form > .button { margin-top: 18px; }
.ai-plan-result { margin-top: 24px; padding-top: 20px; border-top: 1.5px solid #d8d1e3; }
.ai-plan-result h3 { margin: 8px 0; font-size: 28px; }
.ai-plan-result p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.ai-plan-result strong { display: block; margin-top: 16px; font-size: 12px; }
.ai-plan-result ul { margin: 7px 0 0; padding-left: 21px; color: #45414b; font-size: 12px; line-height: 1.65; }
.ai-plan-result li + li { margin-top: 4px; }
.ai-plan-result .button { margin-top: 20px; }
.picker-block { margin: 3px 0 15px; }
.swatch-row, .choice-row { min-height: 39px; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.swatch { position: relative; width: 32px; height: 32px; padding: 0; border: 2px solid var(--ink); border-radius: 50%; cursor: pointer; box-shadow: 2px 2px 0 var(--ink); }
.swatch.is-selected::after { position: absolute; inset: -5px; border: 1.5px solid var(--ink); border-radius: 50%; content: ""; }
.swatch.is-locked { opacity: .44; cursor: not-allowed; }
.hair-choice { min-height: 34px; padding: 0 10px; border: 1.5px solid #9d998f; border-radius: 4px; background: transparent; color: #5c5a55; font-size: 11px; font-weight: 850; cursor: pointer; }
.hair-choice.is-selected { border-color: var(--ink); background: var(--lavender); color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.setup-form .button { margin-top: auto; }
.setup-footnote { margin: 21px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

/* Home dashboard */
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.27fr) minmax(290px, .73fr); align-items: start; gap: 26px; }
.dashboard-main, .dashboard-side { display: grid; gap: 24px; }
.player-card { min-height: 277px; padding: 24px 27px 28px; overflow: hidden; }
.player-card::before { position: absolute; top: -67px; right: -55px; width: 245px; height: 245px; border: 28px solid var(--purple); border-radius: 50%; content: ""; opacity: .92; }
.player-card::after { position: absolute; top: 10px; right: 37px; width: 22px; height: 75px; background: var(--lavender); content: ""; transform: rotate(41deg); }
.player-identity { position: relative; z-index: 1; display: flex; align-items: center; gap: 18px; }
.avatar-large { width: 92px; height: 102px; flex: 0 0 auto; display: grid; place-items: center; }
.avatar-large svg { width: 100%; height: 100%; }
.player-identity .eyebrow { margin-bottom: 8px; }
.player-identity h2 { margin: 0 0 7px; font-size: 32px; text-transform: uppercase; }
.player-rank { display: inline-block; color: rgb(255 253 247 / 58%); font-size: 9px; font-weight: 950; letter-spacing: .16em; }
.player-level-row { position: relative; z-index: 1; margin: 17px 0 8px; display: flex; justify-content: space-between; color: rgb(255 253 247 / 62%); font-size: 9px; font-weight: 900; letter-spacing: .14em; }
.xp-track, .campaign-track { height: 10px; overflow: hidden; border: 1px solid rgb(255 255 255 / 32%); border-radius: 2px; background: rgb(255 255 255 / 10%); }
.xp-track span, .campaign-track span { width: 0; height: 100%; display: block; background: var(--purple); transition: width .4s cubic-bezier(.2,.8,.2,1); }
.player-footer { position: relative; z-index: 1; margin-top: 9px; display: flex; justify-content: space-between; gap: 10px; color: rgb(255 253 247 / 56%); font-size: 10px; font-weight: 700; }
.next-unlock { color: var(--purple); }
.quests-section { min-width: 0; }
.section-heading { margin-bottom: 15px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.section-heading .eyebrow { margin-bottom: 6px; }
.section-heading h2 { font-size: 31px; }
.count-pill, .week-total-pill { min-width: 32px; height: 32px; padding: 0 10px; display: inline-grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 20px; background: var(--white); font-size: 12px; font-weight: 950; }
.quest-list { display: grid; gap: 12px; }
.quest-card { min-height: 82px; padding: 15px 17px; display: grid; grid-template-columns: 39px minmax(0, 1fr) auto; align-items: center; gap: 13px; border: 1.5px solid var(--ink); border-radius: 6px; background: var(--white); transition: transform .15s ease, box-shadow .15s ease; }
.quest-card:hover { transform: translateY(-2px); box-shadow: 3px 4px 0 var(--ink); }
.quest-card.is-done { background: #e8f5e9; }
.quest-symbol { width: 36px; height: 36px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; font-size: 17px; font-weight: 900; }
.quest-info { min-width: 0; }
.quest-title { margin: 0 0 5px; overflow: hidden; font-size: 14px; font-weight: 850; line-height: 1.3; text-overflow: ellipsis; }
.quest-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 10px; font-weight: 750; }
.quest-xp { color: var(--card-green-dark); font-weight: 950; }
.quest-done-label { color: var(--card-green-dark); font-size: 10px; font-weight: 950; letter-spacing: .06em; }
.quest-complete { width: 38px; height: 38px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--white); font-size: 17px; font-weight: 900; cursor: pointer; }
.quest-complete:hover { background: var(--card-green); }
.quest-empty { padding: 28px 22px; border: 1.5px dashed #77736a; border-radius: 7px; color: var(--muted); text-align: center; }
.quest-empty strong { display: block; margin-bottom: 6px; color: var(--ink); font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: 22px; text-transform: uppercase; }
.quest-empty .button { margin-top: 17px; }
.campaign-card { min-height: 215px; padding: 23px; overflow: hidden; }
.campaign-top { display: flex; justify-content: space-between; align-items: center; }
.campaign-marker { width: 30px; height: 30px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; font-size: 17px; }
.campaign-card h2 { max-width: 90%; margin: 24px 0 19px; font-size: 28px; }
.campaign-progress-row { margin-bottom: 8px; display: flex; justify-content: space-between; gap: 12px; font-size: 10px; font-weight: 850; }
.campaign-track { height: 8px; border-color: rgb(29 29 27 / 22%); background: rgb(255 255 255 / 20%); }
.campaign-track span { background: var(--ink); }
.campaign-card .text-link { margin-top: 19px; }
.stats-card { padding: 22px 23px 18px; }
.compact-heading { margin-bottom: 19px; }
.compact-heading h2 { font-size: 27px; }
.stat-mark, .achievement-mark { font-size: 26px; }
.attribute-list { display: grid; gap: 12px; margin-bottom: 17px; }
.attribute-line { display: grid; grid-template-columns: 83px minmax(0,1fr) 22px; align-items: center; gap: 9px; }
.attribute-name { font-size: 10px; font-weight: 850; }
.attribute-level { color: var(--muted); font-size: 9px; font-weight: 900; text-align: right; }
.attribute-track { height: 6px; overflow: hidden; border-radius: 4px; background: #e4e0d6; }
.attribute-track span { height: 100%; display: block; background: var(--purple-dark); border-radius: inherit; }
.weekly-card { min-height: 96px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.weekly-copy { display: grid; gap: 2px; }
.weekly-copy strong { font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: 31px; line-height: 1; }
.weekly-copy > span:last-child { color: #49473f; font-size: 10px; font-weight: 700; }
.week-bars { height: 58px; display: flex; align-items: end; gap: 6px; }
.week-bar { width: 13px; min-height: 4px; position: relative; border: 1px solid var(--ink); background: rgb(29 29 27 / 15%); }
.week-bar.is-active { background: var(--purple); }
.week-bar.is-today { outline: 2px solid var(--ink); outline-offset: 2px; }
.week-bar-label { position: absolute; bottom: -14px; left: 50%; color: var(--ink); font-size: 8px; font-weight: 800; transform: translateX(-50%); }

/* Journey and character */
.journey-banner { min-height: 185px; margin-bottom: 31px; padding: 26px 30px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.journey-banner h2 { margin: 12px 0 9px; font-size: clamp(30px, 4vw, 46px); }
.journey-banner p { margin-bottom: 0; color: rgb(29 29 27 / 73%); font-size: 13px; }
.journey-progress-badge { width: 115px; height: 115px; flex: 0 0 auto; display: grid; place-content: center; border: 2px solid var(--ink); border-radius: 50%; background: var(--lavender); text-align: center; transform: rotate(5deg); }
.journey-progress-badge strong { font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: 30px; }
.journey-progress-badge span { font-size: 8px; font-weight: 950; letter-spacing: .12em; }
.journey-columns { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr); align-items: start; gap: 26px; }
.chapter-section { min-width: 0; }
.chapter-list { display: grid; gap: 11px; margin-bottom: 18px; }
.chapter-card { min-height: 82px; padding: 15px 17px; display: grid; grid-template-columns: 36px minmax(0, 1fr) 42px; align-items: center; gap: 14px; border: 1.5px solid var(--ink); border-radius: 5px; background: var(--white); }
.chapter-index { width: 31px; height: 31px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--lavender); font-family: Impact, Haettenschweiler, sans-serif; font-size: 14px; }
.chapter-card.is-done .chapter-index { background: var(--card-green); }
.chapter-card.is-done .chapter-title { color: #6d6a62; text-decoration: line-through; }
.chapter-title { margin: 0; font-size: 14px; font-weight: 850; }
.chapter-status { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .08em; }
.chapter-check { width: 36px; height: 36px; border: 1.5px solid var(--ink); border-radius: 50%; background: transparent; font-weight: 900; cursor: pointer; }
.chapter-check:hover { background: var(--card-green); }
.chapter-empty { padding: 23px; border: 1.5px dashed #858076; border-radius: 5px; color: var(--muted); font-size: 13px; text-align: center; }
.inline-add { padding: 17px; }
.inline-add label { display: block; margin-bottom: 10px; }
.inline-add-title { display: block; margin-top: 4px; font-size: 13px; font-weight: 850; }
.inline-controls { display: flex; align-items: stretch; gap: 10px; }
.inline-controls .button { flex: 0 0 auto; }
.achievement-section { padding: 23px; }
.achievement-list { display: grid; gap: 10px; }
.achievement-item { min-height: 58px; display: grid; grid-template-columns: 39px 1fr auto; align-items: center; gap: 10px; padding: 9px; border: 1px solid #ded9ce; border-radius: 4px; }
.achievement-icon { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 50%; background: var(--lavender); font-size: 15px; }
.achievement-item.is-locked { filter: grayscale(1); opacity: .42; }
.achievement-title { font-size: 11px; font-weight: 900; }
.achievement-desc { margin-top: 3px; color: var(--muted); font-size: 9px; }
.achievement-state { color: var(--purple-dark); font-size: 9px; font-weight: 950; }
.character-layout { display: grid; grid-template-columns: .76fr 1.24fr; align-items: start; gap: 25px; }
.character-showcase { min-height: 420px; padding: 25px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.character-showcase::after { position: absolute; top: 28px; right: -30px; width: 96px; height: 18px; background: var(--lavender); content: ""; transform: rotate(37deg); }
.avatar-stage-large { width: 250px; height: 273px; }
.character-showcase h2 { margin: 8px 0 7px; font-size: 31px; }
.character-xp { width: min(260px, 100%); margin-top: 18px; color: rgb(255 253 247 / 60%); font-size: 9px; font-weight: 850; }
.character-xp .xp-track { margin-top: 6px; }
.character-editor { padding: 25px; }
.character-editor .field-label { margin-top: 16px; }
.unlock-note { padding: 12px; border-left: 4px solid var(--lavender); background: #f0edf5; color: #555146; font-size: 11px; }
.level-stamp, .total-xp-stamp { padding: 9px 12px; border: 2px solid var(--ink); background: var(--lavender); font-size: 10px; font-weight: 950; letter-spacing: .12em; box-shadow: 3px 3px 0 var(--ink); transform: rotate(2deg); }
.attribute-section { margin-top: 28px; padding: 22px 25px; }
.attribute-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.attribute-tile { padding: 14px 12px; border: 1px solid #dbd6ca; border-radius: 4px; }
.attribute-tile .attribute-name { font-size: 12px; }
.attribute-tile strong { display: block; margin: 8px 0; font-family: Impact, Haettenschweiler, sans-serif; font-size: 22px; }
.attribute-tile .attribute-track { margin-bottom: 6px; }
.attribute-caption { color: var(--muted); font-size: 9px; }
.data-tools { margin-top: 26px; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.data-tools h2 { margin-top: 6px; font-size: 22px; }
.data-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.account-session { min-width: 170px; display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.account-session .eyebrow { color: var(--purple-dark); }
.account-session strong { max-width: 100%; overflow-wrap: anywhere; font-size: 12px; }
.account-session .button { min-height: 40px; padding: 0 12px; font-size: 11px; }

/* History */
.history-summary-grid { margin: 5px 0 24px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 17px; }
.history-summary { min-height: 137px; padding: 20px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; }
.history-summary strong { font-family: Impact, Haettenschweiler, sans-serif; font-size: 42px; line-height: .9; }
.history-summary > span:last-child { color: rgb(29 29 27 / 72%); font-size: 11px; font-weight: 800; }
.history-chart-card, .event-log-card { margin-bottom: 23px; padding: 23px 25px; }
.history-chart { min-height: 190px; padding: 15px 4px 0; display: grid; grid-template-columns: repeat(7, 1fr); align-items: end; gap: 14px; border-bottom: 1px solid #d8d2c6; }
.history-day { height: 170px; display: flex; flex-direction: column; align-items: center; justify-content: end; gap: 7px; }
.history-day-bar { width: min(44px, 70%); min-height: 5px; position: relative; border: 1.5px solid var(--ink); background: #e3dfd5; transition: height .3s ease; }
.history-day-bar.is-active { background: var(--purple); }
.history-day-bar::before { position: absolute; bottom: calc(100% + 4px); left: 50%; color: var(--ink); content: attr(data-count); font-size: 10px; font-weight: 900; transform: translateX(-50%); }
.history-day.is-today .history-day-label { padding: 3px 5px; background: var(--lavender); }
.history-day-label { color: var(--muted); font-size: 9px; font-weight: 850; }
.week-total-pill { font-size: 10px; }
.event-list { display: grid; }
.event-row { min-height: 63px; display: grid; grid-template-columns: 38px minmax(0,1fr) auto; align-items: center; gap: 12px; border-top: 1px solid #e4dfd5; }
.event-row:first-child { border-top: 0; }
.event-dot { width: 32px; height: 32px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--purple); font-size: 13px; font-weight: 900; }
.event-row.is-chapter .event-dot { background: var(--lavender); }
.event-title { margin: 0; font-size: 12px; font-weight: 850; }
.event-date { margin-top: 3px; color: var(--muted); font-size: 9px; }
.event-xp { color: var(--purple-dark); font-size: 11px; font-weight: 950; }
.event-empty { padding: 30px 12px; color: var(--muted); font-size: 13px; text-align: center; }

.app-footer { width: min(1250px, calc(100% - 92px)); min-height: 56px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid rgb(29 29 27 / 20%); color: #77736a; font-size: 9px; font-weight: 900; letter-spacing: .16em; }

/* Dialogs */
.app-dialog { width: min(500px, calc(100vw - 28px)); max-height: min(90vh, 760px); padding: 0; overflow: auto; border: 2px solid var(--ink); border-radius: 8px; background: var(--white); color: var(--ink); box-shadow: 8px 8px 0 var(--ink); }
.app-dialog::backdrop { background: rgb(20 20 19 / 62%); backdrop-filter: blur(2px); }
.dialog-content { position: relative; padding: 28px; }
.dialog-content h2 { max-width: 380px; margin: 7px 35px 23px 0; font-size: 32px; }
.dialog-content > .field-label { margin-top: 15px; }
.dialog-content > .button { margin-top: 23px; }
.dialog-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--lavender); font-size: 22px; line-height: 1; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row > div { min-width: 0; }
.levelup-dialog { overflow: hidden; }
.levelup-content { min-height: 350px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.levelup-content h2 { margin: 8px 0 7px; font-size: 50px; }
.levelup-content p { color: var(--muted); font-size: 13px; }
.levelup-content .button { margin-top: 15px; }
.levelup-star { width: 100px; height: 100px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 50%; background: var(--purple); font-size: 54px; box-shadow: 5px 5px 0 var(--ink); transform: rotate(8deg); }
.toast { position: fixed; z-index: 30; right: 20px; bottom: 22px; max-width: min(360px, calc(100vw - 32px)); padding: 13px 17px; border: 2px solid var(--ink); border-radius: 4px; background: var(--ink); color: var(--white); font-size: 13px; font-weight: 850; box-shadow: 4px 4px 0 var(--purple); opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .main-content, .app-nav, .app-footer { width: min(100% - 48px, 760px); }
  .topbar { padding: 7px 24px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr) minmax(250px, .75fr); gap: 18px; }
  .dashboard-main, .dashboard-side { gap: 18px; }
  .setup-layout { grid-template-columns: .85fr 1.15fr; gap: 17px; }
  .setup-form { padding: 22px; }
  .setup-preview { min-height: 530px; }
  .journey-columns { gap: 18px; }
  .character-layout { grid-template-columns: .85fr 1.15fr; gap: 18px; }
  .attribute-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 680px) {
  .topbar { min-height: 92px; padding: 4px 18px; }
  .brand { gap: 10px; }
  .brand-logo { width: 124px; height: 88px; }
  .topbar-actions { gap: 12px; }
  .save-indicator { gap: 7px; font-size: 10px; }
  .save-indicator i { width: 7px; height: 7px; box-shadow: 0 0 0 3px rgb(143 112 214 / 15%); }
  .avatar-shortcut { width: 40px; height: 40px; font-size: 15px; }
  .app-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; width: 100%; min-height: calc(68px + env(safe-area-inset-bottom)); margin: 0; padding: 7px 8px calc(7px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; border-top: 2px solid var(--line); border-bottom: 0; background: var(--paper); }
  .nav-item { min-width: 0; min-height: 48px; padding: 4px 2px; display: flex; flex-direction: column; justify-content: center; gap: 3px; border-radius: 3px; font-size: 9px; }
  .nav-item svg { width: 19px; height: 19px; }
  .main-content { width: calc(100% - 36px); min-height: calc(100vh - 165px); padding: 27px 0 calc(112px + env(safe-area-inset-bottom)); }
  .screen.login-screen { min-height: calc(100dvh - 190px); align-items: start; padding-top: 24px; }
  .login-form { padding: 25px 21px; }
  .login-form h1 { font-size: clamp(36px, 10vw, 48px); }
  .app-footer { width: calc(100% - 36px); min-height: 45px; margin-bottom: calc(70px + env(safe-area-inset-bottom)); font-size: 8px; }
  .setup-intro { margin-bottom: 21px; }
  .setup-intro h1 { font-size: clamp(48px, 13vw, 70px); }
  .setup-intro p { max-width: 290px; font-size: 15px; }
  .setup-layout { grid-template-columns: 1fr; gap: 16px; }
  .setup-preview { min-height: 295px; padding: 18px; flex-direction: row; justify-content: flex-start; gap: 14px; }
  .setup-preview::after { top: 68px; left: -39px; }
  .preview-meta { top: 15px; right: 16px; left: 16px; font-size: 8px; }
  .avatar-stage { width: 142px; height: 161px; flex: 0 0 auto; margin-top: 22px; }
  .preview-name { max-width: 160px; margin: 28px 0 0; font-size: 24px; text-align: left; overflow-wrap: anywhere; }
  .preview-caption { position: absolute; left: 175px; bottom: 66px; font-size: 10px; }
  .sticker { bottom: 17px; left: 18px; }
  .setup-form { padding: 20px 18px; }
  .form-heading h2 { font-size: 28px; }
  .setup-footnote { font-size: 10px; }
  .page-heading { margin-bottom: 20px; align-items: flex-start; }
  .page-heading h1 { font-size: clamp(34px, 9vw, 46px); }
  .page-heading .eyebrow { font-size: 9px; }
  .page-subtitle { margin-top: 7px; font-size: 13px; }
  .new-quest-trigger { min-height: 42px; padding: 0 10px; font-size: 11px; white-space: nowrap; }
  .dashboard-grid { grid-template-columns: 1fr; gap: 22px; }
  .dashboard-main, .dashboard-side { gap: 20px; }
  .player-card { min-height: 242px; padding: 19px 18px 24px; }
  .player-card::before { top: -88px; right: -70px; width: 220px; height: 220px; border-width: 25px; }
  .player-card::after { right: 14px; width: 15px; height: 58px; }
  .player-identity { gap: 11px; }
  .avatar-large { width: 72px; height: 84px; }
  .player-identity h2 { font-size: 26px; }
  .player-identity .eyebrow { font-size: 8px; }
  .player-rank { font-size: 8px; }
  .player-level-row { margin-top: 14px; }
  .player-footer { font-size: 8px; }
  .section-heading { margin-bottom: 11px; }
  .section-heading h2 { font-size: 27px; }
  .quest-card { min-height: 74px; grid-template-columns: 34px minmax(0,1fr) 36px; padding: 12px 11px; gap: 10px; }
  .quest-symbol { width: 31px; height: 31px; font-size: 14px; }
  .quest-title { font-size: 12px; }
  .quest-meta { font-size: 9px; }
  .quest-complete { width: 34px; height: 34px; }
  .campaign-card { min-height: 192px; padding: 18px; }
  .campaign-card h2 { margin: 18px 0 15px; font-size: 25px; }
  .stats-card { padding: 18px; }
  .weekly-card { min-height: 92px; }
  .journey-banner { min-height: 150px; margin-bottom: 25px; padding: 20px; gap: 12px; }
  .journey-banner h2 { margin: 10px 0 7px; font-size: clamp(25px, 7vw, 34px); }
  .journey-banner p { max-width: 230px; font-size: 11px; line-height: 1.4; }
  .journey-progress-badge { width: 77px; height: 77px; }
  .journey-progress-badge strong { font-size: 23px; }
  .journey-progress-badge span { font-size: 6px; }
  .journey-columns { grid-template-columns: 1fr; gap: 24px; }
  .journey-screen .page-heading .button { min-height: 42px; padding: 0 10px; font-size: 11px; white-space: nowrap; }
  .chapter-card { min-height: 73px; padding: 11px; grid-template-columns: 31px minmax(0,1fr) 38px; gap: 10px; }
  .chapter-index { width: 29px; height: 29px; }
  .chapter-title { font-size: 12px; }
  .chapter-check { width: 33px; height: 33px; }
  .inline-add { padding: 14px; }
  .achievement-section { padding: 18px; }
  .character-layout { grid-template-columns: 1fr; gap: 16px; }
  .character-showcase { min-height: 350px; }
  .avatar-stage-large { width: 210px; height: 225px; }
  .character-editor { padding: 19px; }
  .attribute-section { margin-top: 23px; padding: 18px; }
  .attribute-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .attribute-tile { padding: 11px 9px; }
  .attribute-tile .attribute-name { font-size: 10px; }
  .data-tools { margin-top: 18px; padding: 16px; align-items: flex-start; flex-direction: column; gap: 14px; }
  .data-tools h2 { font-size: 20px; }
  .data-actions .button { min-height: 40px; padding: 0 11px; font-size: 11px; }
  .history-summary-grid { margin-bottom: 19px; gap: 8px; }
  .history-summary { min-height: 105px; padding: 12px; }
  .history-summary .eyebrow { font-size: 7px; letter-spacing: .11em; }
  .history-summary strong { font-size: 32px; }
  .history-summary > span:last-child { font-size: 9px; }
  .history-chart-card, .event-log-card { margin-bottom: 18px; padding: 18px 14px; }
  .history-chart { min-height: 160px; gap: 4px; }
  .history-day { height: 145px; }
  .history-day-bar { width: min(34px, 76%); }
  .history-day-label { font-size: 8px; }
  .week-total-pill { min-width: auto; height: 27px; padding: 0 8px; font-size: 8px; }
  .event-row { min-height: 58px; grid-template-columns: 32px minmax(0,1fr) auto; gap: 9px; }
  .event-dot { width: 29px; height: 29px; font-size: 11px; }
  .event-title { font-size: 11px; }
  .event-xp { font-size: 9px; }
  .level-stamp, .total-xp-stamp { margin-top: 6px; padding: 7px 8px; font-size: 8px; white-space: nowrap; }
  .dialog-content { padding: 22px 18px; }
  .dialog-content h2 { font-size: 27px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .toast { right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); font-size: 12px; }
}

@media (max-width: 390px) {
  .main-content { width: calc(100% - 28px); }
  .topbar { padding-right: 13px; padding-left: 13px; }
  .brand-logo { width: 112px; height: 79px; }
  .save-indicator { font-size: 9px; }
  .avatar-shortcut { width: 36px; height: 36px; }
  .setup-preview { min-height: 270px; gap: 8px; }
  .avatar-stage { width: 124px; height: 145px; }
  .preview-name { max-width: 135px; font-size: 21px; }
  .preview-caption { left: 147px; bottom: 62px; font-size: 9px; }
  .setup-form { padding: 18px 14px; }
  .history-summary { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
