:root {
  --back: #1c1c22;
  --window: #282830;
  --strip: #36363f;
  --selected: #484c7c;
  --text: #e8e8ee;
  --muted: #a0a0ac;
  --buy: #1e90ff;
  --sell: #ff6347;
  --profit: #32cd32;
  --loss: #ff6347;
  --breakeven: #ff00ff;
  --take: #ffd700;
  --danger: #b22222;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--back); color: var(--text);
  font: 15px/1.3 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; border: 0; border-radius: 8px; background: #4a4a56; padding: 10px 14px; }
button:active { filter: brightness(1.3); }
button.primary { background: var(--buy); color: #fff; }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: 6px 10px; font-size: 13px; }
[hidden] { display: none !important; }

/* No key */
#denied { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 24px; text-align: center; }
.brand { font-size: 26px; font-weight: 700; }
.hint { color: var(--muted); margin-bottom: 12px; }
.error { color: var(--loss); }

/* The page: the top bar, then the chart and the series. Upright the series are under the chart, on the side the
   series are to its right. */
#app { height: 100%; position: relative; display: flex; flex-direction: column; }
/* Taps are commands, not text selection: no selection, no long-press menu, no double-tap zoom. */
#app { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.strip, .newSeries, .tab, button { touch-action: manipulation; }
#main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* The chart takes the room left by the bar and the series; the computer draws the snapshot in exactly that size
   (the phone tells it), so the picture shows the whole chart. */
#chartBox { flex: 1; min-height: 0; position: relative; overflow: hidden; background: #000; touch-action: none; }
#chartImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform-origin: 0 0; }
#noImage { position: absolute; top: 45%; width: 100%; text-align: center; color: var(--muted); }
/* Back to the last bars of a chart scrolled back by a swipe: over the chart, left of its price scale. */
#toEnd { position: absolute; right: 64px; bottom: 30px; width: 44px; height: 44px; padding: 0; border-radius: 50%;
  background: rgba(28, 28, 34, .86); box-shadow: 0 2px 10px rgba(0, 0, 0, .5); color: #fff; font-size: 24px;
  font-weight: 700; line-height: 1; }
#takeLine { position: absolute; left: 0; height: 0; border-top: 2px solid var(--take); pointer-events: none; }

/* Top bar: the charts as tabs with their positions, then the result, the link and "close all" */
#top { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; white-space: nowrap;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px; background: var(--back); }
#charts { display: flex; gap: 6px; overflow-x: auto; min-width: 0; flex: 1 1 auto; }
.tab { padding: 6px 10px; background: var(--strip); font-weight: 700; color: var(--muted); }
.tab.active { background: var(--selected); color: #fff; }
.tab.offline { opacity: .55; }
.tab .count { display: inline-block; min-width: 20px; margin-left: 6px; padding: 0 5px; border-radius: 10px;
  background: var(--buy); color: #fff; font-size: 12px; text-align: center; }
#info { display: flex; align-items: center; gap: 8px; margin-left: auto; }
#total { font-weight: 700; }
#link { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
#closeAll { white-space: nowrap; }
#link .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
#link.ok .dot { background: var(--profit); }
#link.stale .dot { background: var(--loss); }
#link.stale { color: var(--loss); }

#banner { position: absolute; top: 8px; left: 8px; right: 8px;
  padding: 10px 12px; border-radius: 8px; background: rgba(255, 215, 0, .92); color: #222; font-weight: 600; }

/* A trade from the phone: the size of the trade and SELL / BUY with the prices, over the top left corner of the
   chart. The field takes text (the app itself has selection off); 16px keeps iOS from zooming into it. */
#trade { position: absolute; top: 8px; left: 8px; width: 184px; padding: 6px; border-radius: 10px;
  background: rgba(28, 28, 34, .86); box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
#trade .lotRow, #trade .sideRow { display: flex; gap: 6px; }
#trade .sideRow { margin-top: 6px; }
#trade .lotRow button { flex: none; width: 44px; padding: 6px 0; font-size: 20px; font-weight: 700; line-height: 1; }
#lotInput { flex: 1; min-width: 0; border: 0; border-radius: 8px; background: #111; color: var(--text);
  font: inherit; font-weight: 700; font-size: 16px; text-align: center; padding: 6px 2px;
  -webkit-user-select: text; user-select: text; }
#trade .sideRow button { flex: 1; min-width: 0; padding: 7px 2px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; color: #fff; }
#trade .sideRow b { font-size: 15px; }
#trade .sideRow span { font-size: 12px; opacity: .9; }
#trade.off .sideRow button { opacity: .45; }
button.sell { background: var(--sell); color: #fff; }
button.buy { background: var(--buy); color: #fff; }

/* The timeframe of the chart: a see-through button exactly the size of BUY, on its level, against the right edge of
   the chart area, upright and on the side. The app places it by the BUY button itself; the numbers here serve until
   BUY has been shown. A tap shows the timeframes under it. */
#tfButton { position: absolute; top: 53px; right: 0; width: 83px; height: 51px; padding: 0; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 8px 0 0 8px;
  background: rgba(74, 74, 86, .5); color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .8); }
#tfButton b { font-size: 15px; }
#tfButton span { font-size: 12px; opacity: .9; }
#tfButton.open { background: rgba(72, 76, 124, .8); }
#tfMenu { position: absolute; top: 110px; right: 0; display: grid; grid-template-columns: repeat(3, 58px); gap: 6px;
  padding: 6px; border-radius: 10px 0 0 10px; background: rgba(28, 28, 34, .8);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
#tfMenu button { padding: 9px 0; font-weight: 700; background: rgba(74, 74, 86, .9); }
#tfMenu button.active { background: var(--selected); color: #fff; }

/* Series */
#sheet { flex: none; max-height: 58%; display: flex; flex-direction: column; background: var(--window);
  border-radius: 14px 14px 0 0; padding-bottom: var(--safe-bottom); }
#sheet.collapsed { max-height: 34px; overflow: hidden; }
#sheetHandle { flex: none; background: none; padding: 10px 0 8px; border-radius: 0; }
#sheetHandle span { display: block; width: 44px; height: 5px; margin: auto; border-radius: 3px; background: #777; }
#series { overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 6px; }

@media (orientation: landscape) {
  #main { flex-direction: row; }
  #sheet { max-height: none; width: min(46%, 420px); flex-direction: row; border-radius: 14px 0 0 0; }
  #sheet.collapsed { max-height: none; width: 30px; }
  #sheetHandle { padding: 0 8px; }
  #sheetHandle span { width: 5px; height: 44px; }
  #series { flex: 1; min-width: 0; padding: 8px 8px 8px 0; }
  #sheet.collapsed #series { display: none; }
}

/* The list scrolls: a strip keeps its height (in a flex column it would shrink and cut its buttons). */
.strip { flex: none; display: flex; background: var(--strip); border-radius: 8px; overflow: hidden; }
.strip.selected { background: var(--selected); }
.strip.flash { animation: flash .7s ease-out; }
@keyframes flash { from { filter: brightness(1.9); } to { filter: brightness(1); } }
.square { width: 64px; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.square .number { font: 900 28px/1 "Arial Black", Arial, sans-serif; color: #fff; }
.square .side { font-weight: 700; font-size: 12px; color: #fff; margin-top: 4px; }
.body { flex: 1; min-width: 0; padding: 7px 9px; }
.row { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; }
.row + .row { margin-top: 3px; }
.title { font-weight: 700; }
.value { font-weight: 700; }
.label { color: #ddd; font-size: 13px; }
.buttons { display: flex; gap: 6px; margin-top: 7px; }
.buttons .close { margin-left: auto; }
.newSeries { flex: none; background: var(--strip); border-radius: 8px; padding: 12px; text-align: center; font-weight: 700;
  font-size: 18px; color: var(--muted); }
.newSeries.selected { background: var(--selected); color: #fff; }

/* Modal and toast */
#modal { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; }
#modal .box { width: 100%; background: var(--window); border-radius: 14px 14px 0 0; padding: 16px 14px
  calc(var(--safe-bottom) + 14px); }
#modalTitle { font-weight: 700; font-size: 18px; }
#modalText { margin: 10px 0 14px; color: #ddd; white-space: pre-line; font-size: 17px; }
#modalAdjust { display: flex; gap: 8px; margin-bottom: 14px; }
#modalAdjust button { flex: 1; }
#modal .buttons button { flex: 1; padding: 13px; }
#toast { position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 70px); padding: 12px;
  border-radius: 10px; background: #111; box-shadow: 0 4px 16px rgba(0, 0, 0, .5); text-align: center; }
#toast.bad { background: #5a1a1a; }
/* While a confirmation is open the answer of the computer shows at the top, not over its text. */
#modal:not([hidden]) ~ #toast { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 56px); }
