  :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;

    --sidebar-w: 300px;
    --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;
  }

  /* ── Sidebar ── */
  .sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--panel);
    border-right: 2px solid var(--line);
    display: flex;
    flex-direction: column;
    z-index: 900;
    transition: transform .25s ease;
  }
  .sidebar-head {
    padding: 18px 18px 14px;
    border-bottom: 2px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .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); }

  .sidebar-search {
    padding: 12px 14px;
    border-bottom: 2px solid var(--line);
  }
  .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-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .story-list-label {
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink-mute);
    padding: 10px 4px 6px;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .story-list-label::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--term-green);
    box-shadow: 0 0 0 2px rgba(42,157,106,.18);
  }
  .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); }
  .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; }
  .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;
  }

  /* ── 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 {
    height: 56px;
    border-bottom: 2px solid var(--line);
    background: var(--panel);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    flex-shrink: 0;
    position: relative;
  }
  .topbar .crumb {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }
  .crumb-prefix {
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
  }
  .crumb-path {
    color: var(--ink-soft);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .crumb-path b { color: var(--ink); font-weight: 700; }
  .topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .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; }
  }

  .template-switch {
    display: inline-flex;
    gap: 0;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
  }
  .template-switch .tb-btn {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    height: 30px;
  }
  .template-switch .tb-btn:hover {
    transform: none;
    box-shadow: none;
    background: var(--rail);
  }
  .template-switch .tb-btn + .tb-btn { border-left: 1.5px solid var(--line); }
  .template-switch .tb-btn.active {
    background: var(--accent);
    color: #fff;
  }
  .template-switch .tb-btn.active:hover { background: var(--accent); }

  /* mobile menu trigger */
  #menu-toggle { display: none; }

  /* progress */
  .progress-track {
    position: relative;
    height: 3px;
    background: var(--line-soft);
    flex-shrink: 0;
  }
  #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%);
  }

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

  /* sticky tool header */
  .tools {
    max-width: 760px;
    margin: 0 auto 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 10px 12px;
    background: var(--panel);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
  }
  .legend-label {
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink-mute);
    margin-right: 4px;
  }
  .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px 4px 4px;
    border: 1.5px solid var(--line-soft);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    background: var(--panel);
    color: var(--ink);
    transition: all .12s;
    user-select: none;
  }
  .pill:hover { border-color: var(--line); }
  .pill .dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 8.5px;
    font-weight: 800;
    color: #fff;
  }
  .pill.filtering {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
  }

  /* slider */
  .slider-card {
    background: var(--panel);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    padding: 18px 14px 12px;
  }
  .slider-inner {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .slider-end {
    font-size: 10px;
    font-weight: 600;
    color: var(--ink-mute);
    letter-spacing: .08em;
    text-transform: uppercase;
    white-space: nowrap;
  }
  .slider-trackw {
    position: relative;
    flex: 1;
    height: 24px;
    display: flex;
    align-items: center;
  }
  .slider-track {
    position: absolute;
    left: 0; right: 0;
    height: 3px;
    background: var(--line-soft);
    border-radius: 2px;
  }
  .slider-fill {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
  }
  .slider-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 18px;
    height: 18px;
    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;
  }
  .slider-thumb:active { cursor: grabbing; }
  .slider-thumb.dragging { transition: none; }
  .thumb-label {
    position: absolute;
    bottom: 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;
    top: 100%; left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--ink);
  }

  /* timeline */
  .timeline {
    width: 100%;
    max-width: 760px;
    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);
  }
  .attach img, .attach video { width: 100%; display: block; }
  .attach audio { width: 100%; display: block; }
  .attach-yt {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
  }
  .attach-yt iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }

  /* 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; }

  /* sidebar overlay backdrop for mobile */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20,24,28,.4);
    z-index: 800;
  }
  .sidebar-backdrop.visible { display: block; }

  /* responsive */
  @media (max-width: 900px) {
    #menu-toggle { display: inline-flex; }
    .sidebar {
      position: fixed;
      inset: 0 auto 0 0;
      transform: translateX(-100%);
      box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .scroll { padding: 16px 14px 80px; }
    .avatar { width: 34px; height: 34px; font-size: 11px; }
    .card { max-width: calc(100% - 46px); }
    .topbar { padding: 0 12px; }
    .tb-btn .btn-label { display: none; }
    .crumb-path { font-size: 12px; }
  }

  /* ────────────── 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;
    transition: filter .25s, opacity .25s;
  }
  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: 0;
    transition: opacity .15s;
  }
  .panel:hover .panel-share { opacity: 1; }
  .panel-share:hover { background: #ffdf3a; }
  .panel.left-speaker .panel-share { left: auto; right: 8px; }

  .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: 0;
    transition: opacity .15s;
    text-transform: uppercase;
    letter-spacing: .08em;
  }
  .bd-panel:hover .bd-share { opacity: 1; }
  .bd-share:hover { background: #f4d35e; }
  .bd-caption-box ~ .bd-share { top: auto; bottom: 6px; left: 6px; right: auto; }

  .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; }
  }

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