:root {
  --bg: #1b1814; --panel: #231f1a; --panel2: #2a251f; --line: #3a332b; --text: #ece3d4; --dim: #a1968a; --faint: #6f665c;
  --acc: #e3a76f; --good: #9cc58f; --bad: #e08a7a;
  --font: "Nunito", system-ui, sans-serif;
}
body[data-era="1"] { --acc: #e3a76f; }
body[data-era="2"] { --acc: #d98b6a; }
body[data-era="3"] { --acc: #c9b26b; }
body[data-era="4"] { --acc: #6fbfb3; }
body[data-era="5"] { --acc: #8fa8e8; }
body[data-era="6"] { --acc: #d68fb4; }
body[data-era="7"] { --acc: #7fa6d9; }
body[data-era="8"] { --acc: #e6cf87; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
sup { font-size: .68em; line-height: 0; position: relative; top: -.15em; }
button { font: inherit; color: inherit; }
#app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }

/* rail */
#rail { border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .3px; padding: 0 6px; }
.mark { width: 30px; height: 18px; stroke: var(--acc); stroke-width: 2.2; stroke-linecap: round; fill: none; }
#layers, .rail-foot { display: flex; flex-direction: column; gap: 2px; }
.rail-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; }
.lay { text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; color: var(--dim); display: flex; justify-content: space-between; align-items: baseline; }
.lay:hover { background: var(--panel); color: var(--text); }
.lay.on { background: var(--panel2); color: var(--text); box-shadow: inset 3px 0 0 var(--acc); }
.lay.fresh::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--acc); margin-left: 6px; align-self: center; }

/* header */
#top { display: grid; grid-template-columns: 230px 1fr 280px; gap: 22px; align-items: center; padding: 14px 26px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 4; }
#year { font-size: 26px; font-weight: 800; color: var(--acc); line-height: 1.1; }
#era { color: var(--dim); font-size: 13px; }
#res { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; }
.chip { display: flex; gap: 6px; align-items: baseline; white-space: nowrap; }
.chip span { color: var(--dim); font-size: 13px; }
.chip b { font-weight: 700; }
.chip.main b { font-size: 21px; }
.chip i { font-style: normal; color: var(--faint); font-size: 12px; }
.goal { font-size: 13px; }
#chapLabel { color: var(--acc); font-weight: 700; }
#goal { color: var(--dim); }
.track { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.track i { display: block; height: 100%; width: 0; background: var(--acc); transition: width .4s; }

/* view */
#view { padding: 16px 26px 120px; max-width: 1180px; }
.cols { display: grid; grid-template-columns: minmax(300px, 1.1fr) 1fr; gap: 18px; align-items: start; }
.cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 4px; font-size: 16px; font-weight: 800; color: var(--acc); }
.key { color: var(--dim); font-size: 13px; margin: 0 0 12px; }
.minor { color: var(--dim); font-size: 13px; }
.bignum { font-size: 34px; font-weight: 800; line-height: 1.1; }
.bignum small { font-size: 15px; color: var(--dim); font-weight: 600; margin-left: 6px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }

/* buttons */
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; cursor: pointer; text-align: left; color: var(--dim); min-width: 150px; }
.btn .t { color: var(--text); font-weight: 700; display: block; }
.btn .s { font-size: 12.5px; display: block; }
.btn.can { color: var(--text); border-color: var(--acc); }
.btn.can:hover { background: #332c24; }
.btn.got { opacity: .7; cursor: default; border-style: dashed; }
.btn.lock { opacity: .35; cursor: default; }
.btn.big { padding: 12px 18px; min-width: 220px; }
.btn.pres.can { background: color-mix(in srgb, var(--acc) 16%, var(--panel2)); }
.small-btn { background: none; border: 1px solid var(--line); border-radius: 5px; padding: 3px 9px; cursor: pointer; color: var(--dim); font-size: 12.5px; }
.small-btn:hover { color: var(--text); }

/* tribe */
.people { display: grid; grid-template-columns: repeat(20, 1fr); gap: 4px; margin: 14px 0 10px; max-width: 360px; }
.people i { aspect-ratio: 1; border-radius: 50%; border: 1.5px solid var(--faint); }
.people i.th { background: var(--acc); border-color: var(--acc); }
.split { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--dim); max-width: 380px; }
.split input { flex: 1; accent-color: var(--acc); }
.trail { list-style: none; margin: 8px 0 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.trail li { position: relative; margin: 0 0 8px; }
.trail li::before { content: ''; position: absolute; left: -20px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--bg); border: 2px solid var(--line); }
.trail li.done::before { background: var(--acc); border-color: var(--acc); }
.trail .btn { width: 100%; }
.trail li.hint .btn { font-style: italic; }

/* canon */
.tablets { display: flex; gap: 10px; flex-wrap: wrap; }
.tablet { width: 132px; min-height: 108px; border-radius: 10px 10px 6px 6px; border: 1.5px solid var(--acc); background: var(--panel2); padding: 10px; cursor: pointer; font-size: 13px; }
.tablet b { display: block; margin-bottom: 4px; }
.tablet span { color: var(--dim); font-size: 12px; }
.tablet.empty { border: 1.5px dashed var(--line); background: none; cursor: default; color: var(--faint); display: grid; place-items: center; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.ms { font-size: 13px; color: var(--faint); margin: 2px 0; }
.ms.on { color: var(--good); }

/* experiments */
.note { background: #262119; border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; background-image: repeating-linear-gradient(transparent 0 23px, #2f2920 23px 24px); }
.note h3 { margin: 0 0 4px; font-size: 15px; }
.note .rule { color: var(--bad); font-size: 13px; }
.note .rew { color: var(--good); font-size: 13px; }
.pips { margin: 8px 0; letter-spacing: 3px; color: var(--acc); }
.note.active { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc) inset; }

/* svg panels */
svg.chart { width: 100%; height: auto; display: block; }
svg .ax { stroke: var(--line); }
svg .lbl { fill: var(--dim); font: 11px var(--font); }
.ladder { display: flex; gap: 3px; margin: 10px 0; flex-wrap: wrap; }
.ladder span { font-size: 11px; padding: 3px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--faint); }
.ladder span.on { border-color: var(--acc); color: var(--text); }
.gauge { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin: 6px 0; }
.gauge i { display: block; height: 100%; background: var(--good); }

/* timeline */
.tl { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); align-items: baseline; }
.tl .y { color: var(--acc); font-weight: 700; }
.tl.fut { color: var(--faint); }

/* dialogue */
#talk { position: fixed; right: 24px; bottom: 24px; width: min(440px, calc(100vw - 48px)); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px 10px; z-index: 30; box-shadow: 0 10px 40px rgba(0,0,0,.45); }
#talk.hidden, #modal.hidden { display: none; }
.talk-head { font-size: 12px; color: var(--faint); display: flex; gap: 8px; }
.talk-head #talkYear { color: var(--acc); }
.talk-body b { display: block; margin-top: 6px; }
.talk-body p { margin: 2px 0 6px; min-height: 44px; }
.talk-foot { display: flex; justify-content: space-between; }
.talk-foot button { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 2px 6px; }
#talkNext { color: var(--acc); font-size: 18px; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px; font-size: 13px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 25; }
#toast.show { opacity: 1; }
#modal { position: fixed; inset: 0; background: rgba(10,8,6,.72); display: grid; place-items: center; z-index: 40; }
.mbox { background: var(--panel); border: 1px solid var(--acc); border-radius: 10px; max-width: 560px; padding: 22px 26px; }
.mbox h2 { margin: 0 0 8px; color: var(--acc); }
.mbox h4 { margin: 16px 0 4px; color: var(--dim); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
.mbox button { margin-top: 16px; background: none; border: 1px solid var(--acc); color: var(--acc); padding: 7px 18px; border-radius: 6px; cursor: pointer; }
select, input[type=number], textarea { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 5px; padding: 5px 8px; font: inherit; }
input[type=number] { width: 80px; }
textarea { width: 100%; height: 80px; font-size: 12px; }
label { color: var(--dim); font-size: 13.5px; }
.auto { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 13px; }
@media (max-width: 960px) { #app { grid-template-columns: 1fr; } #rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; } #top { grid-template-columns: 1fr; } .cols, .cols3 { grid-template-columns: 1fr; } }

#thinkRow { display: flex; justify-content: center; padding: 16px 26px 0; max-width: 1180px; }
#thinkBtn { min-width: 0; white-space: nowrap; padding: 10px 28px; font-weight: 700; color: var(--text); text-align: center; }
#thinkBtn:active { transform: translateY(1px); }
#nextYr { color: var(--faint); font-size: 11.5px; margin-top: 2px; }
.help ul { margin: 6px 0 0; padding-left: 20px; } .help li { margin: 6px 0; line-height: 1.55; } .help b { color: var(--text); }

/* touch: no double-tap zoom on buttons; phones keep the font size we set */
button, .tablet, input[type=range] { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* phones: one scrollable tab bar pinned on top, a compact header that scrolls away, full-width panels */
@media (max-width: 700px) {
  #rail { position: sticky; top: 0; z-index: 6; height: auto; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 4px; padding: 6px 8px; overflow-x: auto; background: var(--bg); border-right: 0; border-bottom: 1px solid var(--line); scrollbar-width: none; }
  #rail::-webkit-scrollbar { display: none; }
  .brand { display: none; }
  #layers, .rail-foot { flex-direction: row; flex: none; }
  .rail-foot { margin: 0; padding: 0 0 0 4px; border-top: 0; border-left: 1px solid var(--line); }
  .lay { flex: none; white-space: nowrap; padding: 7px 11px; }
  .lay.on { box-shadow: inset 0 -2px 0 var(--acc); }
  #top { position: static; gap: 8px; padding: 10px 14px; }
  #year { font-size: 21px; }
  #thinkRow { padding: 12px 12px 0; }
  #thinkBtn { width: 100%; padding: 13px; }
  #view { padding: 12px 12px 110px; }
  .panel { padding: 13px 14px; margin-bottom: 12px; }
  .btn { min-width: 0; flex: 1 1 140px; }
  .btn.big { min-width: 0; width: 100%; }
  .bignum { font-size: 28px; }
  .tablet { width: calc(50% - 5px); }
  .shelf { grid-template-columns: 1fr; }
  .people, .split { max-width: none; }
  .tl { grid-template-columns: 88px 1fr; gap: 4px 10px; }
  .tl > :nth-child(3) { grid-column: 2; justify-self: start; }
  .tl > :nth-child(3):empty { display: none; }
  #talk { right: 8px; bottom: 8px; width: calc(100vw - 16px); }
  #modal { padding: 12px; }
  .mbox { max-height: calc(100vh - 24px); overflow-y: auto; padding: 18px; }
  #toast { bottom: 12px; max-width: calc(100vw - 24px); }
}

.panel.sys{border-left:3px solid var(--acc)}
.panel.sys.locked{opacity:.55;border-left-style:dashed}
