:root {
  color-scheme: light;
  --stage-bg: #fff7e9;
  --stage-panel: #fffaf2;
  --stage-tile: #fff9ef;
  --stage-selected: #fff0bb;
  --stage-border: #ead8c9;
  --stage-rim: #d9bfa9;
  --stage-ink: #17264f;
  --stage-mist: #677087;
  --stage-gold: #ffd334;
  --stage-gold-surface: linear-gradient(165deg, #ffe775 0%, #ffd333 48%, #ffc400 100%);
  --stage-mint-surface: linear-gradient(155deg, #e4fbf2, #bcebdc);
  --stage-highlight: #233760;
  --stage-success: #0c6c57;
  --stage-mint: #dcf5e9;
  --stage-error: #aa343e;
  --stage-coral: #ff997f;
  --stage-shadow: 0 6px 20px #50391d0a, 0 2px 3px #50391d08;
  --stage-font: "MiSans", "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei UI", sans-serif;
  --stage-top: max(8px, env(safe-area-inset-top, 0px));
  --stage-right: max(12px, env(safe-area-inset-right, 0px));
  --stage-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  --stage-left: max(12px, env(safe-area-inset-left, 0px));
  --stage-width: calc(100vw - var(--stage-left) - var(--stage-right));
  --stage-height: calc(100dvh - var(--stage-top) - var(--stage-bottom));
}

.stage-panel {
  box-sizing: border-box;
  border: 1px solid var(--stage-rim);
  border-radius: 32px; box-shadow: inset 0 2px 0 #fffdf8, 0 18px 54px #65413324, 0 4px 0 #d3ae8c33;
  background: radial-gradient(ellipse at 12% 0%, #fffefb 0%, transparent 60%), linear-gradient(145deg, #fff9f0, #fff5e9 58%, #fff9f4);
  color: var(--stage-ink); color-scheme: light;
  font: 14px/1.5 var(--stage-font);
}
.stage-panel *, .stage-panel *::before { box-sizing: border-box; }
.stage-panel [hidden] { display: none !important; }
dialog.stage-panel {
  position: fixed; inset: var(--stage-top) var(--stage-right) var(--stage-bottom) var(--stage-left);
  margin: auto; width: min(var(--stage-panel-width, 388px), var(--stage-width));
  max-width: none; max-height: var(--stage-height);
}
dialog.stage-panel::backdrop { background: #202a4870; backdrop-filter: blur(4px); }
.stage-header {
  display: flex; align-items: center; gap: 8px; flex: none; padding-bottom: 8px;
  border-bottom: 1px solid var(--stage-border);
}
.stage-title { margin: 0; font-size: 22px; font-weight: 850; letter-spacing: -.035em; line-height: 1.25; }
.stage-network-mode {
  flex: none; padding: 4px 10px; border: 1px solid var(--stage-border); border-radius: 999px;
  color: var(--stage-success); background: var(--stage-mint);
  font-size: 12px; line-height: 1.4; font-weight: 600; white-space: nowrap;
}
.stage-network-mode:empty { display: none; }
.stage-panel :focus-visible { outline: 2px solid var(--stage-highlight); outline-offset: -2px; }
.stage-panel .stage-title:focus { outline: 0; }

:is(a, button).stage-command, .room-flow :is(button, summary) {
  --command-fill: linear-gradient(165deg,#fffefb,#fff5e9);
  --command-rim: var(--stage-rim);
  position: relative; isolation: isolate; border: 1px solid var(--command-rim); border-radius: 999px;
  background: var(--command-fill); color: var(--stage-ink); box-shadow: inset 0 2px #fffdf9, 0 3px 0 #a37c5025, 0 5px 10px #a37c500c;
  font-weight: 700; transition: background .15s, border-color .15s, box-shadow .15s;
}
:is(.stage-command, .room-flow :is(button, summary))::before {
  content: none;
}
.stage-command.primary, .room-flow .flow-primary {
  --command-fill: var(--stage-gold-surface);
  --command-rim: #efbd25;
  color: var(--stage-ink); font-weight: 850;
  box-shadow: 0 4px 0 #d5a62730, 0 7px 14px #b98d2514, inset 0 2px #fff7c1;
}
:is(.stage-command, .room-flow :is(button, summary)):focus-visible { outline: 3px solid #20656b; outline-offset: 2px; }
:is(.stage-command, .room-flow :is(button, summary)):not(:disabled):hover { border-color: #c5a580; box-shadow: 0 4px 12px #50391d14; }
:is(.stage-command, .room-flow :is(button, summary)):not(:disabled):active { filter: brightness(.97); box-shadow: none; }
@media (prefers-reduced-motion: reduce) { :is(a, button).stage-command, .room-flow :is(button, summary) { transition: none; } }

.room-flow {
  --flow-padding: 20px;
  overflow: hidden; padding: var(--flow-padding);
}
.room-flow[data-step="pick"] { --stage-panel-width: 660px; }
.room-flow[data-step="settings"] { --stage-panel-width: 536px; }
.room-flow[data-step="upload"] { --stage-panel-width: 536px; }
.room-flow[data-step="network"] { --stage-panel-width: 480px; }
.room-flow form {
  display: flex; flex-direction: column; gap: 8px;
  max-height: calc(var(--stage-height) - 2 * var(--flow-padding) - 3px);
}
.room-flow #flow-note { color: var(--stage-mist); font-size: 12px; }
.room-flow #flow-capacity {
  margin-left: auto; padding: 2px 8px; border: 1px solid var(--stage-rim); border-radius: 3px;
  background: var(--stage-mint); color: var(--stage-success); white-space: nowrap;
}
.flow-content { min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.room-flow footer { display: flex; gap: 8px; flex: none; margin: 0; }
.room-flow button, .room-flow summary {
  min-height: 44px; margin: 0; padding: 0 10px; cursor: pointer; font: inherit;
}
.room-flow button:disabled { opacity: .55; cursor: default; }
.room-flow footer button { flex: 1; white-space: nowrap; }
.room-flow #flow-run { flex: 1.15; }
.flow-picker {
  display: grid; grid-template-columns: minmax(132px, 35%) minmax(0, 1fr); gap: 10px;
  height: clamp(112px, calc(var(--stage-height) - 122px), 216px);
}
.flow-catalog { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 6px; min-width: 0; min-height: 0; }
.flow-catalog-tools { display: flex; gap: 6px; }
.flow-catalog-tools input { flex: 1; }
.flow-catalog-tools button { flex: none; padding-inline: 8px; white-space: nowrap; }
.flow-games {
  display: grid; align-content: start; gap: 6px; overflow: auto; overscroll-behavior: contain;
  padding-right: 1px; scrollbar-width: thin;
}
.flow-games p { margin: 6px; color: var(--stage-mist); font-size: 13px; }
.flow-games button {
  --command-fill: var(--stage-tile);
  --command-rim: var(--stage-border);
  display: grid; grid-template-columns: 56px minmax(0, 1fr); align-items: center; gap: 7px;
  width: 100%; min-height: 48px; text-align: left; padding: 5px 7px;
}
.flow-games button[aria-pressed="true"] { --command-fill: var(--stage-selected); --command-rim: var(--stage-gold); }
.flow-access label:has(:checked) { background: var(--stage-selected); border-color: var(--stage-gold); }
.flow-games button > span:last-child, .flow-preview strong, .flow-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-games button > span:last-child, .flow-summary strong { font-size: 13px; }
.flow-games button small { display: block; color: var(--stage-mist); }
.flow-thumbnail { position: relative; height: 38px; overflow: hidden; border-radius: 2px; background: var(--stage-bg); }
.flow-preview { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.flow-stage {
  flex: 1; position: relative; min-height: 54px; overflow: hidden; border: 1px solid var(--stage-border);
  border-radius: 16px; background: var(--stage-tile);
}
.flow-stage:empty::before { content: "暂无预览"; display: grid; height: 100%; place-items: center; color: var(--stage-mist); }
.flow-download-placeholder { display: grid; place-items: center; color: var(--stage-mist); }
.flow-download-placeholder svg { display: block; width: 24px; height: 24px; }
.flow-download-arrow { color: var(--stage-gold); }
.flow-stage > .flow-download-placeholder svg { width: 48px; height: 48px; }
:is(.flow-stage, .flow-thumbnail) > .flow-download-placeholder,
.flow-thumbnail > canvas, .game-preview, .game-preview canvas {
  position: absolute; inset: 0; pointer-events: none;
}
.flow-thumbnail > canvas, .game-preview canvas {
  display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated;
}
.flow-stage:has(> .game-preview.is-playing) > .flow-download-placeholder,
.flow-thumbnail:has(> canvas, > .game-preview.is-playing) > .flow-download-placeholder {
  display: none;
}
.game-preview [hidden] { display: none; }
.game-preview {
  display: grid; place-items: center; overflow: hidden;
  background: var(--stage-bg); color: var(--stage-mist); font: 14px/1.4 system-ui, sans-serif;
}
.game-preview p { margin: 8px; text-align: center; }
.flow-settings { display: grid; gap: 8px; min-width: 0; padding: 0; margin: 0; border: 0; }
.flow-upload-form { display: grid; gap: 8px; min-width: 0; padding: 0; margin: 0; border: 0; }
.flow-upload-form label { display: grid; gap: 4px; }
.flow-upload-form progress { width: 100%; accent-color: var(--stage-gold); }
.flow-upload-usage { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flow-upload-usage button { flex: none; }
#flow-upload-quota, #flow-upload-limit { margin: 0; font-size: 13px; }
#flow-upload-quota { color: var(--stage-mist); }
#flow-upload-limit { color: var(--stage-highlight); }

.upload-library { --stage-panel-width: 500px; padding: 12px; overflow: hidden; }
.upload-library[open] { display: flex; flex-direction: column; gap: 8px; }
.upload-library :is(header, p, footer) { flex: none; }
.upload-library :is(#upload-library-usage, #upload-library-confirm, #upload-library-error) { margin: 0; font-size: 13px; overflow-wrap: anywhere; }
.upload-library #upload-library-usage { color: var(--stage-mist); }
.upload-library #upload-library-error { color: var(--stage-error); }
.upload-library ul {
  display: grid; align-content: start; gap: 5px; min-height: 0; max-height: 320px;
  margin: 0; padding: 0; list-style: none; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin;
}
.upload-library li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--stage-border); border-radius: 12px; background: var(--stage-tile);
}
.upload-library li > div { min-width: 0; overflow-wrap: anywhere; }
.upload-library li small { display: block; margin-top: 2px; color: var(--stage-mist); }
.upload-library footer { display: flex; justify-content: flex-end; gap: 8px; }
.upload-library .stage-command { flex: none; min-height: 44px; padding-inline: 12px; font: inherit; cursor: pointer; }
.upload-library .upload-delete { --command-rim: #e4b9ae; --command-fill: #fff0eb; color: var(--stage-error); }
.upload-library button:disabled { opacity: .55; cursor: default; }
.flow-summary {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 6px 8px; border: 1px solid var(--stage-border); border-left: 2px solid var(--stage-gold);
  border-radius: 14px; background: var(--stage-tile);
}
.flow-summary .flow-download-placeholder { height: 34px; border-radius: 3px; background: var(--stage-bg); }
.flow-code { display: grid; justify-items: end; gap: 1px; color: var(--stage-mist); font-size: 11px; }
.flow-code output { color: var(--stage-highlight); font: 750 16px ui-monospace, Consolas, monospace; white-space: nowrap; }
.flow-access, .flow-fields { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.flow-access label {
  display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 5px 8px;
  background: var(--stage-tile); border: 1px solid var(--stage-border); border-radius: 14px; cursor: pointer;
}
.flow-access label span { display: grid; }
.flow-access small { color: var(--stage-mist); font-size: 11px; }
.flow-network .flow-access label { min-height: 56px; }
.flow-network .flow-access label:has(input:checked) {
  border-color: var(--stage-gold); background: var(--stage-selected);
}
.flow-network .flow-access small { font-size: 12px; }
.room-flow .flow-access input { width: 16px; height: 16px; min-height: 0; flex: none; margin: 0; padding: 0; accent-color: var(--stage-gold); }
.flow-fields label { display: grid; gap: 4px; font-size: 13px; }
.flow-pin { display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: center; gap: 4px 12px; padding-block: 4px; }
.flow-pin-mark {
  grid-row: span 2; display: grid; place-items: center; width: 48px; height: 48px;
  color: var(--stage-highlight); border: 1px solid var(--stage-rim); border-radius: 50%; background: var(--stage-selected);
}
.flow-pin label { font-weight: 700; }
.flow-pin p { margin: 0; color: var(--stage-mist); font-size: 12px; }
.room-flow #flow-pin { grid-column: 1 / -1; margin-top: 5px; text-align: center; letter-spacing: .35em; }
.flow-save-note { margin: 0; color: var(--stage-mist); font-size: 12px; }
.stage-panel .stage-input, .room-flow :is(select, input:not([type="radio"])) {
  width: 100%; min-width: 0; min-height: 44px; padding: 6px 10px; border: 1px solid var(--stage-border);
  background: var(--stage-panel); color: var(--stage-ink); border-radius: 12px; font: inherit; font-size: 16px;
}
.stage-panel input::placeholder { color: var(--stage-mist); }
.room-flow summary { display: list-item; padding: 12px 10px; }
.room-flow #flow-status, .room-flow #flow-error { flex: none; margin: 0; font-size: 13px; }
.room-flow #flow-status { color: var(--stage-mist); }
.room-flow #flow-error { color: var(--stage-error); }
@media (max-height: 340px) {
  .room-flow { --flow-padding: 12px; }
  .room-flow[data-step="settings"] { --flow-padding: 10px; }
  .room-flow[data-step="settings"] form { gap: 6px; }
  .room-flow[data-step="settings"] header { padding-bottom: 4px; }
  .flow-settings { gap: 4px; }
  .flow-summary { padding-block: 3px; }
  .flow-access label { min-height: 44px; }
  .flow-fields label { gap: 2px; }
  .flow-save-note { font-size: 11px; }
  .room-flow:has(:is(#flow-status, #flow-error):not([hidden])) .flow-save-note { display: none; }
}
@media (orientation: portrait) {
  html:not(.virtual-landscape) .room-flow { display: none; }
  html:not(.virtual-landscape) dialog.room-flow::backdrop { background: transparent; }
}
