:root {
  --panel: rgba(30, 22, 14, 0.9);
  --panel-solid: #1e1710;
  --gold: #c9a45c;
  --gold-hi: #f0d08a;
  --ink: #2a1d10;
  --parch: #efe3c6;
  --text: #efe3c6;
  --muted: #b8a68a;
  --good: #9fe08a;
  --bad: #ff8a74;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #17110b; color: var(--text);
  font-family: 'EB Garamond', Georgia, serif; -webkit-user-select: none; user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; display: block; cursor: grab; }
button { font-family: inherit; cursor: pointer; }
kbd { font-family: inherit; font-size: 11px; padding: 0 4px; border: 1px solid rgba(201,164,92,.6); border-radius: 3px; color: var(--gold-hi); background: rgba(0,0,0,.3); }

/* ---------- top HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 14px; padding: 6px 12px;
  background: linear-gradient(180deg, rgba(24,17,10,.96), rgba(24,17,10,.82)); border-bottom: 1px solid rgba(201,164,92,.55);
  box-shadow: 0 2px 14px rgba(0,0,0,.45); z-index: 10; flex-wrap: wrap; }
.brand { font-family: 'Cinzel', serif; font-weight: 700; letter-spacing: .12em; color: var(--gold-hi); font-size: 17px; text-shadow: 0 1px 0 #000; margin-right: 4px; }
.hud-item { display: flex; align-items: center; gap: 6px; min-width: 64px; }
.hud-item b { font-size: 17px; font-variant-numeric: tabular-nums; }
.hud-item small { display: block; font-size: 12px; color: var(--muted); line-height: 1; }
.hud-item .ic, .ic { width: 24px; height: 24px; display: inline-block; flex: none; }
.ic svg { width: 100%; height: 100%; display: block; }
.hud-item.meter { min-width: 130px; }
.bar { position: relative; height: 9px; background: rgba(0,0,0,.55); border: 1px solid rgba(201,164,92,.45); border-radius: 5px; overflow: hidden; width: 110px; margin-top: 3px; }
.bar .fill { height: 100%; width: 50%; background: linear-gradient(90deg, #d9a040, #ffd27a); transition: width .25s; }
.bar .fill.wall { background: linear-gradient(90deg, #a89068, #f2e6c4); }
.minibar { width: 56px; height: 3px; background: rgba(0,0,0,.5); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.minibar div { height: 100%; background: var(--gold); }
#buffs { display: flex; gap: 6px; }
.buff { font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid; }
.buff.up { color: var(--good); border-color: rgba(159,224,138,.5); }
.buff.down { color: var(--bad); border-color: rgba(255,138,116,.5); }
.hud-btns { margin-left: auto; display: flex; gap: 6px; }
.hud-btns button { min-width: 34px; height: 30px; background: rgba(0,0,0,.35); color: var(--gold-hi); border: 1px solid rgba(201,164,92,.55); border-radius: 6px; font-size: 14px; }
.hud-btns button:hover { background: rgba(201,164,92,.18); }

/* ---------- bottom bar ---------- */
#buildbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; gap: 10px; padding: 8px 12px; z-index: 10;
  background: linear-gradient(0deg, rgba(24,17,10,.96), rgba(24,17,10,.78)); border-top: 1px solid rgba(201,164,92,.55); }
