/* Layout: the 3D realm fills the screen. Forged-iron panels with brass edging hold the controls;
   flat vellum sheets with a crimson head-band carry the story (decree, tutorial, events, dialogs).
   Square edges throughout. Kept to the edges and closed by default so the realm stays the star. */
:root {
  --wood: #26282c;
  --wood-2: #1c1d20;
  --wood-3: #111214;
  --wood-hi: #363940;
  --gold: #c8a050;
  --gold-light: #e9cf8e;
  --gold-dim: rgba(200, 160, 80, 0.5);
  --line: rgba(233, 207, 142, 0.14);
  --vellum: #ece4d2;
  --muted: #a8a191;
  --parch: #ece4d1;
  --parch-2: #dfd4ba;
  --ink: #2a2219;
  --ink-soft: #5e5240;
  --crimson: #8e2f25;
  --crimson-hi: #a8392c;
  --crimson-ink: #6b1f18;
  --good: #8cc574;
  --good-ink: #3f7a2c;
  --warn: #eaa743;
  --bad: #e66f59;
  --bad-ink: #a63a26;
  --display: "IM Fell English SC", "Iowan Old Style", Georgia, serif;
  --story: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --body: "Alegreya Sans", "Gill Sans", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: #9cbdd0; color: var(--vellum); font-family: var(--body); font-size: 15px; line-height: 1.35; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 2px; }
kbd { font-family: var(--body); font-weight: 700; font-size: 12px; background: var(--wood-3); color: var(--vellum); border: 1px solid var(--gold-dim); border-bottom-width: 2px; border-radius: 2px; padding: 0 5px; margin: 0 1px; }

#game { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#view { display: block; width: 100%; height: 100%; cursor: grab; }
#view.placing { cursor: crosshair; }
#vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 60%, rgba(10, 10, 14, 0.28) 100%); mix-blend-mode: multiply; }

/* ---------- materials ---------- */
.panel, .plate {
  background: linear-gradient(180deg, rgba(40, 42, 47, 0.97), rgba(25, 26, 29, 0.97));
  border: 1px solid var(--gold-dim);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55), inset 0 1px 0 1px rgba(233, 207, 142, 0.07), 0 4px 14px rgba(0, 0, 0, 0.4);
}
.scroll {
  color: var(--ink);
  background: linear-gradient(180deg, var(--parch), var(--parch-2));
  border: 1px solid #8a7550;
  border-top: 3px solid var(--crimson);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 252, 240, 0.35), 0 6px 18px rgba(0, 0, 0, 0.35);
}
.scroll .eyebrow { color: var(--crimson); }
.scroll .sub { color: var(--ink-soft); }
.eyebrow { font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); font-weight: 800; }
.sub { font-size: 13px; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--gold-dim); background: linear-gradient(180deg, var(--wood-hi), var(--wood-2)); border-radius: 2px;
  padding: 6px 13px; cursor: pointer; font-weight: 700; font-size: 14px; color: var(--vellum); letter-spacing: 0.02em;
  display: inline-flex; align-items: center; gap: 6px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.btn:hover:not(:disabled) { border-color: var(--gold-light); }
