/* Siege of the Order Book */

:root {
  --night: #0b0e2b;
  --night-2: #12153a;
  --night-3: #1a1e4a;
  --line: rgba(242, 193, 78, .22);
  --text: #ece7f7;
  --dim: #a9a6c9;
  --gold: #f2c14e;
  --bull: #2fd6b0;
  --bull-d: #0e8a73;
  --bear: #ff6b4a;
  --bear-d: #b8391f;
  --magic: #b693ff;
  --parch: #fff6dd;
  --parch-2: #f0e2bd;
  --ink: #1b1730;
  --serif: "IM Fell English", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --display: "Pirata One", "IM Fell English", Georgia, serif;
  --num: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--text);
  font: 16px/1.4 var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
h1, h2, p, ol, ul, table { margin: 0; padding: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.n, .mom-val, .quote-price, .reck td, .tip, .status-pop { font-family: var(--num); font-variant-numeric: tabular-nums; }

.app {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* ------------------------------------------------------------------ header */
.top {
  display: flex; align-items: center; gap: 18px;
  padding: 9px 18px;
  background: linear-gradient(#161a44, #10133a);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 8;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 0; }
.crest { width: 34px; height: 34px; flex: none; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .35)); }
.brand-text { min-width: 0; }
h1 {
  font: 400 27px/1 var(--display);
  letter-spacing: .5px;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tag { font-size: 13.5px; font-style: italic; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.quote { display: flex; flex-direction: column; align-items: center; flex: none; line-height: 1.05; }
.quote-label { font-size: 12px; font-style: italic; color: var(--dim); }
.quote-price { font-size: 25px; font-weight: 700; letter-spacing: -.3px; color: var(--text); transition: color .5s; }
.quote-price.up { color: var(--bull); }
.quote-price.down { color: var(--bear); }

.tools { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 1 1 0; }
.pill, .icon-btn {
  height: 34px; border-radius: 17px;
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .06);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0 13px; font-size: 15px; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.icon-btn { width: 34px; padding: 0; justify-content: center; }
.icon-btn svg { width: 20px; height: 20px; }
.pill:hover, .icon-btn:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .3); }
.pill:focus-visible, .icon-btn:focus-visible, .legend-x:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.icon-btn .snd-on { display: none; }
.icon-btn[aria-pressed="true"] { color: var(--gold); border-color: rgba(242, 193, 78, .6); }
.icon-btn[aria-pressed="true"] .snd-on { display: block; }
.icon-btn[aria-pressed="true"] .snd-off { display: none; }
.help-q { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--gold); color: var(--ink); font: 700 12px/1 var(--num); }
.help[aria-expanded="true"] { border-color: rgba(242, 193, 78, .7); }
.help.nudge { border-color: rgba(242, 193, 78, .8); animation: nudge 2.4s ease-out infinite; }
@keyframes nudge { 0% { box-shadow: 0 0 0 0 rgba(242, 193, 78, .55); } 60%, 100% { box-shadow: 0 0 0 10px rgba(242, 193, 78, 0); } }

.status-wrap { position: relative; }
.beacon { width: 9px; height: 9px; border-radius: 50%; background: #8a88a8; flex: none; }
.status[data-state="live"] .beacon { background: var(--bull); box-shadow: 0 0 0 0 rgba(47, 214, 176, .7); animation: pulse 1.8s infinite; }
.status[data-state="connecting"] .beacon, .status[data-state="syncing"] .beacon, .status[data-state="reconnecting"] .beacon { background: var(--gold); animation: blink 1s infinite; }
.status[data-state="waiting"] .beacon, .status[data-state="offline"] .beacon, .status[data-state="unsupported"] .beacon { background: var(--bear); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(47, 214, 176, 0); } 100% { box-shadow: 0 0 0 0 rgba(47, 214, 176, 0); } }
@keyframes blink { 50% { opacity: .25; } }
.status-pop {
  position: absolute; right: 0; top: 42px; width: 330px; z-index: 8;
  background: var(--parch); color: var(--ink);
  border-radius: 10px; padding: 12px 14px; font-size: 12.5px; line-height: 1.5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.status-pop dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.status-pop dt { color: #6b6280; }
.status-pop dd { margin: 0; text-align: right; font-weight: 600; white-space: nowrap; }

/* -------------------------------------------------------------------- main */
.main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
}
.field { grid-column: 1 / -1; position: relative; min-height: 0; overflow: hidden; background: var(--night); }
#battle { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; transition: filter .6s; }
.field.stale #battle { filter: grayscale(.85) brightness(.62); }

/* momentum banners */
.momentum {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: min(660px, calc(100% - 20px));
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: 12px; row-gap: 3px;
  pointer-events: none; z-index: 2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
  --split: 50%;
}
.momentum::before {
  content: ""; position: absolute; inset: -22px -70px -24px; z-index: -1;
  background: radial-gradient(closest-side, rgba(11, 14, 43, .7), rgba(11, 14, 43, .45) 55%, rgba(11, 14, 43, 0));
}
.mom-title { grid-column: 1 / -1; text-align: center; font-size: 12.5px; font-style: italic; color: var(--dim); }
.mom-side { display: flex; flex-direction: column; line-height: 1.1; }
.mom-side.bear { align-items: flex-end; }
.mom-name { font-size: 13px; font-style: italic; }
.mom-side.bull .mom-name { color: var(--bull); }
.mom-side.bear .mom-name { color: var(--bear); }
.mom-val { font-size: 16px; font-weight: 700; }
.mom-bar { position: relative; height: 20px; display: flex; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .4)); }
.mom-fill { display: block; height: 100%; }
.mom-fill.bull {
  flex: 0 0 var(--split); transition: flex-basis .7s cubic-bezier(.2, .8, .2, 1);
  background: linear-gradient(#5cecca, #1eb592);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 11px 50%);
}
.mom-fill.bear {
  flex: 1 1 0;
  background: linear-gradient(#ff8a6c, #e04a2a);
  clip-path: polygon(0 0, 100% 0, calc(100% - 11px) 50%, 100% 100%, 0 100%);
}
.mom-knot {
  position: absolute; top: -5px; bottom: -5px; left: var(--split); width: 4px; margin-left: -2px; border-radius: 2px;
  background: var(--gold); box-shadow: 0 0 0 1px rgba(27, 23, 48, .8);
  transition: left .7s cubic-bezier(.2, .8, .2, 1);
}
.momentum[data-empty="true"] .mom-fill { filter: grayscale(1) opacity(.45); }
.mom-note { grid-column: 1 / -1; text-align: center; font-size: 13.5px; color: var(--text); }
.mom-note b { font-family: var(--num); font-size: 12.5px; }

.scale-note {
  position: absolute; left: 12px; top: 10px; max-width: 250px; z-index: 1;
  font-size: 12.5px; font-style: italic; line-height: 1.3; color: var(--dim);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
  pointer-events: none;
}
.scale-note b { font-family: var(--num); font-style: normal; font-size: 11.5px; color: var(--text); font-weight: 600; }

/* the always-on pocket key */
.key-strip {
  position: absolute; right: 12px; top: 10px; z-index: 1; list-style: none;
  display: grid; gap: 3px; pointer-events: none;
  font-size: 13px; font-style: italic; color: var(--dim); text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
}
.key-strip li { display: flex; align-items: center; gap: 8px; }
.key-strip b { font-weight: 400; color: var(--text); margin-right: 3px; }
.kg { width: 11px; height: 11px; flex: none; display: inline-block; border-radius: 2px; }
.kg-stone { background: linear-gradient(90deg, #5b7a85 50%, #86605f 50%); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35); }
.kg-shot { border-radius: 50%; background: linear-gradient(#9aa0b0 34%, var(--bull) 34% 66%, #9aa0b0 66%); box-shadow: 0 0 0 1px var(--ink); }
.kg-smash { background: var(--gold); transform: rotate(45deg) scale(.82); }
.kg-magic { border-radius: 50%; background: var(--magic); box-shadow: 0 0 8px var(--magic); }
.kg-mason { background: #efe6cc; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); }

/* champion strike banner */
.champion {
  position: absolute; left: 0; right: 0; top: 27%; text-align: center; z-index: 3;
  pointer-events: none; opacity: 0;
  font: 400 clamp(30px, 6.4vw, 72px)/1 var(--display); letter-spacing: 1px; color: var(--gold);
  text-shadow: 0 3px 0 #5a2a12, 0 0 28px rgba(255, 180, 80, .7);
}
.champion small { display: block; margin-top: 6px; font: 700 clamp(15px, 2.2vw, 24px)/1.1 var(--num); letter-spacing: 0; color: #fff; text-shadow: 0 2px 4px rgba(0, 0, 0, .8); }
.champion.bull small b { color: var(--bull); }
.champion.bear small b { color: var(--bear); }
.champion.show { animation: champ 2.9s ease-out both; }
@keyframes champ {
  0% { opacity: 0; transform: scale(2.1) rotate(-3deg); }
  9% { opacity: 1; transform: scale(.96) rotate(0); }
  14% { transform: scale(1.03); }
  18% { transform: scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* connection veil */
.veil { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; pointer-events: none; opacity: 0; transition: opacity .5s; }
.veil.show { opacity: 1; }
.veil[data-mode="boot"] { background: radial-gradient(ellipse at center, rgba(11, 14, 43, .2), rgba(11, 14, 43, .75)); }
.veil-card {
  max-width: min(440px, calc(100% - 32px)); text-align: center;
  background: rgba(16, 19, 58, .92); border: 1px solid var(--line); border-radius: 14px; padding: 20px 24px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .55);
}
.veil-card h2 { font: 400 26px/1.1 var(--display); color: var(--gold); letter-spacing: .4px; }
.veil-card p { margin-top: 8px; font-size: 15.5px; color: var(--text); }
.veil-card p b { font-family: var(--num); font-size: 14px; }
.raven { width: 54px; height: 36px; color: var(--gold); margin-bottom: 6px; animation: flap 1.6s ease-in-out infinite; }
@keyframes flap { 50% { transform: translateY(-5px) rotate(-3deg); } }

/* tooltip */
.tip {
  position: absolute; z-index: 5; left: 0; top: 0; pointer-events: none;
  min-width: 170px; max-width: 280px;
  background: var(--parch); color: var(--ink);
  border-radius: 9px; padding: 9px 11px 10px;
  font-size: 12.5px; line-height: 1.4;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .55), 0 0 0 1px rgba(27, 23, 48, .25);
}
.tip h3 { margin: 0 0 3px; font: 400 16px/1.15 var(--serif); font-style: italic; display: flex; align-items: center; gap: 6px; }
.tip h3::before { content: ""; width: 9px; height: 9px; border-radius: 2px; background: #8a88a8; flex: none; }
.tip.bull h3::before { background: var(--bull-d); }
.tip.bear h3::before { background: var(--bear-d); }
.tip.magic h3::before { background: var(--magic); border-radius: 50%; }
.tip.gold h3::before { background: #c9962a; }
.tip .big { font-size: 15px; font-weight: 700; }
.tip dl { margin: 5px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 1px 12px; }
.tip dt { color: #6b6280; }
.tip dd { margin: 0; text-align: right; font-weight: 600; }
.tip .note { margin-top: 5px; color: #6b6280; font-family: var(--serif); font-style: italic; font-size: 13px; line-height: 1.25; }

/* ------------------------------------------------------------------ panels */
.panel {
  height: 192px; min-height: 0; overflow: hidden;
  background: linear-gradient(#141840, #0f1232);
  border-top: 1px solid var(--line);
  padding: 10px 18px 10px;
  display: flex; flex-direction: column;
}
.panel + .panel { border-left: 1px solid var(--line); }
.panel h2 { font: 400 21px/1 var(--display); letter-spacing: .5px; color: var(--gold); flex: none; }

.log { list-style: none; margin-top: 7px; overflow-y: auto; flex: 1; min-height: 0; padding-right: 6px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .25) transparent; }
.log li {
  display: grid; grid-template-columns: 62px 16px minmax(0, 1fr); column-gap: 8px; align-items: baseline;
  padding: 3px 0; font-size: 16px; line-height: 1.3;
  border-bottom: 1px dotted rgba(255, 255, 255, .09);
  animation: scribe .5s ease-out both;
}
@keyframes scribe { from { opacity: 0; transform: translateY(-7px); } }
.log time { font: 11.5px/1 var(--num); font-variant-numeric: tabular-nums; color: var(--dim); }
.log .glyph { width: 10px; height: 10px; align-self: center; border-radius: 2px; background: #8a88a8; }
.log li.bull .glyph { background: var(--bull); }
.log li.bear .glyph { background: var(--bear); }
.log li.magic .glyph { background: var(--magic); border-radius: 50%; box-shadow: 0 0 8px var(--magic); }
.log li.gold .glyph { background: var(--gold); transform: rotate(45deg); }
.log li.mason .glyph { background: #d8ccb0; }
.log li.dim { color: var(--dim); font-style: italic; }
.log li.champ p { color: var(--gold); }
.log b { font: 700 13.5px/1 var(--num); font-variant-numeric: tabular-nums; color: #fff; white-space: nowrap; }
.log li.champ b { color: var(--gold); }
.log-empty { color: var(--dim); font-style: italic; margin-top: 8px; }

.reck-head { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.reck-sub { font-size: 13px; font-style: italic; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.reck { width: 100%; border-collapse: collapse; margin-top: 2px; }
.reck th, .reck td { padding: 1.5px 0; border-bottom: 1px dotted rgba(255, 255, 255, .09); line-height: 1.25; }
.reck thead th { font-weight: 400; font-size: 14.5px; text-align: right; }
.reck thead th small { font-style: italic; color: var(--dim); font-size: 12px; }
.reck thead th.bull { color: var(--bull); }
.reck thead th.bear { color: var(--bear); }
.reck tbody th { text-align: left; font-weight: 400; font-size: 14.5px; white-space: nowrap; }
.reck td { text-align: right; font-size: 13px; font-weight: 600; width: 31%; white-space: nowrap; }
.key { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 2px; vertical-align: 0; }
.k-mason { background: #d8ccb0; }
.k-magic { background: var(--magic); border-radius: 50%; }
.k-smash { background: var(--gold); transform: rotate(45deg) scale(.85); }
.reck-verdict { margin-top: 6px; font-size: 14px; font-style: italic; line-height: 1.22; color: var(--text); }
.reck-verdict b { font-family: var(--num); font-style: normal; font-size: 12.5px; color: var(--gold); }

/* ------------------------------------------------------------------ legend */
.legend {
  position: fixed; z-index: 7; right: 14px; top: 62px; width: 392px; max-height: calc(100dvh - 84px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--parch);
  background-image: radial-gradient(ellipse at 20% 0%, rgba(255, 255, 255, .7), transparent 55%), radial-gradient(ellipse at 100% 100%, rgba(196, 160, 96, .28), transparent 60%);
  color: var(--ink);
  border-radius: 12px; padding: 14px 16px 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .6), 0 0 0 1px rgba(27, 23, 48, .3), inset 0 0 0 3px rgba(196, 160, 96, .35);
  animation: unroll .35s ease-out both;
}
@keyframes unroll { from { opacity: 0; transform: translateY(-10px) scale(.98); } }
.legend-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.legend h2 { font: 400 25px/1 var(--display); letter-spacing: .4px; color: #6a3d12; }
.legend-x { width: 30px; height: 30px; border-radius: 50%; border: 1px solid rgba(27, 23, 48, .3); background: rgba(27, 23, 48, .06); font: 400 20px/1 var(--num); color: var(--ink); }
.legend-x:hover { background: rgba(27, 23, 48, .14); }
.legend-lead { margin-top: 6px; font-size: 15.5px; font-style: italic; }
.legend-list { list-style: none; margin-top: 8px; display: grid; gap: 7px; }
.legend-list li { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 11px; align-items: center; }
.legend-list canvas { width: 64px; height: 48px; border-radius: 7px; background: linear-gradient(#1d2459, #3f3f86); box-shadow: inset 0 0 0 1px rgba(27, 23, 48, .4); }
.legend-list p { font-size: 14.5px; line-height: 1.27; }
.legend-list b { font-weight: 400; font-size: 15.5px; color: #6a3d12; }
.legend-foot { margin-top: 10px; padding-top: 8px; border-top: 1px dotted rgba(27, 23, 48, .35); font-size: 14px; font-style: italic; line-height: 1.3; }

.foot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 5px 18px 6px; font-size: 12px; font-style: italic; color: #807da6;
  background: #0d0f2e; border-top: 1px solid rgba(255, 255, 255, .06);
}

/* -------------------------------------------------------------- small screens */
@media (max-width: 900px) {
  .tag { display: none; }
  h1 { font-size: 23px; }
  .help-t { display: none; }
  .pill.help { width: 34px; padding: 0; justify-content: center; }
}
@media (max-width: 1180px) {
  .scale-note, .key-strip { display: none; }
  .main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .reck thead th small { display: none; }
  .reck td { width: 28%; }
  .panel { padding-left: 14px; padding-right: 14px; }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; display: block; }
  .top { position: sticky; top: 0; gap: 10px; padding: 7px 10px; }
  .crest { width: 28px; height: 28px; }
  .brand { gap: 8px; }
  h1 { font-size: 19px; white-space: normal; line-height: .95; max-width: 9.5em; }
  .quote-label { display: none; }
  .quote-price { font-size: 18px; }
  .tools { gap: 6px; flex: none; }
  .pill, .icon-btn { height: 32px; }
  .pill.status { padding: 0 10px; font-size: 14px; }
  .icon-btn, .pill.help { width: 32px; }
  .status-pop { position: fixed; left: 10px; right: 10px; top: 52px; width: auto; }

  .main { display: block; }
  .momentum { top: 6px; column-gap: 8px; row-gap: 1px; width: calc(100% - 16px); }
  .mom-title { font-size: 11.5px; }
  .mom-name { font-size: 11.5px; }
  .mom-val { font-size: 13.5px; }
  .mom-bar { height: 15px; }
  .mom-note { font-size: 12.5px; }
  .field { display: flex; flex-direction: column; height: auto; min-height: 0; overflow: hidden; }
  .momentum::before { inset: -8px -8px -10px; background: radial-gradient(closest-side, rgba(11, 14, 43, .6), rgba(11, 14, 43, 0)); }
  #battle { position: relative; inset: auto; flex: none; height: 64vh; height: min(64svh, 580px); min-height: 360px; }
  .scale-note, .key-strip {
    display: block; position: static; max-width: none; text-shadow: none; pointer-events: auto;
    background: #0d0f2e; border-top: 1px solid rgba(255, 255, 255, .06); font-size: 12.5px;
  }
  .scale-note { order: 3; padding: 2px 12px 8px; border-top: 0; }
  .key-strip { order: 2; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 12px 6px; }
  .key-strip li { gap: 6px; }
  .veil, .champion { bottom: auto; height: min(64svh, 580px); min-height: 360px; }
  .champion { height: auto; }
  .panel { height: auto; padding: 12px 12px; }
  .panel + .panel { border-left: 0; }
  .log { max-height: 250px; }
  .log li { grid-template-columns: 54px 12px minmax(0, 1fr); column-gap: 6px; font-size: 15.5px; }
  .reck td { width: 29%; }
  .reck-head { flex-direction: column; gap: 2px; }
  .reck-sub { white-space: normal; }

  .legend { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 72dvh; animation-name: sheet; }
  @keyframes sheet { from { opacity: 0; transform: translateY(24px); } }
  .foot { padding: 8px 12px 14px; }
}

@media (max-width: 380px) {
  h1 { font-size: 17px; }
  .quote-price { font-size: 16px; }
  #statusText { display: none; }
  .pill.status { width: 32px; padding: 0; justify-content: center; }
}

@media (max-height: 620px) and (min-width: 761px) {
  .panel { height: 150px; }
  .reck-verdict { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .beacon, .raven, .help.nudge { animation: none !important; }
  .mom-fill.bull, .mom-knot { transition: none; }
  .log li, .legend { animation: none; }
  .champion.show { animation: champ-still 2.9s linear both; }
  @keyframes champ-still { 0% { opacity: 0; } 8% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
  #battle { transition: none; }
}