#minimap { width: 220px; height: 110px; border: 1px solid rgba(201,164,92,.6); border-radius: 6px; background: #120d08; cursor: pointer; flex: none; }
#build-buttons { display: flex; gap: 6px; min-width: 0; }
.bbtn { position: relative; width: 86px; height: 104px; padding: 6px 4px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: linear-gradient(180deg, #3a2c1c, #241a10); color: var(--text); border: 1px solid rgba(201,164,92,.6); border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255,230,180,.12), 0 2px 6px rgba(0,0,0,.4); transition: transform .08s, border-color .15s; }
.bbtn:hover { border-color: var(--gold-hi); transform: translateY(-2px); }
.bbtn.active { border-color: #fff0c0; box-shadow: 0 0 0 2px rgba(240,208,138,.6), 0 0 18px rgba(240,208,138,.35); }
.bbtn.poor { opacity: .55; }
.bicon { width: 44px; height: 44px; }
.bicon svg { width: 100%; height: 100%; }
.bname { font-family: 'Cinzel', serif; font-size: 11px; letter-spacing: .03em; color: var(--gold-hi); text-align: center; line-height: 1.1; }
.bcost { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.bcost i { font-style: normal; }
.bcost i.s::before { content: ''; display: inline-block; width: 8px; height: 8px; background: #d8c8a0; margin-right: 3px; border: 1px solid #6a5a3c; }
.bcost i.t::before { content: ''; display: inline-block; width: 10px; height: 6px; background: #9a6a3a; margin-right: 3px; border-radius: 3px; vertical-align: 1px; }
.bbtn kbd { position: absolute; top: 4px; right: 5px; }
.bbtn.trumpet .bname { color: #ffe08a; }
.reserve { margin-left: auto; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; font-size: 14px; color: var(--muted); }
.reserve button { background: rgba(0,0,0,.35); color: var(--gold-hi); border: 1px solid rgba(201,164,92,.55); border-radius: 6px; padding: 5px 10px; font-size: 14px; }
.reserve label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- section panel ---------- */
#panel { position: fixed; right: 12px; top: 64px; width: 290px; max-height: calc(100% - 200px); overflow: auto; z-index: 11;
  background: var(--panel); border: 1px solid rgba(201,164,92,.65); border-radius: 10px; padding: 14px 14px 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); transform: translateX(330px); transition: transform .22s ease; }
#panel.open { transform: none; }
#panel h3 { font-family: 'Cinzel', serif; margin: 0 0 6px; color: var(--gold-hi); font-size: 19px; letter-spacing: .04em; }
#panel blockquote { margin: 0 0 10px; font-style: italic; color: #d8caa8; font-size: 14px; line-height: 1.3; }
#panel blockquote cite { display: block; font-style: normal; font-size: 12px; color: var(--muted); margin-top: 3px; }
#panel .bar { width: 100%; height: 16px; }
#panel .bar span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 15px; color: #1e1408; font-weight: 600; text-shadow: 0 0 3px rgba(255,255,255,.6); }
#panel .bar .fill { background: linear-gradient(90deg, #a89068, #f2e6c4); }
.close { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; }
.stat-row { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; margin: 8px 0 4px; }
.good { color: var(--good); } .bad { color: var(--bad); }
.blink { animation: blink 0.8s infinite; }
@keyframes blink { 50% { opacity: .35; } }
.sub { font-family: 'Cinzel', serif; font-size: 12px; color: var(--gold); letter-spacing: .08em; margin: 10px 0 5px; text-transform: uppercase; }
.workers { display: flex; align-items: center; gap: 10px; font-size: 20px; }
.workers button { width: 32px; height: 32px; border-radius: 6px; background: rgba(0,0,0,.35); color: var(--gold-hi); border: 1px solid rgba(201,164,92,.55); font-size: 18px; }
.workers .muted { font-size: 13px; color: var(--muted); margin-left: auto; }
.stances { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
.stances button { padding: 6px 0; font-size: 12px; background: rgba(0,0,0,.35); color: var(--text); border: 1px solid rgba(201,164,92,.35); border-radius: 5px; }
.stances button.on { background: linear-gradient(180deg, #c9a45c, #8a6a30); color: #1e1408; border-color: #f0d08a; font-weight: 600; }
.split { font-size: 14px; color: var(--muted); margin-top: 6px; }
button.wide { width: 100%; margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 7px; font-size: 15px;
  background: linear-gradient(180deg, #4a3a22, #2a2014); color: #ffe08a; border: 1px solid rgba(240,208,138,.7); border-radius: 7px; }
button.wide svg { width: 26px; height: 26px; }
button.wide:disabled { opacity: .5; cursor: default; }

/* ---------- toasts, banner, hint ---------- */
#toasts { position: fixed; top: 62px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 5px; z-index: 12; pointer-events: none; }
.toast { padding: 5px 14px; border-radius: 16px; background: rgba(24,17,10,.9); border: 1px solid rgba(201,164,92,.5); font-size: 15px; transition: opacity .5s, transform .5s; box-shadow: 0 3px 10px rgba(0,0,0,.4); }
.toast.good { border-color: rgba(159,224,138,.6); color: #e6f6d8; }
.toast.bad { border-color: rgba(255,138,116,.75); color: #ffe0d8; background: rgba(60,16,10,.9); }
.toast.warn { border-color: rgba(240,200,110,.7); }
.toast.out { opacity: 0; transform: translateY(-6px); }
#banner { position: fixed; top: 168px; left: 50%; transform: translate(-50%, -20px); opacity: 0; z-index: 13; pointer-events: none;
  display: flex; align-items: center; gap: 14px; padding: 10px 22px; max-width: min(640px, 92vw);
  background: linear-gradient(180deg, rgba(70,20,14,.95), rgba(40,12,8,.95)); border: 1px solid #e0745a; border-radius: 10px; box-shadow: 0 6px 30px rgba(0,0,0,.6); transition: opacity .4s, transform .4s; }
#banner.show { opacity: 1; transform: translate(-50%, 0); }
.b-arrow { font-size: 38px; font-weight: 700; line-height: 1; text-shadow: 0 0 10px rgba(255,255,255,.3); }
.b-title { font-family: 'Cinzel', serif; font-size: 18px; color: #ffe2d4; }
.b-sub { font-size: 14px; font-style: italic; color: #e8b8a8; }
#hint { display: none; position: fixed; bottom: 136px; left: 50%; transform: translateX(-50%); padding: 6px 14px; border-radius: 6px; background: rgba(24,17,10,.88); border: 1px dashed rgba(240,208,138,.7); color: var(--gold-hi); font-size: 15px; z-index: 12; pointer-events: none; }
#paused { display: none; position: fixed; inset: 0; align-items: center; justify-content: center; pointer-events: none; z-index: 9; }
#paused span { font-family: 'Cinzel', serif; font-size: 42px; letter-spacing: .3em; color: rgba(255,240,200,.85); text-shadow: 0 2px 20px #000; }
#tip { display: none; position: fixed; z-index: 30; max-width: 280px; padding: 8px 11px; background: rgba(20,14,8,.96); border: 1px solid var(--gold); border-radius: 7px; font-size: 14px; line-height: 1.3; pointer-events: none; }
#tip b { color: var(--gold-hi); font-family: 'Cinzel', serif; font-weight: 500; }

/* ---------- modal ---------- */
#modal { display: none; position: fixed; inset: 0; z-index: 40; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(20,12,4,.35), rgba(10,6,2,.75)); }
.card { position: relative; max-width: 620px; width: 100%; max-height: 92vh; overflow: auto; padding: 28px 34px 24px; color: var(--ink);
  background: radial-gradient(ellipse at 30% 20%, #f7eed6, #e9dab4 60%, #d8c494); border-radius: 6px;
  box-shadow: 0 0 0 1px #8a6a3a, 0 0 0 6px rgba(60,40,20,.85), 0 0 0 7px #c9a45c, 0 20px 60px rgba(0,0,0,.7); text-align: center; }
.card::before { content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: 6px;
  background: repeating-linear-gradient(0deg, rgba(120,90,40,.035) 0 2px, transparent 2px 5px); }
.card h1 { font-family: 'Cinzel', serif; font-size: 46px; margin: 4px 0 0; letter-spacing: .08em; color: #3a2610; }
.card h2 { font-family: 'Cinzel', serif; font-size: 22px; margin: 2px 0 14px; color: #6a4a20; letter-spacing: .12em; font-weight: 500; }
.card h3 { font-family: 'Cinzel', serif; color: #6a4a20; margin: 0 0 6px; font-size: 16px; }
.card blockquote { font-style: italic; font-size: 18px; line-height: 1.4; margin: 10px auto 16px; max-width: 520px; color: #3a2a18; }
.card blockquote cite { display: block; font-style: normal; font-family: 'Cinzel', serif; font-size: 13px; color: #8a6a3a; margin-top: 6px; letter-spacing: .08em; }
.card p { font-size: 16px; line-height: 1.4; }
.card .fine { font-size: 14px; color: #7a5a30; font-style: italic; margin-bottom: 0; }
.howto { text-align: left; font-size: 16px; line-height: 1.35; padding-left: 20px; margin: 0 0 18px; }
.howto li { margin-bottom: 6px; }
.title-art { width: 74px; height: 74px; margin: 0 auto; }
.title-art svg { width: 100%; height: 100%; }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.card button { font-size: 17px; padding: 9px 20px; border-radius: 6px; border: 1px solid #8a6a3a; background: #f3e8cc; color: #3a2610; }
.card button.primary { font-family: 'Cinzel', serif; font-weight: 700; letter-spacing: .06em; background: linear-gradient(180deg, #8a5a24, #5a3a14); color: #ffefc8; border-color: #3a2410; box-shadow: 0 2px 0 #2a1a08; }
.card button:hover { filter: brightness(1.08); }
.card.event { max-width: 560px; }
.ev-ref { font-family: 'Cinzel', serif; color: #8a6a3a; font-size: 13px; letter-spacing: .14em; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.card .choice { text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 11px 16px; background: rgba(255,250,235,.6); }
.card .choice b { font-family: 'Cinzel', serif; font-size: 16px; color: #4a2c10; }
.card .choice span { font-size: 15px; color: #4a3a28; }
.card .choice:hover { background: #fffaf0; border-color: #5a3a14; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; text-align: left; }
.cols p { font-size: 15px; margin: 0 0 8px; }
.cols kbd { color: #5a3a14; border-color: #b8945a; background: rgba(255,255,255,.5); font-size: 13px; }
.stats { display: flex; justify-content: center; gap: 22px; margin: 6px 0 10px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-family: 'Cinzel', serif; font-size: 30px; color: #3a2610; }
.stats span { font-size: 13px; color: #7a5a30; }
.card.lose h1 { color: #5a1a10; }

body.placing canvas#game { cursor: crosshair; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .brand, #buffs { display: none; }
  #hud { gap: 8px; padding: 4px 8px; }
  .hud-item { min-width: 0; }
  .hud-item.meter { min-width: 0; }
  .bar { width: 64px; }
  #minimap { display: none; }
  .reserve { display: none; }
  #buildbar { justify-content: center; padding: 6px; gap: 6px; }
  .bbtn { width: 66px; height: 82px; }
  .bicon { width: 32px; height: 32px; }
  .bname { font-size: 9px; }
  .bcost { font-size: 10px; gap: 4px; }
  .bbtn kbd { display: none; }
  #panel { top: auto; bottom: 96px; right: 8px; left: 8px; width: auto; max-height: 52vh; transform: translateY(120%); }
  #panel.open { transform: none; }
  #hint { bottom: 100px; }
  #toasts { top: 96px; width: 92vw; }
  .toast { font-size: 14px; text-align: center; }
  #banner { top: 190px; }
  #panel { max-height: 44vh; padding: 10px 12px; }
  #panel blockquote { font-size: 13px; margin-bottom: 6px; }
  .card { padding: 20px 18px; }
  .card h1 { font-size: 32px; }
  .cols { grid-template-columns: 1fr; }
}

/* title options: difficulty and guide */
.card .opts { display: flex; justify-content: center; align-items: center; gap: 18px; flex-wrap: wrap; margin: 6px 0 0; font-size: 16px; }
.card .seg { display: inline-flex; border: 1px solid #8a6a3a; border-radius: 6px; overflow: hidden; }
.card .seg button { border: 0; border-radius: 0; padding: 6px 18px; font-size: 15px; background: #f3e8cc; }
.card .seg button + button { border-left: 1px solid #8a6a3a; }
.card .seg button.on { background: linear-gradient(180deg, #8a5a24, #5a3a14); color: #ffefc8; }
.card .opts label { display: inline-flex; align-items: center; gap: 6px; color: #4a3a28; }
#m-diff-t { margin-top: 6px; }

/* locked buttons */
.bbtn.locked { opacity: .45; filter: grayscale(.8); }
.bbtn.locked .bcost { font-style: italic; }

/* guide */
#guide { position: fixed; left: 12px; top: 64px; width: 310px; z-index: 12; padding: 10px 14px 12px; border-radius: 8px;
  background: rgba(24,17,10,.94); border: 1px solid var(--gold-hi); box-shadow: 0 6px 24px rgba(0,0,0,.55);
  font-size: 15px; line-height: 1.35; opacity: 0; transform: translateX(-12px); pointer-events: none; transition: opacity .35s, transform .35s; }
#guide.show { opacity: 1; transform: none; pointer-events: auto; }
#guide p { margin: 6px 0 0; }
#guide b { color: var(--gold-hi); }
#guide .g-head { display: flex; justify-content: space-between; align-items: center; font-family: 'Cinzel', serif; font-size: 12px; letter-spacing: .08em; color: var(--muted); }
#guide .g-skip { background: none; border: 0; color: var(--muted); font-size: 12px; text-decoration: underline; padding: 0; cursor: pointer; }
#guide .g-row { margin-top: 8px; text-align: right; }
#guide .g-row button { background: linear-gradient(180deg, #c9a45c, #8a6a30); color: #1e1408; border: 1px solid #f0d08a; border-radius: 5px; padding: 4px 14px; font-weight: 600; cursor: pointer; }
.guide-glow { animation: guideGlow 1.2s ease-in-out infinite; }
@keyframes guideGlow { 0%, 100% { box-shadow: 0 0 0 2px rgba(240,208,138,.9), 0 0 6px rgba(240,208,138,.4); } 50% { box-shadow: 0 0 0 3px #fff0c0, 0 0 22px rgba(240,208,138,.9); } }
@media (max-width: 900px) {
  #guide { left: 8px; right: 8px; width: auto; top: 96px; font-size: 14px; }
  body.guiding #toasts { top: 210px; }
}

/* title: scenario, records, more buttons */
.card .row.small { margin-top: 8px; gap: 8px; }
.card .row.small button { font-size: 15px; padding: 6px 14px; }
.card .best { font-style: italic; color: #6a4a20; font-size: 15px; }
#m-scen-t { min-height: 2.6em; }
.card ul.ach { list-style: none; padding: 0; margin: 8px 0 16px; text-align: left; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card ul.ach li { padding: 7px 10px; border: 1px solid rgba(138,106,58,.4); border-radius: 6px; background: rgba(255,250,235,.35); opacity: .55; display: flex; flex-direction: column; }
.card ul.ach li.got { opacity: 1; background: rgba(255,240,190,.7); border-color: #8a6a3a; }
.card ul.ach li.got b::before { content: '✦ '; color: #a8761e; }
.card ul.ach b { font-family: 'Cinzel', serif; font-size: 14px; color: #4a2c10; }
.card ul.ach span { font-size: 14px; color: #4a3a28; }
.card .new-ach { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin: 0 auto 14px; max-width: 480px; padding: 8px 12px; border: 1px solid #a8761e; border-radius: 6px; background: rgba(255,236,170,.55); font-size: 14px; }
.card .new-ach .h { width: 100%; font-style: italic; color: #6a4a20; }
.card .new-ach b { font-family: 'Cinzel', serif; color: #6a4210; font-size: 13px; }
.card .new-ach b::before { content: '✦ '; color: #a8761e; }

/* HUD clock and music */
#v-clock { align-self: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; min-width: 42px; text-align: right; }
#btn-music.off { opacity: .45; text-decoration: line-through; }

/* section & building panel additions */
#panel .leader { font-size: 14px; line-height: 1.35; margin: 0 0 8px; padding: 6px 8px; border-radius: 6px; background: rgba(240,208,138,.08); border: 1px solid rgba(240,208,138,.25); }
#panel .leader .dia { color: #f3cf6a; }
#panel .leader b { color: var(--gold-hi); }
#panel .warn { color: #f0a050; }
#panel .desc { font-size: 14px; line-height: 1.35; margin: 0 0 6px; color: #d8caa8; }
#panel .lvl { font-size: 14px; color: #f3cf6a; border: 1px solid #f3cf6a; border-radius: 4px; padding: 0 4px; margin-left: 4px; vertical-align: middle; }
#panel .lvl:empty { display: none; }
#panel i.s, #panel i.t { font-style: normal; }
#panel i.s::before { content: '▣ '; color: #d8c8a0; }
#panel i.t::before { content: '▬ '; color: #b5845a; }
button.wide.watch { margin-top: 8px; }
button.wide.watch.on { border-color: #9fb8e8; color: #dfe8ff; background: rgba(60,80,130,.35); }

/* the dedication */
#dedication { position: fixed; left: 50%; top: 70px; transform: translate(-50%, -10px); opacity: 0; pointer-events: none; z-index: 14; width: min(620px, 92vw); box-sizing: border-box;
  text-align: center; padding: 14px 22px; border-radius: 10px; background: rgba(24,17,10,.88); border: 1px solid var(--gold-hi); transition: opacity .8s, transform .8s; }
#dedication.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#dedication .d-title { font-family: 'Cinzel', serif; font-size: 22px; color: var(--gold-hi); letter-spacing: .08em; }
#dedication .d-verse { font-style: italic; font-size: 16px; margin: 6px 0 10px; line-height: 1.35; }
#dedication cite { display: block; font-style: normal; font-size: 13px; color: var(--muted); margin-top: 4px; }
#dedication button { background: linear-gradient(180deg, #c9a45c, #8a6a30); color: #1e1408; border: 1px solid #f0d08a; border-radius: 5px; padding: 5px 16px; font-weight: 600; cursor: pointer; }
body.dedicating #buildbar, body.dedicating #panel, body.dedicating #guide, body.dedicating #toasts { display: none; }

@media (max-width: 900px) {
  #build-buttons { overflow-x: auto; max-width: calc(100vw - 92px); padding-bottom: 2px; }
  .bbtn { flex: none; }
  #v-clock { display: none; }
  .card ul.ach { grid-template-columns: 1fr; }
  #dedication { top: 100px; padding: 10px 14px; }
  #dedication .d-title { font-size: 17px; }
  #dedication .d-verse { font-size: 14px; }
}