.btn.primary { background: linear-gradient(180deg, var(--crimson-hi), var(--crimson)); color: #f6e9cb; border-color: var(--gold); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.scroll .btn:not(.primary) { background: linear-gradient(180deg, #f6f0e2, #e4dac2); color: var(--ink); border-color: #8a7550; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font-size: 13px; }
.scroll .linkbtn { color: var(--ink-soft); }
.linkbtn.danger { color: var(--bad); }
.xbtn { border: 0; background: none; cursor: pointer; font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px; }
.xbtn:hover { color: var(--gold-light); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: flex; background: rgba(0, 0, 0, 0.4); box-shadow: inset 0 0 0 1px var(--line); border-radius: 2px; padding: 2px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 4px 9px; border-radius: 2px; cursor: pointer; font-weight: 800; font-size: 12px; color: var(--muted); white-space: nowrap; }
.seg button:hover { color: var(--vellum); }
.seg button.on { background: var(--crimson); color: #f6e9cb; box-shadow: inset 0 0 0 1px var(--gold-dim); }

/* ---------- top: one bar across the screen ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0; height: calc(env(safe-area-inset-top, 0px) + 46px); padding: env(safe-area-inset-top, 0px) 10px 0;
  display: flex; align-items: center; gap: 14px; pointer-events: none;
  background: linear-gradient(180deg, rgba(20, 21, 24, 0.97), rgba(26, 27, 31, 0.93));
  border-bottom: 1px solid var(--gold-dim); box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
}
#hud > * { pointer-events: auto; }
#hud .plate { background: none; border: 0; box-shadow: none; }
#crest { display: flex; align-items: center; gap: 8px; padding: 0 14px 0 0; flex: none; cursor: pointer; height: 100%; border-right: 1px solid var(--line) !important; }
.shield { width: 26px; height: 30px; flex: none; }
.bname { font-family: var(--display); font-size: 19px; line-height: 1; color: var(--gold-light); letter-spacing: 0.04em; }
.tier { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-top: 2px; }
#ribbon { display: flex; align-items: center; gap: 0; padding: 0; margin: 0 auto; flex-wrap: nowrap; min-width: 0; overflow: hidden; }
#ribbon .sep { width: 1px; align-self: stretch; background: var(--line); margin: 8px 6px; }
.chips { display: flex; flex-wrap: nowrap; gap: 0; }
.chip { display: flex; align-items: center; gap: 5px; padding: 4px 9px; font-size: 14px; white-space: nowrap; }
.chip + .chip { border-left: 1px solid rgba(233, 207, 142, 0.07); }
.chip svg { width: 17px; height: 17px; flex: none; }
.chip b { font-weight: 700; color: var(--vellum); }
.chip .cap { color: var(--muted); font-size: 11px; }
.chip.full b { color: var(--warn); }
.chip.low b { color: var(--bad); }
.chip .delta { font-size: 11px; font-weight: 700; margin-left: 1px; }
.chip .delta.up { color: var(--good); }
.chip .delta.down { color: var(--bad); }
#happyFace { display: flex; }
#clock { display: flex; align-items: center; gap: 8px; padding: 0 0 0 12px; flex: none; height: 100%; border-left: 1px solid var(--line) !important; }
#clock .seg button { padding: 4px 8px; font-size: 10px; letter-spacing: -0.12em; }
#alertBtn { display: flex; align-items: center; gap: 3px; border: 0; background: rgba(0, 0, 0, 0.4); box-shadow: inset 0 0 0 1px var(--line); border-radius: 2px; padding: 4px 9px 4px 7px; cursor: pointer; color: var(--muted); font-weight: 800; font-size: 13px; }
#alertBtn svg { width: 15px; height: 15px; }
#alertBtn.some { color: #2a1d0c; background: var(--gold); }
#alertBtn.danger { color: #fff; background: var(--crimson-hi); animation: ring 1.1s ease-in-out infinite; }
@keyframes ring { 50% { box-shadow: 0 0 0 4px rgba(230, 111, 89, 0.35); } }

/* ---------- docks: panels with a header that fold down to it ---------- */
.dock { display: flex; flex-direction: column; overflow: hidden; }
.dock-head { display: flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 4px 0 11px; border-bottom: 1px solid var(--line); background: rgba(0, 0, 0, 0.22); }
.dock-title { flex: 1; font-size: 10.5px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); }
.ctoggle { flex: none; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 2px; background: none; color: var(--muted); cursor: pointer; }
.ctoggle:hover { color: var(--gold-light); background: rgba(255, 255, 255, 0.05); }
.chev { width: 12px; height: 12px; transition: transform 0.2s; }
.folded .ctoggle .chev { transform: rotate(-90deg); }
.dock.folded > .dock-body { display: none !important; }
.folded > .dock-head { border-bottom: 0; }

/* right: orders, and news from the realm under them */
#right { position: absolute; right: 10px; top: calc(env(safe-area-inset-top, 0px) + 56px); width: 260px; display: flex; flex-direction: column; gap: 8px; z-index: 4; pointer-events: none; }
#right > * { pointer-events: auto; }
#scrolls { display: flex; flex-direction: column; }
.order { width: 100%; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px; padding: 9px 12px 10px; border: 0; background: none; color: var(--vellum); font: inherit; font-size: 14px; }
.order + .order { border-top: 1px solid var(--line); }
.order:hover { background: rgba(255, 255, 255, 0.04); }
.order[hidden] { display: none; }
.order .eyebrow { color: var(--gold); }
#decreeText, #adviceText { font-family: var(--story); font-size: 15px; line-height: 1.25; }
#decreeReward { color: var(--muted); }

/* Do next: the steward's advice, top centre */
#objective { position: absolute; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 56px); width: min(500px, calc(100% - 520px)); min-width: 300px; z-index: 4;
  border-color: var(--gold); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(242, 210, 124, 0.15), 0 6px 22px rgba(0, 0, 0, 0.45), 0 0 18px rgba(242, 210, 124, 0.18); }
