/* THE BIG BOARD — the trading floor (index.html #marketPanel, js/main.js).
   Desktop: list | chart + ticket. A phone held upright: the list fills the
   screen, a tap opens that stock as a full sheet with the order ticket at
   the thumb. A phone on its side: the two columns, compact. */

#marketPanel {
  --mk-up: #6dff8e; --mk-down: #ff6b6b; --mk-up-bg: rgba(109, 255, 142, 0.12); --mk-down-bg: rgba(255, 107, 107, 0.12);
  --mk-line: rgba(255, 255, 255, 0.09); --mk-card: rgba(255, 255, 255, 0.04); --mk-dim: #9aa3b5; --mk-ink: #eef1f6;
}
#marketPanel .market-panel { position: relative; }
#marketPanel .up { color: var(--mk-up); }
#marketPanel .down { color: var(--mk-down); }

/* ---------------------------------------------------------- the list */
#marketPanel .market-list { gap: 6px; padding-right: 2px; width: 330px; max-height: 470px; }
#marketPanel .mkt-row {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) 64px auto; align-items: center; gap: 10px;
  min-height: 56px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--mk-line);
  background: var(--mk-card); font-family: var(--ww-ui, system-ui, sans-serif); color: var(--mk-ink);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
#marketPanel .mkt-row:hover { background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.18); }
#marketPanel .mkt-row.sel { border-color: rgba(92, 242, 196, 0.65); background: rgba(92, 242, 196, 0.08); }
#marketPanel .mkt-row:active { transform: scale(0.99); }
#marketPanel .mkt-row .mkt-dot { width: 10px; height: 28px; border-radius: 4px; margin: 0; }
#marketPanel .mkt-id { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
#marketPanel .mkt-row .mkt-tick { width: auto; font: 700 16px/1.1 var(--ww-ui, system-ui, sans-serif); letter-spacing: 0.04em; }
#marketPanel .mkt-name { font-size: 11.5px; color: var(--mk-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0.02em; }
#marketPanel .mkt-name em { font-style: normal; color: #ffd84a; font-weight: 700; }
#marketPanel .mkt-spark { width: 64px; height: 26px; display: block; overflow: visible; }
#marketPanel .mkt-spark polyline { fill: none; stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
#marketPanel .mkt-spark.up polyline { stroke: var(--mk-up); }
#marketPanel .mkt-spark.down polyline { stroke: var(--mk-down); }
#marketPanel .mkt-q { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-width: 76px; }
#marketPanel .mkt-row .mkt-px { width: auto; font: 700 15px/1 var(--ww-ui, system-ui, sans-serif); color: var(--mk-ink); font-variant-numeric: tabular-nums; }
#marketPanel .mkt-row .mkt-ch {
  width: auto; font: 700 11.5px/1 var(--ww-ui, system-ui, sans-serif); padding: 4px 7px; border-radius: 6px; font-variant-numeric: tabular-nums;
}
#marketPanel .mkt-ch.up { background: var(--mk-up-bg); }
#marketPanel .mkt-ch.down { background: var(--mk-down-bg); }
#marketPanel .mkt-row .mkt-own { display: none; }

/* ---------------------------------------------------------- chart + ticket */
#marketPanel .mkt-back { display: none; }
#marketPanel .market-chart { height: 260px; border-radius: 12px; border: 1px solid var(--mk-line); background: rgba(5, 8, 14, 0.7); touch-action: pan-y; }
#marketPanel .market-sel-name { font: 700 17px/1.2 var(--ww-ui, system-ui, sans-serif); letter-spacing: 0.03em; }
#marketPanel .market-sel-price b { font-size: 30px; font-variant-numeric: tabular-nums; }
#marketPanel .market-chg { font-weight: 700; }

