:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2230;
  --line: #2a3240;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4c8dff;
  --accent-2: #7c5cff;
  --ok: #2ecc8f;
  --warn: #f0a020;
  --err: #ff6b6b;
  --radius: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --panel-2: #f7f9fc;
    --line: #dfe4ec;
    --text: #1a2029;
    --muted: #6b7684;
  }
}

* { box-sizing: border-box; }

/* 下方 .stage video 等规则带 display，会盖掉 UA 的 [hidden]，这里统一兜住。 */
[hidden] { display: none !important; }

/* ---------- 登录门 ---------- */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: 20px; background: var(--bg); z-index: 100;
}
.gate-card {
  width: 100%; max-width: 380px; padding: 30px 28px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; text-align: center;
}
.gate-logo {
  width: 54px; height: 54px; margin: 0 auto 16px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 19px; font-weight: 700; color: #fff;
}
.gate-card h1 { margin: 0 0 5px; font-size: 19px; }
.gate-sub { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.gate-input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px; text-align: center;
  font: inherit; font-size: 15px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.gate-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,141,255,.15); }
.gate-card .alert { margin: 12px 0 0; text-align: left; }
.gate-card .hint { margin: 14px 0 0; }

/* ---------- 钱包 ---------- */
.topbar-right { display: flex; align-items: center; gap: 14px; }
.wallet {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 14px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px; white-space: nowrap;
}
.wallet-label { color: var(--muted); font-size: 12px; }
.wallet b { font-size: 15px; color: var(--ok); }
.linkbtn {
  cursor: pointer; font: inherit; font-size: 12.5px; color: var(--accent);
  background: none; border: none; padding: 0;
}
.linkbtn:hover { text-decoration: underline; }

/* ---------- 流水弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  padding: 20px; background: rgba(0, 0, 0, .55);
}
.modal-card {
  width: 100%; max-width: 460px; max-height: 76vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-close {
  cursor: pointer; font: inherit; font-size: 21px; line-height: 1;
  color: var(--muted); background: none; border: none;
}
.modal-close:hover { color: var(--text); }
.tx-list { overflow-y: auto; padding: 8px 18px 16px; }
.tx-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.tx-item:last-child { border-bottom: none; }
.tx-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tx-main b { font-size: 13.5px; font-weight: 600; }
.tx-amount { font-size: 14px; font-weight: 600; white-space: nowrap; }
.tx-in { color: var(--ok); }
.tx-out { color: var(--warn); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; }
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.center { text-align: center; }

.app { max-width: 1240px; margin: 0 auto; padding: 20px 20px 40px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 18px; margin-bottom: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.brand { display: flex; align-items: center; gap: 13px; }
.logo {
  width: 42px; height: 42px; border-radius: 11px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 700; letter-spacing: .5px; color: #fff;
}
.topbar h1 { margin: 0; font-size: 17px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.status {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,204,143,.16); }
.status.bad .dot { background: var(--err); box-shadow: 0 0 0 3px rgba(255,107,107,.16); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 18px; align-items: start; }
/* minmax(0, …) 是关键：纯 fr 的最小值是 auto，视频的固有尺寸会把列撑到几万像素宽。 */
.layout > .panel { min-width: 0; }
@media (max-width: 980px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.panel-title {
  margin: 22px 0 12px; font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .8px;
}
.panel-title:first-child { margin-top: 0; }

/* ---------- fields ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span, .label-row { display: block; margin-bottom: 7px; font-size: 13.5px; font-weight: 500; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.counter { color: var(--muted); font-size: 12.5px; }

textarea, input[type="text"], select {
  width: 100%; padding: 10px 12px; color: var(--text); font: inherit;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
textarea:focus, input[type="text"]:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,141,255,.15);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 620px) { .grid2 { grid-template-columns: 1fr; } }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.switches { display: flex; flex-wrap: wrap; gap: 16px; margin: 4px 0 14px; }
.switchline { display: flex; align-items: center; gap: 7px; font-size: 13.5px; cursor: pointer; }
.switchline input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- chips / modes / ratios ---------- */
.examples { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-bottom: 4px; }
.chip {
  padding: 5px 11px; font: inherit; font-size: 12.5px; cursor: pointer;
  color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px;
}
.chip:hover { color: var(--text); border-color: var(--accent); }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 9px; }
.mode {
  display: flex; flex-direction: column; gap: 3px; padding: 11px 12px; text-align: left;
  font: inherit; cursor: pointer; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  transition: border-color .15s, background .15s;
}
.mode b { font-size: 13.5px; font-weight: 600; }
.mode small { color: var(--muted); font-size: 12px; }
.mode:hover { border-color: var(--accent); }
.mode.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-2));
}