#objective[hidden] { display: none; }
#objective .dock-head { background: linear-gradient(90deg, rgba(168, 57, 44, 0.55), rgba(0, 0, 0, 0.2)); }
#objective .dock-title { color: var(--gold-light); }
.obj-star { color: var(--gold); margin-right: 3px; }
.obj-count { font-size: 11px; color: var(--muted); font-weight: 700; }
.obj-body { padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 9px; }
#adviceText { margin: 0; font-family: var(--story); font-size: 18px; line-height: 1.3; color: var(--vellum); }
.obj-acts { display: flex; align-items: center; gap: 14px; }
.obj-acts .btn[hidden], .obj-acts .linkbtn[hidden] { display: none; }
#objective.fresh { animation: objIn 0.9s ease-out; }
@keyframes objIn { 0% { box-shadow: 0 0 0 3px var(--gold-light), 0 0 30px rgba(242, 210, 124, 0.7); } 100% { } }
.adv-glow { outline: 2px solid var(--gold) !important; outline-offset: 1px; animation: advPulse 1.6s ease-in-out infinite; position: relative; z-index: 1; }
@keyframes advPulse { 50% { outline-color: rgba(242, 210, 124, 0.3); box-shadow: 0 0 12px 2px rgba(242, 210, 124, 0.5); } }

#paused { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; display: flex; flex-direction: column; gap: 2px; }
#paused span { font-family: var(--display); font-size: 46px; letter-spacing: 0.08em; color: var(--gold-light); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8), 0 0 2px #000; }
#paused small { color: var(--vellum); text-shadow: 0 1px 4px #000; font-weight: 700; }

/* ---------- left: the map, and the buttons that open the drawers ---------- */
#left { position: absolute; left: 10px; top: calc(env(safe-area-inset-top, 0px) + 56px); width: 200px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
#left > * { pointer-events: auto; }
.mmwrap { padding: 6px; line-height: 0; }
#minimap { width: 100%; aspect-ratio: 1; image-rendering: pixelated; cursor: crosshair; touch-action: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); }
#medals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; background: linear-gradient(180deg, rgba(40, 42, 47, 0.97), rgba(25, 26, 29, 0.97)); border: 1px solid var(--gold-dim); border-radius: 2px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.medal {
  position: relative; height: 46px; cursor: pointer; padding: 0; border: 0; border-radius: 0; background: none; color: var(--gold-light);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.medal + .medal { border-left: 1px solid var(--line); }
