:root {
  --ink: #2a1d2e;
  --paper: #f6ead8;
  --paper-2: #efdcc2;
  --wax: #b23a2e;
  --wax-2: #d4573f;
  --dusk: #3b2747;
  --glow: #ffcf6e;
  --teal: #2f6f73;
  --line: rgba(42, 29, 46, 0.18);
  --serif: "Fraunces", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2b1d33; color: var(--ink); font-family: var(--mono); }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }

/* Card */
.card {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
  padding: 28px 28px 22px; box-shadow: 0 30px 80px rgba(20, 8, 30, 0.45);
  background-image: repeating-linear-gradient(0deg, transparent 0 27px, rgba(47, 111, 115, 0.08) 27px 28px);
}
.card::after { /* wax seal */
  content: "P"; position: absolute; right: 22px; top: 20px; width: 54px; height: 54px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--wax-2), var(--wax) 60%, #7d241c);
  color: #f7d9c8; font: 800 26px/54px var(--serif); text-align: center; transform: rotate(-12deg);
  box-shadow: 0 2px 0 rgba(0,0,0,.2);
}
.eyebrow { margin: 0 0 6px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--teal); }
h1 { margin: 0 0 12px; font: 800 56px/1 var(--serif); letter-spacing: -0.02em; }
h1 em { font-style: italic; color: var(--wax); }
.lede { margin: 0 0 18px; font-size: 14px; line-height: 1.6; max-width: 42ch; }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px; }
.results div { border: 1px dashed var(--line); padding: 10px; border-radius: 4px; background: var(--paper-2); }
.results b { display: block; font: 800 28px/1.1 var(--serif); }
.k { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; opacity: .7; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.btn {
  font: 600 14px var(--mono); padding: 12px 18px; border-radius: 4px; cursor: pointer;
  background: transparent; color: var(--ink); border: 1.5px solid var(--ink);
}
.btn:hover { background: rgba(42, 29, 46, 0.07); }
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--wax); outline-offset: 2px; }
.btn.primary { background: var(--wax); border-color: var(--wax); color: #fff6ee; }
.btn.primary:hover { background: #9b3026; }
.btn.small { padding: 7px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.links { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.links a.btn { text-decoration: none; }
.links .ca span { font-weight: 400; margin-left: 4px; }
.links .scan { font-size: 12px; color: var(--teal); }
.controls summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.controls ul { margin: 8px 0 0; padding-left: 18px; font-size: 12.5px; line-height: 1.9; }
kbd { font: 600 11px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 1px 5px; margin-right: 3px; background: #fff8ee; }

/* Chain panel */
.chain {
  position: fixed; right: 16px; top: 16px; width: 280px; max-height: calc(100% - 32px); overflow: auto;
  background: rgba(246, 234, 216, 0.94); border: 1px solid var(--line); border-radius: 6px; padding: 12px; font-size: 12px;
}
.chain header { display: flex; align-items: center; gap: 6px; }
.chain select { flex: 1; min-width: 0; font: 12px var(--mono); padding: 6px; background: #fff8ee; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); }
.net { flex: 1; min-width: 0; font-weight: 600; }
.wallet { margin: 0 0 8px; display: grid; gap: 4px; }
.wallet div { display: flex; justify-content: space-between; }
.wallet dt { opacity: .75; }
.wallet dd { margin: 0; font-weight: 600; }
.run-note { margin: 0 0 12px; font-size: 12.5px; line-height: 1.5; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #9a8a8a; flex: none; }
.dot.on { background: #3c9a5f; }
.c-status { margin: 8px 0; line-height: 1.5; word-break: break-word; }
.callsign { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.callsign input { flex: 1; min-width: 0; font: 12px var(--mono); padding: 6px; border: 1px solid var(--line); border-radius: 4px; background: #fff8ee; color: var(--ink); }
.coo-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chain h2 { font: 800 16px var(--serif); margin: 14px 0 6px; }
.board { margin: 0; padding-left: 22px; line-height: 1.8; }
.board li span { float: right; font-weight: 600; }
.board .me { color: var(--wax); font-weight: 600; }
.muted { opacity: .65; list-style: none; margin-left: -22px; }
.chain a { color: var(--teal); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; color: #fff4e4; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.hud-top { position: absolute; left: 16px; top: 16px; display: flex; gap: 18px; }
.stat .v { display: block; font: 800 26px/1 var(--serif); }
.stat .k { color: #fff4e4; opacity: .8; }
.order { position: absolute; left: 16px; top: 76px; font-size: 13px; max-width: 46ch; background: rgba(42,29,46,.55); padding: 6px 10px; border-radius: 4px; }
.order b { color: var(--glow); }
.stamina { position: absolute; left: 16px; bottom: 20px; display: flex; align-items: center; gap: 8px; }
.stamina .bar { width: 180px; height: 10px; border: 1px solid rgba(255,244,228,.7); border-radius: 6px; overflow: hidden; }
.stamina i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--wax-2), var(--glow)); transition: width .1s; }
.arrow { position: absolute; left: 50%; top: 18%; font-size: 34px; color: var(--glow); transform-origin: center; margin-left: -17px; }
#minimap { position: absolute; left: 16px; bottom: 44px; width: 120px; height: 120px; border-radius: 50%; border: 2px solid rgba(255,244,228,.6); background: rgba(42,29,46,.55); }
.toast { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); font: 800 30px var(--serif); color: var(--glow); opacity: 0; transition: opacity .3s; white-space: nowrap; }
.toast.show { opacity: 1; }
.touch { display: none; }

@media (max-width: 760px) {
  .chain { left: 16px; right: 16px; width: auto; top: auto; bottom: 16px; max-height: 38%; }
  body.flying .chain { display: none; }
  h1 { font-size: 42px; }
  .card { top: 16px; transform: translateX(-50%); max-height: calc(62% - 24px); padding: 20px; }
  .card::after { width: 42px; height: 42px; font-size: 20px; line-height: 42px; }
  .hud-top { gap: 12px; }
  .stat .v { font-size: 20px; }
  #minimap { width: 90px; height: 90px; bottom: 44px; }
}
@media (hover: none) and (pointer: coarse) {
  .touch { display: block; pointer-events: auto; }
  .stick { position: absolute; left: 24px; bottom: 150px; width: 110px; height: 110px; border-radius: 50%; border: 2px solid rgba(255,244,228,.5); background: rgba(42,29,46,.3); touch-action: none; }
  .stick i { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255,244,228,.7); }
  .flap-btn { position: absolute; right: 24px; bottom: 60px; width: 92px; height: 92px; border-radius: 50%; border: 0; background: var(--wax); color: #fff6ee; font: 700 15px var(--mono); touch-action: none; }
}
@media (prefers-reduced-motion: reduce) { .toast, .stamina i { transition: none; } }
