:root {
      --bg: #0f1115;
      --panel: #171a21;
      --panel-2: #1d222b;
      --line: #2a303a;
      --text: #e8ecf3;
      --muted: #9ba7b8;
      --faint: #748090;
      --accent: #df6f57;
      --accent-2: #6ba6ff;
      --good: #5db37a;
      --warn: #d8a23d;
      --bad: #e35d6a;
      --chip: #222835;
      --shadow: 0 12px 32px rgba(0,0,0,.24);
      --radius: 16px;
      --radius-sm: 10px;
      --font: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
    }
    * { box-sizing: border-box; }
    html, body { height: 100%; }
    body {
      margin: 0;
      font-family: var(--font);
      background:
        radial-gradient(circle at top, rgba(223,111,87,.08), transparent 28%),
        radial-gradient(circle at 85% 20%, rgba(107,166,255,.06), transparent 24%),
        var(--bg);
      color: var(--text);
    }
    button, input, textarea {
      font: inherit;
    }
    .app {
      min-height: 100vh;
      display: grid;
      grid-template-rows: auto 1fr;
    }
    .topbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      padding: 18px 22px;
      border-bottom: 1px solid var(--line);
      background: rgba(15,17,21,.86);
      backdrop-filter: blur(12px);
      position: sticky;
      top: 0;
      z-index: 2;
    }
    .brand {
      display: flex;
      align-items: center;
      gap: 14px;
      min-width: 0;
    }
    .sigil {
      width: 42px;
      height: 42px;
      border-radius: 14px;
      background: linear-gradient(135deg, rgba(223,111,87,.85), rgba(107,166,255,.82));
      box-shadow: var(--shadow);
      flex: 0 0 auto;
    }
    .brand h1 {
      margin: 0;
      font-size: 18px;
      font-weight: 600;
      line-height: 1.1;
    }
    .brand p {
      margin: 4px 0 0;
      font-size: 13px;
      color: var(--muted);
    }
    .top-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      justify-content: flex-end;
    }
    .btn {
      border: 1px solid var(--line);
      background: var(--panel);
      color: var(--text);
      padding: 10px 14px;
      border-radius: 12px;
      cursor: pointer;
      transition: .18s ease;
    }
    .btn:hover { border-color: #445064; transform: translateY(-1px); }
    .btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
    .btn.ghost { background: transparent; }
    .shell {
      display: grid;
      grid-template-columns: 1.6fr .84fr;
      gap: 18px;
      padding: 18px;
      align-items: start;
    }
    .panel {
      background: rgba(23,26,33,.95);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      overflow: hidden;
    }
    .story-wrap {
      display: grid;
      grid-template-rows: auto auto 1fr auto;
      min-height: calc(100vh - 102px);
    }
    .hero {
      padding: 18px 20px 10px;
      border-bottom: 1px solid var(--line);
      background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
    }
    .hero-row {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      align-items: flex-start;
      flex-wrap: wrap;
    }
    .hero h2 {
      margin: 0;
      font-size: 22px;
      font-weight: 650;
    }
    .hero .sub {
      margin: 6px 0 0;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.6;
    }
    .chip-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 12px;
    }
    .chip {
      padding: 6px 10px;
      background: var(--chip);
      border: 1px solid var(--line);
      border-radius: 999px;
      color: var(--muted);
      font-size: 12px;
    }
    .chip strong { color: var(--text); font-weight: 600; }
    .progress {
      margin-top: 14px;
      height: 10px;
      background: #11151b;
      border-radius: 999px;
      overflow: hidden;
      border: 1px solid var(--line);
    }
    .progress > div {
      height: 100%;
      width: 8%;
      background: linear-gradient(90deg, var(--accent), var(--accent-2));
      transition: width .25s ease;
    }
    .stagebar {
      display: flex;
      gap: 8px;
      overflow: auto;
      padding: 14px 20px 0;
      scrollbar-width: thin;
    }
    .stage {
      flex: 0 0 auto;
      padding: 8px 12px;
      border-radius: 999px;
      background: #11161d;
      border: 1px solid var(--line);
      color: var(--faint);
      font-size: 12px;
      white-space: nowrap;
    }
    .stage.active {
      color: #fff;
      background: rgba(223,111,87,.18);
      border-color: rgba(223,111,87,.45);
    }
    .content {
      display: grid;
      grid-template-columns: 1.08fr .92fr;
      gap: 16px;
      padding: 18px 20px 0;
      min-height: 0;
    }
    .card {
      background: var(--panel-2);
      border: 1px solid var(--line);
      border-radius: 16px;
      overflow: hidden;
    }
    .card-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      padding: 12px 14px;
      border-bottom: 1px solid var(--line);
      background: rgba(255,255,255,.02);
    }
    .card-head h3 {
      margin: 0;
      font-size: 15px;
      font-weight: 600;
    }
    .card-head span {
      font-size: 12px;
      color: var(--muted);
    }
    .story {
      padding: 16px 16px 18px;
      line-height: 1.78;
      color: #e9edf5;
      font-size: 14px;
      min-height: 320px;
      white-space: pre-wrap;
    }
    .effect-result {
      margin-top: 16px;
      padding: 12px 14px;
      background: rgba(223,111,87,.08);
      border: 1px solid rgba(223,111,87,.25);
      border-radius: 12px;
      color: #ffd4cc;
      font-size: 13px;
      line-height: 1.6;
    }
    .effect-result strong {
      color: var(--accent);
      display: block;
      margin-bottom: 6px;
    }
    .choices {
      display: grid;
      gap: 10px;
      padding: 0 16px 16px;
    }
    .choice {
      width: 100%;
      text-align: left;
      border-radius: 12px;
      padding: 12px 14px;
      border: 1px solid var(--line);
      background: #141921;
      color: var(--text);
      cursor: pointer;
      transition: .18s ease;
      display: flex;
      justify-content: space-between;
      gap: 14px;
      align-items: center;
      text-decoration: none;
      -webkit-tap-highlight-color: rgba(223,111,87,.25);
    }
    .choice:hover { transform: translateY(-1px); border-color: rgba(223,111,87,.5); }
    .choice small {
      display: block;
      color: var(--muted);
      margin-top: 4px;
      font-size: 12px;
      line-height: 1.5;
    }
    .choice .tag {
      flex: 0 0 auto;
      padding: 5px 9px;
      border-radius: 999px;
      background: rgba(255,255,255,.04);
      border: 1px solid var(--line);
      color: var(--muted);
      font-size: 12px;
    }
    .sidebar {
      display: grid;
      gap: 16px;
      min-height: 0;
    }
    .stats {
      display: grid;
      gap: 10px;
      padding: 14px;
    }
    .stat {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      align-items: center;
      padding: 10px 12px;
      background: #12161d;
      border: 1px solid var(--line);
      border-radius: 12px;
      font-size: 13px;
    }
    .stat strong { font-size: 14px; }
    .good { color: var(--good); }
    .warn { color: var(--warn); }
    .bad { color: var(--bad); }
    .section {
      padding: 14px;
    }
    .section h4 {
      margin: 0 0 10px;
      font-size: 14px;
      font-weight: 600;
    }
    .list {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }
    .item {
      padding: 6px 10px;
      background: #12161d;
      border: 1px solid var(--line);
      border-radius: 999px;
      font-size: 12px;
      color: var(--muted);
    }
    .item strong { color: var(--text); }
    .affection {
      display: inline-block;
      margin-left: 6px;
      color: var(--muted);
      font-size: 11px;
    }
    .affection.good { color: var(--good); }
    .affection.warn { color: var(--warn); }
    .affection.faint { color: var(--faint); }
    .log {
      max-height: 240px;
      overflow: auto;
      padding-right: 4px;
    }
    .log-entry {
      padding: 10px 0;
      border-bottom: 1px dashed rgba(255,255,255,.08);
      font-size: 13px;
      color: var(--muted);
      line-height: 1.6;
    }
    .log-entry:last-child { border-bottom: 0; }
    .endings {
      padding: 0 20px 18px;
      display: grid;
      gap: 10px;
    }
    .ending-box {
      border: 1px solid rgba(107,166,255,.25);
      background: rgba(107,166,255,.08);
      border-radius: 14px;
      padding: 14px;
      color: #dfe9ff;
    }
    .ending-box strong { display: block; margin-bottom: 6px; }
    .overlay {
      position: fixed;
      inset: 0;
      background: rgba(7,10,13,.62);
      backdrop-filter: blur(10px);
      display: grid;
      place-items: center;
      padding: 20px;
      z-index: 40;
    }
    .modal {
      width: min(720px, 100%);
      background: #171a21;
      border: 1px solid var(--line);
      border-radius: 22px;
      box-shadow: var(--shadow);
      padding: 22px;
    }
    .modal h2 {
      margin: 0 0 10px;
      font-size: 22px;
    }
    .modal p {
      margin: 0 0 16px;
      color: var(--muted);
      line-height: 1.7;
      font-size: 14px;
    }
    .modal .grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 12px;
      margin-bottom: 18px;
    }
    .tile {
      background: #12161d;
      border: 1px solid var(--line);
      border-radius: 14px;
      padding: 12px;
      min-height: 88px;
    }
    .tile span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
    .tile strong { font-size: 20px; }
    .modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
    .overlay.force-hidden { display: none !important; visibility: hidden !important; pointer-events: none !important; }
    .hidden { display: none !important; }
    .hint {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.6;
    }
    textarea {
      width: 100%;
      min-height: 120px;
      resize: vertical;
      background: #12161d;
      border: 1px solid var(--line);
      color: var(--text);
      border-radius: 12px;
      padding: 10px 12px;
      outline: none;
    }
    .mini-actions {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-top: 10px;
    }
    
    /* 数值变化动画 */
    @keyframes stat-pulse {
      0%, 100% { background: #12161d; border-color: var(--line); }
      50% { background: rgba(223,111,87,.15); border-color: rgba(223,111,87,.5); }
    }
    .stat-highlight {
      animation: stat-pulse 0.6s ease-in-out;
    }
    
    /* 浮动变化量提示 */
    .delta-float {
      position: absolute;
      right: 12px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 16px;
      font-weight: 700;
      pointer-events: none;
      animation: float-up 1.2s ease-out forwards;
      z-index: 10;
    }
    .delta-float.positive { color: var(--good); }
    .delta-float.negative { color: var(--bad); }
    
    @keyframes float-up {
      0% { opacity: 1; transform: translateY(-50%) scale(1); }
      60% { opacity: 1; transform: translateY(-80px) scale(1.1); }
      100% { opacity: 0; transform: translateY(-100px) scale(0.9); }
    }
    
    .stat {
      position: relative;
    }
    
    @media (max-width: 1080px) {
      .shell, .content, .modal .grid { grid-template-columns: 1fr; }
      .story-wrap { min-height: auto; }
    }

    /* 手机适配增强版 */
    .mobile-stats { display: none; }
    @media (max-width: 760px) {
      html {
        height: auto;
        -webkit-text-size-adjust: 100%;
        scroll-behavior: smooth;
      }
      body {
        min-height: 100vh;
        padding-bottom: env(safe-area-inset-bottom);
        background: radial-gradient(circle at top left, rgba(223,111,87,.12), transparent 32%), var(--bg);
      }
      .app { display: block; min-height: 100vh; }
      .topbar {
        padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
        gap: 10px;
        align-items: flex-start;
        flex-direction: column;
      }
      .brand { width: 100%; gap: 10px; }
      .sigil { width: 34px; height: 34px; border-radius: 11px; }
      .brand h1 { font-size: 17px; }
      .brand p { font-size: 12px; line-height: 1.35; }
      .top-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
      }
      .top-actions #btnReset { grid-column: 1 / -1; }
      .btn {
        min-height: 44px;
        padding: 11px 12px;
        border-radius: 12px;
        font-size: 15px;
        touch-action: manipulation;
      }
      .btn:hover, .choice:hover { transform: none; }
      .shell { display: block; padding: 10px; }
      .panel, .card { border-radius: 14px; }
      .story-wrap { min-height: auto; }
      .hero { padding: 14px 14px 12px; }
      .hero-row { display: block; }
      .hero h2 { font-size: 21px; line-height: 1.25; }
      .hero .sub { font-size: 13px; line-height: 1.55; }
      .chip-row { margin-top: 10px; gap: 6px; }
      .chip { font-size: 11px; padding: 5px 8px; }
      .progress { height: 8px; margin-top: 12px; }
      .mobile-stats {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 7px;
        margin-top: 10px;
      }
      .mobile-stat {
        min-width: 0;
        padding: 8px 6px;
        background: rgba(18,22,29,.95);
        border: 1px solid var(--line);
        border-radius: 11px;
        text-align: center;
      }
      .mobile-stat span {
        display: block;
        color: var(--muted);
        font-size: 11px;
        line-height: 1.2;
      }
      .mobile-stat strong {
        display: block;
        margin-top: 3px;
        font-size: 15px;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .stagebar { padding: 10px 12px 0; gap: 6px; }
      .stage { font-size: 11px; padding: 7px 10px; }
      .content { display: block; padding: 12px; }
      .card-head { padding: 11px 12px; }
      .card-head h3 { font-size: 15px; }
      .card-head span { font-size: 11px; }
      .story {
        min-height: 0;
        padding: 15px 14px 16px;
        font-size: 16px;
        line-height: 1.82;
        letter-spacing: .01em;
      }
      .effect-result {
        margin-top: 14px;
        padding: 12px;
        font-size: 14px;
        line-height: 1.75;
      }
      .choices { gap: 10px; padding: 0 12px 14px; }
      .choice {
        min-height: 52px;
        padding: 14px 13px;
        border-radius: 13px;
        align-items: flex-start;
        font-size: 16px;
      }
      .choice .tag { font-size: 11px; padding: 4px 8px; margin-top: 1px; }
      .sidebar { margin-top: 12px; gap: 12px; }
      .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 8px; }
      .stat { padding: 9px 10px; font-size: 13px; }
      .stat strong { font-size: 15px; }
      .section { padding: 12px; }
      .item { font-size: 12px; padding: 6px 9px; }
      .log { max-height: 180px; }
      textarea { min-height: 96px; font-size: 13px; }
      .mini-actions { display: grid; grid-template-columns: 1fr 1fr; }
      .mini-actions #btnCopy { grid-column: 1 / -1; }
      .endings { padding: 0 12px 14px; }
      .ending-box { font-size: 13px; line-height: 1.65; padding: 12px; }
      .shell > aside.panel { display: none; }
      .overlay {
        align-items: start;
        place-items: start center;
        padding: max(330px, calc(24vh + env(safe-area-inset-top))) 10px max(170px, calc(14vh + env(safe-area-inset-bottom)));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
      }
      .modal {
        max-height: none;
        overflow: visible;
        border-radius: 18px;
        padding: 18px;
        margin-bottom: 24px;
      }
      .modal h2 { font-size: 21px; }
      .modal p { font-size: 14px; }
      .modal .grid { grid-template-columns: 1fr; gap: 8px; }
      .tile { min-height: auto; padding: 11px; }
      .tile strong { font-size: 18px; }
      .modal-actions { display: grid; grid-template-columns: 1fr; }
      .delta-float { right: 8px; font-size: 14px; }
    }

    @media (max-width: 380px) {
      .mobile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
      .story, .choice { font-size: 15px; }
    }

    /* ─── 结局弹窗 ─────────────────────────────────────── */
    .ending-modal {
      max-height: 90vh;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
    }
    .ending-modal::-webkit-scrollbar { width: 4px; }
    .ending-modal::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

    .ending-header {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 4px;
    }
    .ending-header h2 {
      margin: 0;
      font-size: 22px;
      line-height: 1.3;
      flex: 1;
      min-width: 0;
    }
    .ending-tags {
      display: flex;
      gap: 8px;
      flex-shrink: 0;
      align-items: center;
    }
    .ending-badge {
      display: inline-block;
      padding: 4px 10px;
      border-radius: 999px;
      font-size: 12px;
      font-weight: 600;
      white-space: nowrap;
      background: rgba(107,166,255,.15);
      color: var(--accent-2);
      border: 1px solid rgba(107,166,255,.3);
    }
    .rank-badge {
      background: rgba(223,111,87,.15);
      color: var(--accent);
      border-color: rgba(223,111,87,.35);
    }
    .ending-meta {
      margin: 0 0 14px !important;
      color: var(--faint) !important;
      font-size: 13px !important;
      line-height: 1.5;
    }
    .ending-text {
      background: #12161d;
      border: 1px solid var(--line);
      border-radius: 14px;
      padding: 14px 16px;
      font-size: 14px;
      line-height: 1.75;
      color: var(--muted);
      white-space: pre-wrap;
      max-height: 260px;
      overflow-y: auto;
    }
    .ending-text::-webkit-scrollbar { width: 3px; }
    .ending-text::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

    /* ─── 评分明细 ─────────────────────────────────────── */
    .breakdown {
      display: grid;
      gap: 10px;
      margin-top: 12px;
    }
    .breakdown-row {
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .breakdown-label {
      width: 80px;
      flex-shrink: 0;
      font-size: 12px;
      color: var(--faint);
      text-align: right;
    }
    .breakdown-bar-wrap {
      flex: 1;
      height: 12px;
      background: #1a1f28;
      border-radius: 999px;
      overflow: hidden;
    }
    .breakdown-bar {
      height: 100%;
      background: linear-gradient(90deg, var(--accent-2), var(--accent));
      border-radius: 999px;
      transition: width 0.6s ease;
      min-width: 0;
    }
    .breakdown-score {
      width: 44px;
      flex-shrink: 0;
      font-size: 12px;
      color: var(--muted);
      text-align: right;
      font-variant-numeric: tabular-nums;
    }

    /* ─── 结局标签 ─────────────────────────────────────── */
    .ending-section {
      margin-top: 16px;
    }
    .ending-section h4 {
      margin: 0 0 8px;
      font-size: 13px;
      font-weight: 600;
      color: var(--muted);
    }
    .ending-tag-list {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }
    .ending-tag {
      display: inline-block;
      padding: 4px 10px;
      border-radius: 999px;
      font-size: 12px;
      background: #1a1f28;
      border: 1px solid var(--line);
      color: var(--text);
    }
    .entry-tag {
      background: rgba(107,166,255,.08);
      border-color: rgba(107,166,255,.2);
      color: var(--accent-2);
    }
    .ending-empty {
      color: var(--faint);
      font-size: 13px;
    }

    /* ─── 多周目记录 ───────────────────────────────────── */
    .ending-records-summary {
      font-size: 13px;
      color: var(--muted);
      margin-bottom: 10px;
      padding: 8px 10px;
      background: #12161d;
      border-radius: 10px;
      text-align: center;
    }
    .ending-records-summary strong {
      color: var(--text);
    }
    .ending-record-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 10px;
      border-bottom: 1px solid rgba(255,255,255,.06);
      font-size: 13px;
    }
    .ending-record-item:last-child { border-bottom: 0; }
    .record-title {
      flex: 1;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      color: var(--text);
    }
    .record-rank {
      padding: 2px 8px;
      border-radius: 999px;
      font-size: 11px;
      font-weight: 700;
      background: rgba(223,111,87,.15);
      color: var(--accent);
    }
    .record-score {
      font-variant-numeric: tabular-nums;
      color: var(--muted);
      min-width: 48px;
      text-align: right;
    }
    .record-date {
      color: var(--faint);
      font-size: 12px;
      min-width: 72px;
      text-align: right;
    }

    @media (max-width: 760px) {
      .ending-record-item {
        flex-wrap: wrap;
        gap: 4px 8px;
      }
      .record-title { width: 100%; }
      .ending-text { max-height: 200px; }
      .breakdown-label { width: 64px; font-size: 11px; }
      .breakdown-score { width: 36px; font-size: 11px; }
    }
