  :root {
    --bg: #0d1117;
    --panel: #141b24;
    --ink: #c9d4df;
    --dim: #6b7d8f;
    --amber: #e8a13a;
    --amber-glow: rgba(232, 161, 58, 0.25);
    --green: #5fd38a;
    --line: #233140;
    --field: #0a0f15;
    --danger: #d9694e;
    --mono: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;
  }
  * { box-sizing: border-box; }
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  body {
    margin: 0;
    background:
      radial-gradient(ellipse at top, #182230 0%, var(--bg) 60%);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    padding: 32px 16px 80px;
  }
  .shell { max-width: 760px; margin: 0 auto; }

  /* Header */
  .crt-head {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 18px 22px;
    margin-bottom: 14px;
  }
  .crt-head h1 {
    margin: 0;
    font-size: 19px;
    letter-spacing: 0.5px;
    color: var(--amber);
    text-shadow: 0 0 12px var(--amber-glow);
    font-weight: 600;
  }
  .crt-head .sub {
    margin: 6px 0 0;
    color: var(--dim);
    font-size: 12.5px;
  }
  .crt-head .step {
    display: inline-block;
    margin-bottom: 10px;
    font-size: 11px;
    letter-spacing: 1.5px;
    color: var(--green);
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 2px 8px;
    text-transform: uppercase;
  }

  /* Step cards */
  .step-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 20px 22px;
    margin-bottom: 14px;
  }
  .step-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
  }
  .step-num {
    flex-shrink: 0;
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 1px solid var(--amber);
    color: var(--amber);
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px var(--amber-glow);
  }
  .step-title {
    margin: 1px 0 0;
    font-size: 14px;
    letter-spacing: 0.5px;
    color: var(--ink);
    text-transform: uppercase;
  }
  .step-title .opt {
    color: var(--dim);
    font-size: 11.5px;
    text-transform: none;
    letter-spacing: 0;
  }
  .step-sub { margin: 3px 0 0; font-size: 12px; color: var(--dim); }
  .step-card .field:last-child,
  .step-card > *:last-child { margin-bottom: 0; }
  .step-card .two-col { margin-bottom: 16px; }
  .step-card .two-col:last-child { margin-bottom: 0; }
  .step-card .two-col > .field { margin-bottom: 0; }

  /* Upload reminder */
  .reminder {
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 14px;
    color: var(--dim);
    font-size: 12.5px;
    background: var(--field);
  }
  .reminder b { color: var(--ink); }
  .link-amber { color: var(--amber); }
  .link-green { color: var(--green); }

  /* Field rows */
  .field { margin-bottom: 20px; }
  .field-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 12px;
  }
  .field-head.end { justify-content: flex-end; }
  label.k {
    color: var(--amber);
    font-size: 12.5px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
  }
  .hint { color: var(--dim); font-size: 11.5px; }

  /* Surprise toggle */
  .surprise {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--dim);
    font-size: 11px;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
  }
  .surprise input { display: none; }
  .surprise .box {
    width: 13px; height: 13px;
    border: 1px solid var(--line);
    border-radius: 2px;
    display: inline-block;
    position: relative;
    transition: all 0.15s;
  }
  .surprise input:checked + .box {
    background: var(--amber);
    border-color: var(--amber);
    box-shadow: 0 0 8px var(--amber-glow);
  }
  .surprise input:checked + .box::after {
    content: '✦';
    position: absolute;
    inset: 0;
    font-size: 10px;
    line-height: 13px;
    text-align: center;
    color: #0d1117;
  }
  .surprise.on { color: var(--amber); }

  input[type=text], textarea, select {
    width: 100%;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 5px;
    color: var(--ink);
    font-family: var(--mono);
    font-size: 14px;
    padding: 10px 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  input[type=text]:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 1px var(--amber-glow);
  }
  textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
  input:disabled, textarea:disabled, select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }
  .field.surprised input,
  .field.surprised textarea,
  .field.surprised select {
    border-style: dashed;
  }
  .surprise-note {
    font-size: 11px;
    color: var(--amber);
    margin-top: 5px;
    display: none;
  }
  .field.surprised .surprise-note { display: block; }

  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  @media (max-width: 520px) { .two-col { grid-template-columns: 1fr; } }

  /* Party rows */
  .pc-row {
    display: grid;
    grid-template-columns: 1.4fr 1.6fr 0.7fr 0.7fr 0.8fr 0.8fr auto;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
  }
  .pc-row input {
    padding: 8px 9px;
    font-size: 13px;
  }
  .pc-row .pc-x {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--dim);
    border-radius: 5px;
    width: 30px; height: 34px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    flex-shrink: 0;
  }
  .pc-row .pc-x:hover { color: var(--danger); border-color: var(--danger); }
  .pc-heads {
    display: grid;
    grid-template-columns: 1.4fr 1.6fr 0.7fr 0.7fr 0.8fr 0.8fr auto;
    gap: 8px;
    margin-bottom: 5px;
  }
  .pc-heads span {
    font-size: 10px;
    color: var(--dim);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding-left: 2px;
  }
  .pc-heads span:last-child { width: 30px; }
  button.addrow {
    margin-top: 4px;
    padding: 8px 14px;
    font-size: 12.5px;
  }
  .party-surprised #partyRows,
  .party-surprised #addPc,
  .party-surprised .pc-heads { display: none; }
  @media (max-width: 600px) {
    .pc-heads { display: none; }
    .pc-row {
      grid-template-columns: 1fr 1fr;
      gap: 6px;
      padding: 10px;
      border: 1px solid var(--line);
      border-radius: 6px;
    }
    .pc-row .pc-x { width: 100%; }
  }

  /* Generate button */
  .actions { margin: 4px 0 0; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
  button.build {
    background: var(--amber);
    color: #0d1117;
    border: none;
    border-radius: 6px;
    font-family: var(--mono);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.5px;
    padding: 12px 22px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 0 16px var(--amber-glow);
  }
  button.build:hover { box-shadow: 0 0 24px var(--amber-glow); }
  button.build:active { transform: translateY(1px); }
  button.ghost {
    background: transparent;
    color: var(--dim);
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 13px;
    padding: 12px 18px;
    cursor: pointer;
  }
  button.ghost:hover { color: var(--ink); border-color: var(--dim); }
  button.btn-subtle {
    background: transparent;
    color: var(--dim);
    border: none;
    font-family: var(--mono);
    font-size: 12px;
    padding: 9px 6px;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: var(--line);
    text-underline-offset: 3px;
  }
  button.btn-subtle:hover { color: var(--ink); text-decoration-color: var(--dim); }

  /* Output */
  .output { margin-top: 26px; display: none; }
  .output.show { display: block; }
  .output-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
  }
  .output-head .label {
    color: var(--green);
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  button.copy {
    background: var(--green);
    color: #0d1117;
    border: none;
    border-radius: 5px;
    font-family: var(--mono);
    font-weight: 600;
    font-size: 12.5px;
    padding: 7px 16px;
    cursor: pointer;
  }
  button.copy.done { background: var(--dim); }
  button.copy.fail { background: var(--danger); }
  pre.block {
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 18px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--ink);
    max-height: 420px;
    overflow-y: auto;
    margin: 0;
  }
  .steps-after {
    margin-top: 16px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--field);
    font-size: 12.5px;
    color: var(--dim);
    line-height: 1.55;
  }
  .steps-after b { color: var(--green); }
  .steps-after p { margin: 0 0 10px; }
  .steps-after p:last-child { margin-bottom: 0; }
  .steps-after ul { margin: 0 0 10px; padding-left: 20px; }
  .steps-after li { margin-bottom: 4px; }
  .steps-after .steps-tip { color: var(--dim); opacity: 0.9; }
  .steps-after .file-legend {
    margin: 4px 0 12px;
    background: var(--bg);
  }
  .steps-after .file-legend > summary {
    padding: 10px 14px;
    font-size: 11px;
  }
  .steps-after .file-legend .adv-body {
    padding: 0 14px 12px;
  }
  .steps-after .file-legend ul { margin: 0; }
  .steps-after .file-legend li { margin-bottom: 8px; }
  .steps-after .file-legend li:last-child { margin-bottom: 0; }
  .cursor-blink::after {
    content: '▋';
    color: var(--amber);
    animation: blink 1.1s steps(1) infinite;
  }
  @keyframes blink { 50% { opacity: 0; } }

  /* Objective Frame + Theme Reels */
  .reel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin-bottom: 14px; }
  @media (max-width: 520px) { .reel-grid { grid-template-columns: 1fr; } }
  .reel label {
    display: block;
    font-size: 10px;
    color: var(--dim);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 4px;
    padding-left: 2px;
  }
  .reel select { font-size: 13px; padding: 8px 9px; }
  .help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 5px;
    border-radius: 50%;
    border: 1px solid var(--line);
    color: var(--dim);
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    position: relative;
    vertical-align: middle;
    text-transform: none;
    -webkit-user-select: none;
    user-select: none;
    transition: color 0.12s ease, border-color 0.12s ease;
  }
  .help:hover, .help:focus { color: var(--amber); border-color: var(--amber); outline: none; }
  .help + .hint { margin-left: 5px; }
  .help-tip {
    position: absolute;
    bottom: calc(100% + 9px);
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    max-width: 240px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.45;
    color: var(--ink);
    text-transform: none;
    white-space: pre-line;
    letter-spacing: normal;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.12s ease;
    z-index: 20;
    pointer-events: none;
  }
  .help-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--line);
  }
  .help:hover .help-tip, .help:focus .help-tip, .help.open .help-tip {
    opacity: 1;
    visibility: visible;
  }
  .reel-preview {
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 12px;
    color: var(--amber);
    background: var(--field);
    margin-bottom: 12px;
    line-height: 1.5;
  }
  .reel-preview:empty { display: none; }
  .mini-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
  .mini-actions button.ghost { padding: 9px 14px; font-size: 12.5px; }
  #resetReels { margin-left: auto; }
  button.spin {
    background: var(--green);
    color: #0d1117;
    border: none;
    border-radius: 6px;
    font-family: var(--mono);
    font-weight: 600;
    font-size: 13px;
    padding: 10px 18px;
    cursor: pointer;
    box-shadow: 0 0 12px rgba(95, 211, 138, 0.2);
    transition: transform 0.1s, box-shadow 0.15s;
  }
  button.spin:hover { box-shadow: 0 0 20px rgba(95, 211, 138, 0.3); }
  button.spin:active { transform: translateY(1px); }
  .seed-file { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
  .seed-file input[type=file] {
    font-size: 12px;
    color: var(--dim);
    background: transparent;
    border: none;
    padding: 0;
    width: auto;
    flex: 1;
    min-width: 180px;
  }
  .seed-note { color: var(--dim); font-size: 11.5px; margin-top: 6px; }
  .seed-note.err { color: var(--danger); }
  .seed-note.ok { color: var(--green); }

  /* Advanced / Import & Export */
  .advanced {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    margin-top: 14px;
  }
  .advanced > summary {
    cursor: pointer;
    padding: 14px 20px;
    color: var(--dim);
    font-size: 12px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    -webkit-user-select: none;
    user-select: none;
  }
  .advanced > summary::-webkit-details-marker { display: none; }
  .advanced > summary::before {
    content: '▸';
    color: var(--amber);
    font-size: 11px;
  }
  .advanced[open] > summary::before { content: '▾'; }
  .advanced > summary:hover { color: var(--ink); }
  .adv-body { padding: 0 20px 20px; }
  .adv-label { display: block; margin-bottom: 10px; }

  /* Continuity modal */
  .continuity-hint {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--dim);
  }
  .field-head.end .addrow { margin-right: auto; }

  .modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  .modal-backdrop.visible { display: flex; }

  .modal {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    width: min(560px, 100%);
    max-height: min(85vh, 720px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  }
  .modal-title {
    margin: 0;
    padding: 18px 20px 0;
    font-family: var(--serif);
    font-size: 1.25rem;
    font-weight: 600;
  }
  .modal-lede {
    margin: 8px 20px 0;
    font-size: 13px;
    color: var(--dim);
    line-height: 1.45;
  }
  .continuity-empty {
    padding: 16px 20px;
    color: var(--dim);
    font-size: 13px;
  }
  .continuity-modal-body {
    overflow: auto;
    padding: 12px 20px;
    flex: 1;
  }
  .continuity-group {
    border: none;
    margin: 0 0 14px;
    padding: 0;
  }
  .continuity-group legend {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--amber);
    margin-bottom: 8px;
  }
  .continuity-check {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 8px 0;
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
  }
  .continuity-check:last-child { border-bottom: none; }
  .continuity-check input { margin-top: 3px; flex-shrink: 0; }
  .modal-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--line);
  }
  .modal-actions .build { padding: 10px 18px; font-size: 13px; }