:root {
  color-scheme: dark;
  --ink: #eeefed;
  --muted: #a3abad;
  --subtle: #788184;
  --line: #ffffff19;
  --paper: #111416;
  --panel: #191d20;
  --teal: #81d5cb;
  --amber: #e8b877;
  --error: #ed9b91;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; letter-spacing: 0; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, a { -webkit-tap-highlight-color: transparent; }
button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; color: inherit; cursor: pointer; transition: color .15s ease, background-color .15s ease, border-color .15s ease; }
button:disabled { cursor: wait; opacity: .5; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--teal); outline-offset: 4px; }
.icon { display: block; flex: 0 0 auto; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#app { display: flex; flex-direction: column; height: 100svh; min-height: 790px; overflow: hidden; }

.topbar { display: flex; flex: 0 0 64px; align-items: center; gap: 32px; height: 64px; padding: 0 24px; background: #121517; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; white-space: nowrap; font-size: 25px; line-height: 1; }
.brand strong { font-weight: 720; }
.brand strong span, .fly-mark { color: var(--teal); }
.fly-mark .icon { width: 30px; height: 30px; stroke-width: 1.5; }
.edition { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.edition > span:first-child { color: var(--amber); font: 12px var(--mono); }
.edition > span + span { border-left: 1px solid var(--line); padding-left: 12px; }
.top-actions { display: flex; align-items: center; gap: 22px; margin-left: auto; }
.presence { color: var(--muted); font-size: 12px; white-space: nowrap; }
.presence::before { display: inline-block; width: 5px; height: 5px; margin: 0 8px 2px 0; background: var(--subtle); border-radius: 50%; content: ""; }
#app[data-connection="online"] .presence::before { background: var(--teal); }
#app[data-connection="offline"] .presence::before, #app[data-connection="error"] .presence::before { background: var(--amber); }
.top-actions button { height: 36px; padding: 0; border: 0; background: transparent; font-size: 13px; }
.top-actions button:hover { color: var(--teal); }
.top-actions #resync { width: 36px; border: 1px solid var(--line); border-radius: 6px; }
.top-actions #resync:hover { border-color: #ffffff40; background: #ffffff09; }
.top-actions #about .icon { width: 15px; height: 15px; color: var(--muted); }

.stage { position: relative; flex: 1 0 600px; min-width: 0; min-height: 600px; overflow: hidden; isolation: isolate; background: #181c1e; }
.world { position: absolute; inset: 0; overflow: hidden; }
.world canvas { display: block; width: 100%; height: 100%; }
.grid-floor { display: none; }
.left-tools { position: absolute; z-index: 2; top: 24px; left: 24px; display: grid; gap: 8px; }
.left-tools button { flex-direction: column; gap: 5px; width: 54px; height: 58px; padding: 7px 0; border: 1px solid var(--line); border-radius: 6px; background: #1b2022ed; color: #c8d0d0; box-shadow: 0 2px 8px #0000000d; }
.left-tools .icon { width: 20px; height: 20px; }
.left-tools small { font-size: 11px; line-height: 1.2; }
.left-tools button:hover { color: var(--ink); border-color: #81d5cb66; background: #293438; }
.left-tools button:active { background: #354446; }
.mode-pill { position: absolute; z-index: 2; top: 24px; right: 24px; display: grid; gap: 4px; width: 270px; min-height: 62px; padding: 11px 15px; border: 1px solid var(--line); border-radius: 5px; background: #171c1fe8; overflow-wrap: anywhere; }
.mode-pill strong { display: flex; align-items: center; gap: 8px; color: var(--ink); font: 600 12px/1.3 var(--mono); }
.mode-pill strong::before { display: block; flex: 0 0 5px; width: 5px; height: 5px; border-radius: 50%; background: currentColor; content: ""; }
.mode-pill span { color: var(--muted); font-size: 12px; line-height: 1.4; }
.mode-pill[data-status="running"] strong, .mode-pill[data-status="waiting"] strong { color: var(--teal); }
.mode-pill[data-status="halted"] strong, .mode-pill[data-status="error"] strong { color: var(--error); }
.mode-pill[data-status="stale"] strong, .mode-pill[data-status="offline"] strong { color: var(--amber); }

.observe { position: absolute; z-index: 2; top: 102px; right: 24px; width: 270px; max-height: calc(100% - 216px); padding: 17px 18px; overflow-x: hidden; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: #181d20f2; scrollbar-width: thin; scrollbar-color: #5b6568 transparent; }
.observe label { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; }
.watching { margin: 19px 0 0; color: var(--teal); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.observe h1 { margin: 6px 0 7px; font-size: 25px; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.chain { margin: 0; color: var(--muted); font: 12px/1.5 var(--mono); overflow-wrap: anywhere; }
.thinking { display: grid; gap: 8px; margin-top: 18px; padding: 15px 0 16px; border-block: 1px solid var(--line); font-size: 12px; line-height: 1.5; }
.thinking b { color: var(--ink); font-size: 13px; font-weight: 600; }
.thinking span { color: var(--muted); }
.thinking b, .thinking span { overflow-wrap: anywhere; }
.thinking span strong { color: #dce3e1; font: 500 12px var(--mono); }
.thinking progress { appearance: none; display: block; width: 100%; height: 3px; margin-top: 3px; border: 0; border-radius: 2px; overflow: hidden; background: #374043; color: var(--teal); }
.thinking progress::-webkit-progress-bar { background: #374043; }
.thinking progress::-webkit-progress-value { background: var(--teal); }
.thinking progress::-moz-progress-bar { background: var(--teal); }
.thinking progress[data-known="false"] { visibility: hidden; }
.state-details { display: grid; gap: 13px; margin: 17px 0 0; font-size: 12px; line-height: 1.5; }
.state-details > div { display: grid; grid-template-columns: minmax(79px, .85fr) minmax(0, 1.15fr); gap: 12px; }
.state-details dt { color: var(--muted); overflow-wrap: anywhere; }
.state-details dd { min-width: 0; margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.waiting { margin: 17px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--amber); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }

.live-log { position: absolute; z-index: 2; left: 24px; bottom: 118px; width: 326px; max-height: 170px; padding: 12px 13px; overflow: hidden; border: 1px solid #dce9e321; border-radius: 6px; background: #12191df5; color: #d5ddde; box-shadow: 0 6px 24px #00000024; pointer-events: none; }
.log-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; padding-bottom: 9px; margin-bottom: 9px; border-bottom: 1px solid #ffffff24; color: #e2e6e3; font-size: 12px; line-height: 1.4; }
.log-heading b { font-weight: 500; }
.log-heading span { max-width: 115px; margin-left: auto; color: #aebfc2; font-size: 11px; text-align: right; overflow-wrap: anywhere; }
.log-open { flex: 0 0 22px; width: 22px; height: 22px; margin: -2px -4px 0 -6px; padding: 0; border: 0; background: transparent; color: #c4d4d6; pointer-events: auto; }
.log-open .icon { width: 15px; height: 15px; }
.log-open:hover { color: var(--teal); }
.log-line { display: grid; grid-template-columns: 61px minmax(0, 1fr); gap: 10px; margin: 5px 0; font: 12px/1.5 var(--mono); }
.log-line time { color: #a4b1b3; }
.log-line span { min-width: 0; overflow-wrap: anywhere; }
.live-log .log-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state, .snapshot-note { margin: 10px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.snapshot-note { color: var(--amber); }
.camera { position: absolute; z-index: 3; bottom: 58px; left: 50%; display: flex; gap: 2px; max-width: calc(100% - 48px); padding: 4px; border: 1px solid #ffffff21; border-radius: 6px; background: #171c1ff2; transform: translateX(-50%); }
.camera button { height: 34px; min-width: 93px; padding: 0 13px; border: 0; border-radius: 3px; background: transparent; color: #a9b3b4; font-size: 12px; white-space: nowrap; }
.camera button:hover { color: var(--ink); background: #ffffff0b; }
.camera button.selected { color: var(--ink); background: #374346; box-shadow: inset 0 -2px var(--teal); }
.camera-number { color: var(--subtle); font: 11px var(--mono); }
.selected .camera-number { color: var(--teal); }
.stage-bottom { position: absolute; z-index: 2; bottom: 0; left: 24px; right: 24px; display: flex; align-items: center; gap: 16px; height: 48px; border-top: 1px solid var(--line); color: #b0babb; font-size: 12px; }
.stage-bottom b { margin-left: 9px; color: var(--ink); font: 500 12px var(--mono); }
.stage-bottom small { margin: 0 auto; color: #8b9698; font-size: 12px; }
.stage-bottom button { flex: 0 0 32px; width: 32px; height: 32px; padding: 0; margin-left: auto; border: 0; border-radius: 4px; background: transparent; color: #c6cfcf; }
.stage-bottom button:hover { color: var(--ink); background: #ffffff10; }

.tape { display: flex; flex: 0 0 auto; align-items: center; gap: 20px; min-height: 48px; padding: 10px 24px; border-block: 1px solid var(--line); background: #1a1e20; font-size: 12px; }
.tape-label { display: flex; flex: 0 0 auto; align-items: center; gap: 12px; padding-right: 20px; border-right: 1px solid var(--line); font-weight: 600; }
.tape-label small { color: var(--amber); font: 11px var(--mono); }
.run-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; min-width: 0; }
.run-summary > span { min-width: 0; color: var(--muted); overflow-wrap: anywhere; }
.run-summary b { margin-left: 8px; color: #d9dedd; font: 12px var(--mono); }
#snapshot-context { margin-left: auto; color: var(--muted); white-space: nowrap; }
.dock { display: flex; flex: 0 0 auto; align-items: center; gap: 24px; min-height: 78px; padding: 14px 24px; background: #121517; }
.dock > div { display: grid; gap: 4px; min-width: 0; max-width: 55%; }
#dock-status { color: var(--ink); font: 500 12px var(--mono); }
#dock-context { overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.dock nav { display: flex; flex: 0 0 auto; gap: 18px; margin-left: auto; }
.dock nav button { height: 36px; padding: 0 6px; border: 0; border-radius: 4px; background: transparent; color: #c0c9cb; font-size: 13px; }
.dock nav button .icon { width: 16px; height: 16px; color: #8e9c9e; }
.dock nav button:hover { background: #ffffff09; color: var(--ink); }
.dock nav button:hover .icon { color: var(--teal); }

dialog { width: 560px; max-width: calc(100% - 32px); max-height: calc(100svh - 40px); padding: 26px; overflow: auto; border: 1px solid #ffffff29; border-radius: 8px; background: #1b2023; color: var(--ink); box-shadow: 0 24px 90px #00000066; }
dialog::backdrop { background: #07090bc7; }
dialog > small { color: var(--teal); font: 12px var(--mono); }
dialog h2 { margin: 10px 36px 18px 0; font-size: 23px; font-weight: 600; line-height: 1.3; }
dialog p { color: #c0c8cb; font-size: 14px; line-height: 1.65; }
dialog .state-details { gap: 14px; font-size: 13px; }
dialog .state-details > div { grid-template-columns: minmax(104px, .8fr) minmax(0, 1.2fr); gap: 20px; }
dialog .close { float: right; width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: transparent; color: #c9d1d2; }
dialog .close:hover { color: var(--ink); background: #ffffff0c; }
.detail-events { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); }
.detail-events .log-line { margin: 10px 0; color: #d0d8d8; }
.detail-events time { color: var(--muted); }

.orders-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; min-height: 18px; padding: 0 4px; border: 1px solid #ffffff26; border-radius: 4px; color: var(--teal); font: 11px var(--mono); }
.orders-count[hidden] { display: none; }
#detail-dialog[data-panel="receipts"] { width: 620px; }
.order-source { margin-bottom: 22px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.order-source-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #d3dcdd; font-size: 13px; }
.source-tag { padding: 3px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font: 11px var(--mono); }
.source-tag[data-status="available"] { color: var(--teal); border-color: #60cdc533; background: #60cdc509; }
.source-tag[data-status="unavailable"] { color: var(--amber); border-color: #d6a65644; }
dialog p.source-time { margin: 8px 0 0; color: var(--muted); font: 11px/1.6 var(--mono); overflow-wrap: anywhere; }
dialog p.detail-note { margin: 18px 0; color: #aab9be; font-size: 12px; line-height: 1.65; }
dialog .detail-section-title { margin: 25px 0 17px; padding-top: 21px; border-top: 1px solid var(--line); color: #e2e8e7; font-size: 14px; font-weight: 500; }
dialog .order-source .snapshot-note, dialog .order-source .empty-state { margin: 10px 0 0; font-size: 12px; }
.receipt-list { display: grid; gap: 10px; margin-top: 22px; }
.receipt-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; width: 100%; min-width: 0; padding: 15px; border: 1px solid #ffffff20; border-radius: 6px; background: #12191c; color: var(--ink); text-align: left; }
.receipt-row:hover, .receipt-row:focus-visible { border-color: #67c8be80; background: #192529; }
.receipt-row:disabled { cursor: default; opacity: .7; }
.receipt-row-heading { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }
.receipt-row-heading strong { font: 500 13px var(--mono); }
.receipt-pair { grid-column: 1 / -1; color: #c0cdce; font: 12px/1.6 var(--mono); overflow-wrap: anywhere; }
.receipt-row time { min-width: 0; color: var(--muted); font: 11px/1.5 var(--mono); overflow-wrap: anywhere; }
.receipt-open { align-self: end; color: #b4d7d1; font-size: 11px; white-space: nowrap; }
.order-state { display: inline-block; width: fit-content; margin: 0; padding: 4px 7px; border: 1px solid #ffffff20; border-radius: 4px; color: #c4cfd0; font: 11px/1.4 var(--mono); }
dialog > div > p.order-state { margin: 0 0 20px; font: 11px/1.4 var(--mono); }
.order-state[data-order-state="CONFIRMED"] { color: var(--teal); border-color: #67c8be55; background: #67c8be08; }
.order-state[data-order-state="SUBMISSION_UNKNOWN"], .order-state[data-order-state="PENDING"], .order-state[data-order-state="DISPATCHING"] { color: var(--amber); border-color: #d6a65644; }
.order-state[data-order-state="FAILED"] { color: #e8a59b; border-color: #b879703d; }
.receipt-back { margin: 0 0 20px; padding: 0; border: 0; background: transparent; color: #afd8d1; font-size: 12px; line-height: 2; }
.receipt-back:hover { color: var(--teal); }
.receipt-transaction { display: grid; gap: 9px; margin-top: 20px; font: 12px/1.6 var(--mono); }
.detail-label { color: var(--muted); font: 13px sans-serif; }
.transaction-link { color: #9ed9d0; text-decoration-color: #9ed9d04d; text-underline-offset: 3px; overflow-wrap: anywhere; }
.transaction-link:hover { color: #c6f3eb; }
.receipt-transaction small { color: var(--muted); font: 11px/1.5 var(--mono); }
.position-list { display: grid; gap: 0; }
.position-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(70px, .5fr); gap: 16px; padding: 15px 0; border-bottom: 1px solid var(--line); font: 12px/1.6 var(--mono); }
.position-token { min-width: 0; color: #bccbce; overflow-wrap: anywhere; }
.position-amount { min-width: 0; color: #e6eeea; text-align: right; overflow-wrap: anywhere; }

@media (min-width: 1101px) {
  .stage[data-camera="character"] .live-log { left: 96px; top: 24px; bottom: auto; }
}

@media (max-width: 1100px) and (min-width: 761px) {
  .edition { display: none; }
  .top-actions { gap: 18px; }
  .mode-pill, .observe { right: 18px; width: 260px; }
  .live-log { top: 18px; left: 92px; bottom: auto; width: 286px; }
  .stage[data-camera="character"] .live-log { width: 244px; }
  .camera { left: calc(50% - 100px); }
  .camera button { min-width: 82px; padding: 0 9px; }
  .stage-bottom small { display: none; }
  .tape { gap: 16px; }
  .tape-label { padding-right: 16px; }
  #snapshot-context { display: none; }
}

@media (min-width: 761px) and (max-height: 820px) {
  #app { min-height: 650px; }
  .topbar { height: 56px; flex-basis: 56px; }
  .stage { flex: 1 1 auto; min-height: 460px; }
  .left-tools { top: 18px; gap: 6px; }
  .left-tools button { height: 48px; gap: 3px; }
  .left-tools small { font-size: 10px; }
  .mode-pill { top: 18px; }
  .observe { top: 96px; max-height: calc(100% - 194px); }
  .camera { bottom: 54px; }
  .tape { min-height: 44px; padding-block: 8px; }
  .dock { min-height: 64px; padding-block: 10px; }
}

@media (max-width: 760px) {
  #app { height: auto; min-height: 100svh; overflow: visible; }
  #app:fullscreen { height: 100dvh; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
  .topbar { gap: 10px; padding: 0 16px; }
  .brand { gap: 8px; font-size: 23px; }
  .fly-mark .icon { width: 25px; height: 25px; }
  .edition, .presence { display: none; }
  .top-actions { gap: 14px; }
  .top-actions #resync { width: 32px; height: 32px; }
  .top-actions #about { font-size: 13px; }
  .top-actions #about .icon { display: none; }
  .stage { display: flex; flex: none; flex-direction: column; min-height: 0; padding-top: 440px; overflow: visible; }
  .world { inset: 0 0 auto; height: 440px; }
  .left-tools { top: 77px; left: 12px; display: flex; gap: 6px; }
  .left-tools button { width: 38px; height: 36px; gap: 4px; padding: 0; }
  .left-tools .icon { width: 19px; height: 19px; }
  .left-tools small { display: none; }
  .mode-pill { top: 14px; left: 12px; right: 12px; width: auto; max-width: none; min-height: 51px; padding: 9px 12px; }
  .mode-pill span { font-size: 12px; }
  .camera { top: 382px; bottom: auto; width: calc(100% - 24px); max-width: 420px; gap: 0; }
  .camera button { flex: 1; min-width: 0; height: 36px; padding: 0 5px; gap: 5px; font-size: 12px; }
  .camera-number { display: none; }
  .observe { position: relative; top: auto; right: auto; width: auto; max-height: none; margin: 0; padding: 24px 20px; overflow: visible; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: #1a1f22; }
  .observe label { font-size: 12px; }
  .watching { margin-top: 15px; font-size: 13px; }
  .observe h1 { font-size: 25px; }
  .thinking { margin-top: 18px; font-size: 13px; }
  .state-details { gap: 14px; font-size: 13px; }
  .state-details > div { grid-template-columns: minmax(110px, .85fr) minmax(0, 1.15fr); gap: 20px; }
  .waiting { font-size: 13px; }
  .live-log { position: relative; left: auto; bottom: auto; width: auto; max-height: 220px; padding: 20px; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: #161b1e; box-shadow: none; }
  .log-heading { margin-bottom: 12px; font-size: 13px; }
  .log-line { margin: 7px 0; }
  .stage-bottom { position: relative; bottom: auto; left: auto; right: auto; height: auto; min-height: 48px; padding: 10px 16px; gap: 10px; background: #161b1e; }
  .stage-bottom > span { min-width: 0; }
  .stage-bottom small { display: none; }
  .stage-bottom b { margin-left: 5px; }
  .tape { align-items: start; flex-wrap: wrap; gap: 12px; padding: 16px; }
  .tape-label { width: 100%; padding: 0; border: 0; }
  .run-summary { display: grid; width: 100%; gap: 8px; }
  .run-summary > span { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; }
  .run-summary b { margin: 0; }
  #snapshot-context { width: 100%; margin: 0; white-space: normal; }
  .dock { min-height: 0; flex-wrap: wrap; gap: 14px; padding: 17px 16px 18px; }
  .dock > div { max-width: 100%; width: 100%; }
  .dock nav { justify-content: space-between; width: 100%; gap: 8px; margin-left: 0; padding-top: 10px; border-top: 1px solid var(--line); }
  .dock nav button { padding: 0; font-size: 12px; }
  dialog { max-width: calc(100% - 24px); padding: 20px; }
  dialog .state-details { font-size: 12px; }
  dialog .state-details > div { grid-template-columns: minmax(86px, .8fr) minmax(0, 1.2fr); gap: 15px; }
  .receipt-row { gap: 9px 8px; padding: 12px; }
  .receipt-row-heading { align-items: start; gap: 8px; }
  .receipt-row-heading .order-state { max-width: 180px; font-size: 10px; }
  .receipt-pair { font-size: 11px; }
  .position-row { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .position-amount { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
