/* Modals, admin page (side nav + sectioned panels), timeline, preset chips/hover card, pivot strip, template detail page, lightbox. */
  /* Modals */
  .modal-backdrop {
    position: fixed; inset: 0;
    background: var(--modal-backdrop);
    z-index: 200;
    display: none;
    align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
  }
  .modal-backdrop.show { display: flex; }
  .modal {
    background: color-mix(in srgb, var(--bg) 92%, var(--fg) 8%);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 24px;
    width: 720px;
    max-width: 92vw;
    max-height: 86vh;
    overflow-y: auto;
  }
  .modal h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
  .modal-actions { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; }
  .modal-cancel {
    padding: 7px 14px; border-radius: 8px;
    background: color-mix(in srgb, var(--fg) 5%, transparent);
    border: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
    color: var(--text-dim);
    font-size: 12px; cursor: pointer;
  }
  .modal-save {
    padding: 7px 14px; border-radius: 8px;
    background: var(--accent); border: none;
    color: #fff; font-size: 12px; font-weight: 600; cursor: pointer;
  }

  /* Admin page — side nav + sectioned panels */
  .admin-shell {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 0;
    align-items: start;
    min-height: calc(100vh - 120px);
  }
  .admin-nav {
    position: sticky;
    top: 72px;
    align-self: start;
    padding: 8px 10px 24px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-right: 1px solid var(--border);
    margin-right: 18px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
  }
  .admin-nav-label {
    font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--text-muted); padding: 10px 12px 6px;
  }
  .admin-nav-btn {
    display: flex; align-items: center; gap: 8px;
    width: 100%; text-align: left;
    border: 0; background: transparent; color: var(--text-dim);
    font: inherit; font-size: 13px; font-weight: 550;
    padding: 9px 12px; border-radius: 9px; cursor: pointer;
    transition: background .12s, color .12s;
  }
  .admin-nav-btn:hover { background: var(--surface-2); color: var(--text); }
  .admin-nav-btn.active {
    background: var(--accent-soft); color: var(--accent-strong);
  }
  .admin-nav-btn .nav-ico { width: 1.1em; opacity: .75; flex: 0 0 auto; }
  .admin-main { min-width: 0; padding-bottom: 48px; }
  .admin-sec { display: none; flex-direction: column; gap: 16px; animation: adminSecIn .18s ease; }
  .admin-sec.active { display: flex; }
  @keyframes adminSecIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
  }
  .admin-sec-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    flex-wrap: wrap; margin-bottom: 2px;
  }
  .admin-sec-head h2 {
    font-size: 20px; font-weight: 750; letter-spacing: -0.02em; color: var(--text); margin: 0;
  }
  .admin-sec-head .sub {
    font-size: 12.5px; color: var(--text-muted); font-weight: 400;
  }
  .admin-grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 18px;
    align-items: start;
  }
  .admin-col { display: flex; flex-direction: column; gap: 14px; }
  .admin-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
  }
  .admin-card-title {
    font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-muted); margin: 0 0 12px;
  }
  .admin-card-title .hint {
    font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-faint, var(--text-muted));
  }
  .admin-two {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start;
  }
  @media (max-width: 960px) {
    .admin-shell { grid-template-columns: 1fr; }
    .admin-nav {
      position: static; flex-direction: row; flex-wrap: wrap; gap: 4px;
      border-right: 0; border-bottom: 1px solid var(--border); margin: 0 0 16px; padding: 0 0 12px;
      max-height: none;
    }
    .admin-nav-label { display: none; }
    .admin-nav-btn { width: auto; padding: 7px 12px; font-size: 12.5px; }
    .admin-two { grid-template-columns: 1fr; }
  }
  .tier-editor { display: flex; flex-direction: column; gap: 8px; }
  .tier-row { display: flex; align-items: center; gap: 10px; }
  .tier-row .tier-name {
    flex: 1;
    font-size: 13px; font-weight: 500;
    color: var(--text);
    text-transform: capitalize;
  }
  .tier-row input {
    width: 90px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    padding: 6px 10px;
    outline: none;
    text-align: right;
    font-family: 'SF Mono', 'JetBrains Mono', ui-monospace, monospace;
  }
  .tier-row input:focus { border-color: var(--accent-border); }

  .users-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 10px; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--text-muted);
    font-family: 'SF Mono', 'JetBrains Mono', ui-monospace, monospace;
  }
  .user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
  }
  .user-row:last-child { border-bottom: none; }
  .user-row:hover { background: var(--surface); }
  @font-face { font-family: 'DejaVuSansWeb'; src: url('/fonts/DejaVuSans.ttf'); font-weight: 400; }
  @font-face { font-family: 'DejaVuSansWeb'; src: url('/fonts/DejaVuSans-Bold.ttf'); font-weight: 700; }
  @font-face { font-family: 'InterWeb'; src: url('/fonts/Inter-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'InterWeb'; src: url('/fonts/Inter-700.woff2') format('woff2'); font-weight: 700; }
  @font-face { font-family: 'PoppinsWeb'; src: url('/fonts/Poppins-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'PoppinsWeb'; src: url('/fonts/Poppins-600.woff2') format('woff2'); font-weight: 600; }
  @font-face { font-family: 'PoppinsWeb'; src: url('/fonts/Poppins-700.woff2') format('woff2'); font-weight: 700; }
  @font-face { font-family: 'MontserratWeb'; src: url('/fonts/Montserrat-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'MontserratWeb'; src: url('/fonts/Montserrat-700.woff2') format('woff2'); font-weight: 700; }
  @font-face { font-family: 'OswaldWeb'; src: url('/fonts/Oswald-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'OswaldWeb'; src: url('/fonts/Oswald-700.woff2') format('woff2'); font-weight: 700; }
  @font-face { font-family: 'BebasNeueWeb'; src: url('/fonts/BebasNeue-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'PlayfairWeb'; src: url('/fonts/PlayfairDisplay-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'PlayfairWeb'; src: url('/fonts/PlayfairDisplay-700.woff2') format('woff2'); font-weight: 700; }
  @font-face { font-family: 'SpaceGroteskWeb'; src: url('/fonts/SpaceGrotesk-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'SpaceGroteskWeb'; src: url('/fonts/SpaceGrotesk-700.woff2') format('woff2'); font-weight: 700; }
  @font-face { font-family: 'JetBrainsMonoWeb'; src: url('/fonts/JetBrainsMono-400.woff2') format('woff2'); font-weight: 400; }
  @font-face { font-family: 'JetBrainsMonoWeb'; src: url('/fonts/JetBrainsMono-700.woff2') format('woff2'); font-weight: 700; }
  @font-face { font-family: 'PacificoWeb'; src: url('/fonts/Pacifico-400.woff2') format('woff2'); font-weight: 400; }
  .text-region-layer { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
  .text-region {
    position: absolute; pointer-events: auto; cursor: text; border-radius: 6px;
    border: 1.5px dashed transparent; transition: border-color .12s, background .12s;
  }
  .text-region:hover { border-color: rgba(212,165,116,.8); background: rgba(0,0,0,.14); }
  .text-region:hover::after {
    content: '𝐓 edit'; position: absolute; top: -22px; left: 0;
    background: rgba(0,0,0,.72); color: #f0e2cc; border: 1px solid rgba(212,165,116,.6);
    font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  }
  .text-scan-badge {
    position: absolute; top: 10px; left: 10px; z-index: 7;
    background: rgba(0,0,0,.65); color: #f0e2cc; font-size: 11px; font-weight: 600;
    padding: 3px 10px; border-radius: 999px; pointer-events: none;
  }
  .text-inplace { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
  .text-inplace .ti-text {
    position: absolute; pointer-events: auto; white-space: nowrap; line-height: 1;
    font-family: 'DejaVuSansWeb', sans-serif; cursor: text;
    outline: 2px dashed rgba(212,165,116,.65); outline-offset: 3px; min-width: 8px;
  }
  .text-inplace .ti-bar {
    position: absolute; pointer-events: auto; display: flex; gap: 7px; align-items: center;
    background: rgba(10,10,14,.88); backdrop-filter: blur(8px);
    border: 1px solid rgba(212,165,116,.5); border-radius: 999px; padding: 5px 10px; z-index: 9;
  }
  .text-inplace .ti-font {
    font: inherit; font-size: 11.5px; background: rgba(255,255,255,.08); color: #f0e2cc;
    border: 1px solid rgba(255,255,255,.22); border-radius: 7px; padding: 3px 6px; max-width: 110px;
  }
  .text-inplace .ti-bar input[type=range] { width: 84px; }
  .text-inplace .ti-bar input[type=color] { width: 26px; height: 20px; padding: 0; border: 0; background: none; }
  .text-inplace .ti-b { color: #f0e2cc; font-size: 12px; font-weight: 800; display: flex; gap: 3px; align-items: center; }
  .text-inplace .ti-apply, .text-inplace .ti-x {
    font: inherit; font-size: 11.5px; font-weight: 700; cursor: pointer; border-radius: 999px;
    padding: 4px 11px; border: 0; background: #d4a574; color: #1a1207;
  }
  .text-inplace .ti-x { background: transparent; color: #c8c8c8; border: 1px solid rgba(255,255,255,.25); }
  .text-inplace .ti-move {
    position: absolute; pointer-events: auto; cursor: grab; user-select: none;
    width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
    background: rgba(10,10,14,.85); color: #f0e2cc; font-size: 13px;
    border: 1px solid rgba(212,165,116,.6); border-radius: 50%; z-index: 9;
    touch-action: none;
  }
  .text-inplace .ti-move:active { cursor: grabbing; }
  .text-inplace .ti-corner {
    position: absolute; width: 12px; height: 12px; z-index: 9; pointer-events: auto;
    background: #d4a574; border: 2px solid rgba(10,10,14,.9); border-radius: 3px;
    touch-action: none;
  }
  .text-inplace .ti-corner[data-c=tl], .text-inplace .ti-corner[data-c=br] { cursor: nwse-resize; }
  .text-inplace .ti-corner[data-c=tr], .text-inplace .ti-corner[data-c=bl] { cursor: nesw-resize; }
  .text-inplace .ti-dup {
    font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; border-radius: 999px;
    padding: 4px 9px; border: 1px solid rgba(255,255,255,.25); background: transparent; color: #f0e2cc;
  }
  .text-add {
    position: absolute; top: 10px; right: 10px; pointer-events: auto; cursor: pointer;
    background: rgba(0,0,0,.68); backdrop-filter: blur(5px);
    border: 1px solid rgba(212,165,116,.65); color: #f0e2cc;
    font-size: 11px; font-weight: 700; font-family: inherit; padding: 3px 10px; border-radius: 999px;
  }
  .text-add:hover { background: rgba(212,165,116,.9); color: #1a1207; }
  .text-asset {
    position: absolute; top: 10px; right: 84px; pointer-events: auto; cursor: pointer;
    background: rgba(0,0,0,.68); backdrop-filter: blur(5px);
    border: 1px solid rgba(212,165,116,.65); color: #f0e2cc;
    font-size: 11px; font-weight: 700; font-family: inherit; padding: 3px 10px; border-radius: 999px;
  }
  .text-asset:hover { background: rgba(212,165,116,.9); color: #1a1207; }
  .asset-marquee { position: absolute; inset: 0; z-index: 10; cursor: crosshair; touch-action: none; }
  .text-place-veil { position: absolute; inset: 0; z-index: 5; cursor: text; touch-action: none; }
  .text-region.lifted { border-style: solid; border-color: rgba(212,165,116,.35); }
  .layers-rail {
    position: fixed; right: 16px; top: 50%; transform: translateY(-50%);
    width: 214px; max-height: 74vh; overflow-y: auto; z-index: 66;
    background: var(--bg); border: 1px solid var(--border-strong); border-radius: 14px;
    padding: 10px; display: flex; flex-direction: column; gap: 5px;
    box-shadow: 0 12px 44px var(--shadow-strong);
  }
  .layers-rail .lr-title { font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
    color: var(--text-muted); font-weight: 700; margin-bottom: 2px; }
  .lr-item { display: flex; gap: 7px; align-items: center; font-size: 12px; color: var(--text-dim);
    padding: 6px 8px; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
    font-family: inherit; }
  .lr-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lr-item:hover { background: var(--surface-2); }
  .lr-item.lr-base { cursor: default; color: var(--text-muted); }
  .lr-item.lifted { color: var(--text); border-color: var(--border-strong); }
  .lr-eye, .lr-x { background: none; border: 0; cursor: pointer; color: var(--text-dim);
    font-size: 12px; padding: 1px 3px; flex: 0 0 auto; }
  .lr-x:hover { color: #ff6b6b; }
  .lr-flatten { margin-top: 6px; padding: 9px 10px; border: 0; border-radius: 9px; cursor: pointer;
    background: var(--accent); color: var(--gen-btn-text); font: inherit; font-size: 12.5px; font-weight: 700; }
  .lr-flatten:disabled { opacity: .5; cursor: default; }
  .lr-discard { background: none; border: 0; cursor: pointer; color: var(--text-faint);
    font: inherit; font-size: 11px; padding: 4px; }
  .lr-discard:hover { color: var(--text-dim); }
  .asset-marquee-rect {
    display: none; position: absolute; border: 1.5px dashed rgba(212,165,116,.95);
    background: rgba(212,165,116,.12); border-radius: 4px; pointer-events: none;
  }
  /* while editing, the card's own controls get out of the way */
  .scene-card.text-editing .scene-card-actions,
  .scene-card.text-editing .scene-card-rate,
  .scene-card.text-editing .result-tag { opacity: 0 !important; pointer-events: none !important; }
  .asset-inplace .al-view {
    position: absolute; pointer-events: auto; cursor: move; z-index: 8;
    outline: 2px dashed rgba(212,165,116,.65); outline-offset: 2px;
    box-shadow: 0 8px 30px rgba(0,0,0,.45);
  }

  /* no ::before "@" here — the row templates carry their own; the pseudo-element
     rendered as a stray grey "@" line on the accounts table's two-line cells */
  .user-row .u-handle { flex: 2; font-size: 13px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-row .u-tier { flex: 1; }
  .user-row .u-tier select {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    padding: 5px 8px;
    cursor: pointer;
    outline: none;
  }
  .user-row .u-usage {
    flex: 1; text-align: right;
    font-size: 12px;
    color: var(--text-dim);
    font-family: 'SF Mono', 'JetBrains Mono', ui-monospace, monospace;
  }
  .user-row .u-usage.maxed { color: #f87171; }
  .user-row .u-del {
    width: 34px;
    background: none; border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    border-radius: 5px;
    transition: color 0.1s, background 0.1s;
  }
  .user-row .u-del:hover { color: #f87171; background: rgba(248,113,113,0.1); }
  .users-empty { padding: 28px 16px; text-align: center; color: var(--text-faint); font-size: 12px; }

  /* Timeline (per-composition history) */
  .timeline {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
    padding-right: 2px;
    margin-bottom: 4px;
  }
  .timeline::-webkit-scrollbar { width: 4px; }
  .timeline::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
  .tl-item {
    display: flex;
    gap: 9px;
    align-items: center;
    padding: 6px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
    position: relative;
  }
  .tl-item:hover { border-color: var(--accent-border); background: var(--surface-2); }
  .tl-item img {
    width: 42px; height: 42px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: #000;
  }
  .tl-item-body { flex: 1; overflow: hidden; }
  .tl-item-time { font-size: 11px; color: var(--text-dim); font-family: 'SF Mono','JetBrains Mono',ui-monospace,monospace; }
  .tl-item-note {
    font-size: 10px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
  }
  .tl-item-use {
    font-size: 9px; font-weight: 600;
    color: var(--accent);
    opacity: 0; transition: opacity 0.12s;
    text-transform: uppercase; letter-spacing: 0.05em;
    white-space: nowrap;
  }
  .tl-item:hover .tl-item-use { opacity: 1; }
  @media (hover: none) { .tl-item-use { opacity: 1; } }
  .tl-empty { font-size: 11px; color: var(--text-faint); padding: 8px 2px; }

  /* Preset chips */
  .preset-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 2px; position: relative; }
  .preset-chip {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    color: var(--text-dim);
    font-size: 11px;
    padding: 4px 5px 4px 10px;
    cursor: pointer;
    transition: all 0.12s;
  }
  .preset-chip .pc-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .preset-chip:hover { border-color: var(--accent-border); color: var(--text); }
  .preset-chip.active { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
  .preset-chip .pc-x {
    font-size: 10px; color: var(--text-faint);
    width: 14px; height: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
  }
  .preset-chip .pc-x:hover { background: rgba(248,113,113,0.15); color: #f87171; }
  .preset-empty { font-size: 11px; color: var(--text-faint); padding: 2px; }

  /* Preset hover card — shows the FULL style + notes the chip will apply */
  .pc-popover {
    position: absolute;
    top: calc(100% + 6px); left: 0;
    z-index: 80;
    width: 248px;
    background: color-mix(in srgb, var(--bg) 92%, var(--fg) 8%);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    padding: 11px 12px;
    box-shadow: 0 12px 34px rgba(0,0,0,0.45);
    text-align: left; white-space: normal; cursor: default;
    opacity: 0; visibility: hidden; transform: translateY(-4px);
    transition: opacity 0.12s, transform 0.12s, visibility 0.12s;
    pointer-events: none;
  }
  .preset-chip:hover .pc-popover { opacity: 1; visibility: visible; transform: translateY(0); }
  .pc-pop-label {
    display: block;
    font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--text-faint);
    margin-bottom: 3px;
  }
  .pc-pop-text {
    display: block;
    font-size: 11px; line-height: 1.45; color: var(--text-dim);
    word-break: break-word;
  }
  .pc-pop-sep { display: block; height: 1px; background: var(--border); margin: 9px 0; }

  /* Pivot strip in scene mode */
  .pivot-strip {
    display: flex;
    gap: 8px;
    padding: 10px 24px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    scrollbar-width: thin;
  }
  .pivot-strip::-webkit-scrollbar { height: 6px; }
  .pivot-strip::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--fg) 12%, transparent); border-radius: 4px; }
  .pivot-thumb {
    flex-shrink: 0;
    width: 60px; height: 60px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    background: color-mix(in srgb, var(--fg) 4%, transparent);
    transition: all 0.12s;
    position: relative;
  }
  /* tiny ✕ — hover-revealed on desktop; on touch only the ACTIVE thumb shows it
     (deliberate two-tap: select, then delete — no accidental strip taps) */
  .pivot-del {
    display: none; position: absolute; top: 1px; right: 1px; z-index: 2;
    width: 17px; height: 17px; line-height: 15px; padding: 0; text-align: center;
    border: 0; border-radius: 6px; font-size: 10px; cursor: pointer;
    background: rgba(0,0,0,.62); color: #fff;
  }
  .pivot-thumb:hover .pivot-del { display: block; }
  .pivot-del:hover { background: rgba(239,68,68,.75); }
  @media (hover: none) { .pivot-thumb.active .pivot-del { display: block; } }
  .pivot-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .pivot-thumb:hover { border-color: rgba(212,165,116,0.5); transform: translateY(-1px); }
  .pivot-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(212,165,116,0.3); }
  .pivot-add {
    flex-shrink: 0;
    width: 60px; height: 60px;
    border-radius: 8px;
    border: 2px dashed color-mix(in srgb, var(--fg) 12%, transparent);
    background: transparent;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.12s;
  }
  .pivot-add:hover { border-color: rgba(212,165,116,0.4); color: var(--accent-strong); }
  .pivot-label {
    flex-shrink: 0;
    font-size: 10px; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--text-muted);
    align-self: center;
    padding-right: 4px;
  }

  /* Template detail page */
  .tmpl-detail {
    padding: 28px 32px;
    overflow-y: auto;
    height: calc(100vh - 61px);
  }
  .tmpl-detail-back {
    display: inline-flex; align-items: center; gap: 6px;
    background: none; border: none;
    color: var(--text-dim);
    font-size: 13px; cursor: pointer;
    margin-bottom: 18px;
    padding: 0;
  }
  .tmpl-detail-back:hover { color: var(--accent-strong); }
  .tmpl-detail-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 32px;
    align-items: start;
  }
  .tmpl-detail-img-wrap {
    background: color-mix(in srgb, var(--fg) 3%, transparent);
    border: 1px solid color-mix(in srgb, var(--fg) 7%, transparent);
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 1;
  }
  .tmpl-detail-img-wrap img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
  }
  .tmpl-field {
    margin-bottom: 14px;
  }
  .tmpl-field label {
    display: block;
    font-size: 10px; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 5px;
  }
  .tmpl-actions {
    display: flex;
    gap: 8px;
    margin-top: 18px;
  }
  .tmpl-use-btn {
    background: var(--accent);
    color: white;
    font-size: 13px; font-weight: 600;
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    cursor: pointer;
  }
  .tmpl-use-btn:hover { background: var(--accent-strong); }
  .tmpl-variations-section {
    margin-top: 32px;
  }
  .tmpl-variations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin-top: 12px;
  }
  .tmpl-var-card {
    background: color-mix(in srgb, var(--fg) 3%, transparent);
    border: 1px solid color-mix(in srgb, var(--fg) 7%, transparent);
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1;
    cursor: zoom-in;
  }
  .tmpl-var-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .tmpl-var-empty {
    color: var(--text-faint);
    font-size: 12px;
    padding: 20px 0;
  }

  /* Lightbox */
  #lightbox {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.92);
    display: none; align-items: center; justify-content: center;
    z-index: 1000;
    cursor: zoom-out;
    padding: 20px;
  }
  #lightbox.show { display: flex; }
  #lightbox img {
    max-width: 95vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.8);
  }