#marketPanel .market-trade {
  margin-top: 14px; padding: 14px; gap: 12px; border-radius: 14px; border: 1px solid var(--mk-line); background: var(--mk-card);
}
#marketPanel .mkt-trade-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
#marketPanel .market-trade-k { width: auto; font: 700 12px/1 var(--ww-ui, system-ui, sans-serif); letter-spacing: 0.16em; color: var(--mk-dim); }
#marketPanel .market-held { font-size: 13px; color: var(--mk-dim); text-align: right; }
#marketPanel .mkt-qty-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#marketPanel .mkt-stepper { display: flex; align-items: stretch; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.16); overflow: hidden; background: rgba(0, 0, 0, 0.35); }
#marketPanel .mkt-step {
  all: unset; cursor: pointer; width: 48px; height: 48px; display: grid; place-items: center;
  font: 600 24px/1 var(--ww-ui, system-ui, sans-serif); color: var(--mk-ink); background: rgba(255, 255, 255, 0.05); touch-action: manipulation;
}
#marketPanel .mkt-step:active { background: rgba(255, 255, 255, 0.16); }
#marketPanel .mkt-stepper .market-qty {
  width: 84px; height: 48px; box-sizing: border-box; border: 0; border-radius: 0; text-align: center; background: transparent;
  font: 700 20px/1 var(--ww-ui, system-ui, sans-serif); color: #fff; padding: 0; -moz-appearance: textfield; font-variant-numeric: tabular-nums;
}
#marketPanel .mkt-stepper .market-qty::-webkit-inner-spin-button, #marketPanel .mkt-stepper .market-qty::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
#marketPanel .mkt-chips { display: flex; gap: 6px; flex: 1; min-width: 0; }
#marketPanel .mkt-chips button {
  all: unset; cursor: pointer; flex: 1; min-width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--mk-line); background: rgba(255, 255, 255, 0.05); font: 700 13px/1 var(--ww-ui, system-ui, sans-serif); color: var(--mk-ink); touch-action: manipulation;
}
#marketPanel .mkt-chips button:hover { border-color: rgba(255, 255, 255, 0.25); }
#marketPanel .mkt-chips button:active { background: rgba(255, 255, 255, 0.16); }
#marketPanel .mkt-cost { font: 500 14px/1.3 var(--ww-ui, system-ui, sans-serif); color: var(--mk-dim); min-height: 18px; }
#marketPanel .mkt-cost b { color: var(--mk-ink); font-variant-numeric: tabular-nums; }
#marketPanel .mkt-cost i { font-style: normal; }
#marketPanel .mkt-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
#marketPanel .mkt-actions .btn { min-height: 54px; font-size: 18px; letter-spacing: 0.12em; border-radius: 14px; margin: 0; }
#marketPanel .mkt-sell { background: rgba(255, 107, 107, 0.12); border: 1px solid rgba(255, 107, 107, 0.55); color: #ffb3b3; }
#marketPanel .mkt-sell:hover:not(:disabled) { background: rgba(255, 107, 107, 0.22); }
#marketPanel .mkt-actions .btn:disabled { opacity: 0.38; cursor: default; }

#marketPanel .mkt-opt { border-top: 1px solid var(--mk-line); padding-top: 10px; }
#marketPanel .mkt-opt summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 36px; }
#marketPanel .mkt-opt summary::-webkit-details-marker { display: none; }
#marketPanel .mkt-opt summary::after { content: '▾'; margin-left: auto; color: var(--mk-dim); transition: transform 0.15s; }
#marketPanel .mkt-opt[open] summary::after { transform: rotate(180deg); }
#marketPanel .mkt-opt-sub { font-size: 13px; color: var(--mk-dim); }
#marketPanel .mkt-opt-row { flex-wrap: wrap; margin-top: 8px; }
#marketPanel .mkt-opt-row .market-qty { height: 44px; box-sizing: border-box; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(0, 0, 0, 0.35); width: 76px; }
#marketPanel .mkt-opt-row select.market-qty { width: auto; }
#marketPanel .mkt-opt-row .btn { min-height: 44px; flex: 1; }
#marketPanel .mkt-prem { text-align: left; margin-top: 8px; }
#marketPanel .market-msg { font-weight: 600; }

/* ---------------------------------------------------------- positions */
#marketPanel .market-positions { border-top: 1px solid var(--mk-line); }
#marketPanel .market-pos-head { letter-spacing: 0.16em; }
#marketPanel .mkt-pos { border-radius: 12px; border: 1px solid var(--mk-line); background: var(--mk-card); min-height: 48px; box-sizing: border-box; }
#marketPanel .mkt-mini { min-height: 36px; border-radius: 9px; border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(0, 0, 0, 0.3); padding: 0 12px; }

