:root {
  --leather: #4A2E1C; --leather-dark: #2E1C10; --parchment: #F1E4C4; --parchment-2: #EAD9B2; --parchment-3: #F6EBD2;
  --paper-line: #E0CFA6; --brass: #B08D3C; --brass-light: #C8B07E; --gold: #C9A24A; --ink: #2B2117; --ink-2: #5E4E3A; --ink-3: #7A6A52;
  --ember: #C2652E; --bar: #D9C39A; --bar-line: #8C6B3F; --sleep: #9C8560;
  --serif: 'Alegreya', Georgia, serif; --sans: 'Alegreya Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--leather-dark); color: var(--ink); font-family: var(--sans); font-size: 15px; -webkit-text-size-adjust: 100%; }
body { display: flex; justify-content: center; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { width: 100%; max-width: 520px; height: 100dvh; display: flex; flex-direction: column; background: var(--leather); padding: env(safe-area-inset-top, 0) 0 0 0; }
.book { flex: 1; min-height: 0; margin: 8px; margin-bottom: 0; background: var(--parchment); border: 2px solid var(--brass); border-radius: 12px 12px 0 0; box-shadow: inset 0 0 40px rgba(90,58,34,.18); display: flex; flex-direction: column; overflow: hidden; }
.screen { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.hidden { display: none !important; }

/* header strips */
.strip { background: var(--parchment-2); border-bottom: 2px solid var(--brass); padding: 10px 14px; }
.hero { display: flex; align-items: center; gap: 10px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--bar); border: 3px solid var(--brass); box-shadow: 0 0 0 3px var(--leather); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.hero-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.effects { display: flex; gap: 4px; min-height: 24px; }
.effect { width: 24px; height: 24px; border-radius: 5px; background: var(--bar); border: 1.5px solid var(--brass); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.effect.dim { background: transparent; border-style: dashed; border-color: var(--sleep); color: var(--sleep); }
.barrow { display: flex; align-items: center; gap: 8px; position: relative; }
.xpbar { flex: 1; height: 8px; background: var(--bar); border: 1.5px solid var(--bar-line); border-radius: 5px; overflow: hidden; position: relative; }
.xpbar > i { display: block; height: 100%; background: var(--brass); transition: width .4s ease; }
.xpbar .tip { position: absolute; left: 50%; top: -26px; transform: translateX(-50%); padding: 1px 6px; background: var(--ink); color: var(--parchment); font-size: 11px; border-radius: 4px; font-weight: 700; display: none; }
.barrow.show .tip { display: block; }
.badge { width: 28px; height: 28px; border-radius: 50%; background: var(--gold); border: 2px solid var(--leather); display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-weight: 700; font-size: 11px; flex-shrink: 0; }
.gold { display: flex; align-items: center; gap: 3px; font-weight: 700; font-size: 13px; }
.coin { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 1.5px solid var(--leather); display: inline-block; }
.subline { font-size: 12px; color: var(--ink-2); line-height: 1; }
.season { padding: 7px 14px; border-bottom: 1.5px solid var(--brass-light); display: flex; flex-direction: column; gap: 5px; }
.season .row { display: flex; justify-content: space-between; font-size: 12px; }
.season .row b { font-family: var(--serif); font-size: 13px; }
.pacebar { height: 6px; background: var(--bar); border-radius: 3px; border: 1px solid var(--bar-line); position: relative; }
.pacebar > i { display: block; height: 100%; background: var(--leather); border-radius: 3px 0 0 3px; }

/* quest log */
.log { padding: 2px 14px 12px; display: flex; flex-direction: column; }
.hdr { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-size: 12px; font-weight: 700; color: var(--ink-2); letter-spacing: .6px; text-transform: uppercase; margin-top: 8px; margin-bottom: 2px; }
.hdr::after { content: ''; flex: 1; height: 1px; background: var(--brass); }
.hdr.ember { color: var(--ember); } .hdr.ember::after { background: var(--ember); }
.hdr .count { font-family: var(--sans); font-weight: 500; text-transform: none; letter-spacing: 0; }
.row-q { display: flex; align-items: center; gap: 8px; min-height: 32px; width: 100%; border: 0; background: none; text-align: left; padding: 2px 0; border-bottom: 1px solid var(--paper-line); color: var(--ink); }
.row-q.sub { padding-left: 22px; }
.row-q.done .title { color: var(--ink-3); text-decoration: line-through; }
.row-q .title { flex: 1; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-q .meta { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.row-q.over .meta { color: var(--ember); }
.box { width: 16px; height: 16px; border: 1.5px solid var(--leather); border-radius: 3px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.row-q.done .box { background: var(--bar-line); border-color: var(--bar-line); }
.mini { width: 64px; height: 5px; background: var(--bar); border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.mini > i { display: block; height: 100%; background: var(--brass); }
.subhead { display: flex; align-items: center; gap: 6px; min-height: 30px; width: 100%; border: 0; background: none; text-align: left; font-size: 13px; font-weight: 700; color: var(--leather); padding: 0; }
.subhead .count { margin-left: auto; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.empty { padding: 20px 10px; text-align: center; color: var(--ink-2); font-size: 14px; line-height: 1.5; }
.empty b { font-family: var(--serif); font-size: 17px; color: var(--ink); display: block; margin-bottom: 4px; }

/* quick add */
.quick { display: flex; gap: 6px; padding: 8px 10px; background: var(--parchment-2); border-top: 2px solid var(--brass); }
.quick input { flex: 1; min-width: 0; height: 44px; border: 1.5px solid var(--bar-line); border-radius: 8px; padding: 0 10px; background: var(--parchment-3); }
.quick input:focus { outline: 2px solid var(--brass); outline-offset: 1px; }
.ibtn { width: 44px; height: 44px; border: 1.5px solid var(--bar-line); border-radius: 8px; background: var(--parchment-3); display: flex; align-items: center; justify-content: center; position: relative; }
.ibtn.on { background: var(--bar); }
.ibtn .dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--ember); }
.ibtn.primary { background: var(--leather); border-color: var(--leather); color: var(--parchment); font-size: 24px; line-height: 1; }

/* tab bar */
.tabs { display: flex; background: var(--leather); padding: 6px 0 calc(8px + env(safe-area-inset-bottom, 0)); border-top: 2px solid var(--brass); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; font-size: 11px; color: var(--brass-light); text-decoration: none; }
.tabs a + a { border-left: 1px solid var(--bar-line); box-shadow: inset 1px 0 0 var(--leather-dark); }
.tabs a.on { color: var(--parchment); font-weight: 700; }
.tabs svg { stroke: currentColor; }

/* generic page */
.page-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.page-h h1 { margin: 0; font-family: var(--serif); font-size: 22px; }
.page-h .sub { font-size: 13px; color: var(--ink-2); }
.subtabs { display: flex; background: var(--parchment-2); border-bottom: 1.5px solid var(--brass-light); }
.subtabs button { flex: 1; min-height: 44px; border: 0; background: none; font-size: 13px; color: var(--ink-2); }
.subtabs button + button { border-left: 1px solid var(--brass); box-shadow: inset 1px 0 0 var(--parchment-3); }
.subtabs button.on { font-weight: 700; color: var(--ink); border-bottom: 3px solid var(--leather); }
.pad { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--parchment-3); border: 1.5px solid var(--brass); border-radius: 10px; padding: 10px 12px; }
.card h3 { margin: 0 0 6px; font-family: var(--serif); font-size: 16px; }
.btn { min-height: 44px; padding: 8px 14px; border: 1.5px solid var(--leather); border-radius: 8px; background: var(--parchment-3); font-weight: 700; font-size: 14px; }
.btn.primary { background: var(--leather); color: var(--parchment); }
.btn.ghost { border-color: var(--bar-line); font-weight: 500; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 10px; border-radius: 12px; border: 1.5px solid var(--brass); background: var(--parchment-3); font-size: 13px; min-height: 32px; }
.chip.on { background: var(--leather); color: var(--parchment); border-color: var(--leather); }
.kv { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--paper-line); }
.kv b { font-weight: 700; }
.stat { text-align: center; padding: 8px; background: var(--parchment-3); border: 1.5px solid var(--brass); border-radius: 8px; font-size: 11px; color: var(--ink-2); }
.stat b { display: block; font-size: 18px; color: var(--ink); }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.row-def { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--paper-line); width: 100%; border-left: 0; border-right: 0; border-top: 0; background: none; text-align: left; }
.row-def .t { flex: 1; min-width: 0; font-size: 14px; }
.row-def .t small { display: block; color: var(--ink-2); font-size: 12px; }
.row-def .m { font-size: 12px; color: var(--ink-2); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 700; }
label.f input, label.f select { height: 40px; border: 1.5px solid var(--bar-line); border-radius: 8px; padding: 0 8px; background: var(--parchment-3); color: var(--ink); font-weight: 400; font-size: 15px; }
label.f input:focus, label.f select:focus { outline: 2px solid var(--brass); }
.frow { display: flex; gap: 8px; } .frow > * { flex: 1; min-width: 0; }

/* sheets and toasts */
.scrim { position: fixed; inset: 0; background: rgba(46,28,16,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto; background: var(--parchment); border: 2px solid var(--brass); border-bottom: 0; border-radius: 14px 14px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0)); display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0; font-family: var(--serif); font-size: 20px; }
.toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--ink); color: var(--parchment); padding: 10px 14px; border-radius: 10px; font-size: 14px; display: flex; align-items: center; gap: 12px; z-index: 30; box-shadow: 0 6px 20px rgba(0,0,0,.35); max-width: 92vw; }
.toast b { color: var(--gold); }
.toast button { background: none; border: 1px solid var(--brass-light); color: var(--parchment); border-radius: 6px; padding: 6px 10px; min-height: 36px; font-weight: 700; }
.fly { position: fixed; pointer-events: none; font-weight: 700; font-family: var(--serif); color: var(--leather); font-size: 18px; animation: fly .9s ease-out forwards; z-index: 40; text-shadow: 0 1px 0 var(--parchment); }
@keyframes fly { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-60px); } }
.levelup { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(46,28,16,.6); z-index: 50; }
.levelup .card { text-align: center; padding: 24px 28px; border-width: 3px; border-color: var(--gold); }
.levelup .card b { font-family: var(--serif); font-size: 42px; display: block; }
.note { font-size: 12px; color: var(--ink-2); line-height: 1.4; }
