
  :root {
    --leather-deep: #120C07;
    --leather: #1A120C;
    --leather-mid: #241A10;
    --parchment: #EFE3C6;
    --parchment-dim: #D9C69E;
    --ink: #2A1E12;
    --ink-soft: #4A3820;
    --gold: #C9A227;
    --gold-dim: #8A6D1F;
    --wax: #8E2F2F;
    --cream: #F0E6CC;
    --serif: "Lora", Georgia, serif;
    --display: "IM Fell English", "Lora", Georgia, serif;
    --sc: "IM Fell English SC", "Lora", Georgia, serif;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { min-height: 100%; }
  body {
    background: var(--leather-deep);
    background-image: radial-gradient(ellipse at 30% 0%, #241A10 0%, var(--leather-deep) 60%);
    color: var(--parchment);
    font-family: var(--serif);
    font-size: 15px;
    line-height: 1.55;
    min-height: 100vh;
  }
  a { color: var(--gold); }

  /* ---------- header ---------- */
  header {
    display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
    padding: 16px 22px;
    border-bottom: 1px solid var(--leather-mid);
  }
  .brand h1 {
    font-family: var(--display);
    font-weight: 400;
    font-size: 24px; letter-spacing: 1px;
    color: var(--parchment);
  }
  .brand h1 .gold { color: var(--gold); }
  .brand .sub { font-size: 12.5px; color: var(--gold-dim); font-style: italic; }
  .top-actions { display: flex; gap: 8px; }
  button {
    font-family: var(--serif);
    font-size: 13.5px;
    min-height: 42px; padding: 8px 14px;
    background: var(--leather-mid);
    color: var(--parchment);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
  }
  button:hover { background: #2f2314; border-color: var(--gold); }
  button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
  button:active { transform: translateY(1px); }
  button.primary { background: var(--wax); border-color: var(--wax); color: var(--cream); }
  button.primary:hover { background: #a83b3b; }

  /* ---------- layout ---------- */
  main.grid {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    gap: 18px;
    max-width: 1100px; margin: 0 auto;
    padding: 20px 22px 30px;
  }
  @media (max-width: 860px) { main.grid { grid-template-columns: 1fr; } }

  /* ---------- left: controls ---------- */
  .panel {
    background: var(--leather);
    border: 1px solid var(--leather-mid);
    border-radius: 6px;
    padding: 16px;
  }
  .panel + .panel { margin-top: 14px; }
  .panel h2 {
    font-family: var(--sc);
    font-weight: 400;
    font-size: 12px; letter-spacing: 2.5px; text-transform: uppercase;
    color: var(--gold);
    margin-bottom: 12px;
  }
  .archetype-btn {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    justify-content: flex-start;
    margin-bottom: 8px;
    text-align: left;
  }
  .archetype-btn .icon { font-size: 20px; }
  .archetype-btn .lbl { font-family: var(--display); font-size: 16px; }
  .archetype-btn.selected { border-color: var(--gold); background: #2a1e10; }
  .generate-row { display: flex; gap: 8px; margin-top: 12px; }
  .generate-row button { flex: 1; }

  input[type="text"] {
    width: 100%;
    font-family: var(--serif); font-size: 14px;
    padding: 10px 12px;
    background: var(--leather-deep);
    color: var(--parchment);
    border: 1px solid var(--leather-mid);
    border-radius: 4px;
    min-height: 42px;
  }
  input[type="text"]:focus { outline: none; border-color: var(--gold); }
  input[type="text"]::placeholder { color: #6b5a3a; }

  .save-row { display: flex; gap: 8px; margin-top: 10px; }
  .save-row input { flex: 1; }
  .save-row button { flex: none; }

  .loc-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
  .loc-item {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 10px;
    background: var(--leather-deep);
    border: 1px solid var(--leather-mid);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13.5px;
  }
  .loc-item:hover { border-color: var(--gold-dim); }
  .loc-item .loc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .loc-item .loc-meta { color: var(--gold-dim); font-size: 11.5px; font-style: italic; white-space: nowrap; }
  .loc-item button.del { min-height: 0; padding: 2px 8px; font-size: 12px; background: transparent; border-color: var(--wax); color: var(--wax); }
  .loc-item button.del:hover { background: var(--wax); color: var(--cream); }
  .empty-note { color: #6b5a3a; font-style: italic; font-size: 13px; }

  /* ---------- right: NPC card ---------- */
  .npccard {
    background: var(--parchment);
    color: var(--ink);
    border-radius: 6px;
    padding: 22px;
    min-height: 480px;
    display: flex; flex-direction: column; gap: 14px;
    box-shadow: 0 18px 40px rgba(0,0,0,0.5);
    position: relative;
  }
  .npccard::before {
    content: "";
    position: absolute; inset: 0;
    pointer-events: none;
    background: linear-gradient(105deg, rgba(0,0,0,0.04) 0%, transparent 40%);
  }
  .npccard .placeholder {
    margin: auto;
    color: #8a7a55;
    font-style: italic;
    text-align: center;
    font-size: 15px;
  }
  .npc-head { display: flex; gap: 16px; align-items: center; }
  .avatar-wrap {
    width: 120px; height: 120px; flex: none;
    background: var(--leather);
    border: 2px solid var(--gold-dim);
    border-radius: 6px;
    overflow: hidden;
  }
  .avatar-wrap canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
  .npc-id { flex: 1; min-width: 0; }
  .npc-name { font-family: var(--display); font-size: 30px; line-height: 1.05; }
  .npc-archetype { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold-dim); margin-top: 2px; }
  .npc-voice {
    margin-top: 8px; font-style: italic; font-size: 14.5px; color: var(--ink-soft);
    border-left: 3px solid var(--gold);
    padding-left: 10px;
  }
  .npc-voice .say { color: var(--wax); }

  .npc-rows { display: flex; flex-direction: column; gap: 8px; font-size: 14.5px; }
  .npc-row { display: flex; gap: 10px; align-items: baseline; }
  .npc-row .k {
    flex: none; width: 74px;
    font-family: var(--sc); font-size: 10.5px; letter-spacing: 1.5px; text-transform: uppercase;
    color: var(--gold-dim); padding-top: 2px;
  }
  .npc-row .v { flex: 1; }

  .inventory { border-top: 1px solid #c9b98f; padding-top: 10px; }
  .inventory h3 {
    font-family: var(--sc); font-weight: 400;
    font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
    color: var(--gold-dim); margin-bottom: 8px;
  }
  .inv-row {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 8px;
    border-bottom: 1px dashed #d8c9a3;
    font-size: 14px;
  }
  .inv-row:last-child { border-bottom: none; }
  .inv-row .qty {
    flex: none; min-width: 34px;
    font-family: var(--sc); font-size: 12px; letter-spacing: 1px;
    color: var(--gold-dim); text-align: center;
    border: 1px solid #c9b98f; border-radius: 4px; padding: 2px 4px;
  }
  .inv-row .item { flex: 1; }
  .inv-row .price { flex: none; font-family: var(--display); font-size: 15px; color: var(--wax); white-space: nowrap; }
  .inv-row.sold .qty { color: #9a8a64; border-color: #d8c9a3; text-transform: uppercase; font-size: 10.5px; }
  .inv-row.sold .item { text-decoration: line-through; color: #9a8a64; }
  .inv-row.sold .price { color: #9a8a64; }
  .inv-row .mini {
    flex: none; min-width: 26px; height: 26px;
    font-size: 14px; line-height: 1;
    background: transparent;
    border: 1px solid #b3a47c; border-radius: 4px;
    color: var(--ink-soft); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 6px;
  }
  .inv-row .mini:hover { background: var(--wax); border-color: var(--wax); color: var(--cream); }
  .inv-row .mini.danger:hover { background: var(--wax); border-color: var(--wax); color: var(--cream); }
  .inv-add {
    display: flex; gap: 6px; align-items: center;
    padding: 8px 8px 4px;
  }
  .inv-add input, .inv-row input[type="text"], .inv-row input[type="number"] {
    background: #fff8e8;
    border: 1px solid #c9b98f; border-radius: 4px;
    padding: 4px 6px; font-size: 13px; color: var(--ink);
    min-width: 0;
  }
  .inv-add .add-name { flex: 1; }
  .inv-add .add-price { width: 62px; }
  .inv-add .add-qty { width: 52px; }
  .inv-row .edit-name { flex: 1; }
  .inv-row .edit-price { width: 62px; }
  .inv-row .edit-qty { width: 52px; }
  .inv-add .mini { flex: none; }

  .mood-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .mood-row .k { width: 74px; flex: none; font-family: var(--sc); font-size: 10.5px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--gold-dim); }
  .mood-chip {
    font-size: 12.5px;
    min-height: 34px; padding: 5px 12px;
    background: transparent;
    border: 1px solid #b3a47c;
    color: var(--ink-soft);
    border-radius: 20px;
  }
  .mood-chip:hover { background: var(--wax); border-color: var(--wax); color: var(--cream); }
  .mood-chip.active { background: var(--wax); border-color: var(--wax); color: var(--cream); }

  .log { border-top: 1px solid #c9b98f; padding-top: 10px; }
  .log h3 {
    font-family: var(--sc); font-weight: 400;
    font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
    color: var(--gold-dim); margin-bottom: 6px;
  }
  .log .log-line { font-size: 13.5px; font-style: italic; color: var(--ink-soft); padding: 2px 0; }
  .log .log-line .when { color: #a3926a; font-style: normal; font-size: 12px; }
  .log-empty { color: #a3926a; font-style: italic; font-size: 13px; }

  footer {
    border-top: 1px solid var(--leather-mid);
    padding: 12px 22px;
    display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    color: #6b5a3a; font-size: 12px;
  }
  footer .gold { color: var(--gold-dim); }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }


  .about-body { font-size: 13.5px; color: var(--parchment-dim); line-height: 1.6; }
  .about-body em { color: var(--gold); font-style: italic; }
  .about-h2 { margin-top: 14px; }
  .about-list { margin: 6px 0 0 18px; font-size: 13px; color: var(--parchment-dim); line-height: 1.7; }
