/* Base reset. The artifact preview supplied these; a standalone page must not rely on that. */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

:root {
    --brand: #662C83;
    --brand-deep: #4A1F60;
    --brand-lift: #7D3C9E;
    --brand-tint: #F2EAF6;
    --on-brand: #FFFFFF;
    --on-brand-soft: #D9C4E4;

    --ground: #FAF7FB;
    --surface: #FFFFFF;
    --surface-sunk: #F4EFF6;
    --ink: #1E1522;
    --ink-soft: #6B5F72;
    --ink-faint: #9A8FA0;
    --line: #E7DEEC;
    --line-firm: #D2C4D9;

    --fuel: #B05A12;
    --fuel-tint: #FBEFE2;
    --high: #2E8F63;
    --mid: #B8860B;
    --low: #C04429;
    --danger: #A83824;
    --danger-tint: #F8E6E1;

    --band-bg: #662C83;
    --band-edge: transparent;
    --lift: 0 1px 2px rgba(30,21,34,0.05), 0 12px 28px -18px rgba(30,21,34,0.35);
    --r: 12px;
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --brand: #A96FD0;
      --brand-deep: #2A1635;
      --brand-lift: #BE8ADD;
      --brand-tint: rgba(169,111,208,0.14);
      --on-brand: #FFFFFF;
      --on-brand-soft: #C9AEDC;
      --ground: #16101A;
      --surface: #201829;
      --surface-sunk: #1A1322;
      --ink: #F1EAF4;
      --ink-soft: #A99BB2;
      --ink-faint: #7A6C83;
      --line: #322640;
      --line-firm: #453653;
      --fuel: #E0923F;
      --fuel-tint: rgba(224,146,63,0.14);
      --high: #4CBE8A;
      --mid: #D8AC3A;
      --low: #E0705A;
      --danger: #E0705A;
      --danger-tint: rgba(224,112,90,0.14);
      --band-bg: #2A1635;
      --band-edge: #453653;
      --lift: 0 1px 2px rgba(0,0,0,0.4), 0 14px 32px -20px rgba(0,0,0,0.8);
      color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --brand: #A96FD0;
    --brand-deep: #2A1635;
    --brand-lift: #BE8ADD;
    --brand-tint: rgba(169,111,208,0.14);
    --on-brand: #FFFFFF;
    --on-brand-soft: #C9AEDC;
    --ground: #16101A;
    --surface: #201829;
    --surface-sunk: #1A1322;
    --ink: #F1EAF4;
    --ink-soft: #A99BB2;
    --ink-faint: #7A6C83;
    --line: #322640;
    --line-firm: #453653;
    --fuel: #E0923F;
    --fuel-tint: rgba(224,146,63,0.14);
    --high: #4CBE8A;
    --mid: #D8AC3A;
    --low: #E0705A;
    --danger: #E0705A;
    --danger-tint: rgba(224,112,90,0.14);
    --band-bg: #2A1635;
    --band-edge: #453653;
    --lift: 0 1px 2px rgba(0,0,0,0.4), 0 14px 32px -20px rgba(0,0,0,0.8);
    color-scheme: dark;
  }

  * { box-sizing: border-box; }
  body {
    background: var(--ground);
    color: var(--ink);
    font-family: "Open Sans", system-ui, sans-serif;
    font-weight: 400;
    padding: 0;
    -webkit-font-smoothing: antialiased;
  }
  .num, .fig .v, .band-stat .v, .meter .read {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
  }

  /* ---------- Brand bar ---------- */
  .topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 20;
  }
  .topbar-inner {
    max-width: 1080px; margin: 0 auto; padding: 13px 16px;
    display: flex; align-items: center; gap: 13px; flex-wrap: wrap;
  }
  .wordmark { display: block; height: 26px; width: auto; }
  :root[data-theme="dark"] .wordmark { filter: brightness(0) invert(1); }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .wordmark { filter: brightness(0) invert(1); }
  }
  .topbar .divider { width: 1px; height: 22px; background: var(--line-firm); }
  .topbar .context {
    font-family: "Aleo", Georgia, serif; font-weight: 400; font-size: 14px;
    letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft);
  }
  .agent-box { margin-left: auto; display: flex; align-items: center; gap: 10px; }
  .agent-name { font-size: 12.5px; color: var(--ink-soft); }
  .agent-name b { font-family: "Aleo", Georgia, serif; font-weight: 700; color: var(--ink); }

  .tabstrip { background: var(--surface); border-bottom: 1px solid var(--line); }
  .tabstrip-inner {
    max-width: 1080px; margin: 0 auto; padding: 0 16px;
    display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  }
  .tabstrip-inner::-webkit-scrollbar { display: none; }
  .tab {
    font: inherit; font-size: 13.5px; font-weight: 400; white-space: nowrap;
    background: transparent; border: none; cursor: pointer;
    color: var(--ink-soft); padding: 12px 14px;
    border-bottom: 3px solid transparent; margin-bottom: -1px;
  }
  .tab:hover { color: var(--ink); }
  .tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
  .tab:focus-visible { outline: 2px solid var(--brand); outline-offset: -3px; }

  /* ---------- Sign in ---------- */
  .gate {
    position: fixed; inset: 0; z-index: 50;
    background: var(--ground);
    display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  }
  .gate-card {
    width: 100%; max-width: 380px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--r);
    box-shadow: var(--lift); padding: 28px 26px;
  }
  .gate-card .wordmark { height: 30px; margin-bottom: 22px; }
  .gate-card h1 {
    font-family: "Aleo", Georgia, serif; font-weight: 700; font-size: 20px;
    margin: 0 0 6px; color: var(--ink);
  }
  .gate-card p { font-size: 13px; color: var(--ink-soft); line-height: 1.55; margin: 0 0 18px; }
  .gate-card button { width: 100%; margin-top: 4px; }
  .gate-known { margin-top: 16px; font-size: 12px; color: var(--ink-faint); }
  .gate-known button {
    width: auto; margin: 5px 5px 0 0; background: var(--surface-sunk);
    border: 1px solid var(--line); color: var(--ink); border-radius: 99px;
    padding: 5px 12px; font-size: 12.5px; cursor: pointer; font-family: inherit;
  }
  .gate-known button:hover { border-color: var(--brand); color: var(--brand); }

  .wrap { max-width: 1080px; margin: 0 auto; padding: 22px 16px 72px; }

  .notice {
    background: var(--brand-tint); border: 1px solid var(--line);
    border-left: 3px solid var(--brand);
    border-radius: 0 8px 8px 0; padding: 11px 14px;
    font-size: 12.5px; line-height: 1.55; color: var(--ink-soft); margin-bottom: 20px;
  }
  .notice b { color: var(--ink); }

  .panel { display: none; }
  .panel.active { display: block; }

  .card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r); box-shadow: var(--lift); padding: 20px;
  }
  .card + .card { margin-top: 16px; }
  h2 {
    font-family: "Aleo", Georgia, serif; font-weight: 700; font-size: 21px;
    letter-spacing: 0; margin: 0 0 5px; text-wrap: balance;
  }
  .hint { font-size: 12.5px; color: var(--ink-soft); line-height: 1.55; margin-bottom: 16px; }

  /* ---------- Summary band ---------- */
  .band {
    background: var(--band-bg); color: var(--on-brand);
    border: 1px solid var(--band-edge);
    border-radius: var(--r); padding: 20px 22px; margin-bottom: 16px;
    box-shadow: var(--lift);
  }
  .band-label {
    font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--on-brand-soft); margin-bottom: 14px;
  }
  .band-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 20px; }
  .band-stat .k { font-size: 11px; color: var(--on-brand-soft); letter-spacing: 0.04em; margin-bottom: 3px; }
  .band-stat .v {
    font-family: "Aleo", Georgia, serif;
    font-size: 30px; font-weight: 700; line-height: 1.05; letter-spacing: -0.01em;
  }
  .band-stat .v small { font-family: "Open Sans", sans-serif; font-size: 13px; font-weight: 400; opacity: 0.8; margin-left: 3px; }

  /* ---------- Forms ---------- */
  label { display: block; font-size: 12px; font-weight: 400; color: var(--ink-soft); margin-bottom: 6px; }
  label small { display: block; font-weight: 400; color: var(--ink-faint); font-size: 11.5px; margin-top: 3px; }
  input, select, textarea {
    font: inherit; font-size: 14px; width: 100%;
    background: var(--ground); color: var(--ink);
    border: 1px solid var(--line-firm); border-radius: 8px; padding: 10px 11px;
  }
  input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
  }
  textarea { resize: vertical; min-height: 64px; }
  .field { margin-bottom: 14px; }
  .g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .g3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
  @media (max-width: 620px) { .g2, .g3 { grid-template-columns: 1fr; } }

  .segmented { display: flex; gap: 0; border: 1px solid var(--line-firm); border-radius: 8px; overflow: hidden; }
  .segmented button {
    flex: 1; font: inherit; font-size: 13px; font-weight: 400; cursor: pointer;
    background: var(--ground); color: var(--ink-soft); border: none; padding: 11px 10px;
  }
  .segmented button + button { border-left: 1px solid var(--line-firm); }
  .segmented button[aria-pressed="true"] { background: var(--brand); color: #FFFFFF; }

  .pack {
    border: 1px solid var(--line); border-left: 3px solid var(--brand);
    border-radius: 0 10px 10px 0; padding: 16px; background: var(--surface-sunk); margin-bottom: 14px;
  }
  .pack h3 {
    font-family: "Aleo", Georgia, serif; font-size: 14px; font-weight: 700;
    margin: 0 0 12px; color: var(--ink);
  }

  button.btn { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 11px 18px; font-size: 14px; font-weight: 400; }
  .btn-primary { background: var(--brand); color: #FFFFFF; }
  .btn-primary:hover { background: var(--brand-lift); }
  .btn-quiet { background: transparent; border-color: var(--line-firm); color: var(--ink); }
  .btn-quiet:hover { border-color: var(--ink-faint); }
  .btn-tiny { padding: 6px 11px; font-size: 12px; }
  .btn-del { background: transparent; border-color: var(--line-firm); color: var(--danger); padding: 6px 11px; font-size: 12px; }
  .btn-del:hover { background: var(--danger-tint); border-color: var(--danger); }
  .err { color: var(--danger); font-size: 12.5px; margin-bottom: 10px; min-height: 1em; }

  /* ---------- Media ---------- */
  .media-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
  .media-actions label.filebtn {
    display: inline-flex; align-items: center; gap: 7px; margin: 0; cursor: pointer;
    font-size: 13.5px; font-weight: 400; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line-firm);
    border-radius: 8px; padding: 10px 15px;
  }
  .media-actions label.filebtn:hover { border-color: var(--brand); color: var(--brand); }
  .media-actions input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
  .media-actions label.filebtn:focus-within { outline: 2px solid var(--brand); outline-offset: 1px; }

  .strip { display: flex; gap: 8px; flex-wrap: wrap; }
  .thumb {
    position: relative; width: 74px; height: 74px; border-radius: 8px; overflow: hidden;
    border: 1px solid var(--line-firm); background: var(--surface-sunk); flex: none;
  }
  .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .thumb .kill {
    position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; padding: 0;
    border-radius: 50%; border: none; cursor: pointer; line-height: 18px; font-size: 13px;
    background: rgba(20,12,24,0.72); color: #FFFFFF; font-family: inherit;
  }
  .thumb.vid {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 6px; text-align: center;
  }
  .thumb.vid .vname {
    font-size: 11px; color: var(--ink-soft); line-height: 1.25;
    overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
  .thumb.vid .vsize { font-size: 11px; color: var(--ink-faint); }
  .play {
    width: 22px; height: 22px; border-radius: 50%; background: var(--brand);
    display: flex; align-items: center; justify-content: center; flex: none;
  }
  .play::after { content: ""; border-left: 7px solid #FFFFFF; border-top: 5px solid transparent; border-bottom: 5px solid transparent; margin-left: 2px; }
  .media-note { font-size: 11.5px; color: var(--ink-faint); margin-top: 9px; }

  .swap-media { padding: 12px 16px; border-top: 1px dashed var(--line); }
  .swap-media .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-faint); margin-bottom: 8px; }

  .lightbox {
    position: fixed; inset: 0; z-index: 60; background: rgba(16,10,20,0.92);
    display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  }
  .lightbox img { max-width: 100%; max-height: 82vh; border-radius: 10px; display: block; }
  .lightbox .close {
    position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,0.14);
    color: #FFFFFF; border: none; border-radius: 8px; padding: 9px 15px;
    font-family: inherit; font-size: 13.5px; cursor: pointer;
  }

  /* ---------- Battery meter ---------- */
  .meter { display: flex; align-items: center; gap: 8px; }
  .cell {
    position: relative; width: 62px; height: 20px; flex: none;
    border: 1.5px solid var(--line-firm); border-radius: 4px;
    background: var(--ground); overflow: hidden;
  }
  .cell::after {
    content: ""; position: absolute; right: -5px; top: 5px;
    width: 3px; height: 8px; background: var(--line-firm); border-radius: 0 2px 2px 0;
  }
  .cell .used, .cell .left { position: absolute; top: 0; bottom: 0; }
  .cell .used { left: 0; background: repeating-linear-gradient(135deg, var(--line) 0 3px, transparent 3px 6px); }
  .cell .left { right: 0; }
  .meter .read { font-size: 12px; color: var(--ink-soft); }
  .meter .read b { color: var(--ink); font-family: "Aleo", Georgia, serif; font-weight: 700; }

  /* ---------- Swap entries ---------- */
  .swap {
    border: 1px solid var(--line); border-radius: var(--r);
    background: var(--surface); box-shadow: var(--lift); margin-bottom: 12px; overflow: hidden;
  }
  .swap-top {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
  }
  .swap-who { font-family: "Aleo", Georgia, serif; font-weight: 700; font-size: 16px; }
  .swap-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
  .swap-meta .dot { color: var(--ink-faint); margin: 0 5px; }
  .swap-body { display: grid; grid-template-columns: 1.1fr 1fr; gap: 0; }
  @media (max-width: 720px) { .swap-body { grid-template-columns: 1fr; } }
  .swap-packs { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
  .swap-figs {
    padding: 14px 16px; border-left: 1px solid var(--line);
    display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px 16px; align-content: start;
  }
  @media (max-width: 720px) { .swap-figs { border-left: none; border-top: 1px solid var(--line); } }
  .fig .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-faint); }
  .fig .v { font-family: "Aleo", Georgia, serif; font-size: 17px; font-weight: 700; margin-top: 3px; }
  .fig .v.fuel { color: var(--fuel); }
  .fig .v.brand { color: var(--brand); }
  .pack-row .pid { font-size: 12.5px; font-weight: 400; margin-bottom: 5px; }
  .note {
    padding: 12px 16px; border-top: 1px dashed var(--line);
    font-size: 13px; line-height: 1.6; color: var(--ink-soft);
  }
  .note b { color: var(--ink); font-weight: 400; }

  .chip {
    display: inline-block; font-size: 11px; font-weight: 400; letter-spacing: 0.05em;
    text-transform: uppercase; padding: 3px 8px; border-radius: 99px;
    background: var(--brand-tint); color: var(--brand); border: 1px solid var(--line);
  }
  .chip.fuelchip { background: var(--fuel-tint); color: var(--fuel); }
  .chip.parallel { background: var(--brand); color: #FFFFFF; border-color: var(--brand); }

  /* ---------- Master lists ---------- */
  .adder { display: flex; gap: 8px; margin-bottom: 14px; }
  .adder input { flex: 1; }
  ul.master { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
  ul.master li {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    background: var(--surface-sunk); border: 1px solid var(--line);
    border-radius: 8px; padding: 9px 12px; font-size: 13.5px;
  }
  ul.master li .nm { font-weight: 400; }
  ul.master li .use { font-size: 11.5px; color: var(--ink-faint); }
  .blank { color: var(--ink-faint); font-size: 13px; padding: 22px 0; text-align: center; }

  .filterbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
  .filterbar .field { margin: 0; min-width: 190px; }