.medal svg { width: 18px; height: 18px; }
.medal span { font-size: 9.5px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.medal:hover { background: rgba(255, 255, 255, 0.05); }
.medal.on { background: var(--crimson); box-shadow: inset 0 0 0 1px var(--gold-dim); }
.medal.on span { color: #f6e9cb; }
.medal i { position: absolute; top: 3px; right: 6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 2px; background: var(--bad); color: #fff; font: 800 11px/19px var(--body); font-style: normal; text-align: center; border: 1px solid var(--wood-3); }

/* ---------- drawers ---------- */
.drawer { position: absolute; left: 218px; top: calc(env(safe-area-inset-top, 0px) + 56px); width: 290px; max-height: calc(100% - 240px); overflow: auto; padding: 0; z-index: 3; }
.drawer summary { display: none; }
.drawer:not([open]) { display: none; }
.dhead { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 8px 14px; margin-bottom: 6px; position: sticky; top: 0; background: var(--wood); border-bottom: 1px solid var(--line); z-index: 1; }
.dhead h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 22px; letter-spacing: 0.04em; color: var(--gold-light); }
.realm-body, .help-body { display: flex; flex-direction: column; gap: 12px; padding: 4px 14px 14px; }
.sect { border-top: 1px solid var(--line); padding-top: 8px; }
.sect:first-child { border-top: 0; padding-top: 0; }
.sect > summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; font-size: 10.5px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); padding: 2px 0 6px; }
.sect > summary::-webkit-details-marker { display: none; }
.sect > summary b { margin-left: auto; font-size: 13px; letter-spacing: 0; color: var(--vellum); }
.sect > summary .chev { margin-left: auto; color: var(--muted); }
.sect > summary b + .chev { margin-left: 4px; }
.sect:not([open]) > summary .chev { transform: rotate(-90deg); }
.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; }
.kv b { font-weight: 800; }
.bar { height: 6px; background: rgba(0, 0, 0, 0.5); border-radius: 2px; overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; width: 50%; background: var(--good); border-radius: 2px; transition: width 0.4s; }
#happyWhy { list-style: none; margin: 6px 0 0; padding: 0; font-size: 12.5px; color: var(--muted); display: grid; gap: 1px; }
#happyWhy li { display: flex; justify-content: space-between; }
#happyWhy .pos { color: var(--good); }
#happyWhy .neg { color: var(--bad); }
#taxSeg { margin-top: 5px; }
#kingdoms { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; }
#kingdoms li { display: grid; grid-template-columns: auto 1fr auto; gap: 1px 7px; align-items: center; }
#kingdoms li.fallen { opacity: 0.5; text-decoration: line-through; }
#kingdoms .kn { font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#kingdoms .kv { color: var(--muted); }
#kingdoms .kp { grid-column: 2 / 4; color: var(--muted); font-size: 12px; }
.kdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--fc); box-shadow: 0 0 0 1.5px rgba(255,240,200,0.7); margin-right: 5px; vertical-align: -1px; }
.decree-full p { margin: 4px 0 2px; font-family: var(--story); font-size: 15px; }
#restartBox, #tutBox { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.buffs { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 3px; font-size: 13px; }
.buffs li { display: flex; justify-content: space-between; gap: 8px; }
.buffs span:last-child { color: var(--muted); }
.keys { border-collapse: collapse; font-size: 13.5px; }
.keys td { padding: 3px 0; vertical-align: top; }
.keys td:first-child { color: var(--muted); padding-right: 12px; white-space: nowrap; }

