/* The look both screens share: the job screen and the overhead map. */
  /*
   * The screen has three places, and each holds one kind of thing:
   *   left    who the troupe are
   *   middle  where they are (the map, never covered)
   *   right   what is in front of them now, and what they can do
   * The right has two tabs: Now, and the Story of what has already happened.
   */
  :root {
    --bg: #0d0b09; --panel: #17130f; --panel2: #1e1913; --line: #33291d; --line2: #4a3b29;
    --text: #dcd3c2; --dim: #948870; --faint: #6a604e; --gold: #d8b25a; --blood: #b5483a; --green: #7fa56b;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); overflow: hidden; }
  button { font: inherit; color: inherit; cursor: pointer; }
  [hidden] { display: none !important; }
  .dim { color: var(--dim); }
  ::-webkit-scrollbar { width: 9px; } ::-webkit-scrollbar-thumb { background: #3a2f21; border-radius: 5px; } ::-webkit-scrollbar-track { background: transparent; }
  :focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

  /* A word from the ladder: always drawn this way, so it reads as a game term. */
  .lw { font-family: var(--sans); font-weight: 700; font-size: 0.8em; letter-spacing: 0.06em; text-transform: uppercase;
        padding: 0 0.32em; border-radius: 3px; white-space: nowrap; border-bottom: 2px solid currentColor; }
  .lw.t1 { color: #b0766a; background: rgba(176,118,106,0.12); }
  .lw.t2 { color: #b9a98a; background: rgba(185,169,138,0.10); }
  .lw.t3 { color: #9fc07f; background: rgba(159,192,127,0.12); }
  .lw.t4 { color: #e3bd5f; background: rgba(227,189,95,0.14); }
  .lw.t5 { color: #f0dfa6; background: rgba(240,223,166,0.18); }
  .lw.up { animation: lwup 2.4s ease-out; }
  @keyframes lwup { 0% { box-shadow: 0 0 0 0 rgba(227,189,95,0.9); transform: scale(1.35); } 100% { box-shadow: 0 0 0 14px rgba(227,189,95,0); transform: scale(1); } }

  /* Something with more to say: a short line first, the rest beside it on hover, focus or click. */
  .has-more { cursor: help; }
  .has-more:not(button):not(.card .name)::after { content: "ⓘ"; font: 12px var(--sans); color: var(--faint); margin-left: 6px; vertical-align: 2px; }
  button.has-more { cursor: pointer; }
  #more-tip { position: fixed; z-index: 30; width: 310px; background: #0f0c09; border: 1px solid var(--line2); border-radius: 8px; padding: 10px 12px; box-shadow: 0 12px 34px rgba(0,0,0,0.75);
              pointer-events: none; font: 14.5px/1.5 var(--serif); color: #cfc5b0; }
  #more-tip b { color: #f3e6c8; } #more-tip .dim { font: 12.5px/1.5 var(--sans); }

  #app { display: grid; grid-template-columns: 250px minmax(0, 1fr) 400px; grid-template-rows: 48px minmax(0, 1fr); height: 100vh; }
  h3 { margin: 0 0 6px; font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); }

  /* ── The top bar: where we are, the two things that change, and the way out. ── */
  header { grid-column: 1 / -1; display: flex; align-items: center; gap: 20px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
  header h1 { font: 600 18px var(--serif); margin: 0; }
  header .where { color: var(--dim); font-size: 13px; }
  header .spacer { flex: 1; }
  .stat { display: flex; align-items: baseline; gap: 7px; }
  .stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--faint); }
  .stat .v { font: 600 15px var(--serif); }
  #alert.a0 { color: var(--green); } #alert.a1 { color: #cfc27a; } #alert.a2 { color: #df9a4e; } #alert.a3 { color: var(--blood); }
  #alert-pips { display: inline-flex; gap: 3px; align-self: center; }
  #alert-pips i { width: 8px; height: 8px; border-radius: 50%; background: #2a2219; }
  #alert-pips i.on.a0 { background: var(--green); } #alert-pips i.on.a1 { background: #cfc27a; } #alert-pips i.on.a2 { background: #df9a4e; } #alert-pips i.on.a3 { background: var(--blood); }
  #purse { color: var(--gold); display: inline-block; transform-origin: 100% 60%; }
  #purse.bump { animation: bump 0.9s ease-out; }
  @keyframes bump { 0% { transform: scale(1.35); text-shadow: 0 0 18px rgba(216,178,90,0.9); } 100% { transform: scale(1); text-shadow: none; } }
  .bar-btn { background: none; border: 1px solid var(--line2); border-radius: 5px; padding: 5px 11px; color: var(--dim); font-size: 13px; }
  .bar-btn:hover:not(:disabled) { color: var(--text); border-color: var(--dim); }
  #story-count { display: inline-block; min-width: 18px; margin-left: 5px; padding: 0 5px; border-radius: 9px; background: #2a2217; color: var(--dim); font-size: 11px; text-align: center; }
  #leave:disabled { opacity: 0.35; cursor: default; }
  #leave:not(:disabled) { border-color: var(--gold); color: var(--gold); }
  #leave.beckon:not(:disabled) { animation: beckon 1.5s ease-in-out infinite; background: #3a2e17; }
  @keyframes beckon { 0%, 100% { box-shadow: 0 0 0 0 rgba(216,178,90,0.6); } 50% { box-shadow: 0 0 0 9px rgba(216,178,90,0); } }

  /* ── Left: who the troupe are. What each can do stays in view; the rest is on request. ── */
  #troupe { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
  .card { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--c, #888); border-radius: 6px; padding: 8px 10px; transition: opacity .4s, border-color .2s; }
  .card.lit { border-color: var(--gold); border-left-color: var(--c); box-shadow: 0 0 0 1px rgba(216,178,90,0.35); }
  .card.dead { opacity: 0.4; filter: grayscale(1); }
  .card.hit { animation: hit 1.6s ease-out; }
  @keyframes hit { 0% { background: #5a1f17; box-shadow: 0 0 0 3px rgba(181,72,58,0.8); } 100% { background: var(--panel2); box-shadow: none; } }
  .card .name { font: 600 16px var(--serif); display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
  .card .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; padding: 1.5px 0; font-size: 13px; color: #c9bfab; }
  .health { font: 600 10.5px var(--sans); text-transform: uppercase; letter-spacing: 0.07em; padding: 1px 6px; border-radius: 9px; background: #25301f; color: var(--green); }
  .health.h1 { background: #3a3018; color: #dfb04e; } .health.h2 { background: #3d1f19; color: #e0705f; } .health.h3 { background: #222; color: #999; }

  /* ── Middle: the map. Nothing is laid over it but its own labels and two small controls. ── */
  #stage { position: relative; overflow: hidden; background: #0a0d0b; cursor: grab; touch-action: none; }
  #stage.drag { cursor: grabbing; }
  #world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
  #map { display: block; filter: brightness(0.72) saturate(0.78) contrast(1.05); }
  #night { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 45%, rgba(40,56,92,0.10), rgba(10,14,30,0.42)); mix-blend-mode: multiply; pointer-events: none; }
  .pin { position: absolute; white-space: nowrap; font-size: 12px; padding: 2px 7px; border-radius: 10px; background: rgba(14,11,8,0.78); border: 1px solid var(--line2); color: var(--dim);
         cursor: pointer; user-select: none; transition: background .15s, color .15s, opacity .15s; }
  .pin:hover { background: #2c2418; color: #fff; border-color: var(--gold); z-index: 2; }
  .pin.main { color: var(--gold); border-color: var(--gold); font-weight: 600; font-size: 13px; }
  .pin.side { color: #c9bd9a; border-color: #8a7a55; }
  .pin.exit { color: #9fc07f; border-color: #58703f; }
  .pin.exit.beckon { animation: beckon-g 1.5s ease-in-out infinite; color: #d5f0bd; border-color: #a9d08a; }
  @keyframes beckon-g { 0%, 100% { box-shadow: 0 0 0 0 rgba(159,192,127,0.7); } 50% { box-shadow: 0 0 0 9px rgba(159,192,127,0); } }
  .pin.done { opacity: 0.5; text-decoration: line-through; }
  /* Places with nothing in them are quiet until looked at, so the three kinds that matter stand out. */
  .pin.minor { font-size: 11px; opacity: 0.38; border-color: transparent; background: none; text-shadow: 0 1px 2px #000; }
  .pin.minor:hover { opacity: 1; background: #2c2418; }
  .pin.going { background: var(--gold); color: #1a1408; border-color: var(--gold); opacity: 1; }
  .tag { position: absolute; font-size: 11px; padding: 1px 6px; border-radius: 3px; background: rgba(60,18,14,0.85); color: #f0c9bf; border: 1px solid #7a3328; pointer-events: none; white-space: nowrap; }
  .tag.gone { display: none; }
  .nm { position: absolute; transform: translate(-50%, -100%) scale(calc(1 / var(--z, 1))); transform-origin: 50% 100%; font: 600 11.5px var(--sans); padding: 0 5px; border-radius: 3px; white-space: nowrap; pointer-events: none; text-shadow: 0 1px 2px #000; }
  .nm.mine { color: #fff; background: color-mix(in srgb, var(--c) 72%, #000); }
  .nm.foe, .nm.other { transform: translate(-50%, 0) scale(calc(1 / var(--z, 1))); transform-origin: 50% 0; }
  .nm.foe { color: #f3cfc6; background: rgba(110,30,22,0.88); }
  .nm.other { color: #cfc8b8; background: rgba(40,36,30,0.85); }
  .nm.down { opacity: 0.6; text-decoration: line-through; }
  #legend { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 12px; background: rgba(14,11,8,0.8); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; font-size: 11.5px; color: var(--dim); pointer-events: none; }
  #legend .m { color: var(--gold); } #legend .s { color: #c9bd9a; } #legend .e { color: #9fc07f; }
  .map-ctl { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
  .map-ctl button { background: rgba(14,11,8,0.82); border: 1px solid var(--line2); border-radius: 6px; padding: 5px 10px; font-size: 12px; color: var(--dim); }
  .map-ctl button:hover { color: var(--gold); border-color: var(--gold); }
  #who-tip, #ladder-tip { position: fixed; z-index: 29; background: #0f0c09; border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.7); pointer-events: none; }
  #who-tip { max-width: 340px; padding: 8px 11px; font-size: 13px; line-height: 1.6; }
  #who-tip b { color: #f3e6c8; } #who-tip .wf { color: var(--faint); font-size: 12px; }
  #ladder-tip { padding: 9px 11px 7px; font-size: 12px; color: var(--dim); z-index: 31; }
  #ladder-tip .pips { display: flex; gap: 2px; margin-bottom: 6px; }
  #ladder-tip .pips i { width: 7px; height: 12px; border-radius: 2px; background: #2a2219; }
  #ladder-tip .pips i.below { background: #5d4c2c; }
  #ladder-tip .pips i.on { background: var(--gold); height: 16px; margin-top: -2px; box-shadow: 0 0 8px rgba(216,178,90,0.8); }
  #ladder-tip .near b { color: var(--gold); }
  #ladder-tip .ends { display: flex; justify-content: space-between; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin-top: 4px; }

  /* ── Right: now. What is in front of the troupe, and what it can do. Always read top to bottom. ── */
  #side { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
  /* Two tabs in one place: what is happening now, and what has happened. Only one is ever on screen. */
  .tabs { display: flex; border-bottom: 1px solid var(--line); flex-shrink: 0; }
  .tabs [role=tab] { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; padding: 11px 8px 9px; font: 600 12px var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); }
  .tabs [role=tab]:hover { color: var(--text); }
  .tabs [role=tab][aria-selected=true] { color: var(--gold); border-bottom-color: var(--gold); }
  /* Something is waiting on the other tab. */
  .tabs [role=tab].fresh::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 7px; border-radius: 50%; background: var(--gold); vertical-align: 1px; animation: dot 1.1s infinite; }
  #now { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 16px 20px; }
  .eyebrow { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--gold); margin-bottom: 4px; }
  .eyebrow small { font: inherit; color: var(--faint); }
  .title { font: 600 22px/1.25 var(--serif); margin: 0 0 14px; color: #f1e8d6; }
  #hint { font: 15px/1.5 var(--serif); color: #cfc5b0; margin: 0 0 14px; }
  #last { font-size: 12.5px; color: var(--dim); }
  #decide { border-top: 3px solid transparent; margin-top: -3px; }
  #decide[data-state="worse"] .eyebrow { color: #e37463; }

  #who { margin-bottom: 16px; }
  #who .o { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; font-size: 14px; }
  #who .o .on { color: #f0c9bf; font-weight: 600; }
  #who .o.prize .on { color: var(--gold); }
  #who .o.out .on { color: var(--dim); font-weight: 400; }
  #who .o.has-more::after { margin-left: auto; }

  .opts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
  .opt { position: relative; text-align: left; background: #221c14; border: 1px solid var(--line2); border-left: 4px solid var(--c, var(--line2)); border-radius: 7px; padding: 8px 34px 8px 11px;
         display: flex; flex-direction: column; gap: 1px; transition: background .12s, border-color .12s, transform .06s; }
  .opt:hover { background: #30271a; border-color: var(--gold); border-left-color: var(--c, var(--gold)); }
  .opt:active { transform: translateY(1px); }
  .opt .by { font: 700 11px var(--sans); text-transform: uppercase; letter-spacing: 0.07em; color: var(--c, var(--gold)); }
  .opt .does { font: 15.5px/1.3 var(--serif); }
  .opt kbd { position: absolute; top: 8px; right: 8px; font: 11px var(--sans); color: var(--faint); border: 1px solid var(--line2); border-radius: 4px; padding: 0 5px; }
  /* The ways that are always open are smaller: they are the fallback, not the headline. */
  .opts.set { flex-direction: row; flex-wrap: wrap; }
  .opt.small { flex-direction: row; align-items: baseline; gap: 7px; padding: 5px 10px; background: #1b1610; }
  .opt.small .does { font-size: 14px; }
  .opt.go { font: 600 16px var(--serif); background: var(--gold); border-color: var(--gold); border-left-color: var(--gold); color: #1a1408; align-items: center; padding: 11px 14px; }
  .opt.go:hover:not(:disabled) { background: #e7c574; }
  .opt.go:disabled { background: #3a2e17; border-color: var(--line2); border-left-color: var(--line2); color: var(--dim); font-style: italic; cursor: default; }
  .opt.ghost { height: 54px; border-left-width: 1px; background: linear-gradient(90deg, #1c1711 25%, #2a2219 37%, #1c1711 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-color: var(--line); }
  @keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
  .note { font-size: 13px; }
  .linkish { background: none; border: 0; padding: 0; color: var(--dim); font-size: 13px; text-decoration: underline dotted; text-underline-offset: 3px; }
  .linkish:hover { color: var(--gold); }

  /* The outcome: what was chosen, the roll, what happened, and one way on. */
  #chosen { font: 15.5px/1.4 var(--serif); color: #cfc5b0; margin-bottom: 12px; padding-left: 10px; border-left: 2px solid var(--line2); }
  #wait-line { display: flex; align-items: center; gap: 10px; font: italic 14px var(--serif); color: var(--dim); margin-top: 10px; }
  .dots span { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; background: var(--gold); animation: dot 1.1s infinite; }
  .dots span:nth-child(2) { animation-delay: .18s; } .dots span:nth-child(3) { animation-delay: .36s; }
  @keyframes dot { 0%, 80%, 100% { opacity: .2; transform: scale(.8); } 40% { opacity: 1; transform: scale(1.1); } }
  #told { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); animation: rise .4s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
  #telling { font: 16.5px/1.55 var(--serif); margin: 0 0 10px; color: #ece3d0; }
  #next { margin-top: 14px; margin-bottom: 0; }
  .plain-verdict { font: 600 17px var(--serif); text-align: center; text-transform: capitalize; }
  .plain-verdict.o0 { color: #a9d08a; } .plain-verdict.o1 { color: #e3c56b; } .plain-verdict.o2 { color: #e09a55; } .plain-verdict.o3 { color: #e37463; }
  .verdict { display: flex; flex-wrap: wrap; gap: 5px 6px; font-size: 12px; }
  .chip { padding: 2px 8px; border-radius: 10px; background: #221c14; border: 1px solid var(--line2); color: var(--dim); }
  .chip.o0 { color: #a9d08a; border-color: #4f6b3c; } .chip.o1 { color: #e3c56b; border-color: #7a6630; } .chip.o2 { color: #e09a55; border-color: #7d5127; } .chip.o3 { color: #e37463; border-color: #7f3327; }
  .chip.cost { color: #e0a08f; } .chip.gain { color: var(--gold); border-color: #8a6f2c; }

  /* ── The story so far: its own tab, because it is for looking back, not for deciding. ── */
  #story { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #feed { flex: 1; overflow-y: auto; padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 11px; }
  #story .foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--faint); }
  #story .foot button { white-space: nowrap; flex-shrink: 0; }
  #referee { flex: 1; min-width: 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .entry.brief { font: italic 14.5px/1.5 var(--serif); color: var(--dim); }
  .entry.place { font: 600 12px var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--gold); margin-top: 6px; }
  .entry.see { font: 14.5px/1.5 var(--serif); color: #bfb49d; }
  .entry.did { font-size: 13px; color: var(--dim); padding-left: 10px; border-left: 2px solid var(--line2); }
  .entry.did b { color: var(--text); }
  .entry.tell { font: 15px/1.55 var(--serif); }
  .entry .verdict { margin-top: 6px; }
  .why { margin-top: 5px; font: 12.5px var(--sans); color: var(--dim); }
  .flag { display: block; margin-top: 6px; background: none; border: 0; padding: 0; font: 11px var(--sans); color: var(--faint); text-decoration: underline dotted; }
  .flag:hover { color: var(--text); } .flag.on { color: var(--blood); text-decoration: none; font-weight: 700; }

  /* ── The opening card and the end. ── */
  #end, #intro { position: absolute; inset: 0; background: rgba(8,6,5,0.88); display: flex; align-items: center; justify-content: center; z-index: 6; cursor: default; }
  #end .box, #intro .box { width: min(600px, 92%); background: var(--panel); border: 1px solid var(--line2); border-radius: 12px; padding: 26px 30px 24px; box-shadow: 0 24px 70px #000; }
  #end h2, #intro h2 { font: 600 28px var(--serif); margin: 2px 0 8px; }
  #end .sub { color: var(--dim); margin-bottom: 16px; font: italic 15px var(--serif); }
  #end .big { font: 600 46px var(--serif); color: var(--gold); }
  #end ul { list-style: none; padding: 0; margin: 14px 0 18px; display: flex; flex-direction: column; gap: 6px; }
  #end li { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px dashed var(--line); }
  #end button, #intro button { background: var(--gold); color: #1a1408; border: 0; border-radius: 7px; padding: 10px 22px; font-weight: 700; font-size: 15px; }
  #end button.quiet { background: none; color: var(--dim); border: 1px solid var(--line2); font-weight: 400; margin-left: 6px; }
  #intro .kicker { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--gold); }
  #intro p { font: 16.5px/1.55 var(--serif); margin: 0 0 16px; color: #cfc5b0; }
  #intro ol { margin: 0 0 20px; padding-left: 20px; color: var(--dim); display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
  #intro ol b { color: var(--text); font-weight: 600; }

  @media (max-width: 1280px) { #app { grid-template-columns: 220px minmax(0, 1fr) 360px; } }