/* desktop: fit an ordinary laptop screen without scrolling */
@media (min-width: 761px) and (min-height: 521px) {
  #marketPanel .market-panel { padding-top: 22px; padding-bottom: 18px; }
  #marketPanel .market-body { margin-top: 10px; }
  #marketPanel .mkt-row { min-height: 50px; padding: 6px 12px; }
  /* the list is as tall as the chart column beside it, and scrolls */
  #marketPanel .market-body { align-items: stretch; }
  #marketPanel .market-list { max-height: none; contain: size; overflow-y: auto; }
  #marketPanel .market-chart { height: clamp(150px, calc(100vh - 620px), 260px); }
  #marketPanel .market-trade { margin-top: 10px; padding: 12px; gap: 10px; }
  #marketPanel .mkt-actions .btn { min-height: 48px; }
  #marketPanel .market-positions { margin-top: 10px; }
  #marketPanel .market-pos-list { max-height: 112px; }
}

/* ================================================= a phone, held upright */
@media (max-width: 760px) {
  #marketPanel.overlay { padding: 0; align-items: stretch; overflow: hidden; }
  #marketPanel .market-panel {
    max-width: none; width: 100%; height: 100dvh; max-height: none; margin: 0; border-radius: 0; border: 0; box-sizing: border-box;
    display: flex; flex-direction: column; overflow: hidden;
    padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 14px) 0 calc(env(safe-area-inset-left) + 14px);
  }
  /* header: name + close on one line, the clock one line under it, then the three numbers */
  #marketPanel .market-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'title close' 'port port'; gap: 8px 10px; flex: none; }
  #marketPanel .market-head > div:first-child { grid-area: title; min-width: 0; }
  #marketPanel .market-title { font-size: 26px; margin: 0; line-height: 1.05; }
  #marketPanel .market-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; margin-top: 3px; }
  #marketPanel .mkt-close { grid-area: close; align-self: start; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 12px; font-size: 0 !important; display: grid; place-items: center; }
  #marketPanel .mkt-close::before { content: '✕'; font-size: 18px; }
  #marketPanel .market-port { grid-area: port; margin: 0; gap: 8px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #marketPanel .market-port-row { text-align: left; padding: 9px 11px; border-radius: 12px; background: var(--mk-card); border: 1px solid var(--mk-line); min-width: 0; }
  #marketPanel .market-port-row span { font-size: 10px; letter-spacing: 0.14em; margin-bottom: 4px; white-space: nowrap; }
  #marketPanel .market-port-row b { font-size: 17px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

  /* positions sit above the list (what you own first), then every quote */
  #marketPanel .market-positions { order: 2; flex: none; margin-top: 12px; padding-top: 0; border: 0; }
  #marketPanel .market-pos-list { max-height: 30vh; }
  #marketPanel .market-body { order: 3; flex: 1; min-height: 0; margin-top: 10px; display: block; }
  #marketPanel .market-list { width: auto; max-height: none; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    padding-bottom: calc(env(safe-area-inset-bottom) + 16px); }
  #marketPanel .mkt-row { grid-template-columns: 8px minmax(0, 1fr) 70px auto; min-height: 64px; padding: 10px 12px; }
  #marketPanel .mkt-spark { width: 70px; }
  #marketPanel .mkt-pos { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: 'tick what btn' 'tick val btn'; gap: 2px 10px; padding: 8px 10px; }
  #marketPanel .mkt-pos .mkt-tick { grid-area: tick; width: auto; font-weight: 700; }
  #marketPanel .mkt-pos span:nth-child(2) { grid-area: what; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #marketPanel .mkt-pos span:nth-child(3) { display: none; }
  #marketPanel .mkt-pos span:nth-child(4) { grid-area: val; font-size: 13px; font-weight: 700; }
  #marketPanel .mkt-pos .mkt-mini { grid-area: btn; min-height: 40px; }

  /* the sheet: one stock, full screen, ticket at the bottom */
  #marketPanel .market-main {
    position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch; background: #0c1018;
    padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 14px) 0 calc(env(safe-area-inset-left) + 14px);
    transform: translateX(100%); visibility: hidden; transition: transform 0.26s cubic-bezier(.2, .9, .25, 1), visibility 0s linear 0.26s;
  }
  #marketPanel .market-panel.detail .market-main { transform: none; visibility: visible; transition: transform 0.26s cubic-bezier(.2, .9, .25, 1); }
  #marketPanel .mkt-back {
    display: inline-flex; align-items: center; align-self: flex-start; min-height: 44px; padding: 0 14px 0 8px; margin: 0 0 6px -8px;
    border: 0; background: transparent; color: #5cf2c4; font: 700 16px/1 var(--ww-ui, system-ui, sans-serif); cursor: pointer; flex: none;
  }
  #marketPanel .market-chart-head { flex-direction: column; align-items: flex-start; gap: 6px; flex: none; }
  #marketPanel .market-sel-name { font-size: 15px; color: var(--mk-dim); }
  #marketPanel .market-sel-price { display: flex; align-items: baseline; gap: 10px; }
  #marketPanel .market-sel-price b { font-size: 40px; line-height: 1; }
  #marketPanel .market-chg { display: inline-block; margin: 0; font-size: 15px; }
  #marketPanel .market-chart { height: 210px; flex: none; margin-top: 10px; }
  #marketPanel .market-hint { font-size: 11.5px; }
  #marketPanel .market-trade { margin: 12px 0 0; flex: none; }
  #marketPanel .market-msg { flex: none; min-height: 22px; margin: 8px 0 0; text-align: center; }
  /* the buttons ride the bottom of the sheet, at the thumb */
  #marketPanel .mkt-actions {
    position: sticky; bottom: 0; z-index: 2; margin: 0 -14px; padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px);
    background: linear-gradient(180deg, rgba(12, 16, 24, 0), rgba(12, 16, 24, 0.96) 30%);
  }
  #marketPanel .market-trade { padding-bottom: 0; overflow: visible; order: 6; margin-top: auto; }
  #marketPanel .market-msg { order: 5; }
  #marketPanel .mkt-opt { padding-bottom: calc(env(safe-area-inset-bottom) + 18px); }
  #marketPanel .market-hint { margin-bottom: 12px; }
  #marketPanel .mkt-qty-row { flex-direction: column; align-items: stretch; }
  #marketPanel .mkt-stepper .market-qty { flex: 1; width: auto; min-width: 0; }
  #marketPanel .mkt-step { width: 64px; height: 52px; }
  #marketPanel .mkt-stepper .market-qty { height: 52px; font-size: 22px; }
}

