/* ── BLOCK 1 ── */
:root {
      --yellow:      var(--brand-secondary);
      --yellow-dark: #a07e00;
      --yellow-light:#ffe566;
      --yellow-bg:   #fffde7;
      --cream:       #FFFBF5;
      --dark:        #1a1500;
      --muted:       #5c5018;
    }
    * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
    input, textarea { user-select: text; -webkit-user-select: text; }

    body {
      font-family: -apple-system, 'Segoe UI', Tahoma, sans-serif;
      background: #000;
      height: 100vh; height: 100dvh;
      overflow: hidden;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    /* ── Mobile: iphone-frame is a plain passthrough ── */
    #iphone-frame {
      width: 100%;
      height: 100vh; height: 100dvh;
      display: flex;
      flex-direction: column;
      align-items: center;
      position: relative;
    }

    #app-shell {
      width: 100%;
      max-width: 430px;
      height: 100vh; height: 100dvh;
      position: relative;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      background: var(--yellow);
      opacity: 0;
      transition: opacity 0.15s;
    }

    /* ── Desktop: iPhone 15 Pro style frame ── */
    @media (min-width: 520px) {
      body { background: #eaeaea; }

      #iphone-frame {
        width: 393px;
        height: min(852px, 96dvh);
        background: linear-gradient(160deg, #2a2a2a 0%, #111 60%, #1a1a1a 100%);
        border-radius: 54px;
        padding: 16px 12px 22px;
        position: relative;
        flex-shrink: 0;
        box-shadow:
          /* outer rim highlight */
          inset 0 0 0 1px rgba(255,255,255,0.12),
          /* inner black bevel */
          inset 0 0 0 3px #000,
          /* depth shadow */
          0 40px 120px rgba(0,0,0,0.95),
          0 8px 40px rgba(0,0,0,0.7);
      }

      /* Side volume buttons (left) */
      #iphone-frame::before {
        content: '';
        position: absolute;
        left: -4px;
        top: 130px;
        width: 4px;
        height: 36px;
        background: #2a2a2a;
        border-radius: 2px 0 0 2px;
        box-shadow: 0 50px 0 #2a2a2a, 0 96px 0 #2a2a2a;
        pointer-events: none;
      }

      /* Power button (right) */
      #iphone-frame::after {
        content: '';
        position: absolute;
        right: -4px;
        top: 168px;
        width: 4px;
        height: 72px;
        background: #2a2a2a;
        border-radius: 0 2px 2px 0;
        pointer-events: none;
      }

      /* Dynamic island */
      #iphone-frame .dynamic-island {
        position: absolute;
        top: 16px;
        left: 50%;
        transform: translateX(-50%);
        width: 120px;
        height: 34px;
        background: #000;
        border-radius: 20px;
        z-index: 9999;
        pointer-events: none;
      }

      /* Home indicator */
      #iphone-frame .home-indicator {
        position: absolute;
        bottom: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 130px;
        height: 5px;
        background: rgba(255,255,255,0.28);
        border-radius: 3px;
        z-index: 9999;
        pointer-events: none;
      }

      #app-shell {
        border-radius: 42px;
        max-width: 100%;
        width: 100%;
        height: 100%;
        box-shadow: none;
      }

      /* Push content below the dynamic island */
      .board-header {
        padding-top: 62px !important;
      }
      .onboard-bg {
        padding-top: 72px !important;
      }
    }
    @media (min-width: 520px) and (prefers-color-scheme: dark) {
      body { background: #111; }
    }
    @media (min-width: 920px) {
      #iphone-frame {
        width: 768px;
        height: min(1024px, 96dvh);
        border-radius: 40px;
        padding: 20px 16px 28px;
      }
      #iphone-frame::before { top: 200px; box-shadow: 0 60px 0 #2a2a2a; }
      #iphone-frame::after  { top: 260px; height: 80px; }
      #iphone-frame .dynamic-island {
        width: 12px; height: 12px;
        border-radius: 50%;
        top: 12px;
      }
      #iphone-frame .home-indicator { width: 220px; }
      #app-shell { border-radius: 30px; }
    }

    /* ── Admin badge ── */
    .admin-badge {
      display: inline-block;
      background: var(--dark);
      color: #fff;
      font-size: 9px;
      font-weight: 800;
      border-radius: 4px;
      padding: 1px 5px;
      letter-spacing: 0.4px;
      vertical-align: middle;
      margin-left: 3px;
    }

    /* ── Deleted post ── */
    .post-deleted {
      opacity: 0.5;
      text-align: center;
      padding: 10px;
      font-size: 13px;
      color: var(--muted);
    }

    /* ── Color swatches ── */
    .color-swatch {
      width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent;
      cursor: pointer; flex-shrink: 0; transition: border-color 0.15s, transform 0.15s;
    }
    .color-swatch.selected { border-color: var(--dark); transform: scale(1.15); }

    /* ── Section label in sheet ── */
    .sheet-label {
      font-size: 11px; font-weight: 700; color: var(--muted);
      text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; display: block;
    }

    /* ── Screens ── */
    .screen { display: none; flex-direction: column; flex: 1; overflow: hidden; }
    .screen.active { display: flex; }

    /* Onboarding screens share a yellow bg + centred card */
    .onboard-bg {
      flex: 1; display: flex; flex-direction: column;
      justify-content: center;
      background: var(--yellow);
      padding: max(60px, env(safe-area-inset-top, 0px)) 24px 40px;
      overflow-y: auto;
    }
    .onboard-logo { text-align: center; margin-bottom: 28px; }
    .onboard-logo img { width: 80px; height: 80px; border-radius: 18px; box-shadow: 0 8px 24px rgba(0,0,0,0.25); margin-bottom: 10px; display: block; margin-left: auto; margin-right: auto; }
    .onboard-logo h1 { font-size: 24px; font-weight: 800; color: var(--dark); letter-spacing: -0.5px; }
    .onboard-logo p  { font-size: 12px; color: var(--dark); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; margin-top: 3px; }

    .card { background: #fff; border-radius: 24px; padding: 24px; box-shadow: 0 8px 32px rgba(0,0,0,0.15); }
    .card-icon  { font-size: 36px; text-align: center; margin-bottom: 10px; }
    .card-title { font-size: 20px; font-weight: 700; color: var(--dark); margin-bottom: 6px; }
    .card-sub   { font-size: 14px; color: var(--muted); line-height: 1.5; margin-bottom: 20px; }
    .card-title.center, .card-sub.center { text-align: center; }

    /* ── Inputs ── */
    .bb-input {
      width: 100%; border: 1.5px solid #ddd; border-radius: 12px;
      padding: 12px 14px; font-size: 15px; outline: none; color: var(--dark);
      font-family: inherit; background: #fff; transition: border-color 0.2s; margin-bottom: 12px;
    }
    .bb-input:focus, .bb-input.valid { border-color: var(--yellow); }
    .input-wrap { position: relative; margin-bottom: 12px; }
    .input-wrap .bb-input { margin-bottom: 0; padding-right: 48px; }
    .input-counter { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--muted); pointer-events: none; }

    /* 6-digit code boxes */
    .code-boxes { display: flex; gap: 6px; margin-bottom: 12px; }
    .code-box {
      flex: 1; min-width: 0; height: 52px; border-radius: 12px;
      background: #f5f5f5; border: 2px solid #eee;
      text-align: center; font-size: 20px; font-weight: 800; color: var(--dark);
      outline: none; transition: all 0.15s; font-family: inherit;
      padding: 0;
    }
    .code-box.filled { background: var(--yellow-bg); border-color: var(--yellow); color: var(--dark); }

    /* ── Buttons ── */
    .btn-primary {
      width: 100%; background: var(--yellow); color: var(--dark);
      border: none; border-radius: 12px; padding: 14px;
      font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
      transition: opacity 0.15s;
    }
    .btn-primary:disabled { background: #d8d8d8; color: #495057; cursor: default; }
    .btn-secondary {
      background: #f0f0f0; color: var(--muted); border: none;
      border-radius: 10px; padding: 11px; font-size: 14px; cursor: pointer; font-family: inherit;
    }
    .btn-outline {
      background: transparent; color: var(--dark);
      border: 2px solid var(--yellow); border-radius: 12px;
      padding: 14px; font-size: 16px; font-weight: 700;
      cursor: pointer; font-family: inherit; min-height: 52px;
      transition: background 0.15s;
    }
    .btn-outline:active { background: var(--yellow-bg); }

    /* Monika preview row */
    .monika-preview {
      display: none; align-items: center; gap: 10px;
      background: var(--yellow-bg); border-radius: 12px;
      padding: 12px 14px; margin-bottom: 14px;
    }
    .monika-preview.show { display: flex; }
    .avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 14px; background: linear-gradient(135deg, var(--yellow-light), var(--yellow-dark)); }

    /* Meds options */
    .med-opt {
      display: flex; align-items: center; gap: 14px; width: 100%;
      background: var(--yellow-bg); border: 2px solid transparent; border-radius: 14px;
      padding: 14px 16px; cursor: pointer; text-align: left; margin-bottom: 10px;
      font-family: inherit; transition: border-color 0.15s;
    }
    .med-opt:hover { border-color: var(--yellow); }
    .med-opt-icon { font-size: 24px; }
    .med-opt-label { font-size: 14px; font-weight: 700; color: var(--dark); }
    .med-opt-sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }

    /* Med entry tags */
    .anon-med-tag {
      display: flex; align-items: center; gap: 6px;
      background: var(--yellow-bg); border: 1.5px solid rgba(245,200,0,0.2);
      border-radius: 9px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px;
    }
    .anon-med-tag-del {
      background: none; border: none; color: #dc3545; cursor: pointer;
      font-size: 14px; font-weight: 700; padding: 0 0 0 4px; line-height: 1; flex-shrink: 0;
    }
    .med-input-row { display: flex; gap: 8px; margin-bottom: 8px; }
    .med-input-row .bb-input { flex: 1; margin: 0; }
    .med-toggle-btn {
      flex: 1; padding: 9px; border-radius: 10px; font-size: 13px; font-weight: 700;
      border: 2px solid #e9ecef; background: #f8f9fa; color: #495057; cursor: pointer;
      font-family: inherit; transition: border-color 0.15s, background 0.15s, color 0.15s;
    }
    .med-toggle-btn.active {
      border-color: var(--yellow); background: var(--yellow-bg); color: var(--dark);
    }

    /* ── Board ── */
    #screen-board { background: var(--cream); position: relative; height: 100%; }

    .board-header {
      background: var(--yellow);
      /* Match the main app pattern: no fixed floor on web (env resolves to 0
         in mobile Safari tabs and on desktop), but still clears the
         translucent iOS status bar in the Capacitor shell and PWA standalone. */
      padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 0;
      flex-shrink: 0;
    }
    .board-header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
    .board-back-btn {
      color: var(--dark); text-decoration: none; background: rgba(0,0,0,0.1);
      padding: 8px 14px; border-radius: 20px; font-size: 0.9em; font-weight: 600;
      transition: background 0.2s; border: none; cursor: pointer; font-family: inherit;
    }
    @media (hover: hover) and (pointer: fine) { .board-back-btn:hover { background: rgba(0,0,0,0.18); } }
    .board-logo { display: flex; align-items: center; gap: 10px; }
    .board-logo img { width: 36px; height: 36px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
    .board-logo-name { font-size: 18px; font-weight: 800; color: var(--dark); letter-spacing: -0.3px; }
    .board-logo-sub  { font-size: 10px; color: var(--dark); letter-spacing: 0.6px; text-transform: uppercase; }

    .board-tabs { display: flex; gap: 4px; }
    .board-tab {
      flex: 1; padding: 10px 0; border-radius: 12px 12px 0 0; border: none;
      cursor: pointer; font-weight: 700; font-size: 13px; font-family: inherit;
      background: rgba(0,0,0,0.1); color: var(--dark);
      transition: all 0.15s; position: relative;
    }
    .board-tab.active { background: var(--cream); color: var(--dark); }

    /* Unseen-message badge dot */
    .board-tab.has-badge::after {
      content: '';
      position: absolute; top: 7px; right: 12px;
      width: 8px; height: 8px;
      background: #e53935;
      border-radius: 50%;
      animation: badge-pulse 1.4s ease-in-out infinite;
    }
    @keyframes badge-pulse {
      0%, 100% { opacity: 1;   transform: scale(1);   }
      50%       { opacity: 0.4; transform: scale(1.5); }
    }

    /* Posts */
    #post-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 110px; }

    .post-card { background: #fff; border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; box-shadow: 0 1px 6px rgba(0,0,0,0.06); }
    .post-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
    .post-avatar { display: flex; align-items: center; gap: 8px; }
    .post-av-circle { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--yellow-light), var(--yellow-dark)); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0; box-shadow: 0 2px 6px rgba(245,200,0,0.3); }
    .post-name { font-size: 13px; font-weight: 700; color: var(--dark); }
    .post-med  { font-size: 10px; color: var(--muted); background: var(--yellow-bg); border-radius: 4px; padding: 1px 5px; display: inline-block; margin-top: 2px; }
    .post-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
    .post-text { font-size: 14px; color: var(--dark); line-height: 1.6; margin-bottom: 12px; }
    .post-actions { display: flex; align-items: center; gap: 8px; }
    .like-btn {
      display: flex; align-items: center; gap: 5px;
      background: #f5f5f5; border: 1px solid transparent; border-radius: 20px;
      padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--muted);
      font-family: inherit; transition: all 0.15s;
    }
    .like-btn.liked { background: var(--yellow-bg); border-color: var(--yellow); color: var(--dark); font-weight: 700; }
    .icon-btn { background: none; border: none; cursor: pointer; font-size: 18px; opacity: 0.5; padding: 4px; line-height: 1; }

    /* System message */
    .sys-card { background: linear-gradient(135deg, var(--yellow), var(--yellow-dark)); border-radius: 16px; padding: 16px; margin-bottom: 10px; text-align: center; }
    .sys-card .sys-emoji { font-size: 22px; margin-bottom: 4px; }
    .sys-card .sys-text  { font-size: 14px; font-weight: 700; color: var(--dark); margin-bottom: 2px; }
    .sys-card .sys-meta  { font-size: 11px; color: var(--dark); }

    /* Announcement card */
    .ann-card { background: rgba(245,200,0,0.08); border: 1px solid rgba(245,200,0,0.2); border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; }

    /* ── FAB Footer ── */
    .fab-footer {
      position: absolute; bottom: 0; left: 0; right: 0;
      display: flex; flex-direction: column; align-items: center;
      padding: 0 12px calc(20px + env(safe-area-inset-bottom, 0px));
      z-index: 40; pointer-events: none;
    }
    .fab-hint {
      background: rgba(28,16,4,0.85); color: #fff; font-size: 12px; font-weight: 600;
      border-radius: 20px; padding: 7px 16px; margin-bottom: 8px;
      opacity: 0; transition: opacity 0.2s; pointer-events: none;
    }
    .fab-hint.show { opacity: 1; }
    .fab-bar { background: #fff; border-radius: 40px; box-shadow: 0 4px 24px rgba(0,0,0,0.14); display: flex; align-items: center; gap: 6px; padding: 8px 14px; pointer-events: all; }
    .fab-btn { width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer; font-size: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: rgba(245,200,0,0.13); transition: all 0.15s; }
    .fab-btn.active { background: var(--yellow); box-shadow: 0 2px 8px rgba(245,200,0,0.4); }
    .fab-btn-compose { width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer; font-size: 22px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: linear-gradient(135deg, var(--yellow-light), var(--yellow-dark)); box-shadow: 0 4px 12px rgba(245,200,0,0.5); }

    /* ── Overlays ── */
    .overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: flex-end; z-index: 100; }
    .overlay.hidden { display: none; }
    .sheet { background: #fff; border-radius: 24px 24px 0 0; padding: 24px 24px calc(40px + env(safe-area-inset-bottom, 0px)); width: 100%; max-height: 90vh; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
    .sheet-icon  { font-size: 36px; text-align: center; margin-bottom: 12px; }
    .sheet-title { font-size: 18px; font-weight: 700; color: var(--dark); text-align: center; margin-bottom: 8px; }
    .sheet-sub   { font-size: 13px; color: var(--muted); text-align: center; line-height: 1.6; margin-bottom: 20px; }
    .btn-row { display: flex; gap: 10px; }
    .btn-danger { flex: 1; background: #e53935; color: #fff; border: none; border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit; }

    .report-opt { display: block; width: 100%; background: var(--yellow-bg); border: none; border-radius: 10px; padding: 12px 14px; font-size: 14px; text-align: left; cursor: pointer; margin-bottom: 8px; color: var(--dark); font-family: inherit; }
    .sheet-note { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }

    .compose-ta { width: 100%; border: 1.5px solid var(--yellow); border-radius: 14px; padding: 10px 12px; font-size: 14px; resize: none; outline: none; font-family: inherit; min-height: 100px; margin-bottom: 10px; }

    .notif-box { background: var(--yellow-bg); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
    .notif-box-title { font-size: 14px; font-weight: 700; color: var(--dark); margin-bottom: 4px; }
    .notif-box-sub   { font-size: 12px; color: var(--muted); margin-bottom: 12px; }

    .e2ee-row { display: flex; gap: 12px; margin-bottom: 14px; align-items: flex-start; }
    .e2ee-row-icon  { font-size: 22px; flex-shrink: 0; }
    .e2ee-row-title { font-size: 13px; font-weight: 700; color: var(--dark); }
    .e2ee-row-sub   { font-size: 12px; color: var(--muted); line-height: 1.5; }

    .empty-state { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 14px; line-height: 1.7; }

    /* ── Pinned posts ── */
    .post-pinned { background: #fffde7; border: 1.5px solid rgba(245,200,0,0.45); }
    .pinned-badge { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 8px; letter-spacing: 0.2px; }
    .pin-active { opacity: 1 !important; color: var(--yellow-dark); }

    /* ── Comment button ── */
    .comment-btn {
      display: flex; align-items: center; gap: 4px;
      background: #f5f5f5; border: 1px solid transparent; border-radius: 20px;
      padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--muted);
      font-family: inherit; transition: all 0.15s;
    }
    .comment-btn:active { background: var(--yellow-bg); }

    /* ── Thread overlay ── */
    .thread-sheet {
      display: flex; flex-direction: column;
      max-height: 90vh; padding: 20px 20px 0; overflow: hidden;
    }
    .thread-header {
      display: flex; align-items: center; gap: 12px;
      padding-bottom: 14px; border-bottom: 1px solid #f0f0f0; margin-bottom: 14px; flex-shrink: 0;
    }
    .thread-close-btn {
      background: #f0f0f0; border: none; border-radius: 50%;
      width: 32px; height: 32px; font-size: 14px; cursor: pointer;
      display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    }
    .thread-scroll {
      flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
      padding: 0 0 12px; overscroll-behavior: contain;
    }
    .thread-orig-post {
      background: var(--yellow-bg); border-radius: 14px;
      padding: 14px 16px; margin-bottom: 14px;
      border: 1px solid rgba(245,200,0,0.3);
    }
    .thread-compose {
      flex-shrink: 0; padding: 10px 0 calc(20px + env(safe-area-inset-bottom, 0px));
      border-top: 1px solid #f0f0f0;
    }
    .thread-compose .compose-ta { margin-bottom: 8px; min-height: 56px; }

    /* ── Comment cards ── */
    .comment-card { padding: 10px 0; border-bottom: 1px solid #f5f5f5; }
    .comment-card:last-child { border-bottom: none; }
    .comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
    .comment-text { font-size: 13px; color: var(--dark); line-height: 1.55; padding-left: 36px; }

    /* ── Wiki tab ── */
    #wiki-section { padding: 12px 12px 110px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
    .wiki-pills { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; padding-bottom: 2px; }
    /* Default (>=520px): row+track wrappers collapse so pills sit in the same
       flex line as before. The mobile @media block below stacks them. */
    .wiki-pill-row, .wiki-pill-track { display: contents; }
    .wiki-pill {
      flex-shrink: 0;
      background: #f5f5f5; border: 1.5px solid transparent;
      border-radius: 20px; padding: 7px 14px; font-size: 13px; font-weight: 600;
      color: var(--muted); cursor: pointer; font-family: inherit; transition: all 0.15s;
    }
    .wiki-pill.active { background: var(--yellow); border-color: var(--yellow-dark); color: var(--dark); }
    .wiki-pill:active { transform: scale(0.96); }
    @media (max-width: 519px) {
      .wiki-pills {
        flex-direction: column;
        gap: 6px;
        overflow: visible;
        padding-bottom: 0;
      }
      /* Both rows are independently scrollable. JS toggles
         .can-scroll-left / .can-scroll-right based on scroll position so
         we fade the edge that has more content to reveal. */
      .wiki-pill-row {
        display: block;
        width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        transition: -webkit-mask-image 0.15s ease, mask-image 0.15s ease;
      }
      .wiki-pill-row::-webkit-scrollbar { display: none; }
      .wiki-pill-row.can-scroll-right:not(.can-scroll-left) {
        -webkit-mask-image: linear-gradient(to right, black 0, black calc(100% - 28px), transparent 100%);
                mask-image: linear-gradient(to right, black 0, black calc(100% - 28px), transparent 100%);
      }
      .wiki-pill-row.can-scroll-left:not(.can-scroll-right) {
        -webkit-mask-image: linear-gradient(to right, transparent 0, black 28px, black 100%);
                mask-image: linear-gradient(to right, transparent 0, black 28px, black 100%);
      }
      .wiki-pill-row.can-scroll-left.can-scroll-right {
        -webkit-mask-image: linear-gradient(to right, transparent 0, black 28px, black calc(100% - 28px), transparent 100%);
                mask-image: linear-gradient(to right, transparent 0, black 28px, black calc(100% - 28px), transparent 100%);
      }
      .wiki-pill-track {
        display: flex;
        gap: 6px;
        width: max-content;
      }
      /* One-time peek nudge on first wiki open per session: each
         overflowing row slides left, then back, so the user sees the
         affordance without an infinite marquee. */
      @keyframes wiki-peek {
        0%   { transform: translateX(0); }
        35%  { transform: translateX(-32px); }
        70%  { transform: translateX(0); }
        100% { transform: translateX(0); }
      }
      .wiki-pill-track.peek { animation: wiki-peek 900ms ease-in-out; }
      @media (prefers-reduced-motion: reduce) {
        .wiki-pill-track.peek { animation: none; }
      }
    }
    .wiki-body { padding-bottom: 20px; }
    .wiki-disclaimer {
      background: var(--yellow-bg); border-left: 3px solid var(--yellow-dark);
      border-radius: 8px; padding: 10px 12px; margin-bottom: 14px;
      font-size: 12px; color: var(--muted); line-height: 1.5;
    }
    .wiki-card {
      background: #fff; border: 1px solid #eee; border-radius: 12px;
      margin-bottom: 8px; overflow: hidden;
    }
    .wiki-card summary {
      list-style: none;
      padding: 12px 14px; cursor: pointer; font-size: 14px; font-weight: 600;
      color: var(--dark); display: flex; align-items: center; justify-content: space-between; gap: 8px;
    }
    .wiki-card summary::-webkit-details-marker { display: none; }
    .wiki-chev { font-size: 10px; color: var(--muted); transition: transform 0.2s; flex-shrink: 0; }
    .wiki-card[open] .wiki-chev { transform: rotate(180deg); }
    .wiki-card-body {
      padding: 0 14px 14px; font-size: 13px; color: var(--dark); line-height: 1.6;
    }
    .wiki-card-body p { margin-bottom: 10px; }
    .wiki-card-body p:last-child { margin-bottom: 0; }
    .wiki-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
    .wiki-meta strong { color: var(--dark); }
    .wiki-meta a { color: var(--yellow-dark); text-decoration: none; }
    .wiki-meta a:hover { text-decoration: underline; }
    .wiki-notes { font-style: italic; color: var(--muted); margin-top: 6px; }
    .wiki-link-btn {
      display: inline-block; margin-top: 6px;
      background: var(--yellow-bg); border: 1.5px solid var(--yellow);
      border-radius: 8px; padding: 6px 12px; font-size: 12px; font-weight: 600;
      color: var(--dark); text-decoration: none;
    }
    .wiki-link-btn:active { background: var(--yellow); }
    .wiki-source-meta {
      display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
      margin-top: 10px; font-size: 11px; line-height: 1.4; color: var(--muted);
    }
    .wiki-source-badge {
      display: inline-flex; align-items: center; gap: 4px;
      padding: 2px 8px; border-radius: 999px;
      font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px;
      text-transform: uppercase;
    }
    .wiki-source-badge--ai {
      background: var(--yellow-bg); color: var(--yellow-dark);
      border: 1px solid var(--yellow);
    }
    .wiki-source-badge--direct {
      background: #e8f3ec; color: #2e6b3d;
      border: 1px solid #c4dfca;
    }
    .wiki-ai-icon {
      width: 11px; height: 11px; flex-shrink: 0;
    }
    .wiki-source-name strong { color: var(--dark); font-weight: 700; }
    .wiki-media-row {
      display: flex; gap: 12px; align-items: flex-start;
      margin-bottom: 10px;
    }
    .wiki-media-cover {
      width: 72px; height: 108px; flex-shrink: 0;
      object-fit: cover; border-radius: 6px;
      background: var(--yellow-bg);
      box-shadow: 0 1px 4px rgba(0,0,0,0.12);
    }
    .wiki-media-text { flex: 1; margin: 0; }
    /* If the image fails to load, drop it from layout — body text reflows full-width. */
    .wiki-media-row--no-cover .wiki-media-cover { display: none; }
    .wiki-region-heading {
      font-size: 13px; font-weight: 700; color: var(--muted);
      text-transform: uppercase; letter-spacing: 0.5px;
      margin: 12px 0 8px;
    }
    .wiki-region-heading:first-child { margin-top: 0; }
    .wiki-loading, .wiki-empty {
      padding: 20px 12px; text-align: center; color: var(--muted);
      font-size: 13px; line-height: 1.6;
    }
    .wiki-empty a { color: var(--yellow-dark); }
    .wiki-wisdom-card {
      background: var(--yellow-bg); border-radius: 14px;
      padding: 14px 16px; margin-bottom: 10px;
      border: 1px solid rgba(245,200,0,0.3);
    }
    .wiki-wisdom-topic {
      display: inline-block; background: var(--yellow); color: var(--dark);
      font-size: 10px; font-weight: 700; text-transform: uppercase;
      letter-spacing: 0.5px; padding: 2px 8px; border-radius: 10px; margin-bottom: 8px;
    }
    .wiki-wisdom-text { font-size: 14px; color: var(--dark); line-height: 1.6; }
    .wiki-wisdom-attr { font-size: 12px; color: var(--muted); margin-top: 8px; font-style: italic; }
    .wiki-search-bar {
      display: flex; gap: 8px; align-items: center;
      margin-bottom: 12px;
    }
    .wiki-search-bar input[type="search"] {
      flex: 1; border: 1.5px solid var(--yellow); border-radius: 12px;
      padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none;
      background: #fff;
    }
    .wiki-search-bar input[type="search"]:focus { border-color: var(--yellow-dark); }
    .wiki-search-close {
      background: #f0f0f0; border: none; border-radius: 50%;
      width: 32px; height: 32px; font-size: 12px; cursor: pointer; flex-shrink: 0;
    }
    .wiki-search-close:active { background: var(--yellow-bg); }
