body { margin: 0; font-family: sans-serif; height: 100vh; display: flex; flex-direction: column; }
#topnav { display: flex; align-items: center; background: #26221c; padding: 6px 10px; position: relative; flex-shrink: 0; }
#topnav .brand { color: #d9b96a; font-weight: bold; position: absolute; left: 50%; transform: translateX(-50%); }
#topnav .brand a { color: inherit; }
.navtab { padding: 4px 14px; margin-right: 6px; cursor: pointer; border: 1px solid #999; background: #fff; }
.navtab.active { background: #d9b96a; }
#ext-options { margin-left: auto; color: #d9b96a; font-size: 12px; }
.tabpage { display: none; flex: 1; min-height: 0; }
.tabpage.active { display: flex; }
#c-left { width: 250px; padding: 8px; overflow-y: auto; background: #f3efe8; box-sizing: border-box; }
#c-left h4.cat { font-size: 15px; margin: 10px 0 4px; }
#c-mid, #b-mid { flex: 1; display: flex; flex-direction: column; align-items: center; background: #3a3a3a; padding-top: 8px; overflow-y: auto; min-width: 0; }
#c-right, #b-right { width: 320px; padding: 8px; overflow-y: auto; background: #f3efe8; box-sizing: border-box; }
#c-preview, #b-preview { margin-top: 10px; background: #222; max-width: calc(100% - 20px); max-height: 68vh; cursor: grab; user-select: none; touch-action: none; }
#c-preview:active, #b-preview:active { cursor: grabbing; }
#c-preview:not([src]), #b-preview:not([src]) { display: none; }
#c-frame-variants, #l-frame-variants { color: #d9b96a; font-size: 12px; margin: 4px 0; }
.fv { margin: 0 3px; font-size: 12px; }
.fv.active { background: #d9b96a; }
#c-status, #b-status, #l-status { color: #ffd77a; margin-left: 8px; }
#c-error, #b-error { color: #ff9a9a; font-size: 12px; max-width: 512px; white-space: pre-line; }
.result-meta { color: #ffd77a; font-size: 12px; }
.mouse-help { color: #bbb; font-size: 11px; }
.item { padding: 3px 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 4px; font-size: 13px; }
.item.active { background: #d9b96a; }
.btnrow { margin: 4px 0 10px; }
.btnrow button { margin: 2px 4px 2px 0; font-size: 12px; }
.tab { padding: 4px 10px; margin: 2px; cursor: pointer; border: 1px solid #999; background: #fff; }
.tab.active { background: #d9b96a; }
.note { font-size: 11px; color: #777; }
.local-note { font-size: 12px; color: #625b4d; margin-top: 6px; }
.log-details { margin-top: 16px; font-size: 12px; }
#log { max-height: 260px; overflow: auto; white-space: pre-wrap; color: #c9d4c5; background: #151617; padding: 8px; }
.error { color: #ff9d96; }
#c-form h3, #b-form h3 { font-size: 14px; margin: 10px 0 2px; color: #61563f; }
#c-form label, #b-form label { display: block; font-size: 12px; margin-top: 8px; }
#c-form input:not([type="checkbox"]), #c-form select, #b-form input, #b-form select { width: 160px; box-sizing: border-box; }
#c-form input[type="number"], #b-form input[type="number"] { width: 85px; }
#c-form textarea { width: 100%; height: 110px; font-size: 12px; box-sizing: border-box; }
#c-form label.check { display: flex; align-items: center; gap: 5px; }
.number-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.render-actions { margin-top: 14px; }
#artwork { width: 100%; font-size: 11px; }
#b-left { width: 130px; padding: 8px; overflow-y: auto; background: #f3efe8; box-sizing: border-box; }
#b-left h4 { font-size: 14px; margin: 4px 0 8px; }
#b-styles button { display: block; width: 100%; margin: 4px 0; padding: 6px; cursor: pointer; }
#b-styles button.active { background: #d9b96a; }
#l-sidebar, #l-props { width: 230px; padding: 8px; overflow-y: auto; background: #f3efe8; box-sizing: border-box; }
#l-main { flex: 1; display: flex; flex-direction: column; align-items: center; background: #3a3a3a; overflow: auto; min-width: 0; }
#l-main button { margin: 4px; }
#l-preview { margin: 12px; cursor: crosshair; background: #222; max-width: calc(100% - 24px); }
#l-props h3 { font-size: 14px; color: #61563f; margin: 8px 0; }
#l-props label { display: block; font-size: 12px; margin-top: 6px; }
#l-props input { width: 90px; }
#l-props input[type="number"] { width: 65px; }
#l-props input[type="checkbox"] { width: auto; }
#l-props fieldset { border: 1px solid #c9c2b2; margin: 8px 0; padding: 5px; }
#l-props legend { font-size: 12px; }
#l-mech { display: none; flex-wrap: wrap; gap: 16px; justify-content: center; align-items: flex-start; margin-top: 12px; overflow-y: auto; }
#l-mech.active { display: flex; }
#l-mech .mech-view h4 { color: #d9b96a; font-size: 12px; margin: 0 0 4px; text-align: center; }
#l-mech canvas { display: block; background: #222; }
[hidden] { display: none !important; }
@media (max-width: 1050px) {
  #topnav .brand { display: none; }
  #c-left { width: 210px; }
  #c-right, #b-right { width: 280px; }
}


/* 响应式布局：桌面保留三栏，平板预览置顶双栏，手机按预览→表单→本地工具单栏排列。 */
@media (max-width: 1050px) {
  body { height: auto; min-height: 100vh; min-height: 100dvh; }
  #topnav { position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
  #tab-cards.active, #tab-battle.active, #tab-layout.active {
    display: grid;
    grid-template-columns: minmax(190px, 1fr) minmax(280px, 2fr);
    grid-template-rows: minmax(430px, 62vh) auto;
    overflow: visible;
  }
  #c-mid, #b-mid, #l-main { grid-column: 1 / -1; grid-row: 1; min-height: 430px; overflow-y: auto; }
  #c-left, #b-left, #l-sidebar { grid-column: 1; grid-row: 2; width: 100%; overflow: visible; }
  #c-right, #b-right, #l-props { grid-column: 2; grid-row: 2; width: 100%; overflow: visible; }
  #c-preview, #b-preview { max-height: 52vh; }
  #l-preview { max-width: calc(100% - 24px); height: auto !important; }
  #l-mech canvas { max-width: 100%; height: auto; }
}

@media (max-width: 760px) {
  #topnav { padding: 6px 4px; }
  .navtab { flex: 1; min-width: 0; margin-right: 3px; padding: 7px 4px; font-size: 12px; white-space: nowrap; }
  #ext-options { display: none; }
  #tab-cards.active, #tab-battle.active, #tab-layout.active {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  #c-mid, #b-mid, #l-main { order: 1; width: 100%; min-height: 390px; max-height: none; overflow: visible; padding-bottom: 10px; }
  #c-right, #b-right { order: 2; width: 100%; padding: 12px; }
  #c-left, #b-left, #l-sidebar { order: 3; width: 100%; padding: 12px; }
  #l-props { order: 4; width: 100%; padding: 12px; }
  #c-preview, #b-preview { max-width: calc(100% - 16px); max-height: 58vh; }
  #c-form input:not([type="checkbox"]), #c-form select, #c-form input[type="number"],
  #b-form input, #b-form select, #b-form input[type="number"] { width: 100%; min-height: 38px; font-size: 16px; }
  #c-form textarea { font-size: 16px; }
  #c-form label, #b-form label { font-size: 13px; }
  #c-form .number-grid { gap: 0 12px; }
  .render-actions button, .btnrow button, #c-mid button, #b-mid button, #l-main button { min-height: 38px; }
  #b-styles { display: flex; gap: 5px; }
  #b-styles button { min-height: 40px; }
  #l-types { display: flex; flex-wrap: wrap; }
  #l-props input[type="number"] { min-height: 36px; font-size: 16px; }
  #l-mech { gap: 10px; padding: 0 8px; }
  .mouse-help { max-width: 94%; text-align: center; line-height: 1.6; }
  body { padding-bottom: env(safe-area-inset-bottom); }
}

@media (pointer: coarse) {
  button, select, input { min-height: 38px; }
  #c-preview, #b-preview { touch-action: none; }
  .item { min-height: 34px; align-items: center; }
}

@media (max-width: 380px) {
  .navtab { font-size: 11px; }
  #c-form .number-grid { grid-template-columns: 1fr; }
}

.power-option { display: flex; gap: 5px; align-items: flex-start; font-size: 11px; line-height: 1.5; color: #625b4d; }
.power-option input { width: auto; min-height: 0; margin-top: 3px; }
#persist-storage { font-size: 11px; }

#c-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
#help-modal { box-sizing: border-box; width: min(680px, calc(100% - 32px)); max-height: 85vh; border: 1px solid #8d8065; border-radius: 6px; padding: 16px 20px; background: #f3efe8; color: #332f28; }
#help-modal::backdrop { background: rgb(0 0 0 / 55%); }
.help-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.help-heading h2 { font-size: 20px; margin: 0; }
#help-modal h3 { margin: 14px 0 4px; font-size: 14px; color: #61563f; }
#help-modal p { margin: 4px 0; font-size: 13px; line-height: 1.65; }
#help-modal code { background: #e4ddcf; padding: 1px 3px; }
.primary-action { background: #d9b96a; border: 1px solid #8a7344; font-weight: bold; }
.data-settings, .advanced-section { margin-top: 14px; border-top: 1px solid #c9c2b2; padding-top: 8px; }
.data-settings summary, .advanced-section summary { cursor: pointer; color: #61563f; font-size: 13px; font-weight: bold; }
.advanced-section { margin-bottom: 12px; }
#help-start-tutorial { margin-top: 12px; }