/* ================================================= a phone on its side */
@media (max-height: 520px) and (min-width: 600px) {
  #marketPanel.overlay { padding: 0; align-items: stretch; }
  #marketPanel .market-panel {
    max-width: none; width: 100%; height: 100dvh; max-height: none; margin: 0; border-radius: 0; border: 0; box-sizing: border-box; overflow-y: auto;
    display: flex; flex-direction: column; overscroll-behavior: contain;
    padding: 8px calc(env(safe-area-inset-right) + 12px) 0 calc(env(safe-area-inset-left) + 12px);
  }
  #marketPanel .market-head { flex: none; align-items: center; gap: 12px; }
  #marketPanel .market-title { font-size: 20px; margin: 0; }
  #marketPanel .market-sub { display: none; }
  #marketPanel .market-port-row b { font-size: 15px; }
  #marketPanel .mkt-close { min-height: 40px; }
  #marketPanel .market-body { flex: none; height: calc(100dvh - 64px); margin-top: 8px; align-items: stretch; }
  #marketPanel .market-list { width: 300px; max-height: none; height: 100%; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 12px; }
  #marketPanel .mkt-row { min-height: 52px; padding: 6px 10px; }
  #marketPanel .market-main { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(env(safe-area-inset-bottom) + 12px); }
  #marketPanel .market-chart { height: 150px; }
  #marketPanel .market-sel-price b { font-size: 24px; }
  #marketPanel .market-trade { padding: 10px; gap: 8px; margin-top: 8px; }
  #marketPanel .market-positions { flex: none; padding-bottom: calc(env(safe-area-inset-bottom) + 12px); }
  #marketPanel .mkt-actions .btn { min-height: 48px; }
}

/* the floor owns the screen: callouts that float over the city (the raid
   countdown, the radio dial) wait behind it */
body:has(#marketPanel:not(.hidden)) #raidCall,
body:has(#marketPanel:not(.hidden)) #raidBar,
body:has(#marketPanel:not(.hidden)) #raidBoard,
body:has(#marketPanel:not(.hidden)) #wwRadio { visibility: hidden !important; }
