/* 仅在窄屏设备跟随系统深色模式；桌面端继续保持原有浅色界面。 */
@media (max-width:820px) and (prefers-color-scheme:dark){
  :root{
    color-scheme:dark;
    --ink:#f2f2ef;
    --muted:#a7a8ae;
    --line:#34363b;
    --soft:#1d1f23;
    --blue:#7eafe3;
    --violet:#aa91dd;
    --shadow:0 18px 46px rgba(0,0,0,.34);
  }

  html,body{background:#101113;color:var(--ink)}
  ::selection{background:#425b78;color:#fff}
  *{scrollbar-color:#4b4d52 #17181b}

  .mobile-nav{border-color:#34363b;background:rgba(24,25,28,.96);box-shadow:0 14px 42px rgba(0,0,0,.42)}
  .mobile-nav .nav-button{color:#999ba1}
  .mobile-nav .nav-button.active{background:#292b2f;color:#f5f5f2}
  .round-button,.icon-nav-button{border-color:var(--line);background:#181a1d;color:#d1d2d5}
.panel,.search-card,.memory-card,.layer-card{background:#101113}
  .panel,.search-card,.layer-card{border-color:var(--line)}

  .context-search{background:#1c1e22;color:var(--ink)}
  .memory-line:before{background:#303b49}
  .memory-line span{background:#101113}
  .memory-card p,.scenario-summary,.layer-prose{color:#c5c6ca}
  .card-source,.scenario-path{color:#85878e}
  .category-tag,.section-label,.section-note,.eyebrow{color:#a4a6ad}

  .primary,.custom-select-option.selected,.passkey-login-button,.unlock-row button{
    border-color:#44515f;
    background:#303943;
    color:#eef1f4;
  }
  .secondary,.button-link,.text-action,.plain-button{background:#17191c;color:var(--ink);border-color:var(--line)}
  .secondary:disabled,.primary:disabled{opacity:.48}
  .icon-action,.mobile-actions summary{color:#aaaeb5}
  .icon-action:hover{background:#292c31!important;color:#fff!important}
  .mobile-actions>div{border-color:var(--line);background:#202226;box-shadow:var(--shadow)}
  .mobile-actions .icon-action span{color:#b8bac0}

  .layer-code,.memory-id{background:#222830;color:#aebdd0}
  .scenario-content.editing{border-color:#3a3d42;background:#191b1e}
  .scenario-content .layer-edit-form textarea,.layer-edit-form textarea{color:#dededf}

  .stack-form label,.dialog-form label,.range-control output,.form-advanced summary,.layer-edit-form label{color:#bbbcc1}
  .stack-form input,.stack-form select,.dialog-form input,.dialog-form textarea,.dialog-form select,
  .search-row input,.pair-card .login-form input,.device-rename-form input,
  .custom-select-trigger,.range-control,.pairing-result input{
    border-color:var(--line);
    background:#1b1d20;
    color:#f0f0ed;
  }
  input::placeholder,textarea::placeholder{color:#777980;opacity:1}
  .stack-form input:focus,.dialog-form input:focus,.dialog-form textarea:focus,.search-row input:focus,
  .device-rename-form input:focus{
    border-color:#789bc4;
    box-shadow:0 0 0 3px rgba(126,175,227,.18);
  }
  .custom-select-trigger:hover,.custom-select.open .custom-select-trigger{border-color:#52555b;background:#232529}
  .custom-select-menu{border-color:var(--line);background:rgba(29,31,35,.99);box-shadow:0 18px 48px rgba(0,0,0,.48)}
  .custom-select-option{color:#d2d3d6}
  .custom-select-option:hover,.custom-select-option:focus-visible{background:#292c31;color:#fff}
  .stack-form input[readonly],.custom-select-trigger:disabled,.custom-select-trigger:disabled:hover{border-color:#303237;background:#17191c;color:#85878e}

  .compact-item,.system-panel dl div,.audit-stats>div,.device-item{background:#1a1c1f}
  .compact-item small,.system-panel dt,.device-item small,.audit-item small{color:#999ba1}
  .vault-actions{border-color:var(--line)}
  .vault-status{background:#292c31;color:#bac0c9}
  .vault-status.valid,.device-status.approved,.memory-state.confirmed,.core-health.healthy,.audit-type.use{background:#20372b;color:#8fd0a7}
  .vault-status.needs_update,.device-status.revoked,.memory-badge.expiry.expired,.memory-state.deleted{background:#402629;color:#ef9ca4}
  .device-status.pending,.memory-badge.expiry.soon,.core-health.degraded{background:#3b3120;color:#e1bd75}
  .memory-core-panel dl .core-log-card.recovered{background:#25272b}.memory-core-panel dl .core-log-card.warning{background:#342b1d}.memory-core-panel dl .core-log-card.critical{background:#3b251f}.core-log-card.recovered dt,.core-log-card.recovered dd{color:#a7abb2}.core-log-card.warning dt,.core-log-card.warning dd{color:#dfbc77}.core-log-card.critical dt,.core-log-card.critical dd{color:#eea18b}.core-failure-panel{border-color:#34363b;background:#17191c}.core-failure-item.severity-recovered{border-color:#3a3d42;background:#24262a}.core-failure-item.severity-warning{border-color:#55472f;background:#30291d}.core-failure-item.severity-critical{border-color:#674137;background:#38241f}.core-failure-item span{color:#c1a978}.core-failure-item p{color:#dbcaa8}.core-failure-item.severity-recovered span,.core-failure-item.severity-recovered p{color:#a4a7ad}.core-failure-item.severity-critical span{color:#e0a28f}.core-failure-item.severity-critical p{color:#f0b5a3}.core-failure-toggle{color:inherit}.core-failure-clear{border-color:#474a50;background:#222428;color:#c5c7cc}.core-failure-clear:hover{background:#2a2c31}
  .device-status,.memory-badge,.memory-state.archived,.audit-type,.core-health{background:#292c31;color:#b8bbc2}
  .memory-state,.memory-state.open-loop,.audit-type.write{background:#213245;color:#91b9e6}
  .candidate-tag,.memory-state.candidate,.audit-type.feedback,.core-health.compat{background:#322944;color:#c6aae9}
  .memory-badge.importance.high,.audit-type.update,.audit-type.lifecycle{background:#3b3025;color:#dab184}
  .core-health.unreachable,.layer-edit-error{background:#402a24;color:#efa58f}

  .credential-notice,.credential-shortcut,.candidate-shelf{
    border-color:#3a3547;
    background:#1c1922;
  }
  .credential-notice-icon{border-color:#3d3948;background:#26222d;color:#b7a1d5}
  .credential-notice span{color:#aaa2b2}
  .credential-notice .notice-close:hover{background:#302b37;color:#eeeaf3}
  .vault-request-context{border-color:#41394f;background:#211d28;color:#c0afd5}
  .candidate-card{border-color:#3a3547}

  dialog{background:#17191c;color:var(--ink)}
  dialog::backdrop{background:rgba(0,0,0,.66)}
  #toast{background:#292d34;color:var(--ink);border:1px solid var(--line);box-shadow:0 12px 34px rgba(0,0,0,.36)}

  .login-body{background:#101113}
  .login-card{border-color:#34363b;background:#181a1d;box-shadow:0 22px 70px rgba(0,0,0,.38)}
  .login-lock{background:#25272b;color:#c8cbd0}
  .unlock-row input{border-color:var(--line);background:#202226;color:#f2f2ef}
  .error{color:#f29aa8}

  .secondary.danger{border-color:#57383b;color:#efa1a8}
  .secondary.danger:hover{border-color:#75484c;background:#2d1e20}
  .secondary.danger:disabled{border-color:#34363b;background:#1b1d20;color:#686a70}
}
@media(max-width:820px) and (prefers-color-scheme:dark){
  .memory-layer-switch{background:#1a1c1f;border-color:var(--line)}
  .memory-layer-switch.archived{background:#202730}
  .memory-layer-switch button{color:#b9bec6}
  .memory-layer-switch button.active{background:#303741;color:#f3f3ef}
  .memory-layer-switch button small{color:#aab7c8}
  .memory-layer-switch button .archive-caption{color:#a5afbc}
  .archive-toggle[aria-pressed="true"]{background:#303b4c;color:#c8d9ee}
  .relation-link{color:#b2c9e7}
  .scenario-state{color:#b3bdcb}
}
