  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --ink: #1b1f24;
    --ink-soft: #4b5563;
    --ink-mute: #8a93a0;
    --line: #1b1f24;
    --line-soft: #e3e6ea;
    --rail: #f0f2f5;

    /* terminal accents (calmer, light-dev palette) */
    --accent: #e0594f;        /* keep red identity but softer */
    --accent-2: #f4d35e;      /* soft yellow */
    --term-green: #2a9d6a;
    --term-blue: #3b82c4;
    --term-purple: #7c5cd1;
    --term-orange: #d68a3a;
    --term-pink: #c75d8b;

    --shadow: 4px 4px 0 var(--line);
    --shadow-sm: 2px 2px 0 var(--line);
    --shadow-lg: 6px 6px 0 var(--line);

    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --comic: 'Comic Neue', 'Comic Sans MS', system-ui, sans-serif;

    --radius: 10px;
    --radius-sm: 6px;
  }

  *, *::before, *::after { box-sizing: border-box; }

  html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 14px;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
  }

  /* ── App shell ── */
  .app {
    display: flex;
    height: 100vh;
    width: 100vw;
  }

  /* ── Brand (shown in the switcher overlay) ── */
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }
  .brand-mark {
    width: 30px;
    height: 30px;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: var(--shadow-sm);
    font-family: var(--comic);
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
  }
  .brand-name {
    font-family: var(--comic);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: .3px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .brand-sub {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--ink-mute);
    letter-spacing: .12em;
    text-transform: uppercase;
    margin-top: 3px;
  }
  .icon-btn {
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: var(--ink-soft);
    display: grid;
    place-items: center;
  }
  .icon-btn:hover { background: var(--rail); color: var(--ink); }

  .search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--rail);
    border: 1.5px solid var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    transition: border-color .15s;
  }
  .search-box:focus-within { border-color: var(--line); }
  .search-box input {
    background: transparent;
    border: 0;
    outline: 0;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink);
    flex: 1;
    min-width: 0;
  }
  .search-box .prefix { color: var(--accent); font-weight: 700; }

  .story-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1.5px solid var(--line-soft);
    border-radius: var(--radius-sm);
    background: var(--panel);
    cursor: pointer;
    transition: transform .12s, box-shadow .12s, border-color .12s;
    min-width: 0;
  }
  .story-item:hover {
    border-color: var(--line);
    transform: translate(-1px, -1px);
    box-shadow: var(--shadow-sm);
  }
  .story-item.active {
    border-color: var(--line);
    background: #fff;
    box-shadow: var(--shadow);
    transform: translate(-2px, -2px);
  }
  .story-item.active .story-dot { background: var(--accent); }
  /* keyboard-highlighted row in the switcher list — distinct from .active
     (the currently-open story), which may be a different row entirely. */
  .story-item.kb-active {
    border-color: var(--accent);
    background: var(--rail);
  }
  .story-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-mute);
    margin-top: 7px;
    flex-shrink: 0;
  }
  .story-meta-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .story-title {
    font-family: var(--comic);
    font-weight: 700;
    font-size: 15px;
    line-height: 1.15;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .story-sub {
    font-size: 10px;
    color: var(--ink-mute);
    display: flex;
    gap: 8px;
    letter-spacing: .04em;
  }
  .story-sub b { color: var(--ink-soft); font-weight: 600; }

  /* Per-story template label — replaces the old global template-switch
     filter buttons; same color-per-template mapping as the admin panel. */
  .story-tpl-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    border: 1.5px solid transparent;
    font-weight: 700;
    letter-spacing: .04em;
  }
  .story-tpl-badge--terminal { background: rgba(59,130,196,.12); border-color: rgba(59,130,196,.35); color: #3b82c4; }
  .story-tpl-badge--comic    { background: rgba(124,92,209,.12); border-color: rgba(124,92,209,.35); color: #7c5cd1; }
  .story-tpl-badge--bd       { background: rgba(214,138,58,.12); border-color: rgba(214,138,58,.35); color: #d68a3a; }
  .story-tpl-badge--cartoon  { background: rgba(255,93,162,.12); border-color: rgba(255,93,162,.35); color: #ff5da2; }

  .new-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--accent-2);
    border: 1.5px solid var(--line);
    color: var(--line);
    letter-spacing: .08em;
    align-self: flex-start;
    margin-top: 4px;
  }

  /* ── Story switcher (command-palette style story navigation) ── */
  .switcher-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20,24,28,.5);
    z-index: 1700;
    justify-content: center;
    padding: 12vh 16px 16px;
    overflow-y: auto;
  }
  .switcher-overlay.visible { display: flex; }
  .switcher-modal {
    width: 100%;
    max-width: 520px;
    max-height: 72vh;
    background: var(--panel);
    border: 2px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    align-self: flex-start;
  }
  .switcher-brand {
    padding: 14px 16px 12px;
    border-bottom: 2px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
  }
  .switcher-search {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1.5px solid var(--line-soft);
    flex-shrink: 0;
  }
  .switcher-search input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    outline: 0;
    font-family: var(--mono);
    font-size: 14px;
    color: var(--ink);
  }
  .switcher-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px;
    border-bottom: 1.5px solid var(--line-soft);
    flex-shrink: 0;
  }
  .chip {
    font-family: var(--mono);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .02em;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1.5px solid var(--line-soft);
    background: var(--panel);
    color: var(--ink-soft);
    cursor: pointer;
    transition: all .12s;
  }
  .chip:hover { border-color: var(--line); color: var(--ink); }
  .chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
  .switcher-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 120px;
  }
  .switcher-empty {
    padding: 28px 12px;
    text-align: center;
    color: var(--ink-mute);
    font-size: 12.5px;
  }
  .switcher-footer {
    display: flex;
    gap: 14px;
    padding: 9px 16px;
    border-top: 1.5px solid var(--line-soft);
    font-size: 10.5px;
    color: var(--ink-mute);
    flex-shrink: 0;
  }
  .switcher-footer .k {
    display: inline-block;
    padding: 1px 5px;
    border: 1.5px solid var(--line-soft);
    border-radius: 4px;
    font-family: var(--mono);
    font-weight: 700;
    color: var(--ink-soft);
    margin-right: 2px;
  }
  @media (max-width: 560px) {
    .switcher-overlay { padding: 0; align-items: stretch; }
    .switcher-modal { max-width: none; max-height: none; height: 100%; border-radius: 0; border-width: 0; }
  }

  /* ── Content ── */
  .content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background:
      radial-gradient(circle at 1px 1px, rgba(27,31,36,.06) 1px, transparent 0) 0 0/22px 22px,
      var(--bg);
  }

  /* top bar */
  .topbar {
    min-height: 56px;
    height: auto;
    background: var(--panel);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
  }
  .topbar-main {
    min-height: 56px;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    flex-shrink: 0;
  }
  .story-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }
  .topbar .crumb {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }
  .story-heading-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
  }
  .story-photo {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
  }
  .story-desc {
    margin: 0;
    font-size: 11px;
    line-height: 1.4;
    color: var(--ink-mute);
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .crumb-prefix {
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
  }
  .crumb-path {
    color: var(--ink-soft);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }
  .crumb-path b { color: var(--ink); font-weight: 700; }
  .topbar-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }
  .tb-btn {
    height: 32px;
    padding: 0 10px;
    border: 1.5px solid var(--line-soft);
    background: var(--panel);
    border-radius: var(--radius-sm);
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-soft);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all .12s;
  }
  .tb-btn:hover {
    border-color: var(--line);
    color: var(--ink);
    transform: translate(-1px, -1px);
    box-shadow: var(--shadow-sm);
  }
  .tb-btn.primary {
    background: var(--accent);
    border-color: var(--line);
    color: #fff;
    box-shadow: var(--shadow-sm);
  }
  .tb-btn.primary:hover { box-shadow: var(--shadow); }

  /* auto-scroll */
  #autoscroll-btn { position: relative; }
  #autoscroll-btn .speed-chip {
    display: none;
    font-family: var(--mono);
    font-weight: 800;
    font-size: 10px;
    letter-spacing: .04em;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--ink);
    color: #fff;
    margin-left: 2px;
  }
  #autoscroll-btn[data-speed="1"],
  #autoscroll-btn[data-speed="2"],
  #autoscroll-btn[data-speed="3"] {
    background: var(--accent);
    border-color: var(--line);
    color: #fff;
    box-shadow: var(--shadow-sm);
  }
  #autoscroll-btn[data-speed="1"] .speed-chip,
  #autoscroll-btn[data-speed="2"] .speed-chip,
  #autoscroll-btn[data-speed="3"] .speed-chip {
    display: inline-block;
    background: rgba(0,0,0,.28);
  }
  #autoscroll-btn[data-speed="1"] .speed-chip::after { content: "1×"; }
  #autoscroll-btn[data-speed="2"] .speed-chip::after { content: "2×"; }
  #autoscroll-btn[data-speed="3"] .speed-chip::after { content: "3×"; }

  .as-toast {
    position: fixed;
    bottom: 18px;
    right: 18px;
    background: var(--panel);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 8px 12px 8px 10px;
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 1500;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
  }
  .as-toast.visible { display: inline-flex; }
  .as-toast .as-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(224,89,79,.18);
    animation: as-pulse 1.1s ease-in-out infinite;
  }
  @keyframes as-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(.78); opacity: .55; }
  }
  .as-toast .as-label { color: var(--ink-soft); }
  .as-toast .as-speed {
    font-weight: 800;
    color: var(--accent);
    letter-spacing: .02em;
  }
  .as-toast .as-hint {
    color: var(--ink-mute);
    font-size: 10px;
    letter-spacing: .1em;
    text-transform: uppercase;
    padding-left: 8px;
    margin-left: 4px;
    border-left: 1px dashed var(--line-soft);
  }
  body[data-template="comic"] .as-toast { background: #fff; border-color: #0a0a0a; }
  body[data-template="bd"] .as-toast { background: #fbf2dc; border-color: #1a0f05; }

  @media (max-width: 900px) {
    .as-toast { bottom: 12px; right: 12px; padding: 6px 10px; font-size: 11px; }
    .as-toast .as-hint { display: none; }
  }

  /* story switcher trigger (topbar) */
  .switcher-trigger-key {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    color: var(--ink-mute);
    background: var(--rail);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    padding: 0 5px;
    line-height: 1.6;
  }

  /* progress + chapter scrubber — sits as the topbar's last child, its
     track/fill standing in for a static bottom border so the bar fills in
     as you read, while the thumb dragged along the same track jumps
     between chapters (see the ticks marking each chapter's position). One
     bar instead of a second boxed slider repeating the same positions. */
  .progress-track {
    position: relative;
    height: 6px;
    background: var(--line-soft);
    flex-shrink: 0;
    cursor: pointer;
  }
  #read-progress {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width .1s ease-out;
  }
  .chapter-tick {
    position: absolute;
    top: 0;
    width: 1px;
    height: 100%;
    background: var(--line);
    opacity: .35;
    transform: translateX(-50%);
  }
  .progress-thumb {
    position: absolute;
    top: 50%;
    left: 0%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--accent);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    z-index: 2;
    transition: left .18s ease;
  }
  .progress-thumb:active { cursor: grabbing; }
  .progress-thumb.dragging { transition: none; }
  .thumb-label {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: .04em;
  }
  .thumb-label::after {
    content: '';
    position: absolute;
    bottom: 100%; left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-bottom-color: var(--ink);
  }

  /* scroll body */
  .scroll {
    flex: 1;
    overflow-y: auto;
    padding: 22px 24px 80px;
    scroll-behavior: smooth;
  }

  /* "who" filter — a reading control, styled as a flat bordered rail to
     match the .tb-btn buttons it sits among in .topbar-actions. */
  .legend {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    background: var(--rail);
    border: 1.5px solid var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 0 10px;
    transition: border-color .15s;
    flex-shrink: 0;
  }
  .legend:focus-within { border-color: var(--line); }
  .legend-label {
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink-mute);
    flex-shrink: 0;
  }
  .who-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    flex: 1 1 0%;
    min-width: 0;
    padding: 0 16px 0 0;
    border: 0;
    outline: 0;
    background:
      transparent
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>")
      no-repeat right center;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
  }

  /* timeline */
  .timeline {
    width: 100%;
    max-width: 880px;
    margin: 0 auto;
    display: none;
  }
  .timeline.active { display: block; }

  /* date divider */
  .date-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 28px 0 14px;
  }
  .date-divider::before,
  .date-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line-soft);
  }
  .date-chip {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink-mute);
    padding: 4px 10px;
    border: 1.5px solid var(--line-soft);
    border-radius: 999px;
    background: var(--panel);
  }
  .date-chip::before {
    content: "//  ";
    color: var(--accent);
  }

  /* ── Message (terminal card) ── */
  .message {
    display: flex;
    flex-direction: column;
    margin: 0 0 18px;
    transition: opacity .25s;
    position: relative;
  }
  .timeline.is-filtering .message { opacity: .15; }
  .timeline.is-filtering .message.highlight { opacity: 1; }

  .msg-body {
    display: flex;
    gap: 12px;
    align-items: flex-start;
  }
  .message.right .msg-body { flex-direction: row-reverse; }

  .avatar {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 2px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-family: var(--mono);
    font-weight: 700;
    font-size: 12px;
    letter-spacing: .02em;
    margin-top: 4px;
  }

  .card {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 50px);
    background: var(--panel);
    border: 1.5px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
  }
  .card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--rail);
    border-bottom: 1.5px solid var(--line-soft);
    font-size: 11px;
  }
  .traffic {
    display: flex;
    gap: 5px;
    margin-right: 4px;
  }
  .traffic span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.15);
  }
  .traffic span:nth-child(1) { background: #ed6a5e; }
  .traffic span:nth-child(2) { background: #f4c150; }
  .traffic span:nth-child(3) { background: #62c655; }
  .card-title {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    font-size: 11.5px;
    color: var(--ink-soft);
    font-weight: 600;
  }
  .card-title .at { color: var(--ink-mute); }
  .card-title .user { color: var(--ink); font-weight: 700; }
  .card-title .sep { color: var(--ink-mute); }
  .card-title .ts { color: var(--ink-mute); font-weight: 500; }
  .card-num {
    font-size: 10px;
    color: var(--ink-mute);
    font-weight: 700;
    letter-spacing: .05em;
    padding: 2px 6px;
    background: var(--panel);
    border: 1.5px solid var(--line-soft);
    border-radius: 4px;
    flex-shrink: 0;
  }
  .card-body {
    padding: 14px 16px 16px;
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ink);
    word-wrap: break-word;
    overflow-wrap: anywhere;
  }
  .card-body::before {
    content: "$ ";
    color: var(--accent);
    font-weight: 700;
    user-select: none;
  }
  .message.right .card-body::before {
    content: "› ";
    color: var(--term-blue);
  }

  /* attachments */
  .attach {
    margin: 10px 16px 14px;
    border: 1.5px solid var(--line-soft);
    border-radius: 6px;
    overflow: hidden;
    background: var(--rail);
  }
  /* Capped instead of rendering at the attachment's native height: a tall
     screenshot/photo (common for shared articles) could otherwise stretch
     a single card to fill most of the viewport, leaving room for barely
     one card at a time. object-fit: cover crops to fill the card's full
     width at that capped height — like the full-width .attach-yt embed
     below — rather than shrinking a narrower/taller image down to fit
     inside the height cap and leaving empty space on either side.
     Templates that lay attachments into a fixed-size panel
     (comic/cartoon/bd) override this below to fill that panel instead. */
  .attach img, .attach video { width: 100%; max-height: 18vh; object-fit: cover; display: block; }
  .attach audio { width: 100%; display: block; }

  /* Several images on one message (attachment given as an array) tile into
     one collage instead of one attachment block per photo. Caps at 4
     visible cells, with a "+N" overlay on the last one for any beyond
     that, same convention as the chat apps this is modeled after. */
  .attach-collage {
    display: grid;
    gap: 2px;
    height: 18vh;
  }
  .attach-collage-2 { grid-template-columns: repeat(2, 1fr); }
  .attach-collage-3 { grid-template-columns: repeat(3, 1fr); }
  .attach-collage-4 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
  .collage-cell { position: relative; overflow: hidden; }
  .collage-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .collage-more {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10,10,10,.55);
    color: #fff;
    font-family: var(--mono);
    font-weight: 700;
    font-size: 15px;
  }

  .attach-yt {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
  }
  .attach-yt iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }
  /* X (Twitter) post — widgets.js replaces the blockquote with a
     self-sizing iframe; until it loads, style the raw fallback link
     so it doesn't look broken. */
  .attach-xpost {
    background: var(--panel);
    padding: 2px;
  }
  .attach-xpost .twitter-tweet {
    margin: 0 !important;
    padding: 12px 14px;
    border: 0;
  }
  .attach-xpost .twitter-tweet a {
    color: var(--accent);
    font-weight: 700;
    font-family: var(--mono);
    font-size: 13px;
    word-break: break-all;
    text-decoration: none;
  }
  .attach-xpost .twitter-tweet a:hover { text-decoration: underline; }
  .attach-xpost iframe { max-width: 100%; }

  /* message tags — small pill chips; template overrides further below */
  .msg-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin: 0 16px 10px;
  }
  .tag-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-2);
    border: 1px solid var(--line-soft);
    color: var(--ink-soft);
    font-family: var(--mono);
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
  }
  .tag-chip::before { content: '#'; opacity: .5; margin-right: 1px; }

  /* card footer / share */
  .card-foot {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1.5px solid var(--line-soft);
    background: linear-gradient(to bottom, transparent, rgba(0,0,0,.01));
  }
  .share-btn {
    background: var(--panel);
    border: 1.5px solid var(--line-soft);
    color: var(--ink-soft);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 5px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all .12s;
  }
  .share-btn:hover {
    border-color: var(--line);
    color: var(--ink);
    background: var(--accent-2);
    transform: translate(-1px, -1px);
    box-shadow: var(--shadow-sm);
  }
  .share-btn:disabled { opacity: .6; cursor: wait; }

  /* author color tag on left edge */
  .card::before {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    left: 0;
    width: 4px;
    background: var(--char-color, var(--accent));
  }
  .message.right .card::before { left: auto; right: 0; }

  /* empty state */
  .empty {
    max-width: 540px;
    margin: 10vh auto 0;
    padding: 28px;
    text-align: center;
    color: var(--ink-soft);
  }
  .empty .glyph {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: var(--shadow);
    font-family: var(--comic);
    font-weight: 700;
    font-size: 32px;
  }
  .empty h1 {
    font-family: var(--comic);
    font-weight: 700;
    font-size: 28px;
    margin: 0 0 6px;
    color: var(--ink);
  }
  .empty p { font-size: 13px; margin: 4px 0; }
  .empty .hint {
    margin-top: 18px;
    font-size: 11px;
    color: var(--ink-mute);
  }
  .empty kbd {
    background: var(--panel);
    border: 1.5px solid var(--line);
    border-radius: 4px;
    padding: 1px 6px;
    font-family: var(--mono);
    font-weight: 700;
    font-size: 11px;
    box-shadow: var(--shadow-sm);
  }

  /* kb-focused outline */
  .message.kb-focused .card {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* overlays */
  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20,24,28,.55);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  .overlay.visible { display: flex; }
  .modal {
    background: var(--panel);
    border: 2px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 22px 22px 18px;
    width: 100%;
    max-width: 380px;
  }
  .modal h3 {
    margin: 0 0 14px;
    font-family: var(--comic);
    font-weight: 700;
    font-size: 18px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--line);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .modal h3 .tag {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--accent);
    background: rgba(224,89,79,.12);
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: .1em;
  }
  .kb-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    font-size: 12px;
    border-bottom: 1px dashed var(--line-soft);
  }
  .kb-row:last-of-type { border-bottom: 0; }
  .kb-row .keys { display: flex; gap: 4px; }
  .kb-row .desc { color: var(--ink-soft); }
  kbd.k {
    display: inline-block;
    padding: 2px 6px;
    border: 1.5px solid var(--line);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    background: var(--rail);
    box-shadow: var(--shadow-sm);
  }
  .modal-btns {
    display: flex;
    gap: 8px;
    margin-top: 14px;
  }
  .modal-btn {
    flex: 1;
    padding: 9px;
    border: 1.5px solid var(--line);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    background: var(--panel);
    color: var(--ink);
    transition: all .12s;
  }
  .modal-btn:hover { transform: translate(-1px,-1px); box-shadow: var(--shadow-sm); }
  .modal-btn.primary { background: var(--accent); color: #fff; }

  /* responsive */
  @media (max-width: 900px) {
    .scroll { padding: 16px 14px 80px; }
    .avatar { width: 34px; height: 34px; font-size: 11px; }
    .card { max-width: calc(100% - 46px); }
    .topbar-main { padding: 6px 12px; flex-wrap: wrap; }
    .story-photo { width: 34px; height: 34px; }
    .tb-btn .btn-label { display: none; }
    .switcher-trigger-key { display: none; }
    .crumb-path { font-size: 12px; }
    .legend-label { display: none; }
  }

  /* ────────────── Comic page template ────────────── */
  body[data-template="comic"] {
    background: #ededed;
    font-family: 'Patrick Hand', 'Comic Neue', cursive;
  }
  body[data-template="comic"] .content {
    background:
      repeating-linear-gradient(45deg, rgba(0,0,0,.018) 0 2px, transparent 2px 6px),
      #ededed;
  }
  body[data-template="comic"] .scroll {
    padding: 28px 24px 100px;
  }
  body[data-template="comic"] .timeline {
    max-width: 920px;
  }
  body[data-template="comic"] .crumb-prefix,
  body[data-template="comic"] .crumb-path {
    font-family: var(--mono);
  }

  /* hide terminal date dividers in comic mode (each page has its own plate) */
  body[data-template="comic"] .date-divider { display: none; }

  /* page */
  .comic-page {
    background: #fff;
    border: 3px solid #0a0a0a;
    box-shadow: 8px 8px 0 rgba(0,0,0,.85), 0 18px 30px -10px rgba(0,0,0,.25);
    padding: 22px 22px 14px;
    margin: 0 auto 36px;
    position: relative;
  }
  .comic-page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid #0a0a0a;
  }
  .comic-page-title {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 26px;
    line-height: 1;
    color: #0a0a0a;
    letter-spacing: .5px;
  }
  .comic-page-stamp {
    font-family: 'Patrick Hand', cursive;
    font-size: 13px;
    color: #0a0a0a;
    letter-spacing: .12em;
    text-transform: uppercase;
    border: 2px solid #0a0a0a;
    padding: 2px 10px;
    transform: rotate(-2deg);
    background: #fff;
  }

  .panel-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
  }

  .panel {
    position: relative;
    background: #fff;
    border: 3px solid #0a0a0a;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 230px;
    max-height: 340px;
    transition: filter .25s, opacity .25s;
  }
  /* A real photo attachment (.panel-photo, appended after the SVG
     .panel-art background) fills the fixed-size panel edge-to-edge rather
     than the base .attach rule's letterboxed max-height — it stands in
     for the art, so it should read as the whole panel, not a thumbnail
     floating inside it. */
  .panel-photo {
    position: relative;
    z-index: 2;
    flex: 1;
    min-height: 0;
  }
  .panel-photo .attach { height: 100%; }
  .panel-photo .attach img,
  .panel-photo .attach video {
    height: 100%;
    max-height: none;
    object-fit: cover;
  }
  body[data-template="comic"] .timeline.is-filtering .panel { opacity: .25; filter: grayscale(1); }
  body[data-template="comic"] .timeline.is-filtering .panel.highlight { opacity: 1; filter: none; }
  body[data-template="comic"] .panel.kb-focused {
    outline: 4px solid var(--accent);
    outline-offset: 3px;
  }

  .panel-art {
    position: absolute;
    inset: 0;
    background: #fff;
  }
  .panel-art svg {
    width: 100%;
    height: 100%;
    display: block;
  }

  .panel-caption {
    position: relative;
    z-index: 2;
    background: #fff;
    border: 2.5px solid #0a0a0a;
    margin: 10px 14px 0;
    padding: 8px 12px 9px;
    font-family: 'Patrick Hand', 'Comic Neue', cursive;
    font-size: 17px;
    line-height: 1.18;
    color: #0a0a0a;
    text-align: center;
    align-self: stretch;
    box-shadow: 3px 3px 0 #0a0a0a;
    word-wrap: break-word;
    overflow-wrap: anywhere;
  }

  .panel-speaker {
    position: absolute;
    bottom: 6px;
    right: 8px;
    z-index: 3;
    font-family: 'Caveat', cursive;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    text-shadow: -1px -1px 0 #0a0a0a, 1px -1px 0 #0a0a0a, -1px 1px 0 #0a0a0a, 1px 1px 0 #0a0a0a;
    letter-spacing: .5px;
    pointer-events: none;
  }
  .panel.left-speaker .panel-speaker { right: auto; left: 8px; }

  .panel-number {
    position: absolute;
    top: 6px;
    right: 8px;
    z-index: 3;
    font-family: 'Patrick Hand', cursive;
    font-size: 11px;
    background: #fff;
    border: 1.5px solid #0a0a0a;
    padding: 0 5px;
    color: #0a0a0a;
    line-height: 1.4;
  }

  .panel-share {
    position: absolute;
    bottom: 6px;
    left: 8px;
    z-index: 4;
    background: #fff;
    border: 1.5px solid #0a0a0a;
    color: #0a0a0a;
    font-family: 'Patrick Hand', cursive;
    font-size: 11px;
    padding: 1px 7px;
    cursor: pointer;
    opacity: .85;
    transition: opacity .15s, background .15s;
  }
  .panel:hover .panel-share,
  .panel-share:focus-visible { opacity: 1; }
  .panel-share:hover { background: #ffdf3a; }
  .panel.left-speaker .panel-share { left: auto; right: 8px; }

  /* comic-style tags — sits in normal flow below the caption box */
  body[data-template="comic"] .msg-tags {
    position: relative;
    z-index: 2;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 14px 0;
    padding: 0;
  }
  body[data-template="comic"] .tag-chip {
    font-family: 'Patrick Hand', cursive;
    background: #fff;
    border: 1.5px solid #0a0a0a;
    border-radius: 3px;
    color: #0a0a0a;
    font-size: 12px;
    padding: 0 7px;
  }
  body[data-template="comic"] .tag-chip::before { content: none; }

  .comic-page-foot {
    text-align: center;
    margin-top: 12px;
    padding-top: 8px;
    font-family: 'Patrick Hand', cursive;
    font-size: 12px;
    color: #555;
    letter-spacing: .1em;
  }

  /* Panel attachments override */
  body[data-template="comic"] .panel .attach {
    margin: 0;
    border: 0;
    border-top: 2.5px solid #0a0a0a;
  }

  @media (max-width: 720px) {
    .panel-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .panel { min-height: 200px; }
    .panel.span-3, .panel.span-2, .panel.span-4, .panel.span-6 { grid-column: span 2 !important; }
    .panel-caption { font-size: 15px; margin: 8px 10px 0; padding: 6px 10px; }
    .comic-page { padding: 16px 14px 10px; }
    .comic-page-title { font-size: 22px; }
  }

  /* ────────────── BD (bande dessinée) template ────────────── */
  body[data-template="bd"] {
    background: #e9dcc1;
    font-family: 'Caveat', 'Patrick Hand', cursive;
  }
  body[data-template="bd"] .content {
    background:
      radial-gradient(ellipse at top, rgba(255,235,180,.35), transparent 60%),
      repeating-linear-gradient(45deg, rgba(80,50,20,.025) 0 2px, transparent 2px 8px),
      #e9dcc1;
  }
  body[data-template="bd"] .crumb-prefix,
  body[data-template="bd"] .crumb-path { font-family: var(--mono); }
  body[data-template="bd"] .scroll { padding: 28px 24px 100px; }
  body[data-template="bd"] .timeline { max-width: 880px; }
  body[data-template="bd"] .date-divider { display: none; }

  .bd-page {
    background: #fbf2dc;
    border: 2.5px solid #1a0f05;
    box-shadow:
      6px 6px 0 rgba(26,15,5,.85),
      0 20px 38px -12px rgba(0,0,0,.3);
    padding: 22px 22px 14px;
    margin: 0 auto 44px;
    position: relative;
  }
  .bd-page::before, .bd-page::after {
    content: "";
    position: absolute;
    pointer-events: none;
  }
  .bd-page::before {
    inset: 4px;
    border: 1px solid rgba(26,15,5,.15);
  }
  .bd-page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid #1a0f05;
    position: relative;
    z-index: 1;
  }
  .bd-page-title {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 30px;
    line-height: 1;
    color: #1a0f05;
    letter-spacing: .5px;
  }
  .bd-page-chapter {
    font-family: var(--mono);
    font-size: 11px;
    color: #1a0f05;
    letter-spacing: .18em;
    text-transform: uppercase;
    border: 1.5px solid #1a0f05;
    padding: 3px 10px;
    background: #f4d35e;
  }
  .bd-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(200px, auto);
    gap: 8px;
    position: relative;
    z-index: 1;
  }
  .bd-panel {
    position: relative;
    border: 2.5px solid #1a0f05;
    background: #d8c79a;
    overflow: hidden;
    min-height: 220px;
    transition: filter .25s, opacity .25s;
  }
  .bd-panel.tall { min-height: 300px; }
  body[data-template="bd"] .timeline.is-filtering .bd-panel { opacity: .25; filter: grayscale(1); }
  body[data-template="bd"] .timeline.is-filtering .bd-panel.highlight { opacity: 1; filter: none; }
  body[data-template="bd"] .bd-panel.kb-focused {
    outline: 4px solid var(--accent);
    outline-offset: 3px;
  }
  .bd-art {
    position: absolute;
    inset: 0;
    background: #d8c79a;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
  }

  .bd-bubble {
    position: absolute;
    background: #fffdf3;
    border: 2px solid #1a0f05;
    border-radius: 50% / 55%;
    padding: 10px 14px 11px;
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 16px;
    line-height: 1.08;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #1a0f05;
    z-index: 3;
    max-width: 78%;
    min-width: 70px;
    box-shadow: 1.5px 1.5px 0 rgba(26,15,5,.4);
  }
  .bd-bubble.long {
    border-radius: 18px / 24px;
    text-align: left;
    text-transform: none;
    font-size: 14px;
    letter-spacing: .2px;
    line-height: 1.18;
    padding: 9px 13px 10px;
  }
  .bd-bubble.short { font-size: 18px; }
  /* tails: two pseudos -> outlined triangle */
  .bd-bubble::before,
  .bd-bubble::after {
    content: "";
    position: absolute;
    width: 0; height: 0;
  }
  /* default tail: bottom-left, pointing down-left */
  .bd-bubble::before {
    bottom: -22px;
    left: 18%;
    border: 12px solid transparent;
    border-top-color: #1a0f05;
    border-right: 0;
    transform: skewX(-8deg);
  }
  .bd-bubble::after {
    bottom: -16px;
    left: 21%;
    border: 9px solid transparent;
    border-top-color: #fffdf3;
    border-right: 0;
    transform: skewX(-8deg);
  }
  .bd-bubble.tail-br::before { left: auto; right: 18%; border: 12px solid transparent; border-top-color: #1a0f05; border-left: 0; transform: skewX(8deg); }
  .bd-bubble.tail-br::after  { left: auto; right: 21%; border: 9px solid transparent; border-top-color: #fffdf3; border-left: 0; transform: skewX(8deg); }
  .bd-bubble.tail-bc::before { left: 45%; border: 11px solid transparent; border-top-color: #1a0f05; }
  .bd-bubble.tail-bc::after  { left: 47.5%; border: 8px solid transparent; border-top-color: #fffdf3; }

  /* narration / caption box (yellow rectangle, top corner) */
  .bd-caption-box {
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    background: #f4d35e;
    border: 2px solid #1a0f05;
    padding: 7px 11px 8px;
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.18;
    letter-spacing: .2px;
    color: #1a0f05;
    z-index: 3;
    box-shadow: 2.5px 2.5px 0 #1a0f05;
    text-transform: none;
    text-align: left;
    max-height: 55%;
    overflow: hidden;
  }
  .bd-caption-box.bottom { top: auto; bottom: 6px; }

  .bd-num {
    position: absolute;
    bottom: 5px;
    right: 7px;
    z-index: 4;
    font-family: var(--mono);
    font-size: 10px;
    background: #1a0f05;
    color: #fbf2dc;
    padding: 1px 6px;
    letter-spacing: .08em;
  }
  .bd-share {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 5;
    background: #fffdf3;
    border: 1.5px solid #1a0f05;
    color: #1a0f05;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    cursor: pointer;
    opacity: .85;
    transition: opacity .15s, background .15s;
    text-transform: uppercase;
    letter-spacing: .08em;
  }
  .bd-panel:hover .bd-share,
  .bd-share:focus-visible { opacity: 1; }
  .bd-share:hover { background: #f4d35e; }
  .bd-caption-box ~ .bd-share { top: auto; bottom: 6px; left: 6px; right: auto; }

  /* bd tags — top-left by default (the one corner never used by share/num);
     when a long-text caption box occupies the whole top strip, bd-share
     swaps to bottom-left, which frees up top-right for tags instead. */
  body[data-template="bd"] .msg-tags {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 6;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 62%;
    margin: 0;
  }
  body[data-template="bd"] .bd-caption-box ~ .msg-tags {
    left: auto;
    right: 6px;
  }
  body[data-template="bd"] .tag-chip {
    font-family: var(--mono);
    background: #fffdf3;
    border: 1.5px solid #1a0f05;
    color: #1a0f05;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 6px;
    text-transform: uppercase;
    letter-spacing: .04em;
  }
  body[data-template="bd"] .tag-chip::before { content: none; }

  .bd-page-foot {
    text-align: center;
    margin-top: 14px;
    padding-top: 6px;
    font-family: var(--mono);
    font-size: 11px;
    color: #5c3d20;
    letter-spacing: .2em;
    position: relative;
    z-index: 1;
  }
  .bd-page-foot::before,
  .bd-page-foot::after {
    content: "—";
    margin: 0 8px;
    opacity: .6;
  }

  body[data-template="bd"] .bd-panel .attach {
    position: absolute;
    inset: auto 6px 6px 6px;
    margin: 0;
    border: 2px solid #1a0f05;
    border-radius: 0;
    background: #1a0f05;
    z-index: 2;
    max-height: 45%;
    overflow: hidden;
  }
  body[data-template="bd"] .bd-panel .attach img,
  body[data-template="bd"] .bd-panel .attach video { max-height: 100%; object-fit: cover; }

  @media (max-width: 720px) {
    .bd-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; }
    .bd-panel { min-height: 180px; }
    .bd-page { padding: 16px 14px 10px; }
    .bd-page-title { font-size: 24px; }
    .bd-bubble { font-size: 14px; padding: 8px 10px; }
    .bd-bubble.long { font-size: 12.5px; }
  }

  /* ────────────── Cartoon template ──────────────
     Same panel-grid layout as Comic, but a bright, bold-outline palette,
     and — the actual special effect — every attachment photo gets run
     through the #toon-shader SVG filter (defined in index.html) so it
     reads as posterized, ink-outlined cartoon cel art instead of a
     regular photograph. */
  body[data-template="cartoon"] {
    background: #fff2e0;
    font-family: 'Comic Neue', 'Patrick Hand', cursive;
  }
  body[data-template="cartoon"] .content {
    background:
      radial-gradient(circle at 12px 12px, rgba(20,19,26,.05) 2px, transparent 2.4px) 0 0/24px 24px,
      #fff2e0;
  }
  body[data-template="cartoon"] .scroll { padding: 28px 24px 100px; }
  body[data-template="cartoon"] .timeline { max-width: 920px; }
  body[data-template="cartoon"] .crumb-prefix,
  body[data-template="cartoon"] .crumb-path { font-family: var(--mono); }
  body[data-template="cartoon"] .date-divider { display: none; }

  .cartoon-page {
    background: #fff;
    border: 3px solid #14131a;
    box-shadow: 8px 8px 0 #ff5da2, 0 18px 30px -10px rgba(0,0,0,.25);
    padding: 22px 22px 14px;
    margin: 0 auto 36px;
    position: relative;
  }
  .cartoon-page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 3px solid #14131a;
  }
  .cartoon-page-title {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 26px;
    line-height: 1;
    color: #14131a;
    letter-spacing: .5px;
  }
  .cartoon-page-stamp {
    font-family: 'Patrick Hand', cursive;
    font-size: 13px;
    color: #fff;
    letter-spacing: .12em;
    text-transform: uppercase;
    border: 2px solid #14131a;
    padding: 2px 10px;
    transform: rotate(-2deg);
    background: #ff5da2;
  }

  .cartoon-panel {
    position: relative;
    background: #fff;
    border: 3px solid #14131a;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 230px;
    max-height: 340px;
    transition: filter .25s, opacity .25s;
  }
  body[data-template="cartoon"] .timeline.is-filtering .cartoon-panel { opacity: .25; filter: grayscale(1); }
  body[data-template="cartoon"] .timeline.is-filtering .cartoon-panel.highlight { opacity: 1; filter: none; }
  body[data-template="cartoon"] .cartoon-panel.kb-focused {
    outline: 4px solid var(--accent);
    outline-offset: 3px;
  }

  body[data-template="cartoon"] .msg-tags {
    position: relative;
    z-index: 2;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 14px 0;
    padding: 0;
  }
  body[data-template="cartoon"] .tag-chip {
    font-family: 'Patrick Hand', cursive;
    background: #ffe8f4;
    border: 1.5px solid #14131a;
    border-radius: 3px;
    color: #14131a;
    font-size: 12px;
    padding: 0 7px;
  }
  body[data-template="cartoon"] .tag-chip::before { content: none; }

  .cartoon-page-foot {
    text-align: center;
    margin-top: 12px;
    padding-top: 8px;
    font-family: 'Patrick Hand', cursive;
    font-size: 12px;
    color: #6b5b8a;
    letter-spacing: .1em;
  }

  /* The special effect: attachment photos get posterized + ink-outlined
     via the toon-shader SVG filter, plus a heavy comic-panel border. */
  body[data-template="cartoon"] .cartoon-panel .attach {
    margin: 0;
    border: 0;
    border-top: 3px solid #14131a;
  }
  body[data-template="cartoon"] .attach img {
    filter: url(#toon-shader) contrast(1.08);
  }

  @media (max-width: 720px) {
    .cartoon-panel { min-height: 200px; }
    .cartoon-panel.span-3, .cartoon-panel.span-2, .cartoon-panel.span-4, .cartoon-panel.span-6 { grid-column: span 2 !important; }
    .cartoon-page { padding: 16px 14px 10px; }
    .cartoon-page-title { font-size: 22px; }
  }

  /* scrollbar */
  .scroll::-webkit-scrollbar,
  .switcher-list::-webkit-scrollbar { width: 10px; }
  .scroll::-webkit-scrollbar-thumb,
  .switcher-list::-webkit-scrollbar-thumb {
    background: var(--line-soft);
    border-radius: 6px;
    border: 2px solid var(--bg);
  }
  .scroll::-webkit-scrollbar-thumb:hover,
  .switcher-list::-webkit-scrollbar-thumb:hover { background: var(--ink-mute); }

/* ── Story share button ────────────────────────────────────────────────────── */
.story-item { position: relative; }

.story-share-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  background: none;
  border: none;
  color: var(--ink2, #57606a);
  cursor: pointer;
  padding: 5px;
  border-radius: 5px;
  line-height: 0;
  transition: opacity .15s, color .15s, background .15s;
  flex-shrink: 0;
}
.story-item:hover .story-share-btn,
.story-share-btn:focus-visible {
  opacity: 1;
}
.story-share-btn:hover {
  color: var(--accent);
  background: rgba(224, 89, 79, .08);
}

/* ── Story share popup ─────────────────────────────────────────────────────── */
#story-share-popup {
  position: fixed;
  z-index: 2000;
  width: 296px;
  background: var(--panel, #fff);
  border: 1.5px solid var(--border, #d0d7de);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.08);
  display: none;
  font-family: var(--mono, 'JetBrains Mono', monospace);
}
#story-share-popup.ssp-open { display: block; }

.ssp-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted, #8c959f);
  margin-bottom: 6px;
}
.ssp-story-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink, #1b1f24);
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ssp-url-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
}
.ssp-url {
  flex: 1;
  font-size: 10px;
  color: var(--muted, #8c959f);
  background: var(--bg, #f6f7f9);
  border: 1px solid var(--border, #d0d7de);
  border-radius: 5px;
  padding: 5px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.ssp-copy {
  font-family: var(--mono, monospace);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 11px;
  background: var(--accent, #e0594f);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
  flex-shrink: 0;
}
.ssp-copy:hover { opacity: .88; }
.ssp-copy.ssp-copied { background: #2da44e; }

.ssp-social {
  display: flex;
  gap: 6px;
}
.ssp-social a {
  flex: 1;
  text-align: center;
  font-family: var(--mono, monospace);
  font-size: 10px;
  font-weight: 700;
  padding: 5px 4px;
  border: 1.5px solid var(--border, #d0d7de);
  border-radius: 5px;
  color: var(--ink2, #57606a);
  text-decoration: none;
  transition: border-color .12s, color .12s;
  white-space: nowrap;
}
.ssp-social a:hover {
  border-color: var(--accent, #e0594f);
  color: var(--accent, #e0594f);
}