.mode-body { margin-top: 12px; }

.ratios { display: flex; flex-wrap: wrap; gap: 8px; }
.ratio {
  display: flex; align-items: center; gap: 8px; padding: 7px 11px; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
.ratio:hover { border-color: var(--accent); }
.ratio.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel-2)); }
.ratio i { display: block; border: 1.5px solid currentColor; opacity: .75; border-radius: 2px; }

/* ---------- upload ---------- */
.slots { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.slot {
  border: 1.5px dashed var(--line); border-radius: 10px; padding: 12px;
  background: var(--panel-2); text-align: center; transition: border-color .15s;
}
.slot.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel-2)); }
.slot.filled { border-style: solid; border-color: var(--ok); }
.slot-title { font-size: 13px; font-weight: 600; }
.slot small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.slot-drop {
  margin-top: 9px; padding: 14px 8px; cursor: pointer;
  border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
}
.slot-drop:hover { border-color: var(--accent); }
.slot-drop input[type="file"] { display: none; }
.slot-preview { position: relative; margin-top: 9px; }
.slot-preview img, .slot-preview video { width: 100%; border-radius: 8px; display: block; max-height: 150px; object-fit: cover; background: #000; }
.slot-preview audio { width: 100%; margin-top: 6px; }
.slot-clear {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; cursor: pointer;
  border: none; border-radius: 50%; color: #fff; background: rgba(0,0,0,.66);
  font-size: 14px; line-height: 1;
}
.slot-name { display: block; margin-top: 6px; font-size: 11.5px; color: var(--muted); word-break: break-all; }
.ref-list { display: grid; gap: 10px; }
.ref-add {
  width: 100%; padding: 9px; cursor: pointer; font: inherit; font-size: 13px;
  color: var(--muted); background: var(--panel-2);
  border: 1px dashed var(--line); border-radius: 9px;
}
.ref-add:hover { color: var(--text); border-color: var(--accent); }

.ref-del {
  width: 100%; margin-top: 7px; padding: 7px; cursor: pointer; font: inherit; font-size: 12.5px;
  color: var(--muted); background: none;
  border: 1px solid var(--line); border-radius: 8px;
}
.ref-del:hover { color: var(--err); border-color: var(--err); }

/* ---------- cost ---------- */
.cost {
  margin: 16px 0 12px; padding: 13px 15px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
}
.cost-line { display: flex; justify-content: space-between; font-size: 13.5px; padding: 3px 0; color: var(--muted); }
.cost-line b { color: var(--text); font-weight: 600; }
.cost-line.total { margin-top: 7px; padding-top: 9px; border-top: 1px solid var(--line); font-size: 15px; }
.cost-line.total b { font-size: 19px; color: var(--accent); }

.submit {
  width: 100%; padding: 13px; cursor: pointer; font: inherit; font-size: 15px; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; border-radius: 10px; transition: opacity .15s, transform .1s;
}
.submit:hover:not(:disabled) { opacity: .92; }
.submit:active:not(:disabled) { transform: translateY(1px); }
.submit:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- stage ---------- */
/* ---------- 结果预览框 ---------- */
/* 外层负责居中，内层 .stage 跟随视频真实比例。
   宽度用 min(档位宽度, 档位高度 × 宽高比) 计算：
   横屏受宽度约束，竖屏受高度约束，两种朝向都不会撑出过大的框。 */
.stage-wrap { width: 100%; display: flex; justify-content: center; }

.stage {
  position: relative;  /* .stage-empty 用 absolute inset:0 定位，必须靠它建立包含块 */
  width: 100%;
  max-width: min(var(--size-w, 460px), calc(var(--size-h, 380px) * var(--stage-num, 1.7778)));
  aspect-ratio: var(--stage-ar, 16 / 9);
  border-radius: 10px; overflow: hidden;
  background: #000; border: 1px solid var(--line);
}
/* 尺寸档位：同时给出宽度与高度上限。
   「大」档的高度上限用 px 而非 vh —— vh 与无单位数值相乘后作为 max-width
   在 flex 容器里解析不可靠（实测竖屏会退化成只受宽度约束）。 */
.stage[data-size="small"]  { --size-w: 300px; --size-h: 240px; }
.stage[data-size="medium"] { --size-w: 460px; --size-h: 380px; }
.stage[data-size="large"]  { --size-w: 100%;  --size-h: 520px; }
/* 没有视频时固定 16:9，避免空状态塌成一条线 */
.stage:not(.has-video) { aspect-ratio: 16 / 9; }

.stage video {
  width: 100%; height: 100%; max-width: 100%;
  display: block; object-fit: contain;
}

/* 尺寸切换按钮 */
.size-switch { display: inline-flex; gap: 3px; margin-left: auto; }
.panel-title { display: flex; align-items: center; }
.size-switch button {
  padding: 3px 10px; cursor: pointer; font: inherit; font-size: 11.5px;
  color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px;
}
.size-switch button:hover { color: var(--text); border-color: var(--accent); }
.size-switch button.active {
  color: #fff; background: var(--accent); border-color: var(--accent);
}
.stage-empty {
  position: absolute; inset: 0; display: grid; place-content: center;
  justify-items: center; gap: 6px; color: var(--muted); text-align: center;
  /* 纯装饰层，不该拦截任何点击 */
  pointer-events: none;
}
.stage-icon { font-size: 30px; opacity: .4; }
.stage-empty p { margin: 0; font-size: 14px; }
.stage-empty small { font-size: 12px; }

/* ---------- progress ---------- */
.progress { margin-top: 14px; padding: 13px 15px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.steps { display: flex; gap: 6px; }
.step { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.step i { display: block; height: 4px; border-radius: 3px; background: var(--line); margin-bottom: 6px; }
.step.active i { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.step.done i { background: var(--ok); }
.step.done, .step.active { color: var(--text); }
@keyframes pulse { 50% { opacity: .45; } }

.progress-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.progress-meta .mono { word-break: break-all; }

/* ---------- alert / usage / actions ---------- */
.alert {
  margin-top: 13px; padding: 11px 14px; border-radius: 9px; font-size: 13.5px;
  border: 1px solid; white-space: pre-wrap; word-break: break-word;
}
.alert.err { color: #ffb4b4; background: rgba(255,107,107,.1); border-color: rgba(255,107,107,.35); }
.alert.warn { color: #ffd79a; background: rgba(240,160,32,.1); border-color: rgba(240,160,32,.35); }
@media (prefers-color-scheme: light) {
  .alert.err { color: #a11212; }
  .alert.warn { color: #8a5a00; }
}

.result-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 13px; }
.btn {
  padding: 9px 15px; cursor: pointer; font: inherit; font-size: 13.5px; text-decoration: none;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 9px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }

.usage { margin-top: 13px; padding: 11px 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; font-size: 13px; }
.usage .u-row { display: flex; justify-content: space-between; padding: 2px 0; color: var(--muted); }
.usage .u-row b { color: var(--text); }

/* ---------- history ---------- */
.history { display: grid; gap: 8px; }
.hitem {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
.hthumb { width: 52px; height: 30px; border-radius: 5px; flex: 0 0 auto; background: #000; object-fit: cover; }
.hmain { flex: 1; min-width: 0; }
.hprompt { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hmeta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.herr { color: var(--err); }
.hstate { font-size: 11.5px; padding: 3px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid; }
.hstate.ok { color: var(--ok); border-color: rgba(46,204,143,.4); }
.hstate.bad { color: var(--err); border-color: rgba(255,107,107,.4); }
.hstate.wait { color: var(--warn); border-color: rgba(240,160,32,.4); }
.hopen { cursor: pointer; font-size: 12.5px; color: var(--accent); background: none; border: none; font-family: inherit; }

/* ---------- footer ---------- */
.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