/* army drawer */
#armyBody { display: flex; flex-direction: column; gap: 10px; padding: 4px 12px 12px; font-size: 13px; }
.troops { display: grid; gap: 6px; }
.trow { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.tname { display: flex; flex-direction: column; min-width: 0; }
.tname b { font-size: 14px; }
.tname span { color: var(--muted); font-size: 12px; }
.tsel { display: flex; align-items: center; gap: 4px; }
.tsel button { width: 24px; height: 24px; border-radius: 2px; border: 1px solid var(--gold-dim); background: var(--wood-2); color: var(--vellum); cursor: pointer; font-weight: 800; }
.tsel button:disabled { opacity: 0.35; cursor: default; }
.tsel output { min-width: 20px; text-align: center; font-weight: 800; }
.tbtn { grid-column: 1 / 3; display: flex; align-items: center; justify-content: space-between; gap: 6px; border: 1px solid var(--gold-dim); background: linear-gradient(180deg, var(--wood-hi), var(--wood-2)); color: var(--vellum); border-radius: 2px; padding: 4px 9px; font: 700 12px var(--body); cursor: pointer; }
.tbtn:hover:not(:disabled) { border-color: var(--gold-light); }
.tbtn:disabled { opacity: 0.45; cursor: default; }
.tbtn .costs svg { width: 13px; height: 13px; }
.queue { display: flex; flex-wrap: wrap; gap: 4px; }
.queue span { position: relative; overflow: hidden; background: rgba(0, 0, 0, 0.4); border-radius: 2px; padding: 2px 7px; font-size: 12px; color: var(--muted); }
.queue span.now { color: var(--vellum); }
.queue span i { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--gold); }
.armies { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.armies li { display: flex; gap: 8px; align-items: baseline; }
.armies li span { color: var(--muted); flex: 1; }

/* ---------- map labels ---------- */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.alabel { position: absolute; transform: translate(-50%, -100%); pointer-events: none; font: 800 12px var(--body); color: #fff; background: var(--fc); border: 1.5px solid rgba(255,240,200,0.9); border-radius: 2px; padding: 0 6px; min-width: 18px; text-align: center; box-shadow: 0 2px 6px rgba(0,0,0,0.35); }
.alabel.mine { border-color: var(--gold-light); }
.alabel.hurt { background: #e66f59; }
.hpbar { position: absolute; transform: translate(-50%, -100%); width: 44px; height: 6px; background: rgba(30,18,8,0.75); border-radius: 2px; overflow: hidden; pointer-events: none; border: 1px solid rgba(242,210,124,0.4); }
.hpbar i { display: block; height: 100%; background: linear-gradient(90deg, #e66f59, #eaa743 60%, #8cc574); }
.float { position: absolute; transform: translate(-50%, -100%); font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 3px; white-space: nowrap; color: var(--vellum); text-shadow: 0 1px 2px rgba(0,0,0,.8), 0 0 6px rgba(0,0,0,.45); }
.float svg { width: 14px; height: 14px; }
.float.bad { color: #ffb3a3; }
#flash { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 160px 40px rgba(200, 40, 30, 0.6); opacity: 0; transition: opacity 1.2s; }
#flash.on { opacity: 1; transition: opacity 0.1s; }

/* hover tooltip */
#tip { position: absolute; z-index: 20; pointer-events: none; max-width: 260px; padding: 7px 10px; font-size: 13px; line-height: 1.3; border-radius: 2px; background: rgba(22, 23, 26, 0.97); border: 1px solid var(--gold-dim); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
#tip b { font-family: var(--display); font-weight: 400; font-size: 16px; color: var(--gold-light); display: block; }
#tip .ok { color: var(--good); } #tip .warn { color: var(--warn); } #tip .bad { color: var(--bad); }
#tip .costs { margin-top: 3px; }

/* ---------- toasts ---------- */
#toasts { position: absolute; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 200px); width: min(420px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 5px; pointer-events: none; z-index: 5; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 12px; font-size: 14px; border-left: 4px solid var(--gold); animation: toastIn 0.25s ease-out; border-radius: 2px; }
.toast > span { flex: 1; }
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
.toast .go { flex: none; padding: 2px 9px; font-size: 12px; }
.toast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes toastIn { from { transform: translateY(-6px); opacity: 0; } }

/* ---------- bottom ---------- */
#bottom { position: absolute; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#bottom .row { display: flex; align-items: flex-end; gap: 8px; pointer-events: none; }
#bottom .row > * { pointer-events: auto; }
#modehint { align-self: center; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 5px 6px 5px 16px; font-size: 14px; max-width: 100%; }
#modehint b { font-family: var(--display); font-weight: 400; font-size: 17px; color: var(--gold-light); }
#modehint .msg { min-width: 0; }
#modehint .warn { color: var(--warn); }
#modehint .bad { color: var(--bad); }
#modehint .ok { color: var(--good); }
#modehint .costs { display: inline-flex; }

#build { align-self: center; max-width: 100%; }
#build .dock-head { padding: 0 2px 0 4px; }
#tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#tabs button {
  display: flex; align-items: center; gap: 6px; border: 0; border-bottom: 2px solid transparent; background: transparent; padding: 7px 10px 5px; border-radius: 0;
  cursor: pointer; font-weight: 700; font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
#tabs button svg { width: 15px; height: 15px; flex: none; }
#tabs button kbd { font-size: 10px; opacity: 0.6; }
#tabs button:hover { color: var(--vellum); }
#tabs button.on { color: #f6e9cb; border-bottom-color: var(--crimson-hi); background: rgba(168, 57, 44, 0.18); }
#tabs button.on kbd { background: rgba(0, 0, 0, 0.25); color: #f6e9cb; border-color: rgba(246, 233, 203, 0.3); }
#build.folded #tabs button.on { border-bottom-color: transparent; background: none; color: var(--muted); }
#items { display: flex; gap: 6px; overflow-x: auto; padding: 8px; scrollbar-width: thin; min-width: 0; align-items: stretch; }
.card {
  position: relative; flex: none; width: 92px; text-align: center; cursor: pointer; padding: 4px 4px 6px;
  background: linear-gradient(180deg, rgba(236, 228, 210, 0.08), rgba(0, 0, 0, 0.3)); border: 1px solid var(--line); border-radius: 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.card img, .card .ico { width: 64px; height: 64px; display: block; }
.card .ico { display: grid; place-items: center; }
.card .ico svg { width: 38px; height: 38px; }
.card:hover { border-color: var(--gold-dim); background: linear-gradient(180deg, rgba(236, 228, 210, 0.14), rgba(0, 0, 0, 0.25)); }
.card.on { border-color: var(--gold-light); box-shadow: inset 0 0 0 1px var(--gold-light); background: linear-gradient(180deg, rgba(168, 57, 44, 0.35), rgba(0, 0, 0, 0.3)); }
.card.locked { opacity: 0.5; }
.card .nm { font-weight: 800; font-size: 12.5px; line-height: 1.1; }
.card .lock { position: absolute; top: 4px; right: 4px; font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; color: #f6e9cb; background: var(--crimson); border-radius: 0; padding: 0 4px; font-weight: 700; }
.card .have { position: absolute; top: 4px; left: 5px; font-size: 11px; font-weight: 800; color: var(--muted); }
.card .costs { justify-content: center; font-size: 12px; }
.card .cant { filter: grayscale(0.6); }
.costs { display: flex; flex-wrap: wrap; gap: 2px 7px; font-size: 13px; font-weight: 800; }
.costs .c { display: inline-flex; align-items: center; gap: 2px; }
.costs .c svg { width: 13px; height: 13px; }
.costs .c.short { color: var(--bad); }
.scroll .costs .c.short { color: var(--bad-ink); }

/* info panel */
#bottom .row { position: relative; }
#info { position: absolute; right: 0; bottom: 0; width: min(330px, 100%); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; max-height: min(52vh, calc(100vh - 330px)); overflow-y: auto; }
.ihead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.ihead .ibtns { display: flex; align-items: center; gap: 2px; }
#info.folded > :not(.ihead) { display: none; }
#info.folded .ihead { padding-bottom: 0; border-bottom: 0; }
#info.folded .ctoggle .chev { transform: rotate(-90deg); }
.ihead h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 23px; line-height: 1.05; color: var(--gold-light); }
.pill { align-self: flex-start; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 8px; border-radius: 0; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); }
.pill.ok { color: var(--good); }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); }
.desc { margin: 0; font-size: 14px; color: var(--muted); }
#info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 14px; }
#info dt { color: var(--muted); }
#info dd { margin: 0; font-weight: 800; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
#info dd svg { width: 14px; height: 14px; }
.prog { height: 5px; background: rgba(0, 0, 0, 0.5); border-radius: 2px; overflow: hidden; }
.prog i { display: block; height: 100%; width: 0; background: var(--gold); }
.reqs { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: 14px; }
.reqs li::before { content: "○ "; color: var(--muted); }
.reqs li.ok::before { content: "● "; color: var(--good); }
#adviceList { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
#adviceList .linkbtn { display: inline; text-align: left; font-size: 14px; color: inherit; }
#adviceList li::before { content: "› "; color: var(--gold); font-weight: 800; }
.works { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.works li { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.works li .btn { flex: none; }
.odds { font-weight: 800; }
.odds.good { color: var(--good); } .odds.warn { color: var(--warn); } .odds.bad { color: var(--bad); }

/* tutorial and events: parchment scrolls above the build bar */
#tut, #event { align-self: center; width: min(460px, 100%); padding: 11px 16px 12px; display: flex; flex-direction: column; gap: 6px; }
#event { width: 100%; animation: toastIn 0.3s ease-out; }
#event h3 { font-size: 20px; }
#event p { font-size: 14px; }
#event .btn { font-size: 13px; padding: 5px 10px; }
#tut h3, #event h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 22px; line-height: 1.1; color: var(--crimson-ink); }
#tut p, #event p { margin: 0; font-size: 14.5px; line-height: 1.4; color: var(--ink); }
#tut kbd, #event kbd, .sheet kbd { background: #f6f0e2; color: var(--ink); border-color: #8a7550; }
.tut-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tut-bar, .ev-bar { height: 4px; border-radius: 0; background: rgba(120, 90, 40, 0.2); overflow: hidden; }
.tut-bar i, .ev-bar i { display: block; height: 100%; background: var(--crimson); transition: width 0.4s linear; }
#event .choices { display: flex; flex-wrap: wrap; gap: 6px; }
.tut-glow { outline: 2px solid var(--gold-light) !important; outline-offset: 2px; animation: tutPulse 1.2s ease-in-out infinite; position: relative; z-index: 1; }
@keyframes tutPulse { 50% { outline-color: rgba(242, 210, 124, 0.25); box-shadow: 0 0 14px 3px rgba(242, 210, 124, 0.6); } }

/* ---------- main menu and multiplayer ---------- */
.menu-sect { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid rgba(138, 117, 80, 0.4); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.field input { font: inherit; font-size: 16px; font-weight: 600; padding: 7px 10px; border: 1px solid #8a7550; border-radius: 2px; background: #fbf7ec; color: var(--ink); }
.sheet .seg { background: rgba(60, 40, 20, 0.12); }
.sheet .seg button { color: var(--ink-soft); }
.sheet .seg button.on { color: #f6e9cb; }
.roomcode { font-family: var(--display); font-size: 44px; letter-spacing: 0.3em; text-align: center; padding: 8px 0 6px; color: var(--crimson-ink); background: rgba(255, 252, 244, 0.6); border: 1px dashed #8a7550; user-select: all; -webkit-user-select: all; }
.seats { list-style: none; padding: 0 !important; display: grid; gap: 4px; }
.seats li { display: flex; align-items: center; gap: 6px; }
.sheet .bad { color: var(--bad-ink); margin: 0; }
.sheet a { color: var(--crimson-ink); }
.abtn { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 2px; background: rgba(0, 0, 0, 0.4); box-shadow: inset 0 0 0 1px var(--line); color: var(--gold-light); cursor: pointer; }
.abtn svg { width: 15px; height: 15px; }
.abtn.off { color: var(--muted); opacity: 0.5; }
.abtn:hover { opacity: 1; }
.roomchip.late { color: #fff; background: var(--crimson); border-color: var(--gold); }
.roomchip { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; color: var(--gold-light); padding: 3px 8px; border: 1px solid var(--gold-dim); border-radius: 2px; white-space: nowrap; }

/* ---------- modal ---------- */
#modal { position: absolute; inset: 0; background: rgba(10, 10, 12, 0.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.sheet { width: min(480px, 100%); padding: 22px 26px; display: flex; flex-direction: column; gap: 12px; max-height: 90%; overflow-y: auto; }
.sheet h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 32px; line-height: 1.05; color: var(--crimson-ink); letter-spacing: 0.02em; text-wrap: balance; }
.sheet p { margin: 0; color: var(--ink); }
.sheet ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 14.5px; }
.sheet .sub { color: var(--ink-soft); }
.modes { display: grid; gap: 8px; }
.modecard { display: flex; flex-direction: column; gap: 3px; text-align: left; cursor: pointer; padding: 12px 14px; border-radius: 2px; border: 1px solid #8a7550; border-left: 3px solid var(--crimson); background: rgba(255, 252, 244, 0.5); color: var(--ink); font: inherit; }
.modecard b { font-family: var(--display); font-weight: 400; font-size: 24px; color: var(--crimson-ink); }
.modecard span { color: var(--ink-soft); font-size: 14px; }
.modecard:hover, .modecard:focus-visible { border-color: var(--crimson-ink); background: rgba(255, 252, 244, 0.85); outline: none; }
.gains { display: flex; flex-wrap: wrap; gap: 6px 14px; font-weight: 800; }
.gains span { display: inline-flex; gap: 4px; align-items: center; }
.gains svg { width: 15px; height: 15px; }

@media (max-width: 1100px) {
  .chip .cap { display: none; }
  #crest .tier { display: none; }
}
@media (max-width: 900px) {
  #orders { display: none; }
}
@media (max-width: 1100px) {
  #objective { width: auto; left: 220px; right: 280px; transform: none; min-width: 0; }
}
@media (max-width: 900px) {
  #objective { right: 10px; }
}
@media (max-width: 720px) {
  #objective { left: 10px; top: calc(env(safe-area-inset-top, 0px) + 96px); }
  #adviceText { font-size: 16px; }
  #right { left: 10px; right: 10px; width: auto; top: calc(env(safe-area-inset-top, 0px) + 96px); }
}
@media (max-width: 720px) {
  body { font-size: 14px; }
  #hud { flex-wrap: wrap; height: auto; padding-bottom: 4px; row-gap: 0; }
  #crest { display: none; }
  #ribbon { order: 2; flex-basis: 100%; overflow-x: auto; }
  #clock { margin-left: auto; height: 40px; border-left: 0 !important; }
  #left { width: 132px; top: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 168px); }
  .medal { height: 40px; }
  .medal span { display: none; }
  .drawer { left: 12px; right: 12px; width: auto; top: calc(env(safe-area-inset-top, 0px) + 100px); max-height: 55%; }
  .chip .cap { display: none; }
  #tabs button span { display: none; }
  #tabs button kbd { display: none; }
  #tabs button { padding: 4px; }
  .card { width: 78px; }
  .card img, .card .ico { width: 52px; height: 52px; }
  #info { max-height: 40vh; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .bar i { transition: none; }
  .tut-glow, #alertBtn.danger, .adv-glow, #objective.fresh { animation: none; }
}
