/* ============================================================
   AI Scenario — extracted styles
   Auto-generated: do not edit the HTML file's <style> tags
   ============================================================ */

/* ── Block 1 ──────────────────────────────────────────────── */
    /* ===================== CSS VARIABLES ===================== */
    :root {
      --bg-base: #111111;
      --bg-panel: #181818;
      --bg-card: #1e1e1e;
      --bg-input: #242424;
      --bg-hover: #2a2a2a;
      --bg-user-msg: #222222;
      --bg-bot-msg: #1f1f1f;

      --accent: #e8621a;
      --accent-dim: #c0511400;
      --accent-glow: rgba(232, 98, 26, 0.25);
      --accent2: #2ebdd9;

      --border: #2e2e2e;
      --border-light: #383838;

      --text-primary: #ffffff;
      --text-secondary: #ffffff;
      --text-dim: #808080;
      --text-dialogue: #ffffff;
      --text-bot: #2ebdd9;
      --text-user: #29bad6;
      --text-narration-bot: #2ebdd9;
      --text-narration-user: #29bad6;

      --sidebar-w: 280px;
      --topbar-h: 52px;

      --font-display: 'Inter', sans-serif;
      --font-body: 'Inter', sans-serif;

      --radius: 6px;
      --radius-lg: 10px;
      --transition: 0.18s ease;
    }

    /* ===================== RESET ===================== */
    *,
    *::before,
    *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    html,
    body {
      height: 100%;
      overflow: hidden;
      background: var(--bg-base);
      color: var(--text-primary);
      font-family: var(--font-body);
      font-size: 14px;
    }

    button {
      cursor: pointer;
      border: none;
      background: none;
      font-family: inherit;
      color: inherit;
    }

    input,
    textarea,
    select {
      font-family: inherit;
      color: inherit;
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 8px 12px;
      outline: none;
      width: 100%;
      transition: all 0.2s ease;
    }

    select {
      appearance: none;
      -webkit-appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 12px center;
      padding-right: 36px;
      cursor: pointer;
      opacity: 0.9;
    }

    select:hover {
      opacity: 1;
      border-color: rgba(255, 255, 255, 0.2);
    }

    select:focus {
      border-color: var(--accent);
      opacity: 1;
    }

    input:focus,
    textarea:focus,
    select:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px rgba(232, 98, 26, 0.1);
    }

    select option {
      background: var(--bg-panel);
    }

    textarea {
      resize: vertical;
    }

    a {
      color: inherit;
      text-decoration: none;
    }

    #charModal input,
    #charModal textarea,
    #charModal select {
      background: #1a1a1a;
      border: 1px solid #333333;
      border-radius: 8px;
      padding: 12px 14px;
      color: #ffffff;
      font-size: 14px;
      transition: border-color 0.2s;
    }

    #charModal select {
      padding-right: 36px;
      background-position: right 14px center;
      opacity: 0.9;
    }

    #charModal select:hover {
      opacity: 1;
      border-color: #444;
    }

    #charModal input::placeholder,
    #charModal textarea::placeholder {
      color: #666666;
    }

    #charModal input:focus,
    #charModal textarea:focus,
    #charModal select:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px rgba(232, 98, 26, 0.15);
    }

    /* ===================== CACHE INDICATOR STYLES ===================== */
    .cache-badge {
      display: none !important;
    }

    .cache-badge .material-symbols-outlined {
      font-size: 14px;
      line-height: 1;
      font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
    }

    .cache-badge.active .material-symbols-outlined {
      color: rgba(232, 98, 26, 0.7);
    }

    .cache-badge.cached {
      display: none;
    }

    /* User messages are row-reversed; badge after name = visually left of name, so reset order */
    .user-msg .cache-badge {
      order: 0;
    }


    .msg-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 12px;
      color: var(--text-dim);
      margin-bottom: 4px;
    }

    ::-webkit-scrollbar {
      width: 5px;
      height: 5px;
    }

    ::-webkit-scrollbar-track {
      background: transparent;
    }

    ::-webkit-scrollbar-thumb {
      background: #333;
      border-radius: 3px;
    }

    /* ===================== AUTH & COMMUNITY STYLES ===================== */
    .auth-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.85);
      backdrop-filter: blur(8px);
      z-index: 2000;
      display: none;
      align-items: center;
      justify-content: center;
    }

    .auth-modal {
      background: var(--bg-panel);
      width: 100%;
      max-width: 400px;
      padding: 32px;
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    }

    .auth-modal h2 {
      font-family: var(--font-display);
      margin-bottom: 24px;
      text-align: center;
      color: var(--accent);
    }

    .auth-tabs {
      display: flex;
      gap: 16px;
      margin-bottom: 24px;
      border-bottom: 1px solid var(--border);
    }

    .auth-tab {
      padding: 8px 0;
      flex: 1;
      text-align: center;
      font-weight: 600;
      color: var(--text-dim);
      border-bottom: 2px solid transparent;
    }

    .auth-tab.active {
      color: var(--text-primary);
      border-bottom-color: var(--accent);
    }

    .auth-form {
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    /* ── Home carousels ─────────────────────────────────────────── */
    .home-carousel-section {
      padding: 0 32px;
      margin-bottom: 32px;
    }
    .home-carousel-header {
      display: flex;
      align-items: flex-end;
      justify-content: space-between;
      margin-bottom: 14px;
    }
    .home-carousel-title {
      font-size: 28px;
      font-weight: 800;
      font-family: var(--font-display);
      background: linear-gradient(90deg, #fff 0%, #e8621a 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }
    .home-carousel-sub {
      font-size: 12px;
      color: var(--text-dim);
      margin-top: 2px;
    }
    .home-carousel-arrows { display: flex; gap: 6px; }
    .home-carousel-arrow {
      background: rgba(255,255,255,0.07);
      border: 1px solid rgba(255,255,255,0.1);
      color: var(--text-primary);
      width: 32px; height: 32px;
      border-radius: 50%;
      cursor: pointer;
      font-size: 18px;
      line-height: 1;
      display: flex; align-items: center; justify-content: center;
      transition: background 0.15s;
    }
    .home-carousel-arrow:hover { background: rgba(255,255,255,0.14); }
    .home-carousel-track {
      display: flex;
      gap: 14px;
      overflow-x: auto;
      scroll-behavior: smooth;
      padding-bottom: 10px;
      scrollbar-width: none;
    }
    .home-carousel-track::-webkit-scrollbar { display: none; }
    .home-carousel-2row {
      display: grid;
      grid-template-rows: 1fr 1fr;
      grid-auto-flow: column;
      grid-auto-columns: 364px;
      gap: 14px;
      overflow-x: auto;
      scroll-behavior: smooth;
    }
    .home-carousel-card {
      flex: 0 0 364px;
      width: 364px;
      height: 259px;
      border-radius: 14px;
      overflow: hidden;
      position: relative;
      cursor: pointer;
      background: linear-gradient(135deg,#1a1a2e,#16213e);
      transition: transform 0.18s, box-shadow 0.18s;
      flex-shrink: 0;
    }
    .home-carousel-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
    .home-carousel-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
    .home-carousel-card-overlay {
      position: absolute; inset: 0;
      background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.2) 55%, transparent 100%);
      display: flex; flex-direction: column; justify-content: flex-end;
      padding: 10px;
    }
    .home-carousel-card-title {
      font-size: 16px; font-weight: 700; color: #fff;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
      line-height: 1.3;
    }
    .home-carousel-card-meta {
      font-size: 12px; color: rgba(255,255,255,0.65);
      margin-top: 4px;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .home-carousel-card-desc {
      font-size: 11px; color: rgba(255,255,255,0.5);
      margin-top: 3px;
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
      overflow: hidden; line-height: 1.4;
    }
    .home-carousel-like-btn {
      position: absolute; top: 7px; right: 7px;
      background: rgba(0,0,0,0.5); border: none; border-radius: 50%;
      width: 26px; height: 26px; cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      color: #fff; backdrop-filter: blur(4px);
      transition: background 0.15s;
    }
    .home-carousel-like-btn:hover, .home-carousel-like-btn.liked { background: rgba(229,62,62,0.75); }
    .home-carousel-placeholder {
      color: var(--text-dim); font-size: 13px; padding: 40px 0; text-align: center; width: 100%;
    }

    /* ── Floating Discord button ────────────────────────────────── */
    #discordFab {
      position: fixed;
      bottom: 24px;
      right: 24px;
      z-index: 9000;
      display: flex;
      align-items: center;
      gap: 0;
    }
    .discord-fab-main {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 10px 16px;
      background: var(--accent);
      border: none;
      border-radius: 50px 0 0 50px;
      color: #fff;
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      box-shadow: 0 4px 20px rgba(232,98,26,0.45);
      transition: transform 0.18s, box-shadow 0.18s, background 0.18s;
    }
    .discord-fab-main:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 28px rgba(232,98,26,0.6);
      background: #f07030;
    }
    .discord-fab-dismiss {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 26px;
      height: 38px;
      background: rgba(232,98,26,0.75);
      border: none;
      border-radius: 0 50px 50px 0;
      border-left: 1px solid rgba(255,255,255,0.2);
      color: #fff;
      font-size: 16px;
      cursor: pointer;
      transition: background 0.15s;
      line-height: 1;
      padding: 0;
    }
    .discord-fab-dismiss:hover { background: rgba(180,60,10,0.9); }
    .discord-fab-label { letter-spacing: 0.01em; }
    @media (max-width: 600px) {
      #discordFab { bottom: 72px; right: 16px; }
      .discord-fab-main { padding: 10px 13px; border-radius: 50px 0 0 50px; }
      .discord-fab-label { display: none; }
    }

    /* ── Discord popup ───────────────────────────────────────────── */
    #discordPopup {
      position: fixed;
      inset: 0;
      z-index: 10050;
      background: rgba(0,0,0,0.65);
      backdrop-filter: blur(4px);
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .discord-popup-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 18px;
      padding: 36px 28px 28px;
      max-width: 360px;
      width: 90%;
      text-align: center;
      position: relative;
    }
    .discord-popup-close {
      position: absolute; top: 12px; right: 14px;
      background: none; border: none; color: var(--text-dim);
      font-size: 22px; cursor: pointer; line-height: 1;
    }
    .discord-popup-close:hover { color: var(--text-primary); }
    .discord-popup-icon {
      width: 58px; height: 58px;
      background: var(--accent);
      border-radius: 50%;
      display: flex; align-items: center; justify-content: center;
      margin: 0 auto 16px;
      box-shadow: 0 4px 18px rgba(232,98,26,0.4);
    }
    .discord-popup-title {
      font-size: 20px; font-weight: 800;
      color: var(--text-primary); margin-bottom: 8px;
      font-family: var(--font-display);
    }
    .discord-popup-desc {
      font-size: 13px; color: var(--text-dim);
      line-height: 1.65; margin-bottom: 24px;
    }
    .discord-popup-btn {
      display: inline-flex; align-items: center; gap: 8px;
      background: var(--accent); color: #fff;
      border-radius: 10px; padding: 12px 26px;
      font-size: 14px; font-weight: 700;
      text-decoration: none; cursor: pointer;
      transition: background 0.15s, transform 0.15s;
    }
    .discord-popup-btn:hover { background: #f07030; transform: translateY(-1px); }
    @media (max-width: 600px) {
      .home-carousel-section { padding: 0 14px; }
      .home-carousel-title { font-size: 20px; }
      .home-carousel-card { flex: 0 0 220px; width: 220px; height: 156px; }
      .home-carousel-2row { grid-auto-columns: 220px; }
      .home-carousel-card-title { font-size: 12px; }
      .home-carousel-card-meta { font-size: 10px; }
    }

    .community-section {
      margin-top: 32px;
    }

    .community-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
      gap: 16px;
      margin-top: 16px;
    }

    .scenario-card.community {
      border-color: var(--accent2);
    }

    .user-tier-badge {
      font-size: 10px;
      padding: 2px 6px;
      border-radius: 4px;
      background: var(--bg-card);
      border: 1px solid var(--border);
      color: var(--text-dim);
      text-transform: uppercase;
      font-weight: 800;
      margin-left: 8px;
    }

    .user-tier-badge.pro {
      background: linear-gradient(135deg, var(--accent) 0%, #ff8c00 100%);
      color: white;
      border: none;
    }

    /* ===================== LAYOUT ===================== */
    #app {
      display: flex;
      flex-direction: row;
      height: 100vh;
      width: 100vw;
      overflow: hidden;
    }

    /* ===================== SIDEBAR ===================== */
    #sidebar {
      width: var(--sidebar-w);
      min-width: var(--sidebar-w);
      background: linear-gradient(to bottom, #000 60%, rgba(232, 98, 26, 0.2) 100%);
      display: flex;
      flex-direction: column;
      transition: width var(--transition);
      overflow: hidden;
      position: relative;
      z-index: 10;
      border-right: none;
    }

    #sidebar.collapsed {
      width: 52px;
      min-width: 52px;
    }

    /* Collapsed sidebar — hide everything except icons */
    #sidebar.collapsed .nav-label {
      display: none;
    }

    #sidebar.collapsed .sidebar-logo-text {
      display: none;
    }

    #sidebar.collapsed .sidebar-section-label {
      display: none;
    }

    #sidebar.collapsed .chat-history-list {
      display: none;
    }

    #sidebar.collapsed .music-player {
      display: none;
    }

    #sidebar.collapsed .user-info {
      display: none;
    }

    #sidebar.collapsed .sidebar-user-area {
      padding: 10px 0;
      border-top: none;
      margin-top: auto;
    }

    #sidebar.collapsed .user-avatar {
      width: 36px;
      height: 36px;
      font-size: 14px;
    }

    #sidebar.collapsed .nav-item {
      padding: 12px 0;
      justify-content: center;
      gap: 0;
    }

    #sidebar.collapsed .sidebar-nav {
      padding: 12px 0;
    }

    .sidebar-logo {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 0 14px;
      height: var(--topbar-h);
      flex-shrink: 0;
    }

    .sidebar-logo svg {
      flex-shrink: 0;
    }

    .sidebar-logo-text {
      font-family: var(--font-display);
      font-size: 20px;
      font-weight: 700;
      color: var(--text-primary);
      white-space: nowrap;
      overflow: hidden;
      padding-bottom: 2px;
    }

    .sidebar-logo-text span {
      color: var(--accent);
    }

    .sidebar-collapse-btn {
      position: absolute;
      top: 14px;
      right: 10px;
      width: 24px;
      height: 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: rgba(255, 255, 255, 0.92);
      border-radius: 4px;
      transition: background var(--transition);
    }

    .sidebar-collapse-btn:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    #sidebar.collapsed .sidebar-collapse-btn {
      right: 14px;
    }

    .sidebar-nav {
      padding: 0 0 8px;
      flex-shrink: 0;
    }

    .nav-item {
      display: flex;
      align-items: center;
      gap: 14px;
      padding: 16px 20px;
      color: var(--text-secondary);
      cursor: pointer;
      border-radius: 0;
      transition: background var(--transition), color var(--transition);
      white-space: nowrap;
      overflow: hidden;
      font-size: 15px;
      font-weight: 500;
      letter-spacing: 0.1px;
    }

    .nav-item:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .nav-item.active {
      background: linear-gradient(90deg, rgba(232, 98, 26, 0.18) 0%, rgba(232, 98, 26, 0.08) 78%, rgba(232, 98, 26, 0) 100%);
      color: var(--accent);
      border-right: 3px solid var(--accent);
    }

    .nav-item svg {
      flex-shrink: 0;
    }

    .nav-label {
      overflow: hidden;
      white-space: nowrap;
    }

    .sidebar-section-label {
      padding: 16px 18px 6px;
      font-size: 11px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.2px;
      color: var(--text-dim);
      white-space: nowrap;
      overflow: hidden;
    }

    .chat-history-list {
      flex: 1;
      overflow-y: auto;
      padding: 0;
    }

    .chat-history-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 12px;
      cursor: pointer;
      color: var(--text-secondary);
      transition: background var(--transition);
      overflow: hidden;
    }

    .chat-history-item:hover {
      background: var(--bg-hover);
    }

    .chat-history-item:hover .chat-menu-btn {
      opacity: 1 !important;
    }

    .chat-menu-btn {
      cursor: pointer;
      transition: all var(--transition);
    }

    .chat-menu-btn:hover {
      color: var(--accent) !important;
      background: var(--bg-card);
    }

    .chat-del-btn:hover {
      color: #e05252 !important;
      background: rgba(224, 82, 82, 0.1);
    }

    .chat-history-avatar {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      background: var(--bg-card);
      flex-shrink: 0;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 10px;
      color: var(--text-dim);
      border: 1px solid var(--border);
    }

    .chat-history-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .chat-history-info {
      overflow: hidden;
      flex: 1;
    }

    .chat-history-name {
      font-size: 13px;
      font-weight: 600;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .chat-history-time {
      font-size: 11px;
      color: var(--text-dim);
      margin-top: 1px;
    }

    .sidebar-user-area {
      border-top: none;
      padding: 16px 14px 14px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      flex-shrink: 0;
      cursor: pointer;
      transition: background var(--transition);
      margin-top: 0;
    }

    .sidebar-user-area:hover {
      background: transparent;
    }

    .user-avatar {
      width: 96px;
      height: 96px;
      border-radius: 50%;
      background: var(--accent);
      flex-shrink: 0;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 700;
      font-size: 32px;
      border: 2px solid rgba(255,255,255,0.1);
      transition: box-shadow 0.3s ease;
    }

    .sidebar-user-area:hover .user-avatar {
      box-shadow: 0 0 22px rgba(232, 98, 26, 0.55);
    }

    .user-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .user-info {
      overflow: hidden;
      width: 100%;
      text-align: center;
    }

    .user-name-script {
      font-family: 'Comfortaa', 'Nothing You Could Do', cursive;
      font-size: 22px;
      font-weight: 700;
      color: #ffffff;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      line-height: 1.2;
      letter-spacing: 0.5px;
    }

    /* ===================== MAIN CONTENT ===================== */
    #main {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      position: relative;
      min-width: 0;
    }

    /* ===================== TOP BAR ===================== */
    #topbar {
      height: var(--topbar-h);
      background: #000;
      display: flex;
      align-items: center;
      padding: 0 20px;
      gap: 14px;
      flex-shrink: 0;
      position: relative;
      z-index: 5;
      justify-content: flex-end;
      border-bottom: none;
    }

    .topbar-search {
      flex: 1;
      max-width: 480px;
      position: relative;
    }

    .topbar-search input {
      background: var(--bg-input);
      border: 1px solid var(--border);
      padding: 7px 12px 7px 34px;
      border-radius: 20px;
      font-size: 13px;
      color: var(--text-secondary);
    }

    .topbar-search input::placeholder {
      color: var(--text-dim);
    }

    .topbar-search-icon {
      position: absolute;
      left: 10px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-dim);
    }

    .topbar-actions {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-left: auto;
      padding-right: 20px;
    }

    .topbar-btn {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      transition: background var(--transition);
    }

    .topbar-btn:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .topbar-avatar {
      width: 34px;
      height: 34px;
      flex-shrink: 0;
      border-radius: 50%;
      background: var(--accent);
      overflow: hidden;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 700;
      font-size: 13px;
    }

    .topbar-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    /* Chat topbar */
    #chat-topbar {
      height: var(--topbar-h);
      background: var(--bg-base);
      border-bottom: 1px solid var(--border);
      display: none;
      align-items: center;
      padding: 0 16px;
      gap: 12px;
      flex-shrink: 0;
    }

    .chat-topbar-scenario-img {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      background: var(--bg-card);
      overflow: hidden;
      flex-shrink: 0;
      border: 2px solid var(--border);
    }

    .chat-topbar-scenario-img img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .chat-topbar-info {
      flex: 1;
      overflow: hidden;
      min-width: 80px;
      flex-shrink: 1;
    }

    .chat-topbar-info:hover .chat-topbar-name {
      color: var(--accent);
    }

    .chat-topbar-name {
      font-size: 13px;
      font-weight: 700;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .chat-topbar-sub {
      font-size: 11px;
      color: var(--text-dim);
    }

    .chat-topbar-badge {
      font-size: 10px;
      background: var(--accent);
      color: white;
      padding: 1px 6px;
      border-radius: 10px;
      font-weight: 700;
      font-family: var(--font-display);
    }

    .chat-topbar-actions {
      display: flex;
      gap: 6px;
      margin-left: auto;
      align-items: center;
      flex-shrink: 1;
      overflow: hidden;
      min-width: 0;
    }

    .persona-picker-btn {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 4px 10px 4px 6px;
      border-radius: 20px;
      border: 1px solid var(--border);
      background: var(--bg-card);
      color: var(--text-secondary);
      font-size: 11px;
      font-weight: 600;
      cursor: pointer;
      transition: border-color var(--transition), color var(--transition);
      max-width: 140px;
    }

    .persona-picker-btn:hover {
      border-color: var(--accent);
      color: var(--text-primary);
    }

    .persona-picker-btn.active {
      border-color: var(--accent);
      color: var(--accent);
    }

    .persona-picker-avatar {
      width: 22px;
      height: 22px;
      border-radius: 50%;
      background: var(--bg-input);
      flex-shrink: 0;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px solid var(--border);
    }

    .persona-picker-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .persona-picker-name {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    /* Persona picker dropdown */
    #personaPickerMenu {
      position: fixed;
      z-index: 300;
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
      display: none;
      max-height: 480px;
    }

    #personaPickerMenu.open {
      display: flex;
      flex-direction: row;
      padding: 0;
      overflow: hidden;
      border-radius: var(--radius-lg);
    }

    /* Left list — scrollable */
    .picker-list-col {
      display: flex;
      flex-direction: column;
      width: 210px;
      flex-shrink: 0;
      border-right: 1px solid var(--border);
      overflow: hidden;
    }

    .picker-list-scroll {
      flex: 1;
      overflow-y: auto;
      padding: 6px;
    }

    .picker-list-scroll::-webkit-scrollbar {
      width: 4px;
    }

    .picker-list-footer {
      padding: 6px;
      border-top: 1px solid var(--border);
      flex-shrink: 0;
    }

    /* Right preview */
    .picker-preview-col {
      width: 200px;
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      background: var(--bg-card);
    }

    .picker-preview-col.empty {
      align-items: center;
      justify-content: center;
      padding: 20px;
      color: var(--text-dim);
      font-size: 11px;
      text-align: center;
      gap: 8px;
    }

    .picker-preview-hero {
      width: 100%;
      height: 130px;
      background: linear-gradient(135deg, #1a0e2e, #2d1b4e);
      flex-shrink: 0;
      overflow: hidden;
    }

    .picker-preview-hero img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      object-position: top center;
    }

    .picker-preview-hero-placeholder {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: rgba(167, 139, 250, 0.25);
    }

    .picker-preview-body {
      padding: 10px 12px;
      flex: 1;
      overflow-y: auto;
      min-height: 0;
    }

    .picker-preview-body::-webkit-scrollbar {
      width: 3px;
    }

    .picker-preview-name {
      font-size: 13px;
      font-weight: 700;
      color: var(--text-primary);
      margin-bottom: 6px;
      line-height: 1.3;
    }

    .picker-preview-desc {
      font-size: 11px;
      color: var(--text-secondary);
      line-height: 1.6;
      white-space: pre-wrap;
      word-break: break-word;
    }

    .picker-preview-actions {
      padding: 8px 10px;
      border-top: 1px solid var(--border);
      display: flex;
      gap: 6px;
      flex-shrink: 0;
    }

    .persona-picker-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 10px;
      border-radius: var(--radius);
      cursor: pointer;
      font-size: 13px;
      color: var(--text-secondary);
      transition: background var(--transition), color var(--transition);
    }

    .persona-picker-item:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .persona-picker-item.selected {
      color: var(--accent);
    }

    .persona-picker-item-avatar {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      background: var(--bg-card);
      flex-shrink: 0;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px solid var(--border);
      font-size: 10px;
      color: var(--text-dim);
    }

    .persona-picker-item-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .persona-picker-item-info {
      flex: 1;
      overflow: hidden;
    }

    .persona-picker-item-name {
      font-weight: 600;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .persona-picker-divider {
      height: 1px;
      background: var(--border);
      margin: 4px 0;
    }

    .chat-topbar-btn {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      transition: background var(--transition);
    }

    .chat-topbar-btn:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .chat-topbar-icon-btn {
      width: 30px;
      height: 30px;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      transition: background var(--transition), color var(--transition);
      flex-shrink: 0;
      position: relative;
    }

    .chat-topbar-icon-btn:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .chat-topbar-icon-btn .material-symbols-outlined {
      font-size: 18px;
    }

    .chat-topbar-icon-btn::after {
      content: attr(data-tooltip);
      position: absolute;
      bottom: calc(100% + 6px);
      left: 50%;
      transform: translateX(-50%) translateY(4px);
      background: #2a2a2a;
      color: var(--text-secondary);
      font-size: 11px;
      font-weight: 500;
      white-space: nowrap;
      padding: 4px 8px;
      border-radius: 5px;
      border: 1px solid var(--border-light);
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.15s ease, transform 0.15s ease;
      z-index: 500;
    }

    .chat-topbar-icon-btn:hover::after {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }

    .chat-overflow-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 14px;
      font-size: 13px;
      color: var(--text-secondary);
      width: 100%;
      text-align: left;
      transition: background var(--transition), color var(--transition);
    }

    .chat-overflow-item:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    /* ===================== VIEWS ===================== */
    .view {
      display: none;
      flex: 1 1 auto;
      overflow: hidden;
      width: 100%;
      min-width: 0;
    }

    .view.active {
      display: flex;
      flex-direction: column;
    }

    /* Subtle warm gradient on all views except chat */
    .view.active:not(#view-chat) {
      background: linear-gradient(to bottom, #000 60%, rgba(232, 98, 26, 0.2) 100%);
    }

    /* ===================== HOME VIEW ===================== */
    #view-home {
      overflow-y: auto;
    }

    .home-content {
      padding: 36px 40px 24px;
      max-width: 1600px;
      margin: 0 auto;
      width: 100%;
    }

    .featured-header {
      display: flex;
      align-items: center;
      gap: 10px;
      margin-bottom: 14px;
    }

    .featured-header h2 {
      font-family: var(--font-display);
      font-size: 16px;
      font-weight: 600;
    }

    .featured-header .add-btn {
      width: 22px;
      height: 22px;
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 16px;
      transition: background var(--transition);
    }

    .featured-header .add-btn:hover {
      background: var(--accent);
      color: white;
    }

    .featured-banner {
      width: 100%;
      height: 520px;
      flex-shrink: 0;
      background: #0a0a0a;
      overflow: hidden;
      position: relative;
      border: none;
      border-radius: 0;
      display: flex;
      align-items: stretch;
      cursor: default;
      isolation: isolate;
    }

    .featured-banner-img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(135deg, #1a0a0a 0%, #2a1a0a 50%, #1a0a1a 100%);
      transition: opacity 0.4s ease, transform 1.4s ease, filter 0.9s ease;
      z-index: 0;
    }

    .featured-banner:hover .featured-banner-img {
      transform: scale(1.03);
      filter: saturate(1.1) brightness(1.04);
    }

    .featured-banner-img img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      object-position: center 25%;
      display: block;
    }

    .featured-banner-overlay {
      position: absolute;
      inset: 0;
      z-index: 1;
      pointer-events: none;
      background:
        linear-gradient(to top,
          rgba(0,0,0,0.97) 0%,
          rgba(0,0,0,0.82) 22%,
          rgba(0,0,0,0.42) 50%,
          rgba(0,0,0,0.08) 100%),
        linear-gradient(to right,
          rgba(0,0,0,0.65) 0%,
          rgba(0,0,0,0.3) 40%,
          transparent 75%);
    }

    .featured-banner-content {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 3;
      padding: 0 60px 52px;
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      text-align: left;
      transition: opacity 0.4s ease, transform 0.35s ease;
    }

    .featured-banner:hover .featured-banner-content {
      transform: translateY(-3px);
    }

    .featured-banner-eyebrow {
      font-size: 11px;
      font-weight: 700;
      letter-spacing: 3px;
      text-transform: uppercase;
      color: var(--accent);
      margin-bottom: 10px;
      text-shadow: 0 1px 8px rgba(0,0,0,0.9);
    }

    .featured-banner-title {
      font-family: 'Cinzel', serif;
      font-size: clamp(36px, 4vw, 58px);
      font-weight: 800;
      text-transform: uppercase;
      letter-spacing: 4px;
      color: #ffffff;
      text-shadow: 0 2px 32px rgba(0,0,0,0.95), 0 0 80px rgba(0,0,0,0.7);
      margin-bottom: 14px;
      line-height: 1.08;
      max-width: 700px;
    }

    .featured-banner-desc {
      font-size: 15px;
      color: rgba(255,255,255,0.88);
      max-width: 520px;
      line-height: 1.65;
      margin-bottom: 28px;
      text-shadow: 0 1px 12px rgba(0,0,0,0.95);
      font-weight: 400;
    }

    .featured-btn-start {
      font-size: 15px !important;
      padding: 13px 28px !important;
      font-weight: 700 !important;
      border-radius: 8px !important;
    }

    .featured-btn-details {
      font-size: 15px !important;
      padding: 13px 24px !important;
      font-weight: 600 !important;
      border-radius: 8px !important;
      background: rgba(255,255,255,0.12) !important;
      border-color: rgba(255,255,255,0.25) !important;
      backdrop-filter: blur(6px) !important;
    }

    .featured-btn-details:hover {
      background: rgba(255,255,255,0.2) !important;
      border-color: rgba(255,255,255,0.45) !important;
    }

    .featured-nav-btn {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      width: 36px;
      height: 36px;
      background: rgba(0, 0, 0, 0.45);
      border: 1px solid rgba(255, 255, 255, 0.15);
      border-radius: 50%;
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      z-index: 10;
      transition: background 0.2s;
      opacity: 0;
      transition: opacity 0.2s, background 0.2s;
    }

    .featured-banner:hover .featured-nav-btn {
      opacity: 1;
    }

    .featured-nav-btn:hover {
      background: rgba(232, 98, 26, 0.7);
    }

    .featured-nav-prev {
      left: 12px;
    }

    .featured-nav-next {
      right: 12px;
    }

    .featured-dots {
      position: absolute;
      bottom: 14px;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      gap: 7px;
      z-index: 10;
    }

    .featured-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.35);
      cursor: pointer;
      transition: background 0.3s, transform 0.3s;
    }

    .featured-dot.active {
      background: #ffffff;
      transform: scale(1.25);
    }

    .featured-banner-actions {
      display: flex;
      gap: 12px;
    }

    .featured-banner-actions .btn-primary,
    .featured-banner-actions .btn-secondary {
      font-size: 14px;
      padding: 10px 22px;
      font-weight: 600;
    }

    .btn-primary {
      background: var(--accent);
      color: white;
      padding: 7px 16px;
      border-radius: var(--radius);
      font-size: 12px;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 6px;
      transition: background var(--transition), transform var(--transition);
    }

    .btn-primary:hover {
      background: #d0561a;
      transform: translateY(-1px);
    }

    .btn-secondary {
      background: rgba(255, 255, 255, 0.08);
      color: var(--text-primary);
      padding: 7px 16px;
      border-radius: var(--radius);
      font-size: 12px;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 6px;
      border: 1px solid rgba(255, 255, 255, 0.12);
      transition: background var(--transition);
    }

    .btn-secondary:hover {
      background: rgba(255, 255, 255, 0.14);
    }

    .btn-danger {
      background: rgba(224, 82, 82, 0.15);
      color: #e05252;
      padding: 7px 16px;
      border-radius: var(--radius);
      font-size: 12px;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 6px;
      border: 1px solid rgba(224, 82, 82, 0.3);
      transition: background var(--transition);
    }

    .btn-danger:hover {
      background: rgba(224, 82, 82, 0.28);
    }

    .creator-bottom-actions {
      position: sticky;
      bottom: 0;
      z-index: 4;
      display: flex;
      justify-content: flex-end;
      gap: 12px;
      padding: 12px 0 12px;
      margin-top: 8px;
      background: linear-gradient(to bottom, transparent, var(--bg-main) 40%);
    }

    /* ── Publishing Panel ── */
    .publish-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      padding: 14px 0;
      border-bottom: 1px solid rgba(255,255,255,0.07);
    }
    .publish-row:last-child { border-bottom: none; }
    .publish-row-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
    .publish-row-sub { font-size: 11px; color: rgba(255,255,255,0.7); margin-top: 2px; }

    /* Big pill toggle */
    .pub-toggle-pill {
      display: flex;
      align-items: center;
      gap: 10px;
      flex-shrink: 0;
    }
    .pub-toggle-word {
      font-size: 12px;
      font-weight: 600;
      color: var(--text-dim);
      transition: color 0.2s;
      min-width: 40px;
    }
    .pub-toggle-word.active { color: var(--accent); }
    .pub-toggle-track {
      position: relative;
      width: 48px;
      height: 26px;
      border-radius: 13px;
      background: rgba(255,255,255,0.12);
      cursor: pointer;
      transition: background 0.2s;
      flex-shrink: 0;
    }
    .pub-toggle-track.on { background: var(--accent); }
    .pub-toggle-track input {
      opacity: 0; position: absolute; width: 0; height: 0;
    }
    .pub-toggle-thumb {
      position: absolute;
      top: 3px; left: 3px;
      width: 20px; height: 20px;
      background: #fff;
      border-radius: 50%;
      transition: transform 0.2s;
      pointer-events: none;
    }
    .pub-toggle-track.on .pub-toggle-thumb { transform: translateX(22px); }

    /* Playable character toggle in char modal */
    .char-playable-row { display: flex; align-items: center; gap: 14px; padding: 12px 0 4px; border-top: 1px solid rgba(255,255,255,0.07); margin-top: 10px; }
    .char-playable-info { flex: 1; }
    .char-playable-info strong { font-size: 13px; font-weight: 600; color: #e0e0e0; display: block; }
    .char-playable-info span { font-size: 11px; color: #888; }
    .char-card-playable-badge { display: inline-block; font-size: 10px; font-weight: 700; color: #e8621a; background: rgba(232,98,26,0.15); border: 1px solid rgba(232,98,26,0.35); border-radius: 4px; padding: 2px 6px; margin-left: 6px; vertical-align: middle; text-transform: uppercase; letter-spacing: 0.04em; }

    /* Playable character selection modal */
    #playableCharModal { display:none; position:fixed; inset:0; z-index:11000; background:rgba(0,0,0,0.85); align-items:center; justify-content:center; }
    #playableCharModal.open { display:flex; }
    .playable-char-box { background:#181818; border:1px solid #2e2e2e; border-radius:16px; padding:32px; max-width:520px; width:90%; max-height:80vh; overflow-y:auto; }
    .playable-char-box h2 { font-size:20px; font-weight:800; color:#fff; margin:0 0 6px; }
    .playable-char-box .playable-sub { font-size:13px; color:#888; margin-bottom:24px; }
    .playable-char-list { display:flex; flex-direction:column; gap:10px; }
    .playable-char-option { display:flex; align-items:center; gap:14px; padding:14px 16px; border:2px solid #2e2e2e; border-radius:10px; cursor:pointer; background:#111; transition:border-color 0.15s, background 0.15s; }
    .playable-char-option:hover { border-color:#444; background:#1a1a1a; }
    .playable-char-option.selected { border-color:#e8621a; background:rgba(232,98,26,0.08); }
    .playable-char-avatar { width:44px; height:44px; border-radius:50%; background:#2e2e2e; flex-shrink:0; overflow:hidden; display:flex; align-items:center; justify-content:center; }
    .playable-char-avatar img { width:100%; height:100%; object-fit:cover; }
    .playable-char-name { font-size:15px; font-weight:700; color:#fff; }
    .playable-char-traits { font-size:12px; color:#888; margin-top:2px; }
    .playable-char-persona-tag { font-size:10px; font-weight:700; color:#6366f1; background:rgba(99,102,241,0.15); border:1px solid rgba(99,102,241,0.3); border-radius:4px; padding:2px 7px; margin-left:8px; text-transform:uppercase; }
    .playable-char-tag { font-size:10px; font-weight:700; color:#e8621a; background:rgba(232,98,26,0.15); border:1px solid rgba(232,98,26,0.3); border-radius:4px; padding:2px 7px; margin-left:8px; text-transform:uppercase; }
    .playable-char-actions { display:flex; justify-content:flex-end; gap:12px; margin-top:24px; }

    /* Content warning chips */
    .warn-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
    .warn-chip {
      display: inline-flex; align-items: center; gap: 5px;
      padding: 5px 11px;
      border-radius: 20px;
      font-size: 11px; font-weight: 600;
      border: 1.5px solid rgba(255,255,255,0.12);
      background: rgba(255,255,255,0.05);
      color: var(--text-dim);
      cursor: pointer;
      transition: all 0.15s;
      user-select: none;
    }
    .warn-chip:hover { border-color: rgba(255,255,255,0.25); color: #fff; }
    .warn-chip.active[data-warn="violence"]  { background: rgba(232,123,53,0.18); border-color: #e87b35; color: #e87b35; }
    .warn-chip.active[data-warn="gore"]      { background: rgba(204,34,34,0.18);  border-color: #cc2222; color: #e06060; }
    .warn-chip.active[data-warn="sexual"]    { background: rgba(155,89,182,0.18); border-color: #9b59b6; color: #c39bd3; }
    .warn-chip.active[data-warn="substance"] { background: rgba(41,128,185,0.18); border-color: #2980b9; color: #7fc4f0; }
    .warn-chip.active[data-warn="language"]  { background: rgba(127,140,141,0.18);border-color: #7f8c8d; color: #aab7b8; }
    .warn-chip.active[data-warn="dark"]      { background: rgba(80,60,120,0.22);  border-color: #7d6aaa; color: #b2a4d4; }
    .warn-chip.active[data-warn="dead-dove"] { background: rgba(160,160,180,0.15); border-color: #9090a8; color: #c0c0d0; }
    .warn-chip.active[data-warn="noncon"]    { background: rgba(200,30,30,0.18);   border-color: #cc2222; color: #e08080; }
    .warn-chip.active[data-warn="dubcon"]    { background: rgba(200,100,30,0.18);  border-color: #d06020; color: #e0a070; }
    .warn-chip.active[data-warn="trauma"]    { background: rgba(100,60,160,0.18);  border-color: #8060b0; color: #c0a0e0; }

    /* Warning badge on scenario cards */
    .sc-warn-badges {
      position: absolute;
      bottom: 6px; left: 6px;
      display: flex; flex-wrap: wrap; gap: 3px;
      max-width: calc(100% - 12px);
    }
    .sc-warn-badge {
      font-size: 9px; font-weight: 700;
      padding: 2px 6px;
      border-radius: 3px;
      letter-spacing: 0.3px;
      text-transform: uppercase;
    }
    .sc-warn-badge.violence  { background: rgba(232,123,53,0.85); color: #fff; }
    .sc-warn-badge.gore      { background: rgba(180,30,30,0.85);  color: #fff; }
    .sc-warn-badge.sexual    { background: rgba(120,60,170,0.85); color: #fff; }
    .sc-warn-badge.substance { background: rgba(30,100,160,0.85); color: #fff; }
    .sc-warn-badge.language  { background: rgba(80,90,90,0.85);   color: #ccc; }
    .sc-warn-badge.dark      { background: rgba(50,35,80,0.85);   color: #bbb; }

    .section-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;
    }

    .section-header h3 {
      font-family: var(--font-display);
      font-size: 14px;
      font-weight: 600;
    }

    .scenario-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 24px;
      margin-bottom: 28px;
    }

    .scenario-card {
      background: transparent;
      border: none;
      border-radius: 0;
      overflow: visible;
      cursor: pointer;
      transition: all 0.2s ease;
      position: relative;
      aspect-ratio: auto;
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .scenario-card:hover {
      transform: none;
    }

    .scenario-card-img {
      position: relative;
      inset: auto;
      width: 100%;
      aspect-ratio: 16/9;
      background: #1a1a1a;
      border: 1px solid transparent;
      border-radius: 8px;
      overflow: hidden;
      transition: border-color 0.2s ease;
    }

    .scenario-card:hover .scenario-card-img {
      border-color: rgba(232, 98, 26, 0.5);
    }

    .scenario-card-img img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .scenario-card-overlay {
      position: absolute;
      inset: 0;
      background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.4) 50%, rgba(0, 0, 0, 0) 100%);
      display: none;
    }

    .scenario-card-age {
      position: absolute;
      top: 8px;
      left: 8px;
      font-size: 9px;
      font-weight: 700;
      background: rgba(0, 0, 0, 0.7);
      border: 1px solid var(--border);
      padding: 2px 6px;
      border-radius: 4px;
      color: var(--text-secondary);
      display: none;
    }

    .scenario-card-menu-btn {
      position: absolute;
      top: 8px;
      right: 8px;
      width: 28px;
      height: 28px;
      background: rgba(0, 0, 0, 0.6);
      border-radius: 6px;
      display: none;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 16px;
      z-index: 2;
    }

    .scenario-card:hover .scenario-card-menu-btn {
      display: flex;
    }

    .prof-sc-menu-popup {
      background: #1e1e1e;
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 10px;
      box-shadow: 0 8px 32px rgba(0,0,0,0.6);
      overflow: hidden;
      min-width: 200px;
    }
    .prof-sc-menu-popup button {
      display: flex;
      align-items: center;
      gap: 10px;
      width: 100%;
      padding: 12px 16px;
      background: none;
      border: none;
      color: var(--text-primary);
      font-size: 14px;
      text-align: left;
      cursor: pointer;
      transition: background 0.15s;
    }
    .prof-sc-menu-popup button:hover { background: rgba(255,255,255,0.07); }
    .prof-sc-menu-popup button.danger { color: #e05555; }
    .prof-sc-menu-popup button.danger:hover { background: rgba(224,85,85,0.1); }
    .prof-sc-menu-popup button + button { border-top: 1px solid rgba(255,255,255,0.06); }

    .scenario-card-body {
      position: static;
      padding: 0;
      z-index: 1;
    }

    .scenario-card-title {
      font-size: 14px;
      font-weight: 700;
      color: #ffffff;
      margin-bottom: 6px;
      line-height: 1.3;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .scenario-card-desc {
      font-size: 12px;
      color: #a7b0bd;
      line-height: 1.5;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    /* ===================== CREATE CONTENT HUB ===================== */
    #view-create-hub {
      overflow-y: auto;
    }

    .create-hub-content {
      padding: 48px 60px;
      max-width: 900px;
      margin: 0 auto;
      width: 100%;
      display: flex;
      flex-direction: column;
      gap: 20px;
    }

    .create-hub-title {
      font-family: var(--font-display);
      font-size: 22px;
      font-weight: 700;
      text-align: center;
      margin-bottom: 10px;
      color: var(--text-primary);
    }

    .create-hub-card {
      width: 100%;
      height: 220px;
      border-radius: var(--radius-lg);
      overflow: hidden;
      position: relative;
      cursor: pointer;
      border: 1px solid var(--border);
      transition: transform var(--transition), border-color var(--transition);
    }

    .create-hub-card:hover {
      transform: translateY(-3px);
      border-color: var(--border-light);
    }

    .create-hub-card-bg {
      position: absolute;
      inset: 0;
      background-size: cover;
      background-position: center;
      transition: transform 0.4s ease;
    }

    .create-hub-card:hover .create-hub-card-bg {
      transform: scale(1.03);
    }

    .hub-card-scenarios .create-hub-card-bg {
      background-image: url("assets/create.jpg");
      background-size: cover;
      background-position: center;
    }

    .create-hub-card-overlay {
      position: absolute;
      inset: 0;
      background: linear-gradient(to right, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.1) 100%);
    }

    .create-hub-card-label {
      position: absolute;
      bottom: 18px;
      left: 22px;
      font-family: var(--font-display);
      font-size: 26px;
      font-weight: 700;
      color: white;
      text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
      letter-spacing: 0.5px;
    }

    .create-hub-card-tag {
      position: absolute;
      top: 16px;
      right: 18px;
      font-size: 12px;
      font-weight: 700;
      color: #f5c842;
      font-family: var(--font-display);
      text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
    }

    /* ===================== MEMORY CARD ===================== */
    .memory-card {
      background: linear-gradient(135deg, rgba(232, 98, 26, 0.08), rgba(46, 189, 217, 0.06));
      border: 1px solid rgba(232, 98, 26, 0.3);
      border-radius: var(--radius-lg);
      margin: 12px 40px;
      overflow: hidden;
      transition: all 0.15s ease;
    }

    .memory-card:hover {
      border-color: rgba(232, 98, 26, 0.5);
      box-shadow: 0 4px 12px rgba(232, 98, 26, 0.1);
    }

    .memory-card-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 14px 16px;
      cursor: pointer;
      user-select: none;
      background: rgba(255, 255, 255, 0.01);
      transition: background 0.15s ease;
    }

    .memory-card-header:hover {
      background: rgba(255, 255, 255, 0.04);
    }

    .memory-card-title {
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      color: var(--accent);
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .memory-card-header-right {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .memory-card-edit-btn {
      font-size: 11px;
      font-weight: 600;
      color: var(--text-dim) !important;
      padding: 6px 12px;
      border-radius: 6px;
      background: rgba(232, 98, 26, 0.08);
      border: 1px solid rgba(232, 98, 26, 0.2);
      cursor: pointer;
      transition: all var(--transition);
      display: inline-block !important;
      visibility: visible !important;
    }

    .memory-card-edit-btn:hover {
      color: var(--accent) !important;
      border-color: var(--accent);
      background: rgba(232, 98, 26, 0.15);
    }

    .memory-card-delete-btn {
      font-size: 11px;
      font-weight: 600;
      color: #ffb4b4 !important;
      padding: 6px 12px;
      border-radius: 6px;
      background: rgba(224, 82, 82, 0.08);
      border: 1px solid rgba(224, 82, 82, 0.2);
      cursor: pointer;
      transition: all var(--transition);
      display: inline-block !important;
      visibility: visible !important;
    }

    .memory-card-delete-btn:hover {
      color: #ff6b6b !important;
      border-color: rgba(224, 82, 82, 0.4);
      background: rgba(224, 82, 82, 0.15);
    }

    .memory-card-toggle {
      color: var(--text-dim);
      font-size: 12px;
      transition: transform 0.2s;
    }

    .memory-card.open .memory-card-toggle {
      transform: rotate(180deg);
    }

    .memory-card-body {
      display: none;
      padding: 0 16px 14px;
    }

    .memory-card.open .memory-card-body {
      display: block;
    }

    .memory-card-content {
      font-size: 13px;
      color: var(--text-secondary);
      line-height: 1.6;
      white-space: pre-wrap;
      margin-bottom: 12px;
    }

    .memory-card-summary {
      font-size: 13px;
      font-weight: 600;
      color: var(--text-primary);
      line-height: 1.5;
      margin-bottom: 10px;
      padding: 8px 12px;
      background: rgba(255, 255, 255, 0.03);
      border-radius: 8px;
      border-left: 3px solid #a78bfa;
    }

    .memory-card-chars {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }

    .memory-card-char-tag {
      font-size: 11px;
      font-weight: 600;
      background: rgba(232, 98, 26, 0.12);
      color: var(--accent);
      border: 1px solid rgba(232, 98, 26, 0.25);
      padding: 3px 10px;
      border-radius: 12px;
      transition: all 0.15s ease;
    }

    .memory-card-char-tag:hover {
      background: rgba(232, 98, 26, 0.18);
      border-color: rgba(232, 98, 26, 0.4);
    }

    .memory-card.story-arc {
      background: linear-gradient(135deg, rgba(46, 189, 217, 0.08), rgba(46, 189, 217, 0.04));
      border-color: rgba(46, 189, 217, 0.35);
    }

    .memory-card.story-arc:hover {
      border-color: rgba(46, 189, 217, 0.6);
      box-shadow: 0 4px 12px rgba(46, 189, 217, 0.1);
    }

    .memory-card.story-arc .memory-card-title {
      color: var(--accent2);
    }

    .memory-card.archived-memory-card {
      opacity: 0.72;
      border-left-color: #6b7280;
    }

    .memory-card.archived-memory-card:hover {
      opacity: 0.95;
    }

    /* Memory Edit Modal */
    #memEditModal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 450;
      background: rgba(0, 0, 0, 0.74);
      backdrop-filter: blur(4px);
      align-items: center;
      justify-content: center;
    }

    #memEditModal-overlay.open {
      display: flex;
    }

    #memEditModal {
      background: #141414;
      border: 1px solid #2d2d2d;
      border-radius: 18px;
      width: 760px;
      max-width: 94vw;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 26px 70px rgba(0, 0, 0, 0.88);
    }

    .memEditModal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 24px 28px;
      border-bottom: 1px solid #2d2d2d;
      flex-shrink: 0;
    }

    .memEditModal-header h3 {
      font-family: var(--font-display);
      font-size: 20px;
      font-weight: 800;
      margin: 0;
      text-transform: uppercase;
      letter-spacing: 2px;
      color: #d8d8d8;
    }

    .memEditModal-body {
      flex: 1;
      overflow-y: auto;
      padding: 26px 32px 28px;
      display: flex;
      flex-direction: column;
      gap: 22px;
    }

    .memEditModal-field {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .memEditModal-label {
      font-size: 12px;
      font-weight: 800;
      text-transform: uppercase;
      letter-spacing: 1.8px;
      color: #a7adba;
    }

    .memEditModal-subtle {
      color: #777;
      font-size: 12px;
      font-weight: 500;
      text-transform: none;
      letter-spacing: 0;
      margin-left: 6px;
    }

    .memEditModal-body input,
    .memEditModal-body textarea {
      width: 100%;
      background: #1d1d1d;
      border: 1px solid #282828;
      border-radius: 12px;
      padding: 14px 16px;
      color: #f4f4f4;
      font-family: inherit;
      font-size: 15px;
      line-height: 1.65;
      transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    }

    .memEditModal-body input:focus,
    .memEditModal-body textarea:focus {
      border-color: rgba(255, 156, 0, 0.55);
      outline: none;
      box-shadow: 0 0 0 2px rgba(255, 156, 0, 0.08);
      background: #202020;
    }

    #memEditTitle {
      font-size: 18px;
      font-weight: 700;
    }

    #memEditContent {
      min-height: 360px;
      resize: vertical;
      white-space: pre-wrap;
    }

    .memEditModal-footer {
      padding: 18px 28px 22px;
      border-top: 1px solid #2d2d2d;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 14px;
      flex-shrink: 0;
    }

    .memEditModal-footer-actions {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .memEditModal-footer .btn-primary,
    .memEditModal-footer .btn-secondary,
    .memEditModal-footer .btn-danger {
      border-radius: 10px;
      font-size: 14px;
      padding: 10px 18px;
    }

    @media (max-width: 640px) {
      #memEditModal {
        width: 96vw;
        max-height: 92vh;
        border-radius: 14px;
      }

      .memEditModal-header {
        padding: 20px;
      }

      .memEditModal-body {
        padding: 20px;
      }

      .memEditModal-footer {
        padding: 16px 20px;
        flex-direction: column-reverse;
        align-items: stretch;
      }

      .memEditModal-footer-actions {
        width: 100%;
      }

      .memEditModal-footer-actions button,
      .memEditModal-footer>button {
        flex: 1;
        justify-content: center;
      }
    }

    /* ===================== CROP MODAL ===================== */
    #cropModal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 10100;
      background: rgba(0, 0, 0, 0.75);
      backdrop-filter: blur(4px);
      align-items: center;
      justify-content: center;
    }

    #cropModal-overlay.open {
      display: flex;
    }

    #cropModal {
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      width: 520px;
      max-width: 95vw;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8);
    }

    .cropModal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 14px 18px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .cropModal-header h3 {
      font-family: var(--font-display);
      font-size: 13px;
      font-weight: 700;
      letter-spacing: 1px;
      text-transform: uppercase;
    }

    .cropModal-body {
      padding: 16px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 12px;
      background: #0d0d0d;
    }

    #cropCanvas {
      border: 1px solid var(--border);
      border-radius: var(--radius);
      cursor: crosshair;
      max-width: 100%;
      display: block;
    }

    .cropModal-hint {
      font-size: 11px;
      color: var(--text-dim);
      text-align: center;
    }

    .cropModal-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 10px;
      padding: 12px 18px;
      border-top: 1px solid var(--border);
      flex-shrink: 0;
    }

    .cropModal-footer-actions {
      display: flex;
      gap: 8px;
    }

    #cropAspectBtns {
      display: flex;
      gap: 6px;
    }

    .crop-aspect-btn {
      font-size: 11px;
      font-weight: 600;
      padding: 4px 10px;
      border-radius: 4px;
      border: 1px solid var(--border);
      background: var(--bg-card);
      color: var(--text-secondary);
      transition: background var(--transition), border-color var(--transition);
    }

    .crop-aspect-btn:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .crop-aspect-btn.active {
      border-color: var(--accent);
      color: var(--accent);
      background: rgba(232, 98, 26, 0.1);
    }

    /* ===================== PERSONA MODAL ===================== */
    #personaModal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 400;
      background: rgba(0, 0, 0, 0.7);
      backdrop-filter: blur(3px);
      align-items: center;
      justify-content: center;
    }

    #personaModal-overlay.open {
      display: flex;
    }

    #personaModal {
      background: var(--bg-base);
      border: 1px solid var(--border);
      border-radius: 18px;
      width: 500px;
      max-width: 96vw;
      max-height: 92vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85);
    }

    .personaModal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 22px 24px 0;
      flex-shrink: 0;
    }

    .personaModal-header h3 {
      font-size: 22px;
      font-weight: 700;
      color: var(--text-primary);
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .personaModal-header-help {
      width: 20px;
      height: 20px;
      border-radius: 50%;
      border: 1.5px solid var(--border-light);
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      font-size: 11px;
      font-weight: 700;
      cursor: default;
      flex-shrink: 0;
    }

    .personaModal-close {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 20px;
      font-weight: 300;
      transition: background var(--transition);
      background: none;
      border: none;
      cursor: pointer;
    }

    .personaModal-close:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .personaModal-body {
      flex: 1;
      overflow-y: auto;
      padding: 16px 24px 24px;
      display: flex;
      flex-direction: column;
      gap: 14px;
      align-items: center;
    }

    .persona-avatar-upload {
      width: 200px;
      height: 200px;
      border-radius: 12px;
      background: var(--bg-card);
      border: 2px solid var(--border-light);
      margin: 4px auto 0;
      overflow: hidden;
      cursor: pointer;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      transition: border-color var(--transition);
      flex-shrink: 0;
    }

    .persona-avatar-upload:hover {
      border-color: var(--accent);
    }

    .persona-avatar-upload img {
      width: 100%;
      height: 100%;
      object-fit: contain;
      background: transparent;
      border-radius: 12px;
    }

    .persona-avatar-overlay {
      position: absolute;
      inset: 0;
      border-radius: 12px;
      background: rgba(0, 0, 0, 0.5);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity var(--transition);
      color: white;
      font-size: 11px;
      font-weight: 600;
      gap: 4px;
    }

    .persona-avatar-upload:hover .persona-avatar-overlay {
      opacity: 1;
    }

    .personaModal-fields {
      width: 100%;
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .personaModal-fields input {
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 12px 16px;
      font-size: 15px;
      color: var(--text-primary);
      width: 100%;
    }

    .personaModal-fields input:focus {
      border-color: var(--border-light);
      outline: none;
    }

    .personaModal-textarea-wrap {
      position: relative;
      width: 100%;
    }

    .personaModal-fields textarea {
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 12px 16px;
      font-size: 13px;
      line-height: 1.7;
      resize: vertical;
      min-height: 160px;
      width: 100%;
      color: var(--text-primary);
    }

    .personaModal-fields textarea:focus {
      border-color: var(--border-light);
      outline: none;
    }

    .personaModal-charcount {
      position: absolute;
      bottom: 10px;
      right: 14px;
      font-size: 11px;
      color: var(--text-dim);
      pointer-events: none;
    }

    .personaModal-footer {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      padding: 14px 24px 18px;
      flex-shrink: 0;
    }

    .personaModal-footer .btn-secondary {
      padding: 10px 24px;
      border-radius: 20px;
      font-size: 14px;
    }

    .personaModal-footer .btn-primary {
      padding: 10px 28px;
      border-radius: 20px;
      font-size: 14px;
    }

    #charModal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 350;
      background: rgba(0, 0, 0, 0.8);
      backdrop-filter: blur(4px);
      align-items: center;
      justify-content: center;
    }

    #charModal-overlay.open {
      display: flex;
    }

    #charModal {
      background: #111111;
      border: 1px solid #2e2e2e;
      border-radius: 12px;
      width: 600px;
      max-width: 96vw;
      max-height: 85vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    }

    .charModal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 24px 32px;
      border-bottom: 1px solid #2e2e2e;
      flex-shrink: 0;
      background: rgba(30, 30, 30, 0.3);
    }

    .charModal-header h3 {
      font-family: var(--font-display);
      font-size: 18px;
      font-weight: 700;
      color: #f0ece6;
      margin: 0;
    }

    .charModal-body {
      flex: 1;
      overflow-y: auto;
      padding: 32px;
      display: flex;
      flex-direction: column;
      gap: 24px;
    }

    .charModal-field label {
      display: block;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.2px;
      color: #888888;
      margin-bottom: 10px;
    }

    .charModal-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 16px;
      padding: 20px 32px;
      border-top: 1px solid #2e2e2e;
      flex-shrink: 0;
    }

    /* Character card grid layout */
    #storyCharactersList {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
      gap: 16px;
    }

    .char-card {
      background: #1a1a1a;
      border: 1px solid #333333;
      border-left: 4px solid #2ebdd9;
      border-radius: 8px;
      padding: 0;
      display: flex;
      flex-direction: row;
      overflow: hidden;
      transition: all var(--transition);
      cursor: pointer;
      align-items: stretch;
    }

    .char-card:hover {
      border-color: #555555;
      background: #242424;
    }

    /* Character card type variants */
    .char-card.protagonist {
      border-left-color: #e8621a;
    }

    .char-card.antagonist {
      border-left-color: #d946a6;
    }

    .char-card.ally {
      border-left-color: #2ebdd9;
    }

    .char-card.neutral {
      border-left-color: #8b5cf6;
    }

    .char-card.mentor {
      border-left-color: #10b981;
    }

    .char-card.comic {
      border-left-color: #f59e0b;
    }

    .char-card-image {
      width: 120px;
      height: 140px;
      background: #242424;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
    }

    .char-card-image img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .char-card-content {
      padding: 12px;
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 6px;
      justify-content: flex-start;
    }

    .char-card-badge {
      display: inline-block;
      padding: 2px 8px;
      background: rgba(46, 189, 217, 0.1);
      border: 1px solid rgba(46, 189, 217, 0.3);
      border-radius: 4px;
      font-size: 11px;
      font-weight: 600;
      color: var(--accent2);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      width: fit-content;
      flex-shrink: 0;
    }

    .char-card-name {
      font-family: var(--font-display);
      font-size: 14px;
      font-weight: 700;
      color: var(--text-primary);
      line-height: 1.3;
    }

    .char-card-desc {
      font-size: 12px;
      color: var(--text-secondary);
      line-height: 1.4;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    /* ===================== STORY CARDS ===================== */
    .story-card {
      display: flex;
      border: 1px solid var(--border);
      border-left: 4px solid var(--accent2);
      border-radius: var(--radius-lg);
      background: #1a1a1d;
      padding: 10px 14px;
      overflow: hidden;
      transition: all var(--transition);
      position: relative;
      cursor: pointer;
    }

    .story-card[style*="row"] {
      gap: 16px;
      align-items: flex-start;
    }

    .story-card[style*="column"] {
      flex-direction: column;
      gap: 10px;
    }

    .story-card:hover {
      background: #1f1f23;
      border-color: var(--accent2);
      box-shadow: 0 2px 8px rgba(46, 189, 217, 0.1);
    }

    .story-card-image {
      width: 110px;
      height: 110px;
      min-width: 110px;
      background: rgba(46, 189, 217, 0.1);
      border-radius: 6px;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 28px;
    }

    .story-card-image img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .story-card-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 10px;
      min-width: 0;
      padding-top: 4px;
    }

    .story-card-header {
      display: flex;
      align-items: flex-start;
      flex-direction: column;
      gap: 12px;
    }

    .story-card-header-inline {
      display: flex;
      align-items: center;
      gap: 2px;
      margin-bottom: 8px;
      margin-top: 4px;
    }

    .story-card-title-section {
      flex: 1;
    }

    .story-card-type {
      font-size: 10px;
      font-weight: 600;
      padding: 2px 8px;
      border-radius: 3px;
      width: fit-content;
      border: 1px solid;
      margin-bottom: 2px;
    }

    .story-card-type.character {
      background: rgba(46, 189, 217, 0.15);
      color: #6ac9e0;
      border-color: rgba(46, 189, 217, 0.4);
    }

    .story-card-type.location {
      background: rgba(76, 175, 80, 0.15);
      color: #66bb6a;
      border-color: rgba(76, 175, 80, 0.4);
    }

    .story-card-type.faction {
      background: rgba(156, 39, 176, 0.15);
      color: #ba68c8;
      border-color: rgba(156, 39, 176, 0.4);
    }

    .story-card-type.item {
      background: rgba(233, 30, 99, 0.15);
      color: #ec407a;
      border-color: rgba(233, 30, 99, 0.4);
    }

    .story-card-type.event {
      background: rgba(255, 152, 0, 0.15);
      color: #ffb74d;
      border-color: rgba(255, 152, 0, 0.4);
    }

    .story-card-type.custom {
      background: rgba(158, 158, 158, 0.15);
      color: #bdbdbd;
      border-color: rgba(158, 158, 158, 0.4);
    }

    /* Type-based left border colors */
    .story-card.character {
      border-left-color: #6ac9e0;
    }

    .story-card.location {
      border-left-color: #66bb6a;
    }

    .story-card.faction {
      border-left-color: #ba68c8;
    }

    .story-card.item {
      border-left-color: #ec407a;
    }

    .story-card.event {
      border-left-color: #ffb74d;
    }

    .story-card.custom {
      border-left-color: #bdbdbd;
    }

    /* Section headers for type-based grouping */
    .story-card-section-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 12px 0;
      margin-bottom: 12px;
      margin-top: 24px;
      border-bottom: 1px solid var(--border);
      cursor: pointer;
      user-select: none;
    }

    .story-card-section-header:first-of-type {
      margin-top: 0;
    }

    .story-card-section-header svg {
      color: var(--text-dim);
    }

    .story-card-section-header.collapsed svg {
      transform: rotate(-90deg);
    }

    .story-card-section-title {
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      margin: 0;
      color: var(--text-primary);
    }

    .story-card-section-count {
      font-size: 13px;
      color: var(--text-dim);
      font-weight: 500;
    }

    .story-card-section-icon {
      font-size: 16px;
      opacity: 0.6;
    }

    .story-card-section-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 12px;
      margin-bottom: 16px;
    }

    @media (min-width: 768px) {
      .story-card-section-grid {
        grid-template-columns: repeat(2, 1fr);
      }
    }

    @media (min-width: 1024px) {
      .story-card-section-grid {
        grid-template-columns: repeat(3, 1fr);
      }
    }

    .story-card-name {
      font-size: 15px;
      font-weight: 600;
      color: var(--text-primary);
      margin: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .story-card-triggers {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      margin-top: 4px;
    }

    .story-card-trigger-pill {
      font-size: 10px;
      font-weight: 600;
      padding: 2px 8px;
      border-radius: 10px;
      background: rgba(46, 189, 217, 0.2);
      color: var(--accent2);
      border: 1px solid rgba(46, 189, 217, 0.3);
    }

    .story-card-entry {
      font-size: 13px;
      color: #999;
      line-height: 1.4;
      overflow: hidden;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
    }

    .story-card-actions {
      display: flex;
      gap: 12px;
      margin-top: 8px;
    }

    .story-card-actions button {
      background: none;
      border: none;
      color: #999;
      cursor: pointer;
      font-size: 12px;
      padding: 0;
      font-weight: 500;
      transition: color var(--transition);
    }

    .story-card-actions button:hover {
      color: var(--accent2);
    }

    /* Active indicator in chat — shows which cards are currently injected */
    .story-card-active-badge {
      position: absolute;
      top: 8px;
      right: 8px;
      font-size: 9px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      padding: 2px 6px;
      border-radius: 3px;
      background: rgba(46, 189, 217, 0.15);
      color: var(--accent2);
      border: 1px solid rgba(46, 189, 217, 0.3);
    }

    /* Event Card styling — IF/THEN mechanics cards */
    .story-card.event-card {
      border-style: dashed;
      border-left-color: #ffb74d;
      opacity: 0.95;
    }

    .story-card.event-card:hover {
      background: rgba(255, 152, 0, 0.05);
    }

    .story-card.event-card .story-card-type.event {
      background: rgba(255, 152, 0, 0.25);
      border-color: rgba(255, 152, 0, 0.6);
    }

    /* Story card modal */
    #scModal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 500;
      background: rgba(0, 0, 0, 0.8);
      backdrop-filter: blur(4px);
      align-items: center;
      justify-content: center;
    }

    #scModal-overlay.open {
      display: flex;
    }

    #scModal {
      background: #111111;
      border: 1px solid #2e2e2e;
      border-radius: 12px;
      width: 800px;
      max-width: 96vw;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    }

    .scModal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 24px 32px;
      border-bottom: 1px solid #2e2e2e;
      flex-shrink: 0;
      background: rgba(30, 30, 30, 0.3);
    }

    .scModal-header h3 {
      font-family: var(--font-display);
      font-size: 18px;
      font-weight: 700;
      color: #f0ece6;
      margin: 0;
    }

    .scModal-body {
      flex: 1;
      overflow-y: auto;
      padding: 32px;
      display: flex;
      flex-direction: column;
      gap: 32px;
    }

    .scModal-field label {
      display: block;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.2px;
      color: #888888;
      margin-bottom: 10px;
    }

    .scModal-field label span {
      text-transform: none;
      letter-spacing: 0;
      font-weight: 400;
      color: #666666;
    }

    .sc-modal-menu button:hover {
      background-color: rgba(224, 82, 82, 0.1);
    }

    .sc-modal-menu button:active {
      background-color: rgba(224, 82, 82, 0.2);
    }

    .scModal-footer {
      padding: 20px 32px;
      border-top: 1px solid #2e2e2e;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      flex-shrink: 0;
      gap: 12px;
      background: rgba(30, 30, 30, 0.5);
    }

    #scModal input,
    #scModal textarea,
    #scModal select {
      background: #1a1a1a;
      border: 1px solid #333333;
      border-radius: 8px;
      padding: 12px 14px;
      color: #ffffff;
      font-size: 14px;
      transition: border-color 0.2s;
    }

    #scModal select {
      padding-right: 36px;
      background-position: right 14px center;
      opacity: 0.9;
    }

    #scModal select:hover {
      opacity: 1;
      border-color: #444;
    }

    #scModal input::placeholder,
    #scModal textarea::placeholder {
      color: #666666;
    }

    #scModal input:focus,
    #scModal textarea:focus,
    #scModal select:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px rgba(232, 98, 26, 0.15);
    }

    .scenario-detail-content {
      max-width: 1000px;
      margin: 0 auto;
      width: 100%;
      padding-bottom: 40px;
    }

    .scenario-detail-hero {
      width: 100%;
      height: 480px;
      position: relative;
      overflow: hidden;
      background: #0a0a0a;
      flex-shrink: 0;
      isolation: isolate;
    }

    .scenario-detail-hero-img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(135deg, #1a0a0a 0%, #1a0a1a 100%);
    }

    .scenario-detail-hero-img img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      object-position: center 25%;
      display: block;
    }

    .scenario-detail-hero-overlay {
      position: absolute;
      inset: 0;
      z-index: 1;
      pointer-events: none;
      background:
        linear-gradient(to top,
          rgba(0,0,0,0.97) 0%,
          rgba(0,0,0,0.82) 22%,
          rgba(0,0,0,0.42) 50%,
          rgba(0,0,0,0.08) 100%),
        linear-gradient(to right,
          rgba(0,0,0,0.65) 0%,
          rgba(0,0,0,0.3) 40%,
          transparent 75%);
    }

    .scenario-detail-header {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 3;
      padding: 0 60px 48px;
      display: flex;
      flex-direction: column;
      align-items: flex-start;
    }

    .scenario-detail-title {
      font-family: var(--font-display);
      font-size: 34px;
      font-weight: 700;
      color: var(--text-primary);
      margin-bottom: 8px;
      text-shadow: 0 2px 16px rgba(0, 0, 0, 0.8);
      line-height: 1.1;
    }

    .scenario-detail-desc {
      font-size: 13px;
      color: var(--text-secondary);
      max-width: 580px;
      line-height: 1.6;
      margin-bottom: 14px;
    }

    .scenario-detail-creator {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 10px;
    }

    .scenario-detail-creator-avatar {
      width: 24px;
      height: 24px;
      border-radius: 50%;
      background: var(--accent);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      font-weight: 700;
      color: #fff;
      overflow: hidden;
      flex-shrink: 0;
    }

    .scenario-detail-creator-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .scenario-detail-creator-name {
      font-size: 12px;
      color: rgba(255,255,255,0.55);
      font-weight: 500;
      letter-spacing: 0.2px;
      transition: color 0.15s;
    }
    .scenario-detail-creator:hover .scenario-detail-creator-name {
      color: var(--accent);
    }

    .scenario-detail-tags {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-bottom: 18px;
    }

    .scenario-detail-tag {
      font-size: 11px;
      font-weight: 600;
      background: rgba(255, 255, 255, 0.08);
      border: 1px solid rgba(255, 255, 255, 0.14);
      color: var(--text-secondary);
      padding: 3px 10px;
      border-radius: 20px;
    }

    .scenario-detail-actions {
      display: flex;
      gap: 10px;
      align-items: center;
    }

    .btn-start-scenario {
      background: var(--accent);
      color: white;
      padding: 10px 24px;
      border-radius: var(--radius);
      font-size: 13px;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 8px;
      transition: background var(--transition), transform var(--transition);
    }

    .btn-start-scenario:hover {
      background: #d0561a;
      transform: translateY(-1px);
    }

    .btn-customise {
      background: rgba(255, 255, 255, 0.08);
      color: var(--text-primary);
      padding: 10px 20px;
      border-radius: var(--radius);
      font-size: 13px;
      font-weight: 700;
      border: 1px solid rgba(255, 255, 255, 0.15);
      display: flex;
      align-items: center;
      gap: 8px;
      transition: background var(--transition);
    }

    .btn-customise:hover {
      background: rgba(255, 255, 255, 0.14);
    }

    .btn-cancel-detail {
      color: var(--text-dim);
      padding: 10px 12px;
      font-size: 13px;
      transition: color var(--transition);
    }

    .btn-cancel-detail:hover {
      color: var(--text-secondary);
    }

    /* Scenario detail top-right icon strip */
    .detail-corner-strip {
      position: absolute;
      top: 14px;
      right: 16px;
      z-index: 20;
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .detail-corner-btn {
      display: flex;
      align-items: center;
      gap: 5px;
      padding: 7px 10px;
      border-radius: 8px;
      background: rgba(0,0,0,0.55);
      backdrop-filter: blur(8px);
      border: 1px solid rgba(255,255,255,0.12);
      color: rgba(255,255,255,0.8);
      font-size: 11px;
      font-weight: 600;
      cursor: pointer;
      transition: background 0.15s, color 0.15s;
    }

    .detail-corner-btn:hover {
      background: rgba(0,0,0,0.75);
      color: #fff;
    }

    .detail-corner-btn.liked {
      color: #f87171;
      border-color: rgba(248,113,113,0.4);
      background: rgba(0,0,0,0.6);
    }

    .detail-corner-btn.liked svg {
      fill: #f87171;
      stroke: #f87171;
    }

    .detail-corner-close {
      color: rgba(255,255,255,0.6);
    }

    .detail-corner-close:hover {
      color: #fff;
    }

    /* Folder manager modal */
    .folder-mgr-overlay {
      position: fixed; inset: 0; z-index: 10500;
      background: rgba(0,0,0,0.6);
      display: flex; align-items: center; justify-content: center;
    }

    .folder-mgr-modal {
      background: var(--bg-panel);
      border: 1px solid var(--border-light);
      border-radius: 16px;
      width: min(640px, 95vw);
      max-height: 80vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 24px 60px rgba(0,0,0,0.6);
    }

    .folder-mgr-head {
      padding: 20px 24px 16px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 12px;
      flex-shrink: 0;
    }

    .folder-mgr-title { font-size: 18px; font-weight: 800; color: var(--text-primary); }
    .folder-mgr-sub  { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
    .folder-mgr-count { font-size: 12px; color: var(--text-dim); white-space: nowrap; margin-top: 4px; }

    .folder-mgr-body {
      flex: 1; overflow-y: auto; padding: 12px 16px;
    }

    .folder-mgr-row {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 14px;
      border-radius: 10px;
      border: 1px solid var(--border);
      margin-bottom: 8px;
      background: var(--bg-card);
      cursor: default;
      transition: border-color 0.15s;
    }

    .folder-mgr-row:hover { border-color: var(--border-light); }
    .folder-mgr-row.dragging { opacity: 0.4; }

    .folder-mgr-drag {
      color: var(--text-dim);
      cursor: grab;
      flex-shrink: 0;
      padding: 2px;
    }

    .folder-mgr-badge {
      width: 28px; height: 28px;
      background: #c07d10;
      border-radius: 6px;
      display: flex; align-items: center; justify-content: center;
      font-size: 11px; font-weight: 800; color: #fff;
      flex-shrink: 0;
    }

    .folder-mgr-badge.auto { background: rgba(232,98,26,0.25); color: var(--accent); }

    .folder-mgr-info { flex: 1; min-width: 0; }
    .folder-mgr-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
    .folder-mgr-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

    .folder-mgr-vis {
      background: none; border: none;
      color: #34d399; cursor: pointer; padding: 4px;
      transition: opacity 0.15s;
    }
    .folder-mgr-vis.hidden { color: var(--text-dim); }
    .folder-mgr-del {
      background: none; border: none;
      color: var(--text-dim); cursor: pointer; padding: 4px;
      transition: color 0.15s;
    }
    .folder-mgr-del:hover { color: #f87171; }

    .folder-mgr-foot {
      padding: 12px 16px;
      border-top: 1px solid var(--border);
      flex-shrink: 0;
    }

    .folder-mgr-create-btn {
      width: 100%;
      padding: 13px;
      border-radius: 10px;
      border: 1px dashed var(--border-light);
      background: rgba(232,98,26,0.05);
      color: var(--accent);
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      display: flex; align-items: center; justify-content: center; gap: 8px;
      transition: background 0.15s;
    }
    .folder-mgr-create-btn:hover { background: rgba(232,98,26,0.12); }

    /* Add to folder modal */
    .add-folder-modal {
      background: var(--bg-panel);
      border: 1px solid var(--border-light);
      border-radius: 16px;
      width: min(560px, 95vw);
      max-height: 75vh;
      display: flex; flex-direction: column;
      overflow: hidden;
      box-shadow: 0 24px 60px rgba(0,0,0,0.6);
    }

    .add-folder-row {
      display: flex; align-items: center; gap: 12px;
      padding: 13px 16px;
      border-radius: 10px;
      border: 1px solid var(--border);
      margin-bottom: 8px;
      background: var(--bg-card);
      cursor: pointer;
      transition: all 0.15s;
    }
    .add-folder-row:hover, .add-folder-row.in-folder {
      border-color: var(--accent);
      background: rgba(232,98,26,0.06);
    }

    /* Settings folder card */
    .sm-folder-card {
      display: flex; align-items: center; gap: 14px;
      padding: 14px 16px;
      border-radius: 10px;
      border: 1px solid var(--border);
      background: var(--bg-card);
      cursor: pointer;
      transition: border-color 0.15s, background 0.15s;
      margin-top: 8px;
    }
    .sm-folder-card:hover { border-color: var(--border-light); background: rgba(255,255,255,0.04); }
    .sm-folder-card-icon { font-size: 28px; flex-shrink: 0; }
    .sm-folder-card-info { flex: 1; min-width: 0; }
    .sm-folder-card-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
    .sm-folder-card-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

    .scenario-detail-body {
      padding: 28px 32px;
      display: flex;
      flex-direction: column;
      gap: 28px;
    }

    .scenario-detail-section-title {
      font-family: var(--font-display);
      font-size: 11px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 2px;
      color: var(--accent);
      margin-bottom: 14px;
    }

    .scenario-detail-intro {
      font-size: 13px;
      color: var(--text-secondary);
      line-height: 1.8;
    }
    .scenario-detail-intro img {
      max-width: 100% !important;
      height: auto !important;
      border-radius: 6px;
      display: block !important;
      margin: 8px auto !important;
    }

    .scenario-detail-chars {
      display: flex;
      flex-wrap: wrap;
      gap: 18px;
      justify-content: flex-start;
    }

    .detail-char-card {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      width: 90px;
      cursor: default;
    }

    .detail-char-avatar {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      overflow: hidden;
      flex-shrink: 0;
      background: var(--bg-input);
      border: 2px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      transition: border-color var(--transition);
    }

    .detail-char-card:hover .detail-char-avatar {
      border-color: var(--accent);
    }

    .detail-char-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .detail-char-name {
      font-family: var(--font-display);
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      color: var(--text-primary);
      text-align: center;
      line-height: 1.3;
      word-break: break-word;
    }

    .detail-char-role {
      display: none;
    }

    .scenario-card[draggable="true"] {
      cursor: grab;
    }

    .scenario-card[draggable="true"]:active {
      cursor: grabbing;
    }

    .scenario-card.drag-over {
      outline: 2px dashed var(--accent);
      outline-offset: 2px;
      opacity: 0.7;
    }

    .scenario-card.dragging {
      opacity: 0.35;
    }

    #slashMenu {
      display: none;
      position: absolute;
      bottom: 100%;
      left: 0;
      right: 0;
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: 12px;
      margin-bottom: 6px;
      box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
      overflow: hidden;
      z-index: 50;
    }

    #slashMenu.open {
      display: block;
    }

    .slash-cmd {
      padding: 12px 16px;
      cursor: pointer;
      border-bottom: 1px solid var(--border);
      transition: background var(--transition);
      display: flex;
      flex-direction: column;
      gap: 3px;
    }

    .slash-cmd:last-child {
      border-bottom: none;
    }

    .slash-cmd:hover,
    .slash-cmd.active {
      background: var(--bg-hover);
    }

    .slash-cmd-name {
      font-size: 13px;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .slash-cmd-name span {
      font-family: var(--font-body);
      color: var(--text-primary);
    }

    .slash-cmd-arg {
      font-size: 11px;
      font-weight: 600;
      color: var(--accent);
      background: rgba(232, 98, 26, 0.12);
      border: 1px solid rgba(232, 98, 26, 0.25);
      padding: 1px 7px;
      border-radius: 6px;
    }

    .slash-cmd-desc {
      font-size: 12px;
      color: var(--text-dim);
    }

    /* ===================== MUSIC PLAYER ===================== */
    .music-player {
      border-top: none;
      padding: 8px 14px 12px;
      flex-shrink: 0;
    }

    .music-player-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 6px;
    }

    .music-player-label {
      font-size: 8px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.5px;
      color: var(--text-dim);
      display: flex;
      align-items: center;
      gap: 4px;
    }

    .music-manage-btn {
      font-size: 9px;
      color: var(--text-dim);
      background: none;
      border: none;
      cursor: pointer;
      padding: 2px 5px;
      border-radius: 4px;
      transition: color var(--transition);
    }

    .music-manage-btn:hover { color: var(--text-primary); }

    .music-now-playing {
      font-size: 12px;
      font-weight: 600;
      color: var(--text-primary);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 10px;
      min-height: 16px;
    }

    .music-now-playing:not(.active) { color: var(--text-dim); font-weight: 400; }

    /* Seek bar */
    .music-seek-wrap {
      margin-bottom: 8px;
    }
    .music-seek-track {
      width: 100%;
      height: 3px;
      background: rgba(255,255,255,0.1);
      border-radius: 2px;
      position: relative;
      cursor: pointer;
    }
    .music-seek-fill {
      height: 100%;
      background: var(--accent);
      border-radius: 2px;
      width: 0%;
      pointer-events: none;
      transition: width 0.25s linear;
    }
    .music-seek-input {
      position: absolute;
      inset: -6px 0;
      opacity: 0;
      cursor: pointer;
      width: 100%;
    }
    .music-time-row {
      display: flex;
      justify-content: space-between;
      margin-top: 4px;
    }
    .music-time-row span {
      font-size: 9px;
      color: var(--text-dim);
    }

    /* Controls row */
    .music-controls {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0;
    }

    .music-btn {
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background: none;
      border: none;
      color: rgba(255,255,255,0.45);
      cursor: pointer;
      padding: 6px;
      border-radius: 8px;
      transition: color 0.18s;
    }

    .music-btn:hover { color: #fff; }

    .music-btn.play-btn {
      color: #fff;
      background: var(--accent);
      border-radius: 50%;
      width: 34px;
      height: 34px;
      padding: 0;
    }

    .music-btn.play-btn:hover { opacity: 0.88; }

    .music-vol-slider {
      width: 52px;
      height: 3px;
      accent-color: rgba(255,255,255,0.4);
      cursor: pointer;
      opacity: 0.6;
    }
    .music-vol-slider:hover { opacity: 1; }

    #musicModal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 400;
      background: rgba(0, 0, 0, 0.7);
      backdrop-filter: blur(3px);
      align-items: center;
      justify-content: center;
    }

    #musicModal-overlay.open {
      display: flex;
    }

    #musicModal {
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: 16px;
      width: 480px;
      max-width: 95vw;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85);
    }

    .musicModal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px 12px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .musicModal-header h3 {
      font-family: var(--font-display);
      font-size: 14px;
      font-weight: 700;
    }

    .musicModal-body {
      flex: 1;
      overflow-y: auto;
      padding: 16px 20px;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .music-track-item {
      display: flex;
      align-items: center;
      gap: 10px;
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 10px 12px;
    }

    .music-track-item.playing {
      border-color: var(--accent2);
      background: rgba(46, 189, 217, 0.06);
    }

    .music-track-name {
      flex: 1;
      font-size: 12px;
      font-weight: 600;
      color: var(--text-primary);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .musicModal-footer {
      padding: 12px 20px;
      border-top: 1px solid var(--border);
      flex-shrink: 0;
    }

    .music-add-row {
      display: flex;
      gap: 8px;
      margin-top: 6px;
    }

    .music-add-row input {
      flex: 1;
      font-size: 12px;
    }

    .music-add-row button {
      flex-shrink: 0;
      font-size: 12px;
      padding: 7px 14px;
      border-radius: 8px;
    }

    /* ===================== SLIDE-IN RIGHT PANEL ===================== */
    .side-panel-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 200;
      background: rgba(0, 0, 0, 0.4);
    }

    .side-panel-overlay.open {
      display: block;
    }

    .side-panel {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      z-index: 201;
      width: 380px;
      max-width: 95vw;
      background: var(--bg-panel);
      border-left: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
      transform: translateX(100%);
      transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
      overflow: hidden;
    }

    .side-panel.open {
      transform: translateX(0);
    }

    .side-panel-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .side-panel-header h3 {
      font-family: var(--font-display);
      font-size: 15px;
      font-weight: 700;
    }

    .side-panel-close {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 18px;
      background: none;
      border: none;
      cursor: pointer;
      transition: background var(--transition);
    }

    .side-panel-close:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .side-panel-body {
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      -webkit-overflow-scrolling: touch;
    }

    /* Memory bank panel cards */
    .mem-bank-card {
      padding: 14px 20px;
      border-bottom: 1px solid var(--border);
      cursor: pointer;
      transition: background var(--transition);
    }

    .mem-bank-card:hover {
      background: var(--bg-hover);
    }

    .mem-bank-card-title {
      font-size: 13px;
      font-weight: 700;
      color: var(--accent);
      margin-bottom: 4px;
    }

    .mem-bank-card-content {
      font-size: 12px;
      color: var(--text-secondary);
      line-height: 1.5;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .mem-bank-card-chars {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      margin-top: 6px;
    }

    .mem-bank-card-char {
      font-size: 10px;
      font-weight: 600;
      background: rgba(232, 98, 26, 0.1);
      color: var(--accent);
      border: 1px solid rgba(232, 98, 26, 0.2);
      padding: 1px 7px;
      border-radius: 10px;
    }

    .mem-bank-empty {
      padding: 40px 20px;
      text-align: center;
      font-size: 13px;
      color: var(--text-dim);
      line-height: 1.7;
    }

    #memoryPanel-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 400;
      background: rgba(0, 0, 0, 0.7);
      backdrop-filter: blur(3px);
      align-items: center;
      justify-content: center;
    }

    #memoryPanel-overlay.open {
      display: flex;
    }

    #memoryPanel {
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: 16px;
      width: 520px;
      max-width: 95vw;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85);
    }

    .memoryPanel-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 18px 20px 14px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .memoryPanel-header h3 {
      font-family: var(--font-display);
      font-size: 15px;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .memoryPanel-header h3 svg {
      color: #a78bfa;
    }

    .memoryPanel-body {
      flex: 1;
      overflow-y: auto;
      padding: 16px 20px;
      display: flex;
      flex-direction: column;
      gap: 18px;
    }

    .memoryPanel-chronicle {
      background: rgba(167, 139, 250, 0.05);
      border: 1px solid rgba(167, 139, 250, 0.15);
      border-radius: 12px;
      padding: 16px;
      margin-bottom: 4px;
    }

    .chronicle-title {
      font-size: 11px;
      font-weight: 700;
      color: #a78bfa;
      text-transform: uppercase;
      letter-spacing: 1px;
      margin-bottom: 8px;
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .chronicle-content {
      font-size: 13px;
      color: var(--text-primary);
      line-height: 1.6;
      white-space: pre-wrap;
      font-style: italic;
    }

    .memoryPanel-section-label {
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--text-dim);
      margin-bottom: 8px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .memory-fact-list {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }

    .memory-fact-item {
      display: flex;
      align-items: center;
      gap: 8px;
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 7px 10px;
      font-size: 12px;
      color: var(--text-secondary);
    }

    .memory-fact-item.pinned {
      border-color: #a78bfa44;
      background: rgba(167, 139, 250, 0.07);
    }

    .memory-fact-item input[type="text"] {
      flex: 1;
      background: transparent;
      border: none;
      padding: 0;
      font-size: 12px;
      color: var(--text-primary);
      outline: none;
    }

    .memory-fact-pin-btn {
      width: 22px;
      height: 22px;
      border-radius: 4px;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      background: none;
      border: none;
      cursor: pointer;
      transition: color var(--transition);
    }

    .memory-fact-pin-btn.active {
      color: #a78bfa;
    }

    .memory-fact-pin-btn:hover {
      color: #a78bfa;
    }

    .memory-fact-del-btn {
      width: 22px;
      height: 22px;
      border-radius: 4px;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      background: none;
      border: none;
      cursor: pointer;
      transition: color var(--transition);
    }

    .memory-fact-del-btn:hover {
      color: #e05252;
    }

    .memory-add-row {
      display: flex;
      gap: 8px;
      margin-top: 4px;
    }

    .memory-add-row input {
      flex: 1;
      font-size: 12px;
      padding: 7px 10px;
      border-radius: 8px;
    }

    .memory-add-row button {
      padding: 7px 14px;
      border-radius: 8px;
      font-size: 12px;
      flex-shrink: 0;
    }

    .memory-extract-btn {
      width: 100%;
      padding: 9px;
      border-radius: 8px;
      font-size: 12px;
      font-weight: 600;
      background: rgba(167, 139, 250, 0.12);
      border: 1px solid rgba(167, 139, 250, 0.3);
      color: #a78bfa;
      cursor: pointer;
      transition: background var(--transition);
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
    }

    .memory-extract-btn:hover {
      background: rgba(167, 139, 250, 0.22);
    }

    .memory-extract-btn:disabled {
      opacity: 0.5;
      cursor: default;
    }

    .memoryPanel-footer {
      padding: 12px 20px;
      border-top: 1px solid var(--border);
      display: flex;
      justify-content: flex-end;
      gap: 8px;
      flex-shrink: 0;
    }

    .memory-facts-badge {
      display: none;
      position: absolute;
      top: -4px;
      right: -4px;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: #a78bfa;
      color: white;
      font-size: 9px;
      font-weight: 700;
      align-items: center;
      justify-content: center;
    }

    #charProfileModal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 400;
      background: rgba(0, 0, 0, 0.75);
      backdrop-filter: blur(4px);
      align-items: center;
      justify-content: center;
    }

    #charProfileModal-overlay.open {
      display: flex;
    }

    #charProfileModal {
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: 18px;
      width: 420px;
      max-width: 95vw;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85);
    }

    .charProfile-hero {
      width: 100%;
      height: 180px;
      background: linear-gradient(135deg, #1a0a2e, #2d1b4e);
      position: relative;
      flex-shrink: 0;
      display: flex;
      align-items: flex-end;
      padding: 0 24px 16px;
      gap: 18px;
    }

    .charProfile-hero-img {
      width: 90px;
      height: 90px;
      border-radius: 50%;
      border: 3px solid var(--accent);
      overflow: hidden;
      flex-shrink: 0;
      background: var(--bg-card);
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      margin-bottom: -30px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    }

    .charProfile-hero-img img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .charProfile-hero-info {
      padding-bottom: 4px;
    }

    .charProfile-name {
      font-family: var(--font-display);
      font-size: 17px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.5px;
      color: var(--text-primary);
      text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
    }

    .charProfile-role {
      font-size: 12px;
      color: var(--accent);
      font-weight: 600;
      margin-top: 3px;
    }

    .charProfile-close {
      position: absolute;
      top: 12px;
      right: 14px;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background: rgba(0, 0, 0, 0.4);
      border: none;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 16px;
      transition: background var(--transition);
    }

    .charProfile-close:hover {
      background: rgba(0, 0, 0, 0.7);
      color: white;
    }

    .charProfile-body {
      flex: 1;
      overflow-y: auto;
      padding: 40px 24px 24px;
      display: flex;
      flex-direction: column;
      gap: 14px;
    }

    .charProfile-section-label {
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--text-dim);
      margin-bottom: 5px;
    }

    .charProfile-text {
      font-size: 13px;
      color: var(--text-secondary);
      line-height: 1.7;
    }

    .charProfile-traits {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }

    .charProfile-trait {
      font-size: 11px;
      font-weight: 600;
      background: rgba(232, 98, 26, 0.12);
      color: var(--accent);
      border: 1px solid rgba(232, 98, 26, 0.3);
      padding: 3px 10px;
      border-radius: 20px;
    }

    #view-create {
      overflow-y: auto;
    }

    .creator-content {
      padding: 32px 60px;
      max-width: 1400px;
      margin: 0 auto;
      width: 100%;
    }

    .creator-title {
      font-family: var(--font-display);
      font-size: 18px;
      font-weight: 700;
      margin-bottom: 32px;
      text-align: center;
      display: flex;
      align-items: center;
      gap: 16px;
      color: var(--text-primary);
    }

    .creator-title::before,
    .creator-title::after {
      content: '';
      flex: 1;
      height: 1px;
      background: var(--border);
    }

    .form-section {
      background: none;
      border: none;
      border-radius: 0;
      padding: 0;
      margin-bottom: 32px;
    }

    .form-section-title {
      font-family: var(--font-display);
      font-size: 12px;
      font-weight: 700;
      color: var(--text-primary);
      text-transform: uppercase;
      letter-spacing: 2px;
      margin-bottom: 20px;
      text-align: left;
      display: flex;
      align-items: center;
      gap: 12px;
      background: linear-gradient(90deg, #1a1a1a 0%, #111111 100%);
      border-left: 4px solid #e8621a;
      padding: 16px 24px;
      margin-left: -60px;
      margin-right: -60px;
      padding-left: 60px;
      padding-right: 60px;
    }

    .form-section-title.blue {
      border-left-color: #3b82f6;
    }

    .form-section-title.green {
      border-left-color: #10b981;
    }

    .form-section-title.purple {
      border-left-color: #8b5cf6;
    }

    .form-section-title.amber {
      border-left-color: #f59e0b;
    }

    .form-section-title.teal {
      border-left-color: #14b8a6;
    }

    .form-section-title::before,
    .form-section-title::after {
      display: none;
    }

    .form-row {
      display: flex;
      gap: 16px;
      margin-bottom: 14px;
    }

    .form-col {
      flex: 1;
    }

    .form-group {
      margin-bottom: 14px;
    }

    .form-label {
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 12px;
      font-weight: 700;
      color: var(--text-secondary);
      margin-bottom: 6px;
    }

    .form-label .info-icon,
    .info-icon {
      width: 15px;
      height: 15px;
      border-radius: 50%;
      background: var(--bg-input);
      border: 1px solid var(--border);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 9px;
      color: var(--text-dim);
      cursor: help;
      flex-shrink: 0;
      font-style: normal;
      font-weight: 700;
      line-height: 1;
      vertical-align: middle;
    }

    .info-icon::after {
      content: 'i';
    }

    /* Info-icon tooltip (data-tip attribute) */
    .info-icon[data-tip] {
      position: relative;
    }
    .info-icon[data-tip]::before {
      content: attr(data-tip);
      position: absolute;
      bottom: calc(100% + 7px);
      left: 50%;
      transform: translateX(-50%);
      background: #222428;
      color: var(--text-secondary);
      font-size: 11px;
      font-weight: 400;
      font-style: normal;
      line-height: 1.5;
      white-space: normal;
      width: 210px;
      padding: 7px 10px;
      border-radius: 7px;
      border: 1px solid var(--border-light);
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.15s;
      z-index: 600;
      box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    }
    .info-icon[data-tip]:hover::before { opacity: 1; }
    .info-icon[data-tip]:hover::after  { content: 'i'; } /* keep the i */

    /* Comment section */
    .scenario-comments { padding: 0 24px 32px; max-width: 760px; margin: 0 auto; }
    .scenario-comments-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
    .comment-input-row { display: flex; gap: 10px; margin-bottom: 20px; }
    .comment-input-row textarea { flex: 1; resize: none; height: 68px; font-size: 13px; border-radius: 10px; padding: 10px 13px; }
    .comment-input-row .btn-primary { align-self: flex-end; padding: 10px 18px; font-size: 13px; white-space: nowrap; }
    .comment-list { display: flex; flex-direction: column; gap: 12px; }
    .comment-card { background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
    .comment-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
    .comment-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-input); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--text-dim); overflow: hidden; flex-shrink: 0; }
    .comment-avatar img { width: 100%; height: 100%; object-fit: cover; }
    .comment-author { font-size: 13px; font-weight: 600; color: var(--text-primary); }
    .comment-date { font-size: 11px; color: var(--text-dim); margin-left: auto; }
    .comment-body { font-size: 13px; color: var(--text-secondary); line-height: 1.6; word-break: break-word; }
    .comment-report-btn { background: none; border: none; color: var(--text-dim); font-size: 11px; cursor: pointer; padding: 4px 0; margin-top: 6px; opacity: 0.6; transition: opacity 0.15s; }
    .comment-report-btn:hover { opacity: 1; color: #e05252; }
    .comment-delete-btn { background: none; border: none; color: #e05252; font-size: 11px; cursor: pointer; padding: 4px 0; margin-top: 6px; margin-left: 10px; opacity: 0.6; transition: opacity 0.15s; }
    .comment-delete-btn:hover { opacity: 1; }
    .sc-like-btn { position:absolute; bottom:10px; right:10px; background:rgba(0,0,0,0.55); border:1px solid rgba(255,255,255,0.15); border-radius:20px; color:#fff; font-size:12px; cursor:pointer; padding:4px 9px; display:flex; align-items:center; gap:5px; backdrop-filter:blur(4px); transition:background 0.15s,color 0.15s; z-index:3; }
    .sc-like-btn:hover,.sc-like-btn.liked { background:rgba(229,62,62,0.7); border-color:rgba(229,62,62,0.5); color:#fff; }
    .sc-like-btn.liked svg { fill:#fff; }
    .comments-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 24px 0; }

    .char-count {
      font-size: 10px;
      color: var(--text-dim);
      text-align: right;
      margin-top: 3px;
    }

    .image-upload-area {
      width: 100%;
      aspect-ratio: 16 / 9;
      height: auto;
      background: var(--bg-input);
      border: 2px dashed var(--border);
      border-radius: var(--radius-lg);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: border-color var(--transition);
      gap: 8px;
      color: var(--text-dim);
      font-size: 12px;
      text-align: center;
      overflow: hidden;
      position: relative;
      flex-shrink: 0;
    }

    .image-upload-area:hover {
      border-color: var(--accent);
      color: var(--text-secondary);
    }

    .image-upload-area img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .image-upload-area input[type=file] {
      position: absolute;
      inset: 0;
      opacity: 0;
      cursor: pointer;
    }

    #scenarioImgUpload {
      aspect-ratio: 16 / 9;
      height: auto;
    }

    .image-upload-actions {
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .btn-upload-action {
      background: var(--bg-input);
      border: 1px solid var(--border);
      color: var(--text-secondary);
      padding: 8px 14px;
      border-radius: var(--radius);
      font-size: 12px;
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 8px;
      transition: background var(--transition), border-color var(--transition);
      cursor: pointer;
    }

    .btn-upload-action:hover {
      background: var(--bg-hover);
      border-color: var(--border-light);
      color: var(--text-primary);
    }

    .rich-toolbar {
      display: flex;
      align-items: center;
      gap: 2px;
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-bottom: none;
      border-radius: var(--radius) var(--radius) 0 0;
      padding: 4px 8px;
      flex-wrap: wrap;
    }

    .rich-toolbar button {
      width: 24px;
      height: 24px;
      border-radius: 3px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      font-weight: 700;
      color: var(--text-secondary);
      transition: background var(--transition);
    }

    .rich-toolbar button:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .rich-toolbar .divider {
      width: 1px;
      height: 16px;
      background: var(--border);
      margin: 0 4px;
    }

    .rich-textarea h3 {
      font-size: 15px;
      font-weight: 700;
      margin: 6px 0 4px;
      color: var(--text-primary);
    }

    .rich-textarea blockquote {
      border-left: 3px solid var(--accent);
      padding-left: 10px;
      margin: 4px 0;
      color: var(--text-secondary);
      font-style: italic;
    }

    .rich-textarea ul {
      padding-left: 18px;
      margin: 4px 0;
    }

    .rich-textarea ul li {
      margin: 2px 0;
    }

    .rich-textarea a {
      color: var(--accent2);
      text-decoration: underline;
    }

    .tag-btn-group {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 4px;
    }

    .tag-btn {
      padding: 6px 14px;
      border-radius: 20px;
      font-size: 12px;
      font-weight: 600;
      background: var(--bg-input);
      border: 1px solid var(--border);
      color: var(--text-secondary);
      cursor: pointer;
      transition: background var(--transition), border-color var(--transition), color var(--transition);
      user-select: none;
    }

    .tag-btn:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
      border-color: var(--border-light);
    }

    .tag-btn.selected {
      background: rgba(232, 98, 26, 0.15);
      border-color: var(--accent);
      color: var(--accent);
    }

    .creator-bottom-actions {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      padding: 14px 0 2px;
    }

    /* ── Tag Picker ──────────────────────────────────────── */
    .tag-picker-wrap { position: relative; }

    .tag-selected-pills {
      display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 0;
    }

    .tag-selected-pill {
      display: inline-flex; align-items: center; gap: 5px;
      padding: 4px 10px 4px 12px;
      background: rgba(232,98,26,0.14); border: 1px solid var(--accent);
      border-radius: 20px; font-size: 12px; font-weight: 600; color: var(--accent);
      cursor: default;
    }

    .tag-selected-pill-x {
      display: flex; align-items: center; justify-content: center;
      width: 14px; height: 14px; border-radius: 50%;
      background: rgba(232,98,26,0.25); font-size: 11px; cursor: pointer;
      line-height: 1; color: var(--accent);
    }
    .tag-selected-pill-x:hover { background: var(--accent); color: #fff; }

    .tag-picker-trigger {
      display: inline-flex; align-items: center; gap: 6px;
      padding: 7px 14px; border-radius: 8px;
      background: var(--bg-input); border: 1px dashed var(--border);
      color: var(--text-dim); font-size: 12px; cursor: pointer;
      transition: border-color 0.15s, color 0.15s;
    }
    .tag-picker-trigger:hover, .tag-picker-trigger.open {
      border-color: var(--accent); color: var(--accent);
    }

    .tag-picker-popup {
      position: absolute; top: calc(100% + 6px); left: 0;
      width: 480px; max-width: 95vw;
      background: var(--bg-secondary, #1a1a2e); border: 1px solid var(--border);
      border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.6);
      z-index: 300; display: none;
      flex-direction: column; overflow: hidden;
    }
    .tag-picker-popup.open { display: flex; }

    .tag-picker-search-row {
      padding: 10px 12px; border-bottom: 1px solid var(--border);
      display: flex; align-items: center; gap: 8px;
    }

    .tag-picker-search {
      flex: 1; background: none; border: none; outline: none;
      color: var(--text-primary); font-size: 13px;
    }
    .tag-picker-search::placeholder { color: var(--text-dim); }

    .tag-picker-body {
      display: flex; height: 300px; overflow: hidden;
    }

    .tag-picker-cats {
      width: 130px; flex-shrink: 0;
      border-right: 1px solid var(--border);
      overflow-y: auto; padding: 6px 0;
    }

    .tag-picker-cat-btn {
      display: block; width: 100%;
      padding: 8px 12px; text-align: left;
      font-size: 11px; font-weight: 600; color: var(--text-dim);
      background: none; border: none; cursor: pointer;
      transition: background 0.1s, color 0.1s;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .tag-picker-cat-btn:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
    .tag-picker-cat-btn.active { color: var(--accent); background: rgba(232,98,26,0.08); }

    .tag-picker-list {
      flex: 1; overflow-y: auto; padding: 8px;
      display: flex; flex-direction: column; gap: 2px;
    }

    .tag-picker-item {
      display: flex; align-items: center; gap: 8px;
      padding: 7px 10px; border-radius: 6px;
      cursor: pointer; font-size: 12px; color: var(--text-secondary);
      transition: background 0.1s;
    }
    .tag-picker-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
    .tag-picker-item.selected { background: rgba(232,98,26,0.1); color: var(--accent); }
    .tag-picker-item.disabled { opacity: 0.35; cursor: not-allowed; }

    .tag-picker-item-emoji { font-size: 14px; width: 20px; text-align: center; flex-shrink: 0; }

    .tag-picker-footer {
      padding: 8px 12px; border-top: 1px solid var(--border);
      font-size: 11px; color: var(--text-dim);
    }

    /* ===================== CHAT VIEW ===================== */
    #view-chat {
      flex-direction: column;
    }

    #view-chat.active {
      display: flex;
    }

    .chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: 20px 24px;
      display: flex;
      flex-direction: column;
      gap: 0;
    }

    .chat-date-divider {
      display: flex;
      align-items: center;
      gap: 12px;
      margin: 16px 0;
      color: var(--text-dim);
      font-size: 11px;
      font-weight: 600;
    }

    .chat-date-divider::before,
    .chat-date-divider::after {
      content: '';
      flex: 1;
      height: 1px;
      background: var(--border);
    }

    .chat-msg {
      display: flex;
      gap: 14px;
      padding: 14px 16px;
      position: relative;
      align-items: flex-start;
    }

    .chat-msg.user-msg {
      flex-direction: row-reverse;
    }

    /* Archived messages: visible to you, invisible to the AI (in memory card) */
    .chat-msg.archived-msg {
      opacity: 0.35;
      filter: saturate(0.4);
      transition: opacity 0.15s ease, filter 0.15s ease;
    }

    .chat-msg.archived-msg:hover {
      opacity: 0.7;
      filter: saturate(0.7);
    }

    .chat-msg.archived-msg .msg-bubble::after {
      content: 'archived — AI reads summary';
      display: block;
      font-size: 10px;
      color: var(--text-dim);
      margin-top: 6px;
      font-style: italic;
      letter-spacing: 0.02em;
    }

    .msg-avatar {
      width: 56px;
      height: 56px;
      border-radius: 50%;
      background: var(--bg-card);
      flex-shrink: 0;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      color: var(--text-dim);
      border: 1px solid var(--border);
      margin-top: 0;
    }

    .msg-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .msg-body {
      flex: 1;
      min-width: 0;
      max-width: 78%;
      display: flex;
      flex-direction: column;
      gap: 4px;
      /* removed overflow:hidden to allow menu to sit outside */
    }

    .user-msg .msg-body {
      align-items: flex-end;
      margin-left: auto;
      margin-right: 0;
    }

    .chat-msg:not(.user-msg) .msg-body {
      margin-right: auto;
      margin-left: 0;
    }

    .msg-name {
      font-size: 11px;
      font-weight: 700;
      color: var(--text-dim);
      padding: 0 4px;
      letter-spacing: 0.5px;
      text-transform: uppercase;
    }

    .msg-header {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 11px;
      color: var(--text-dim);
    }

    .msg-sender {
      font-weight: 700;
      font-size: 12px;
      color: var(--text-secondary);
    }

    .user-msg .msg-header {
      flex-direction: row-reverse;
    }

    .msg-bubble {
      padding: 12px 16px;
      border-radius: 10px;
      line-height: 1.7;
      font-size: var(--chat-font-size, 14px);
      position: relative;
      font-family: var(--font-body);
      text-align: left;
    }

    .bot-bubble {
      background: var(--bg-bot-msg);
      color: var(--text-bot);
      border: 1px solid var(--border);
      border-top-left-radius: 2px;
    }

    .user-bubble {
      background: var(--bg-user-msg);
      color: var(--text-user);
      border: 1px solid var(--border);
      border-top-right-radius: 2px;
    }

    /* ── Chat background mode ── */
    #view-chat.has-chat-bg {
      background-size: cover;
      background-position: center;
      background-attachment: local;
    }
    #view-chat.has-chat-bg .chat-messages {
      background: transparent !important;
    }
    #view-chat.has-chat-bg .bot-bubble {
      background: rgba(20, 20, 26, 0.18) !important;
      backdrop-filter: blur(20px) saturate(200%);
      -webkit-backdrop-filter: blur(20px) saturate(200%);
      border: 1px solid rgba(255,255,255,0.18) !important;
      border-top-left-radius: 10px !important;
      box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.35),
        inset 0 -1px 0 rgba(0,0,0,0.2),
        0 4px 24px rgba(0,0,0,0.35);
    }
    #view-chat.has-chat-bg .user-bubble {
      background: rgba(20, 20, 26, 0.18) !important;
      backdrop-filter: blur(20px) saturate(200%);
      -webkit-backdrop-filter: blur(20px) saturate(200%);
      border: 1px solid rgba(232,98,26,0.35) !important;
      border-top-right-radius: 10px !important;
      box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.25),
        inset 0 -1px 0 rgba(0,0,0,0.2),
        0 4px 24px rgba(0,0,0,0.35);
    }
    #view-chat.has-chat-bg .chat-input-area {
      background: transparent !important;
      backdrop-filter: none !important;
      -webkit-backdrop-filter: none !important;
      border-top: 1px solid rgba(255,255,255,0.08) !important;
    }
    #view-chat.has-chat-bg .chat-input-row {
      background: rgba(20, 20, 26, 0.18) !important;
      backdrop-filter: blur(20px) saturate(200%);
      -webkit-backdrop-filter: blur(20px) saturate(200%);
      border-color: rgba(255,255,255,0.18) !important;
      box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.25),
        inset 0 -1px 0 rgba(0,0,0,0.15),
        0 4px 24px rgba(0,0,0,0.3);
    }
    #view-chat.has-chat-bg #chat-topbar {
      background: rgba(20, 20, 24, 0.65) !important;
      backdrop-filter: blur(20px) saturate(160%);
      -webkit-backdrop-filter: blur(20px) saturate(160%);
      border-bottom-color: rgba(255,255,255,0.08) !important;
    }
    #view-chat.has-chat-bg #mobileLogoBar {
      background: rgba(20, 20, 24, 0.65) !important;
      backdrop-filter: blur(20px) saturate(160%);
      -webkit-backdrop-filter: blur(20px) saturate(160%);
    }
    .chat-bg-presets {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-top: 10px;
    }
    .chat-bg-preset {
      width: 52px;
      height: 52px;
      border-radius: 8px;
      border: 2px solid transparent;
      cursor: pointer;
      transition: border-color 0.15s, transform 0.15s;
      flex-shrink: 0;
    }
    .chat-bg-preset:hover { transform: scale(1.08); }
    .chat-bg-preset.active { border-color: var(--accent); }
    .chat-bg-upload-btn {
      width: 52px;
      height: 52px;
      border-radius: 8px;
      border: 2px dashed var(--border-light);
      background: var(--bg-card);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-dim);
      font-size: 22px;
      transition: border-color 0.15s;
      flex-shrink: 0;
    }
    .chat-bg-upload-btn:hover { border-color: var(--accent); color: var(--accent); }

    .bot-bubble em {
      font-style: italic;
      color: var(--text-bot);
      opacity: 0.85;
    }

    .user-bubble em {
      font-style: italic;
      color: var(--text-user);
      opacity: 0.85;
    }

    .bot-bubble strong,
    .user-bubble strong {
      font-weight: 700;
      font-style: normal;
    }

    .bot-bubble strong {
      color: var(--text-dialogue);
    }

    .user-bubble strong {
      color: var(--text-dialogue);
    }

    /* dialogue = quoted speech — normal weight so **bold** and *italic* can work inside it */
    .bot-bubble .dialogue,
    .user-bubble .dialogue {
      color: var(--text-dialogue);
      font-weight: normal;
    }

    .bot-bubble .dialogue em,
    .user-bubble .dialogue em {
      color: var(--text-dialogue);
      font-style: italic;
      opacity: 0.9;
    }

    .bot-bubble .dialogue strong,
    .user-bubble .dialogue strong {
      color: var(--text-dialogue);
      font-weight: 700;
    }

    /* backtick code spans */
    .bot-bubble .backtick,
    .user-bubble .backtick {

      /* Protective CSS: Prevent color bleed from parent spans */
      .msg-bubble span:not(.dialogue):not(.backtick) {
        color: inherit;
      }

      font-family: 'Courier New',
      monospace;
      font-size: 0.9em;
      background: rgba(255, 255, 255, 0.08);
      border-radius: 3px;
      padding: 1px 5px;
      color: #f5c842;
    }

    /* Hover menu - now sits to the side of bubble */
    .msg-hover-controls {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 6px;
      flex-shrink: 0;
      align-self: center;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.08s ease;
    }

    .chat-msg:hover .msg-hover-controls {
      opacity: 1;
      pointer-events: auto;
    }

    .response-menu {
      position: absolute !important;
      bottom: 0 !important;
      flex-direction: column !important;
      background: none !important;
      backdrop-filter: none !important;
      border-radius: 0 !important;
      padding: 0 !important;
      align-self: flex-end !important;
      margin-bottom: 0 !important;
      justify-content: flex-end !important;
      z-index: 10;
      box-shadow: none !important;
      gap: 4px !important;
    }

    .bot-bubble .response-menu {
      right: -38px !important;
      left: auto !important;
    }

    .user-bubble .response-menu {
      left: -38px !important;
      right: auto !important;
    }

    .hover-btn {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 13px;
      background: var(--bg-panel);
      border: 1px solid var(--border);
      transition: background var(--transition), color var(--transition);
      flex-shrink: 0;
    }

    .hover-btn:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
      border-color: var(--border-light);
    }

    .hover-btn.listen-btn.playing {
      color: var(--accent);
      border-color: var(--accent);
    }

    /* Inline message edit */
    .msg-edit-wrap {
      display: flex;
      flex-direction: column;
      gap: 10px;
      width: 100%;
    }

    .msg-edit-textarea {
      width: 100%;
      background: var(--bg-input);
      border: 1px solid var(--border-light);
      border-radius: 10px;
      padding: 12px 16px;
      font-size: var(--chat-font-size, 14px);
      font-family: var(--font-body);
      color: var(--text-primary);
      line-height: 1.7;
      resize: vertical;
      min-height: 80px;
      outline: none;
    }

    .msg-edit-textarea:focus {
      border-color: var(--accent);
    }

    .msg-edit-actions {
      display: flex;
      gap: 8px;
    }

    .msg-edit-save {
      background: var(--text-primary);
      color: var(--bg-base);
      border: none;
      border-radius: 20px;
      padding: 8px 22px;
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      font-family: var(--font-body);
      transition: opacity var(--transition);
    }

    .msg-edit-save:hover {
      opacity: 0.85;
    }

    .msg-edit-cancel {
      background: var(--bg-card);
      color: var(--text-secondary);
      border: 1px solid var(--border);
      border-radius: 20px;
      padding: 8px 22px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      font-family: var(--font-body);
      transition: background var(--transition);
    }

    .msg-edit-cancel:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    /* Three dots context menu - sized to content */
    .ctx-menu {
      display: none;
      position: fixed;
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      min-width: 190px;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
      z-index: 1000;
      overflow: hidden;
      width: auto;
    }

    .ctx-menu.open {
      display: block;
    }

    .ctx-menu-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 16px;
      font-size: 13px;
      color: var(--text-secondary);
      transition: background var(--transition);
      cursor: pointer;
      white-space: nowrap;
    }

    .ctx-menu-item:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .ctx-menu-item.danger {
      color: #e05252;
    }

    .ctx-menu-item.danger:hover {
      background: rgba(224, 82, 82, 0.1);
    }

    /* Chat input */
    .chat-input-area {
      padding: 12px 20px 10px;
      border-top: 1px solid var(--border);
      background: var(--bg-panel);
      flex-shrink: 0;
    }

    .chat-input-row {
      display: flex;
      align-items: center;
      gap: 10px;
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      padding: 10px 12px;
      transition: border-color var(--transition);
    }

    .chat-input-row:focus-within {
      border-color: var(--accent);
    }

    .chat-textarea {
      flex: 1;
      background: transparent;
      border: none;
      resize: none;
      min-height: 22px;
      max-height: 140px;
      font-size: 13.5px;
      line-height: 1.5;
      color: var(--text-primary);
      padding: 0;
    }

    .chat-textarea::placeholder {
      color: var(--text-dim);
    }

    .chat-image-btn {
      height: 30px;
      min-width: 30px;
      border-radius: 999px;
      background: rgba(255, 214, 138, 0.12);
      color: #ffd68a;
      border: 1px solid rgba(255, 214, 138, 0.35);
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      flex-shrink: 0;
      padding: 0 10px;
      font-size: 11px;
      font-weight: 700;
      transition: background var(--transition), transform var(--transition), border-color var(--transition);
    }

    .chat-image-btn:hover {
      background: rgba(255, 214, 138, 0.2);
      border-color: rgba(255, 214, 138, 0.55);
      transform: scale(1.03);
    }

    .chat-image-btn svg {
      flex-shrink: 0;
    }

    .chat-send-btn {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background: var(--accent);
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background var(--transition), transform var(--transition);
    }

    .chat-send-btn:hover {
      background: #d0561a;
      transform: scale(1.05);
    }

    .chat-input-footer {
      text-align: center;
      font-size: 10px;
      color: var(--text-dim);
      margin-top: 6px;
    }

    /* ===================== MY SCENARIOS VIEW ===================== */
    #view-scenarios {
      overflow-y: auto;
    }

    .scenarios-content {
      padding: 40px;
      max-width: 1400px;
      margin: 0 auto;
      width: 100%;
    }

    .scenarios-content .section-header {
      margin-bottom: 32px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border: none;
      padding: 0;
    }

    .scenarios-content .section-header h3 {
      font-size: 20px;
      font-weight: 700;
      color: #ffffff;
    }

    /* ===================== PERSONAS VIEW ===================== */
    #view-personas {
      overflow-y: auto;
    }

    .personas-content {
      padding: 24px;
      max-width: 900px;
      margin: 0 auto;
      width: 100%;
    }

    .personas-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 16px;
    }

    .personas-header h2 {
      font-family: var(--font-display);
      font-size: 16px;
      font-weight: 600;
    }

    .personas-search {
      margin-bottom: 16px;
      position: relative;
    }

    .personas-search input {
      padding-left: 34px;
    }

    .personas-search-icon {
      position: absolute;
      left: 10px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-dim);
    }

    .personas-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 16px;
    }

    .persona-card {
      background: linear-gradient(135deg, rgba(107, 114, 128, 0.08), rgba(107, 114, 128, 0.04));
      border: 1px solid rgba(107, 114, 128, 0.25);
      border-radius: var(--radius-lg);
      overflow: hidden;
      cursor: pointer;
      transition: all var(--transition);
      position: relative;
      display: flex;
      flex-direction: row;
    }

    .persona-card:hover {
      transform: translateY(-2px);
      border-color: rgba(107, 114, 128, 0.5);
      box-shadow: 0 4px 12px rgba(107, 114, 128, 0.1);
    }

    .persona-card-img {
      width: 140px;
      height: 140px;
      flex-shrink: 0;
      background: var(--bg-input);
      overflow: hidden;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .persona-card-img img {
      max-width: 100%;
      max-height: 100%;
      object-fit: scale-down;
      object-position: center;
      background: transparent;
    }

    .persona-card-menu {
      position: absolute;
      top: 6px;
      right: 6px;
      width: 26px;
      height: 26px;
      background: rgba(0, 0, 0, 0.65);
      border-radius: 4px;
      display: none;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 16px;
    }

    .persona-card:hover .persona-card-menu {
      display: flex;
    }

    .persona-card-body {
      padding: 12px 14px;
      flex: 1;
      display: flex;
      flex-direction: column;
    }

    .persona-card-badge {
      display: inline-block;
      font-size: 9px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      background: rgba(236, 72, 153, 0.15);
      color: #ec4899;
      border: 1px solid rgba(236, 72, 153, 0.3);
      padding: 3px 10px;
      border-radius: 12px;
      width: fit-content;
      margin-bottom: 6px;
    }

    .persona-card-name {
      font-size: 13px;
      font-weight: 700;
      margin-bottom: 4px;
    }

    .persona-card-desc {
      font-size: 11px;
      color: var(--text-secondary);
      line-height: 1.4;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    /* ===================== ORIGINAL CHARACTERS ===================== */
    .hub-card-characters-original .create-hub-card-bg {
      background-image: url('assets/characters.jpg');
      background-size: cover;
      background-position: center center;
    }

    .characters-content {
      padding: 24px;
      max-width: 1100px;
      margin: 0 auto;
      width: 100%;
    }

    .characters-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      flex-wrap: wrap;
      margin-bottom: 14px;
    }

    .characters-header h2 {
      font-family: var(--font-display);
      font-size: 16px;
      font-weight: 700;
    }

    .characters-search {
      position: relative;
      margin-bottom: 18px;
    }

    .characters-search-icon {
      position: absolute;
      left: 12px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-dim);
    }

    .characters-search input {
      padding-left: 36px;
      height: 42px;
      border-radius: 10px;
    }

    .characters-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 16px;
    }

    .character-sections-wrap {
      display: flex;
      flex-direction: column;
      gap: 24px;
    }

    .character-section-block {
      margin-top: 24px;
    }

    .character-section-dropzone {
      min-height: 110px;
      border: 2px dashed rgba(255, 255, 255, 0.08);
      border-radius: 16px;
      padding: 14px;
      transition: all 0.15s ease;
      background: transparent;
      grid-column: 1 / -1;
    }

    .character-section-dropzone.drag-over,
    .characters-grid.drag-over {
      border-color: rgba(232, 98, 26, 0.8);
      background: rgba(232, 98, 26, 0.08);
      box-shadow: inset 0 0 20px rgba(232, 98, 26, 0.1);
    }

    .character-section-title {
      display: flex;
      align-items: center;
      gap: 12px;
      margin: 0 0 12px;
      padding: 12px 16px;
      background: linear-gradient(90deg, rgba(139, 92, 246, 0.25), rgba(139, 92, 246, 0.12));
      border-left: 4px solid #8b5cf6;
      border-radius: 6px;
      color: #fff;
      font-family: var(--font-display);
      font-size: 16px;
      font-weight: 700;
      letter-spacing: 0.2px;
      position: relative;
      overflow: visible;
    }

    .character-section-title-text {
      white-space: nowrap;
      flex: 1;
    }

    .character-section-title::before,
    .character-section-title::after {
      display: none;
    }

    .character-section-title-actions {
      display: flex !important;
      align-items: center;
      gap: 6px;
      margin-left: auto;
    }

    .character-section-title-btn:hover {
      color: #fff;
      border-color: rgba(232, 98, 26, 0.35);
      background: rgba(232, 98, 26, 0.10);
    }

    .character-section-title-btn.delete:hover {
      color: #ffb4b4;
      border-color: rgba(224, 82, 82, 0.35);
      background: rgba(224, 82, 82, 0.10);
    }

    .character-card {
      transition: transform 0.12s cubic-bezier(0.23, 1, 0.320, 1),
        box-shadow 0.12s ease,
        opacity 0.12s ease,
        filter 0.12s ease;
    }

    .character-card[draggable="true"] {
      cursor: grab;
    }

    .character-card[draggable="true"]:active {
      cursor: grabbing;
    }

    .character-card.dragging {
      opacity: 0.45;
      transform: scale(0.98) translateY(-2px);
      cursor: grabbing;
      filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.3));
    }

    .character-card.drop-before {
      box-shadow: inset 0 3px 0 0 var(--accent);
    }

    .character-card.drop-after {
      box-shadow: inset 0 -3px 0 0 var(--accent);
    }

    .character-card.drop-target {
      border: 2px solid var(--accent);
      background: rgba(232, 98, 26, 0.08);
      transform: scale(1.02);
    }

    .character-card:hover:not(.dragging) {
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .character-section-block.is-empty .character-section-dropzone {
      min-height: 72px;
    }

    .simple-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.72);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 4000;
      padding: 20px;
    }

    .simple-overlay.open {
      display: flex;
    }

    .simple-modal {
      width: 100%;
      max-width: 420px;
      background: var(--bg-panel);
      border: 1px solid var(--border);
      border-radius: 16px;
      overflow: hidden;
      box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    }

    .simple-modal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 18px 20px;
      border-bottom: 1px solid var(--border);
    }

    .simple-modal-header h3 {
      margin: 0;
      font-size: 17px;
      font-weight: 700;
    }

    .simple-modal-body {
      padding: 18px 20px 6px;
    }

    .simple-modal-label {
      display: block;
      margin-bottom: 8px;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      color: var(--text-dim);
    }

    .simple-modal-footer {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      padding: 16px 20px 20px;
    }

    .character-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 12px;
      overflow: hidden;
      cursor: pointer;
      transition: transform 0.2s cubic-bezier(0.23, 1, 0.32, 1), border-color 0.2s, box-shadow 0.2s, filter 0.2s;
      position: relative;
    }

    .character-card:hover {
      transform: translateY(-3px) scale(1.02);
      border-color: rgba(46, 189, 217, 0.5);
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4), inset 0 0 1px rgba(46, 189, 217, 0.1);
    }

    .character-card-img {
      width: 100%;
      height: 180px;
      background: linear-gradient(135deg, #151922 0%, #1e2234 60%, #20172f 100%);
      overflow: hidden;
      position: relative;
    }

    .character-card-img img {
      width: 100%;
      height: 100%;
      max-width: 100%;
      max-height: 180px;
      object-fit: contain;
      object-position: center center;
      display: block;
      transition: transform 0.3s ease;
    }

    .character-card:hover .character-card-img img {
      transform: scale(1.05);
    }

    .character-card-img::after {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.1) 48%, rgba(0, 0, 0, 0.02) 100%);
      pointer-events: none;
    }

    .character-card-body {
      padding: 14px;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0) 100%);
    }

    .character-card-name {
      font-size: 14px;
      font-weight: 700;
      color: #fff;
      margin-bottom: 4px;
      letter-spacing: 0.2px;
    }

    .character-card-role {
      font-size: 11px;
      color: var(--accent2);
      margin-bottom: 6px;
      font-weight: 500;
    }

    .character-card-desc {
      font-size: 11px;
      color: var(--text-secondary);
      line-height: 1.55;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .character-card-menu {
      position: absolute;
      top: 8px;
      right: 8px;
      z-index: 2;
      width: 28px;
      height: 28px;
      border-radius: 8px;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(0, 0, 0, 0.55);
      color: #fff;
    }

    .character-card:hover .character-card-menu {
      display: flex;
    }

    .characters-action-buttons {
      display: flex;
      gap: 10px;
      margin-bottom: 16px;
      flex-wrap: wrap;
      align-items: center;
    }

    .characters-action-buttons button {
      padding: 9px 18px;
      background: var(--accent);
      border: none;
      border-radius: 6px;
      color: #fff;
      cursor: pointer;
      font-weight: 600;
      font-size: 13px;
      transition: background var(--transition);
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .characters-action-buttons button:hover {
      background: #d4561c;
    }

    .characters-action-buttons button svg {
      width: 16px;
      height: 16px;
    }

    .char-menu-popover {
      position: absolute;
      top: 100%;
      right: 0;
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
      min-width: 140px;
      box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
      z-index: 50;
      margin-top: 4px;
    }

    .char-menu-popover button {
      width: 100%;
      text-align: left;
      padding: 10px 14px;
      background: none;
      border: none;
      color: var(--text-secondary);
      cursor: pointer;
      font-size: 13px;
      font-weight: 400;
      border-bottom: 1px solid var(--border);
    }

    .char-menu-popover button:last-child {
      border-bottom: none;
    }

    .char-menu-popover button:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    #characterSheetOverlay,
    #characterEditorOverlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.72);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 410;
      padding: 20px;
    }

    #characterSheetOverlay.open,
    #characterEditorOverlay.open {
      display: flex;
    }

    .character-sheet-modal,
    .character-editor-modal {
      width: min(100%, 1100px);
      max-height: min(92vh, 980px);
      background: #111214;
      border: 1px solid var(--border);
      border-radius: 20px;
      overflow: hidden;
      box-shadow: 0 32px 80px rgba(0, 0, 0, 0.55);
      display: flex;
      flex-direction: column;
    }

    .character-editor-modal {
      width: min(100%, 980px);
    }

    .character-sheet-topbar,
    .character-editor-topbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 18px 22px;
      border-bottom: 1px solid var(--border);
      background: rgba(255, 255, 255, 0.02);
      position: relative;
    }

    .character-sheet-topbar h3,
    .character-editor-topbar h3 {
      font-size: 22px;
      font-weight: 800;
      color: #fff;
      flex: 1;
    }

    .character-sheet-header-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      font-size: 14px;
      text-transform: uppercase;
      letter-spacing: 1px;
      font-weight: 700;
      color: var(--accent2);
      border: 1px solid rgba(46, 189, 217, 0.3);
      padding: 8px 14px;
      border-radius: 4px;
      background: rgba(46, 189, 217, 0.08);
      margin-bottom: 32px;
      width: fit-content;
    }

    .character-sheet-header-badge::before {
      content: '';
      display: inline-block;
      width: 8px;
      height: 8px;
      background: var(--accent2);
      border-radius: 50%;
    }

    .character-sheet-body {
      overflow-y: auto;
      display: grid;
      grid-template-columns: 420px minmax(0, 1fr);
      min-height: 0;
    }
    @media (max-width: 700px) {
      .character-sheet-body { grid-template-columns: 1fr; }
      .character-sheet-visual { border-right: none; border-bottom: 1px solid var(--border); }
      .character-sheet-mainimg { aspect-ratio: 16/9; max-height: 280px; }
      .character-sheet-album { grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px; }
      .character-sheet-thumb { border-radius: 8px; }
      .character-sheet-details { padding: 16px; }
    }

    .character-sheet-visual {
      border-right: 1px solid var(--border);
      background: linear-gradient(180deg, rgba(46, 189, 217, 0.08) 0%, rgba(255, 255, 255, 0.01) 100%);
      display: flex;
      flex-direction: column;
    }

    .character-sheet-mainimg {
      width: 100%;
      aspect-ratio: 4/5;
      background: #181b22;
      overflow: hidden;
    }

    .character-sheet-mainimg img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .character-sheet-album {
      padding: 14px;
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
    }

    .character-sheet-thumb {
      aspect-ratio: 1/1;
      border-radius: 12px;
      overflow: hidden;
      border: 1px solid var(--border);
      background: var(--bg-card);
      cursor: pointer;
    }

    .character-sheet-thumb img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    .character-sheet-details {
      padding: 80px 24px 24px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
    }

    .character-sheet-header {
      color: var(--accent);
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 2px;
      font-weight: 700;
      margin-bottom: 16px;
      min-height: 18px;
    }

    .character-sheet-name {
      font-size: 56px;
      font-weight: 900;
      color: #ffffff;
      margin-bottom: 16px;
      line-height: 1.0;
      letter-spacing: -1px;
      text-transform: uppercase;
    }

    .character-sheet-role {
      color: var(--accent2);
      font-size: 16px;
      font-weight: 600;
      margin-bottom: 8px;
      display: none;
    }

    .character-sheet-tagline {
      color: var(--text-secondary);
      font-size: 13px;
      line-height: 1.6;
      margin-bottom: 24px;
      padding-bottom: 24px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .character-sheet-attributes-label {
      color: var(--text-dim);
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 1.5px;
      font-weight: 700;
      margin-bottom: 16px;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .character-sheet-chiprow {
      display: flex;
      flex-wrap: wrap;
      gap: 12px;
    }

    .character-sheet-chip {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 12px;
      border-radius: 4px;
      border: 1px solid rgba(61, 189, 218, 0.3);
      background: #111217;
      color: var(--text-secondary);
      font-size: 11px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      position: relative;
    }

    .character-sheet-chip::before {
      content: '';
      display: inline-block;
      width: 6px;
      height: 6px;
      background: var(--accent);
      border-radius: 50%;
      flex-shrink: 0;
    }

    .character-sheet-actions {
      display: flex;
      gap: 10px;
      margin-top: auto;
      padding-top: 16px;
    }

    #characterSheetOverlay.view-only .character-sheet-topbar .btn-secondary,
    #characterSheetOverlay.view-only .character-sheet-topbar .btn-danger {
      display: none !important;
    }

    /* Intro rich-text editor */
    .intro-editor-toolbar {
      display: flex;
      flex-wrap: wrap;
      gap: 2px;
      align-items: center;
      padding: 6px 10px;
      background: #1a1a1a;
      border: 1px solid var(--border);
      border-bottom: none;
      border-radius: 8px 8px 0 0;
      position: sticky;
      top: 0;
      z-index: 50;
    }
    .intro-editor-toolbar button {
      background: none;
      border: 1px solid transparent;
      color: var(--text-dim);
      border-radius: 4px;
      padding: 3px 7px;
      font-size: 13px;
      cursor: pointer;
      transition: all 0.12s;
      font-weight: 600;
      line-height: 1.4;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 26px;
    }
    .intro-editor-toolbar button:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }
    .intro-editor-toolbar button.tb-active { color: var(--accent2); background: rgba(46,189,217,0.1); }
    .intro-editor-toolbar .tb-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
    .intro-editor-toolbar select {
      background: #1a1a1a;
      border: 1px solid var(--border);
      color: var(--text-secondary);
      border-radius: 4px;
      padding: 3px 6px;
      font-size: 12px;
      cursor: pointer;
      font-family: inherit;
      outline: none;
      transition: all 0.12s;
      height: 26px;
    }
    .intro-editor-toolbar select:hover { border-color: var(--border-light); }
    @media (max-width: 700px) {
      .intro-editor-toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 6px 8px;
      }
      .intro-editor-toolbar::-webkit-scrollbar { display: none; }
      .intro-editor-toolbar button,
      .intro-editor-toolbar select { flex-shrink: 0; }
    }
    /* Color picker popup */
    .tb-color-popup {
      position: absolute;
      z-index: 700;
      background: var(--bg-panel);
      border: 1px solid var(--border-light);
      border-radius: 8px;
      padding: 8px;
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      width: 152px;
      box-shadow: 0 6px 20px rgba(0,0,0,0.5);
    }
    .tb-color-swatch {
      width: 20px; height: 20px;
      border-radius: 4px;
      cursor: pointer;
      border: 2px solid transparent;
      transition: transform 0.1s;
    }
    .tb-color-swatch:hover { transform: scale(1.2); border-color: #fff4; }
    .tb-color-btn-wrap { position: relative; display: inline-flex; }
    .intro-link-modal {
      position: fixed; inset: 0; z-index: 9100;
      display: flex; align-items: center; justify-content: center;
      background: rgba(0,0,0,0.55);
    }
    .intro-link-modal-box {
      background: var(--bg-panel);
      border: 1px solid var(--border-light);
      border-radius: 12px;
      padding: 22px 24px;
      width: 380px;
      max-width: 90vw;
    }
    .intro-link-modal-title { font-weight: 700; font-size: 14px; margin-bottom: 14px; }
    .intro-link-modal input {
      width: 100%; background: var(--bg-input); border: 1px solid var(--border);
      border-radius: 6px; padding: 9px 12px; font-size: 13px; outline: none; color: var(--text-primary);
    }
    .intro-link-modal input:focus { border-color: var(--accent); }
    .intro-link-modal-hint { font-size: 11px; color: var(--text-dim); margin-top: 6px; margin-bottom: 14px; }
    .intro-link-modal-row { display: flex; gap: 8px; justify-content: flex-end; }
    .intro-editor-body {
      min-height: 220px;
      overflow-y: auto;
      padding: 12px 14px;
      font-size: 14px;
      line-height: 1.7;
      border: 1px solid var(--border);
      border-radius: 0 0 8px 8px;
      background: rgba(255,255,255,0.02);
      color: var(--text-primary);
      outline: none;
      resize: vertical;
    }
    .intro-editor-body:focus { border-color: rgba(46,189,217,0.35); }
    .intro-editor-body img { max-width: min(480px, 100%); border-radius: 6px; margin: 6px auto; display: block; cursor: pointer; }
    .intro-editor-body img.intro-img-selected { outline: 2px solid var(--accent2); outline-offset: 2px; }
    .intro-yt-wrap { display:block; width:100%; margin:14px 0; border-radius:10px; overflow:hidden; aspect-ratio:16/9; background:#000; }
    .intro-yt-wrap iframe { width:100%; height:100%; border:0; display:block; }
    .scenario-detail-intro .intro-yt-wrap { border-radius:10px; overflow:hidden; }
    .scenario-detail-intro .intro-yt-wrap iframe { width:100%; height:100%; border:0; aspect-ratio:16/9; display:block; }
    #introImgToolbar {
      position: fixed;
      background: var(--bg-card, #1e1e2e);
      border: 1px solid rgba(255,255,255,0.15);
      border-radius: 8px;
      padding: 5px 7px;
      display: none;
      gap: 4px;
      align-items: center;
      z-index: 9999;
      box-shadow: 0 4px 16px rgba(0,0,0,0.5);
      font-size: 11px;
    }
    #introImgToolbar button {
      background: rgba(255,255,255,0.06);
      border: 1px solid rgba(255,255,255,0.1);
      color: var(--text-primary);
      border-radius: 5px;
      padding: 3px 7px;
      cursor: pointer;
      font-size: 11px;
      white-space: nowrap;
    }
    #introImgToolbar button:hover { background: rgba(255,255,255,0.12); }
    #introImgToolbar button.active { background: rgba(46,189,217,0.15); border-color: var(--accent2); color: var(--accent2); }
    #introImgToolbar .itb-sep { width: 1px; height: 16px; background: rgba(255,255,255,0.12); margin: 0 2px; }
    #introImgToolbar input[type=range] { width: 80px; accent-color: var(--accent2); cursor: pointer; }
    .intro-editor-body p { margin: 0 0 8px; }
    .intro-editor-body:empty:before {
      content: attr(data-placeholder);
      color: var(--text-dim);
      pointer-events: none;
    }

    /* Backstory subsections */
    .backstory-subsections { display: flex; flex-direction: column; gap: 18px; }
    .backstory-sub { }
    .backstory-sub-label {
      font-size: 12px;
      font-weight: 700;
      color: var(--text-secondary);
      text-transform: uppercase;
      letter-spacing: 0.07em;
      margin-bottom: 6px;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .backstory-sub-label .sub-limit {
      font-weight: 400;
      font-size: 11px;
      text-transform: none;
      letter-spacing: 0;
      color: var(--text-dim);
    }
    .backstory-sub textarea {
      width: 100%;
      resize: vertical;
    }

    .character-editor-body {
      overflow-y: auto;
      padding: 22px 24px 28px;
      display: grid;
      grid-template-columns: 240px minmax(0, 1fr);
      gap: 20px;
    }

    .character-editor-media {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .character-editor-mainupload {
      width: 100%;
      aspect-ratio: 1/1;
      border-radius: 8px;
      border: 1px dashed rgba(46, 189, 217, 0.35);
      background: rgba(46, 189, 217, 0.06);
      overflow: hidden;
      position: relative;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      text-align: center;
      padding: 16px;
    }

    .character-editor-mainupload img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    .character-editor-albumgrid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px;
    }

    .character-editor-albumslot {
      aspect-ratio: 1/1;
      border-radius: 6px;
      border: 1px dashed rgba(184, 124, 255, 0.35);
      background: rgba(184, 124, 255, 0.05);
      overflow: hidden;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      font-size: 11px;
      text-align: center;
      padding: 8px;
    }

    .character-editor-albumslot img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    .character-editor-fields {
      display: flex;
      flex-direction: column;
      gap: 10px;
      min-width: 0;
    }

    .character-editor-grid2 {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 12px;
    }

    .character-editor-field label {
      display: block;
      margin-bottom: 6px;
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--text-dim);
      font-weight: 700;
    }

    .character-editor-field small {
      color: var(--text-dim);
      font-size: 11px;
      line-height: 1.5;
      display: block;
      margin-top: 6px;
    }

    .character-editor-footer {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      padding: 16px 24px 22px;
      border-top: 1px solid var(--border);
    }

    @media (max-width: 920px) {

      .character-sheet-body,
      .character-editor-body {
        grid-template-columns: 1fr;
      }

      .character-sheet-visual {
        border-right: none;
        border-bottom: 1px solid var(--border);
      }
    }

    /* ===================== SETTINGS PANEL ===================== */
    #settings-overlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 200;
      background: rgba(0, 0, 0, 0.5);
      backdrop-filter: blur(2px);
    }

    #settings-overlay.open {
      display: block;
    }

    #settings-panel {
      position: absolute;
      top: 0;
      right: 0;
      width: 380px;
      height: 100vh;
      background: var(--bg-panel);
      border-left: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      transform: translateX(100%);
      transition: transform 0.25s ease;
    }

    #settings-overlay.open #settings-panel {
      transform: translateX(0);
    }

    #settings-main-view {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-height: 0;
    }

    #edit-char-panel {
      display: none;
      flex-direction: column;
      flex: 1;
      min-height: 0;
    }

    #edit-char-panel.open {
      display: flex;
    }

    .settings-body {
      flex: 1;
      overflow-y: scroll;
      padding: 0 0 40px;
      min-height: 0;
    }

    .settings-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .settings-header h2 {
      font-family: var(--font-display);
      font-size: 14px;
      font-weight: 700;
    }

    .settings-close {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      transition: background var(--transition);
    }

    .settings-close:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    .settings-section {
      border-bottom: 1px solid var(--border);
      padding: 24px 20px;
    }

    .settings-section-label {
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--text-dim);
      margin-bottom: 12px;
    }

    .settings-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 0;
      border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    }

    .settings-row:last-child {
      border-bottom: none;
    }

    .settings-row-label {
      font-size: 14px;
      font-weight: 600;
    }

    .settings-row-sub {
      font-size: 11px;
      color: var(--text-dim);
      margin-top: 2px;
    }

    /* Toggle */
    .toggle {
      width: 44px;
      height: 24px;
      background: var(--bg-input);
      border-radius: 12px;
      position: relative;
      cursor: pointer;
      border: 1px solid var(--border);
      transition: background var(--transition);
      flex-shrink: 0;
    }

    .toggle.on {
      background: var(--accent);
      border-color: var(--accent);
    }

    .toggle::after {
      content: '';
      position: absolute;
      top: 3px;
      left: 3px;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: var(--text-secondary);
      transition: left var(--transition), background var(--transition);
    }

    .toggle.on::after {
      left: 23px;
      background: white;
    }

    /* Select */
    .settings-select {
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 10px 30px 10px 12px;
      font-size: 13px;
      color: var(--text-primary);
      width: 100%;
      appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235a544c' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 10px center;
      margin-top: 8px;
    }

    /* Slider */
    .slider-row {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .slider-spinbox {
      width: 60px;
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 4px 8px;
      font-size: 12px;
      text-align: center;
    }

    input[type=range] {
      flex: 1;
      -webkit-appearance: none;
      height: 4px;
      background: var(--border);
      border-radius: 2px;
      border: none;
      padding: 0;
    }

    input[type=range]::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: var(--accent);
      cursor: pointer;
    }

    /* Segment control */
    .segment-control {
      display: flex;
      background: var(--bg-input);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      overflow: hidden;
      width: 100%;
      margin-top: 8px;
    }

    .segment-btn {
      flex: 1;
      padding: 8px;
      font-size: 13px;
      font-weight: 600;
      color: var(--text-secondary);
      transition: background var(--transition), color var(--transition);
      text-align: center;
    }

    .segment-btn.active {
      background: var(--bg-hover);
      color: var(--text-primary);
    }

    /* Color row */
    .color-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 8px 0;
      border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    }

    .color-row:last-child {
      border-bottom: none;
    }

    .color-row-label {
      font-size: 13px;
      font-weight: 600;
    }

    .color-row-right {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .color-row-hex {
      font-size: 12px;
      color: var(--text-dim);
      font-family: monospace;
    }

    .color-swatch {
      width: 22px;
      height: 22px;
      border-radius: 3px;
      border: 1px solid var(--border);
      cursor: pointer;
      flex-shrink: 0;
      position: relative;
      overflow: hidden;
    }

    .color-swatch input[type=color] {
      position: absolute;
      inset: -4px;
      opacity: 0;
      cursor: pointer;
      width: 200%;
      height: 200%;
    }

    .btn-reset {
      width: 100%;
      padding: 10px;
      background: var(--bg-hover);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      color: var(--text-secondary);
      font-size: 13px;
      font-weight: 600;
      margin-top: 12px;
      transition: background var(--transition);
    }

    .btn-reset:hover {
      background: var(--border);
      color: var(--text-primary);
    }

    /* LLM Model row */
    .model-banner {
      width: 100%;
      height: 54px;
      background: linear-gradient(135deg, #1a0e2e, #2d1b4e);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 14px;
      cursor: pointer;
      margin-top: 8px;
      overflow: hidden;
      position: relative;
    }

    .model-banner-bg {
      position: absolute;
      inset: 0;
      background: linear-gradient(135deg, #1a0e2e 0%, #3a1e5e 50%, #1a0e2e 100%);
      opacity: 0.8;
    }

    .model-banner-label {
      font-size: 15px;
      font-weight: 700;
      color: var(--accent);
      font-family: var(--font-display);
      position: relative;
    }

    .model-banner-size {
      font-size: 10px;
      color: var(--text-dim);
      margin-left: 4px;
    }

    .model-banner-arrow {
      position: relative;
      color: var(--text-secondary);
    }

    .settings-nav-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 13px 0;
      border-bottom: 1px solid rgba(255, 255, 255, 0.04);
      cursor: pointer;
      transition: color var(--transition);
    }

    .settings-nav-row:hover {
      color: var(--text-primary);
    }

    .settings-nav-row:last-child {
      border-bottom: none;
    }

    .settings-nav-label {
      font-size: 14px;
      font-weight: 600;
    }

    .settings-nav-arrow {
      color: var(--text-dim);
    }

    /* ===================== EDIT CHARACTER SUBPANEL ===================== */
    #settings-main-view {
      display: flex;
      flex-direction: column;
      height: 100%;
      overflow: hidden;
    }

    #edit-char-panel {
      display: none;
      flex-direction: column;
      height: 100%;
      overflow: hidden;
    }

    #edit-char-panel.open {
      display: flex;
    }

    .settings-back-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 14px 20px;
      border-bottom: 1px solid var(--border);
      color: var(--text-secondary);
      cursor: pointer;
      font-size: 13px;
      font-weight: 600;
      transition: color var(--transition);
    }

    .settings-back-btn:hover {
      color: var(--text-primary);
    }

    /* Temperature sliders subpanel */
    .param-group {
      padding: 18px 20px;
      border-bottom: 1px solid var(--border);
    }

    .param-title {
      font-size: 16px;
      font-weight: 700;
      margin-bottom: 4px;
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .param-desc {
      font-size: 12px;
      color: var(--text-secondary);
      line-height: 1.5;
      margin-bottom: 14px;
    }

    .param-value {
      font-size: 16px;
      font-weight: 700;
      color: var(--text-secondary);
      text-align: right;
    }

    .param-slider-row {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .param-slider {
      flex: 1;
    }

    /* Number input styling for LLM settings */
    .llm-param-input {
      background: var(--bg-secondary) !important;
      border: 1px solid var(--border-color) !important;
      border-radius: 6px !important;
      color: var(--text-primary) !important;
      padding: 8px 10px !important;
      font-size: 14px !important;
      font-weight: 600 !important;
      width: auto !important;
      max-width: 120px !important;
      min-width: 80px !important;
      box-sizing: border-box;
      text-align: center;
    }

    .llm-param-input:focus {
      outline: none !important;
      border-color: var(--accent2) !important;
      background: var(--bg-secondary) !important;
    }

    /* Spinner buttons */
    .llm-param-input::-webkit-outer-spin-button,
    .llm-param-input::-webkit-inner-spin-button {
      -webkit-appearance: inner-spin-button !important;
      opacity: 1;
    }

    /* ===================== MISC ===================== */
    .empty-state {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      flex: 1;
      gap: 12px;
      color: var(--text-dim);
      font-size: 13px;
      padding: 40px;
      text-align: center;
    }

    .empty-state svg {
      opacity: 0.3;
    }

    .badge-plus {
      font-size: 9px;
      background: var(--accent);
      color: white;
      padding: 1px 5px;
      border-radius: 8px;
      font-weight: 700;
      font-family: var(--font-display);
      vertical-align: middle;
    }

    /* ===================== HD TOGGLE ===================== */

    /* ===================== SETTINGS VIEW ===================== */
    #view-settings {
      overflow-y: auto;
    }

    #view-edit-char {
      overflow-y: auto;
    }

    #view-profile,
    #view-scenario-detail {
      overflow-y: auto;
    }

    #view-ai-rules {
      overflow-y: auto;
    }

    #view-cloud-sync {
      overflow-y: auto;
    }

    .settings-content {
      padding: 0;
      max-width: 750px;
      margin: 0 auto;
      width: 100%;
      padding-bottom: 40px;
    }

    .subpage-view .settings-content {
      padding-top: 18px;
    }

    .model-settings-picker-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 12px;
      margin-bottom: 16px;
    }

    .model-settings-picker-card {
      padding: 16px 18px;
      border: 1.5px solid var(--border);
      border-radius: 12px;
      background: var(--bg-card);
    }

    .model-settings-picker-label {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 11px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--text-dim);
      margin-bottom: 8px;
    }

    .model-settings-picker-label .material-symbols-outlined {
      font-size: 16px;
      color: var(--accent);
    }

    .model-settings-picker-card .settings-select {
      margin-top: 0;
    }

    @media (max-width: 700px) {
      .model-settings-picker-grid {
        grid-template-columns: 1fr;
      }
    }

    .settings-view-header {
      display: flex;
      align-items: center;
      gap: 14px;
      padding: 20px 24px 0;
      margin-bottom: 4px;
    }

    .settings-view-header h2 {
      font-family: var(--font-display);
      font-size: 16px;
      font-weight: 700;
    }

    .settings-back-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 20px 24px 0;
      color: var(--text-secondary);
      cursor: pointer;
      font-size: 13px;
      font-weight: 600;
      transition: color var(--transition);
      margin-bottom: 8px;
    }

    .settings-back-btn:hover {
      color: var(--text-primary);
    }

    .settings-section {
      border-bottom: 1px solid var(--border);
      padding: 24px 24px;
    }

    .settings-section-label {
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--text-dim);
      margin-bottom: 12px;
    }

    .settings-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 0;
      border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    }

    .settings-row:last-child {
      border-bottom: none;
    }

    .settings-row-label {
      font-size: 14px;
      font-weight: 600;
    }

    .settings-row-sub {
      font-size: 11px;
      color: var(--text-dim);
      margin-top: 2px;
    }

    .settings-nav-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 13px 0;
      border-bottom: 1px solid rgba(255, 255, 255, 0.04);
      cursor: pointer;
      transition: color var(--transition);
    }

    .settings-nav-row:hover {
      color: var(--text-primary);
    }

    .settings-nav-row:last-child {
      border-bottom: none;
    }

    .settings-nav-label {
      font-size: 14px;
      font-weight: 600;
    }

    .settings-nav-arrow {
      color: var(--text-dim);
      font-size: 18px;
    }

    .profile-avatar-wrap {
      position: relative;
      width: 72px;
      height: 72px;
      flex-shrink: 0;
    }

    .profile-avatar-display {
      width: 72px;
      height: 72px;
      border-radius: 50%;
      background: var(--accent);
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 700;
      font-size: 24px;
      color: white;
      border: 2px solid var(--border-light);
    }

    .profile-avatar-display img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .profile-avatar-edit-btn {
      position: absolute;
      bottom: 0;
      right: 0;
      width: 22px;
      height: 22px;
      border-radius: 50%;
      background: var(--accent);
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 2px solid var(--bg-panel);
      cursor: pointer;
    }

    .profile-avatar-edit-btn:hover {
      background: #d0561a;
    }

    /* ===================== NOTIFICATION ===================== */
    /* ===================== NOTIFICATION ===================== */
    .toast {
      position: fixed;
      bottom: 24px;
      left: 50%;
      transform: translateX(-50%);
      background: var(--bg-panel);
      border: 1px solid var(--accent);
      border-radius: var(--radius-lg);
      padding: 10px 20px;
      font-size: 13px;
      color: var(--text-primary);
      z-index: 9999;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.2s;
    }

    .toast.show {
      opacity: 1;
    }

    /* ===================== COMPRESS PROGRESS BAR ===================== */
    #compressProgress {
      position: fixed;
      bottom: 24px;
      left: 50%;
      transform: translateX(-50%);
      background: var(--bg-panel);
      border: 1px solid var(--accent);
      border-radius: var(--radius-lg);
      padding: 12px 20px 10px;
      min-width: 260px;
      z-index: 10000;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.2s;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    #compressProgress.show {
      opacity: 1;
    }

    #compressProgressLabel {
      font-size: 12px;
      font-weight: 600;
      color: var(--text-primary);
      display: flex;
      align-items: center;
      gap: 8px;
    }

    #compressProgressLabel .cp-spinner {
      width: 12px;
      height: 12px;
      border: 2px solid rgba(232, 98, 26, 0.3);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: cpSpin 0.7s linear infinite;
      flex-shrink: 0;
    }

    #compressProgressLabel .cp-tick {
      width: 12px;
      height: 12px;
      color: #4caf50;
      font-size: 13px;
      line-height: 1;
      flex-shrink: 0;
    }

    .cp-track {
      height: 4px;
      background: var(--bg-input);
      border-radius: 2px;
      overflow: hidden;
    }

    #compressProgressBar {
      height: 100%;
      width: 0%;
      background: var(--accent);
      border-radius: 2px;
      transition: width 0.4s ease;
    }

    #compressProgressSub {
      font-size: 10px;
      color: var(--text-dim);
      letter-spacing: 0.2px;
    }

    @keyframes cpSpin {
      to {
        transform: rotate(360deg);
      }
    }

    @keyframes typingDot {

      0%,
      60%,
      100% {
        opacity: 0.2;
        transform: scale(0.8);
      }

      30% {
        opacity: 1;
        transform: scale(1.2);
      }
    }

    /* ===================== MOBILE OPTIMIZATIONS ===================== */
    @media (max-width: 768px) {

      html,
      body {
        font-size: 14px !important;
        overflow: hidden;
      }

      #sidebar {
        display: none !important;
      }

      #main {
        flex: 1;
        width: 100vw;
        padding-bottom: 64px;
      }

      #view-chat.active {
        display: flex !important;
        flex-direction: column !important;
      }

      #view-chat:not(.active) {
        display: none !important;
      }

      #topbar {
        display: none !important;
      }

      /* Mobile logo topbar */
      #mobileLogoBar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 54px;
        padding: 0 10px;
        background: var(--bg-panel);
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 50;
      }

      #mobileLogoBarBtn {
        width: 38px;
        height: 38px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: var(--text-dim);
        border-radius: 50%;
        flex-shrink: 0;
        cursor: pointer;
      }

      #mobileLogoBarBtn:active {
        background: var(--bg-hover);
      }

      #mobileLogoBarCenter {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        align-items: center;
        gap: 8px;
        pointer-events: none;
      }

      #mobileLogoImg {
        width: 32px;
        height: 32px;
        object-fit: contain;
        mix-blend-mode: lighten;
        filter: drop-shadow(0 0 5px rgba(232, 98, 26, 0.6));
      }

      #mobileLogoText {
        font-family: var(--font-display);
        font-size: 18px;
        font-weight: 700;
        color: var(--text-primary);
        white-space: nowrap;
      }

      #mobileLogoText span {
        color: var(--accent);
      }

      #mobileLogoBarSpacer {
        width: 38px;
        flex-shrink: 0;
      }

      /* chat-topbar: let JS control display */
      #chat-topbar {
        align-items: center;
        height: 56px !important;
        padding: 0 12px !important;
        gap: 10px !important;
        background: var(--bg-panel) !important;
        border-bottom: 1px solid var(--border) !important;
        position: sticky;
        top: 0;
        z-index: 50;
        flex-shrink: 0;
        overflow: visible !important;
      }

      #chat-topbar>button:first-child {
        flex-shrink: 0;
        width: 36px !important;
        height: 36px !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary) !important;
        background: none;
        border: none;
        padding: 0 !important;
        margin-right: 0 !important;
      }

      .chat-topbar-scenario-img {
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important;
        flex-shrink: 0;
      }

      .chat-topbar-info {
        flex: 1;
        min-width: 0;
        overflow: hidden;
      }

      .chat-topbar-name {
        font-size: 15px !important;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .chat-topbar-sub {
        font-size: 11px !important;
      }

      .chat-topbar-actions {
        display: flex !important;
        gap: 2px !important;
        align-items: center;
        flex-shrink: 0;
        margin-left: auto;
        overflow: visible !important;
      }

      .chat-topbar-icon-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        border-radius: 50% !important;
        flex-shrink: 0;
      }

      .chat-topbar-icon-btn .material-symbols-outlined {
        font-size: 20px !important;
      }

      .persona-picker-btn {
        display: none !important;
      }

      .chat-messages {
        padding: 12px 4px !important;
        flex: 1;
        overflow-y: auto !important;
        min-height: 0;
      }

      #mobileBottomNav {
        display: flex !important;
      }
    }

    #mobileBottomNav {
      display: none;
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      height: 64px;
      background: var(--bg-panel);
      border-top: 1px solid var(--border);
      z-index: 200;
      align-items: stretch;
      justify-content: space-around;
      padding: 0 4px;
      padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mob-tab {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 3px;
      background: none;
      border: none;
      color: var(--text-dim);
      font-size: 10px;
      font-family: var(--font-body);
      font-weight: 500;
      padding: 6px 4px 4px;
      cursor: pointer;
      transition: color 0.15s ease;
      -webkit-tap-highlight-color: transparent;
    }

    .mob-tab svg {
      transition: transform 0.15s ease;
    }

    .mob-tab:active svg {
      transform: scale(0.88);
    }

    .mob-tab.active {
      color: var(--accent);
    }

    .mob-tab.active svg {
      stroke: var(--accent);
    }

    .mob-tab span {
      line-height: 1;
      letter-spacing: 0.1px;
    }

    .mob-tab-create {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      background: var(--accent);
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 14px rgba(232, 98, 26, 0.45);
      margin-bottom: 2px;
    }

    .mob-tab-create svg {
      stroke: #fff;
    }

    .mob-tab[data-view="create-hub"] {
      padding-top: 4px;
    }


    /* ===== MOBILE LORE CARD READABILITY PATCH ===== */
    @media (max-width: 768px) {

      .story-card,
      .story-card[style*="row"],
      .story-card[style*="column"] {
        flex-direction: column !important;
        gap: 10px !important;
        padding: 10px !important;
      }

      .story-card-image {
        width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
        border-radius: 8px !important;
      }

      .story-card-content {
        width: 100% !important;
        padding-top: 0 !important;
        gap: 8px !important;
      }

      .story-card-header {
        gap: 6px !important;
        margin-top: 0 !important;
      }

      .story-card-name {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        line-height: 1.25 !important;
        font-size: 14px !important;
      }

      .story-card-type {
        margin-bottom: 0 !important;
      }
    }


    /* ===== MOBILE CHAT BUBBLE PATCH ===== */
    @media (max-width: 768px) {

      /* ── 1. Avatar at TOP of bubble, not bottom ── */
      .chat-msg {
        gap: 8px !important;
        padding: 4px 12px !important;
        align-items: flex-start !important;
      }

      .msg-avatar {
        width: 34px !important;
        height: 34px !important;
        border-radius: 50% !important;
        flex-shrink: 0;
        margin-top: 2px;
      }

      /* ── 2. Bubble body width ── */
      .msg-body {
        max-width: 80% !important;
        flex: none !important;
        min-width: 0;
      }

      .user-msg .msg-body {
        align-items: flex-end !important;
        margin-left: auto !important;
        margin-right: 0 !important;
      }

      .chat-msg:not(.user-msg) .msg-body {
        margin-right: auto !important;
        margin-left: 0 !important;
      }

      .msg-name {
        font-size: 10px !important;
        margin-bottom: 2px !important;
      }

      .bot-bubble, .user-bubble {
        padding: 12px 14px !important;
        line-height: 1.55 !important;
        font-size: 14px !important;
      }

      .response-menu {
        position: absolute !important;
        bottom: 0 !important;
        flex-direction: column !important;
        margin-bottom: 0 !important;
        background: none !important;
        backdrop-filter: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        gap: 4px !important;
      }

      .bot-bubble .response-menu {
        right: -32px !important;
        left: auto !important;
      }

      .user-bubble .response-menu {
        left: -32px !important;
        right: auto !important;
      }

      .hover-btn {
        width: 30px !important;
        height: 30px !important;
        background: rgba(255, 255, 255, 0.07) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        flex-shrink: 0;
      }

      /* ── 4. Input bar pill style ── */
      .chat-input-area {
        padding: 8px 12px 10px !important;
        background: transparent !important;
        border-top: none !important;
        flex-shrink: 0 !important;
        min-height: 60px;
        margin-bottom: 64px !important;
      }

      #view-personas .chat-input-area,
      #view-home .chat-input-area,
      #view-create .chat-input-area,
      #view-scenarios .chat-input-area,
      #view-create-hub .chat-input-area,
      #view-profile .chat-input-area,
      #view-browse .chat-input-area {
        display: none !important;
      }

      .chat-input-row {
        background: rgba(255, 255, 255, 0.06) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        border-radius: 28px !important;
        padding: 6px 6px 6px 16px !important;
        gap: 6px !important;
        align-items: center !important;
      }

      #chatInput {
        background: transparent !important;
        border: none !important;
        border-radius: 0 !important;
        padding: 8px 0 !important;
        font-size: 14px !important;
        min-height: 36px !important;
        box-shadow: none !important;
      }

      #chatInput:focus {
        box-shadow: none !important;
      }

      .chat-send-btn {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        border-radius: 50% !important;
        flex-shrink: 0;
      }

      .chat-input-footer {
        font-size: 10px !important;
        text-align: center !important;
        margin-top: 6px !important;
        color: var(--text-dim) !important;
        padding: 0 !important;
      }

      /* ── 5. Featured banner: mobile card stack ── */
      .featured-banner {
        height: 420px !important;
      }

      .featured-banner-content {
        padding: 0 18px 24px !important;
      }

      .featured-banner-eyebrow {
        font-size: 10px !important;
        margin-bottom: 6px !important;
      }

      .featured-banner-title {
        font-size: 20px !important;
        letter-spacing: 1px !important;
        margin-bottom: 6px !important;
      }

      .featured-banner-desc {
        font-size: 12px !important;
        margin-bottom: 12px !important;
        max-width: 100% !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
      }

      .featured-banner-actions { gap: 8px !important; }

      .featured-btn-start, .featured-btn-details {
        font-size: 12px !important;
        padding: 9px 14px !important;
      }

      .featured-nav-btn { display: none !important; }

      /* ── Home ── */
      .home-content {
        padding: 12px 14px !important;
      }

      .featured-header {
        margin-bottom: 12px !important;
      }

      /* ── Scenarios grid ── */
      .scenario-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
      }

      .scenarios-content {
        padding: 12px 14px !important;
      }

      .scenarios-content .section-header {
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 12px 0 8px !important;
      }

      .scenarios-content .section-header>div {
        flex-wrap: wrap !important;
        gap: 6px !important;
      }

      /* ── Create hub cards ── */
      .create-hub-content {
        padding: 16px 14px !important;
        gap: 12px !important;
      }

      .create-hub-title {
        font-size: 17px !important;
        margin-bottom: 4px !important;
      }

      .create-hub-card {
        height: 130px !important;
        border-radius: 12px !important;
      }

      .create-hub-card-label {
        font-size: 20px !important;
        bottom: 14px !important;
        left: 16px !important;
      }

      .create-hub-card-tag {
        font-size: 11px !important;
        top: 12px !important;
        right: 14px !important;
      }
    }


    /* ===== SETTINGS POLISH CLEANUP ===== */
    .model-settings-current-card {
      padding: 16px 18px;
      border: 1px solid var(--border);
      border-radius: 16px;
      background: linear-gradient(135deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015));
      margin-bottom: 18px;
    }

    .model-settings-picker-grid {
      gap: 18px;
      margin-bottom: 18px;
    }

    .model-settings-picker-card {
      border-radius: 16px;
    }

    #view-model-settings .settings-section {
      border-radius: 16px;
      border-bottom: none !important;
      padding: 28px 24px !important;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }

    #view-model-settings .settings-section:last-of-type {
      border-bottom: none !important;
    }

    #view-settings .settings-section {
      border-radius: 14px;
    }

    #sceneImageGenerationSection textarea {
      min-height: 112px !important;
    }

    @media (max-width: 720px) {
      .model-settings-picker-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
      }

      .model-settings-current-card {
        margin: 0 0 14px;
        padding: 14px;
      }

      #view-settings .settings-section,
      #view-model-settings .settings-section {
        margin-left: 0;
        margin-right: 0;
      }
    }



    /* ===================== POLISHED SETTINGS SUBPAGES ===================== */
    .provider-banner-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 12px;
      margin-bottom: 14px;
    }

    .provider-banner {
      position: relative;
      min-height: 110px;
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.08);
      overflow: hidden;
      padding: 0;
      display: flex;
      align-items: stretch;
      justify-content: stretch;
      cursor: pointer;
      background: var(--bg-card);
      color: var(--text-primary);
      transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease, filter .22s ease;
      isolation: isolate;
    }

    .provider-banner::before {
      content: "";
      position: absolute;
      inset: 0;
      opacity: .94;
      transition: opacity .22s ease, transform .45s ease, filter .22s ease;
      z-index: 0;
    }

    .provider-banner::after {
      content: "";
      position: absolute;
      inset: 0;
      z-index: 1;
      background:
        linear-gradient(to top, rgba(0, 0, 0, .84) 0%, rgba(0, 0, 0, .44) 48%, rgba(0, 0, 0, .18) 100%),
        radial-gradient(circle at 50% 100%, rgba(232, 98, 26, .18), transparent 42%);
      transition: opacity .22s ease;
    }

    .provider-banner:hover {
      transform: translateY(-2px) scale(1.01);
      border-color: rgba(232, 98, 26, .55);
      box-shadow: 0 14px 34px rgba(0, 0, 0, .42), 0 0 26px rgba(232, 98, 26, .12);
    }

    .provider-banner:hover::before {
      transform: scale(1.055);
      opacity: 1;
      filter: saturate(1.12) brightness(1.06);
    }

    .provider-banner:active {
      transform: translateY(0) scale(.985);
    }

    .provider-banner.active {
      border-color: var(--accent);
      box-shadow: 0 0 0 1px rgba(232, 98, 26, .44), 0 14px 34px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, .08);
    }

    .provider-banner.active::after {
      background:
        linear-gradient(to top, rgba(0, 0, 0, .78) 0%, rgba(0, 0, 0, .38) 48%, rgba(0, 0, 0, .12) 100%),
        radial-gradient(circle at 50% 100%, rgba(232, 98, 26, .32), transparent 46%);
    }

    .provider-banner-title {
      position: relative;
      z-index: 2;
      width: 100%;
      align-self: flex-end;
      padding: 0 18px 16px;
      text-align: left;
      font-size: 22px;
      font-weight: 900;
      letter-spacing: .3px;
      color: #fff;
      text-shadow: 0 2px 14px rgba(0, 0, 0, .85);
    }

    .provider-banner-sub {
      display: none !important;
    }


    .provider-banner.deepseek::before {
      background: radial-gradient(circle at 76% 20%, rgba(46, 189, 217, .8), transparent 32%), radial-gradient(circle at 18% 80%, rgba(20, 75, 112, .55), transparent 36%), linear-gradient(135deg, #06151e, #142735 48%, #07090b);
    }

    .provider-banner.xai::before {
      background: radial-gradient(circle at 74% 18%, rgba(255, 255, 255, .38), transparent 30%), radial-gradient(circle at 20% 72%, rgba(110, 110, 110, .45), transparent 38%), linear-gradient(135deg, #060606, #232323 48%, #030303);
    }

    .provider-banner.nanogpt::before {
      background: radial-gradient(circle at 20% 20%, rgba(0, 200, 120, .75), transparent 35%), radial-gradient(circle at 80% 80%, rgba(0, 120, 200, .45), transparent 38%), linear-gradient(135deg, #041a0e, #062818 48%, #050f0a);
    }

    .settings-card-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }

    .settings-action-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 14px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      min-height: 112px;
    }

    .settings-action-card-title {
      font-size: 14px;
      font-weight: 800;
      color: var(--text-primary);
    }

    .settings-action-card-sub {
      font-size: 12px;
      line-height: 1.45;
      color: var(--text-dim);
      flex: 1;
    }

    .settings-action-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-top: 2px;
    }

    .api-key-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 14px;
    }

    .api-key-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 14px;
    }

    .api-key-card-title {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 13px;
      font-weight: 800;
      color: var(--text-primary);
      margin-bottom: 8px;
    }

    .api-key-card-sub {
      font-size: 11px;
      color: var(--text-dim);
      margin-top: 6px;
      line-height: 1.45;
    }

    @media (max-width: 700px) {

      .provider-banner-grid,
      .settings-card-grid {
        grid-template-columns: 1fr;
      }

      .provider-banner {
        min-height: 92px;
      }

      .provider-banner-title {
        font-size: 20px;
        padding: 0 16px 14px;
      }
    }



    /* ===================== SETTINGS SPACING POLISH PATCH ===================== */
    #settings-panel .subpage-view .settings-content {
      padding: 0 20px 42px !important;
      max-width: none;
    }

    #settings-panel .subpage-view .settings-back-btn {
      margin: 0 -20px 18px !important;
      padding: 16px 20px !important;
      border-bottom: 1px solid rgba(255, 255, 255, 0.075) !important;
      color: var(--text-secondary);
      background: rgba(255, 255, 255, 0.01);
    }

    #settings-panel .subpage-view .settings-view-header {
      padding: 4px 0 18px !important;
      margin: 0 0 16px !important;
      border-bottom: 0 !important;
    }

    #settings-panel .subpage-view .settings-view-header h2 {
      margin: 0 !important;
      line-height: 1.15;
    }

    #settings-panel .subpage-view .settings-section {
      padding: 18px 0 !important;
      border-bottom: 1px solid rgba(255, 255, 255, 0.07) !important;
    }

    #settings-panel .subpage-view .settings-section:first-of-type {
      padding-top: 4px !important;
    }

    #settings-panel .subpage-view .settings-card-grid,
    #settings-panel .subpage-view .api-key-grid {
      gap: 14px !important;
    }

    @media (max-width: 720px) {
      #settings-panel .subpage-view .settings-content {
        padding-left: 18px !important;
        padding-right: 18px !important;
      }

      #settings-panel .subpage-view .settings-back-btn {
        margin-left: -18px !important;
        margin-right: -18px !important;
        padding-left: 18px !important;
        padding-right: 18px !important;
      }
    }



    /* ===================== IN-SITE CONFIRM / PROMPT MODAL ===================== */
    .app-dialog-backdrop {
      position: fixed;
      inset: 0;
      z-index: 5000;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(0, 0, 0, 0.62);
      backdrop-filter: blur(8px);
      padding: 18px;
    }

    .app-dialog-backdrop.open {
      display: flex;
    }

    .app-dialog {
      width: min(420px, 100%);
      background: var(--bg-panel);
      border: 1px solid var(--border-light);
      border-radius: 16px;
      box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
      overflow: hidden;
    }

    .app-dialog-head {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 16px 18px 10px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .app-dialog-icon {
      width: 30px;
      height: 30px;
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(232, 98, 26, 0.14);
      color: var(--accent);
      flex-shrink: 0;
    }

    .app-dialog-title {
      font-size: 15px;
      font-weight: 800;
      color: var(--text-primary);
    }

    .app-dialog-body {
      padding: 14px 18px 4px;
      color: var(--text-secondary);
      font-size: 13px;
      line-height: 1.55;
      white-space: pre-wrap;
    }

    .app-dialog-input {
      width: calc(100% - 36px);
      margin: 8px 18px 0;
      display: none;
    }

    .app-dialog-input.open {
      display: block;
    }

    .app-dialog-actions {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      padding: 18px;
    }

    .app-dialog .btn-secondary,
    .app-dialog .btn-danger,
    .app-dialog .btn-primary {
      min-width: 88px;
      justify-content: center;
    }

    .image-cleanup-status {
      margin-top: 8px;
      font-size: 11px;
      line-height: 1.45;
      color: var(--text-dim);
    }

/* ── Block 2 ──────────────────────────────────────────────── */
    /* ===================== SETTINGS SIDEBAR ALIGNMENT PATCH ===================== */
    #settings-panel {
      --settings-x-pad: 24px;
      --settings-row-h: 58px;
      --settings-soft-line: rgba(255, 255, 255, 0.075);
    }

    #settings-panel .settings-header {
      min-height: 72px !important;
      padding: 0 var(--settings-x-pad) !important;
      display: flex !important;
      align-items: center !important;
      justify-content: space-between !important;
      border-bottom: 1px solid var(--settings-soft-line) !important;
    }

    #settings-panel .settings-header h2 {
      margin: 0 !important;
      line-height: 1 !important;
      font-size: 22px !important;
      letter-spacing: -0.02em;
    }

    #settings-panel .settings-close {
      width: 40px !important;
      height: 40px !important;
      display: flex !important;
      align-items: center !important;
      justify-content: center !important;
      flex: 0 0 40px !important;
    }

    #settings-panel .settings-body {
      padding: 0 0 44px !important;
    }

    #settings-panel .settings-section {
      padding: 18px var(--settings-x-pad) !important;
      border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
    }

    #settings-panel .settings-section-label {
      margin: 0 0 14px !important;
      line-height: 1.15 !important;
    }

    #settings-panel .settings-row,
    #settings-panel .settings-nav-row,
    #settings-panel .color-row {
      min-height: 48px !important;
      padding-top: 10px !important;
      padding-bottom: 10px !important;
      display: flex !important;
      align-items: center !important;
    }

    #settings-panel .settings-row>div:first-child,
    #settings-panel .settings-nav-row>div:first-child {
      min-width: 0;
    }

    #settings-panel .settings-row-label,
    #settings-panel .settings-nav-label,
    #settings-panel .color-row-label {
      line-height: 1.2 !important;
    }

    #settings-panel .settings-row-sub {
      line-height: 1.35 !important;
      margin-top: 4px !important;
    }

    #settings-panel .settings-select,
    #settings-panel .segment-control,
    #settings-panel .model-banner {
      margin-top: 10px !important;
    }

    #settings-panel .subpage-view .settings-content {
      padding: 0 var(--settings-x-pad) 46px !important;
      max-width: none !important;
    }

    #settings-panel .subpage-view .settings-back-btn {
      height: var(--settings-row-h) !important;
      min-height: var(--settings-row-h) !important;
      margin: 0 calc(var(--settings-x-pad) * -1) !important;
      padding: 0 var(--settings-x-pad) !important;
      display: flex !important;
      align-items: center !important;
      gap: 12px !important;
      border-top: 0 !important;
      border-bottom: 1px solid var(--settings-soft-line) !important;
      background: rgba(255, 255, 255, 0.012) !important;
      color: var(--text-secondary) !important;
      line-height: 1 !important;
    }

    #settings-panel .subpage-view .settings-back-btn svg,
    #settings-panel .subpage-view .settings-back-btn .material-symbols-outlined {
      flex: 0 0 auto !important;
      display: block !important;
    }

    #settings-panel .subpage-view .settings-view-header {
      min-height: 68px !important;
      margin: 0 !important;
      padding: 0 !important;
      display: flex !important;
      align-items: center !important;
      gap: 14px !important;
      border-bottom: 0 !important;
    }

    #settings-panel .subpage-view .settings-view-header h2 {
      margin: 0 !important;
      line-height: 1.05 !important;
      font-size: 22px !important;
      letter-spacing: -0.025em;
    }

    #settings-panel .subpage-view .settings-view-header .material-symbols-outlined,
    #settings-panel .subpage-view .settings-view-header svg {
      flex: 0 0 auto !important;
      color: var(--accent) !important;
    }

    #settings-panel .subpage-view .settings-section:first-of-type {
      padding-top: 10px !important;
    }

    #settings-panel .subpage-view .settings-section {
      padding-left: 0 !important;
      padding-right: 0 !important;
    }

    #settings-panel .settings-nav-row:hover,
    #settings-panel .settings-back-btn:hover {
      background: rgba(255, 255, 255, 0.025) !important;
    }

    @media (max-width: 720px) {
      #settings-panel {
        --settings-x-pad: 20px;
        --settings-row-h: 56px;
      }

      #settings-panel .settings-header {
        min-height: 68px !important;
      }

      #settings-panel .settings-header h2,
      #settings-panel .subpage-view .settings-view-header h2 {
        font-size: 21px !important;
      }
    }

    /* === SETTINGS SUBPAGE ALIGNMENT MICRO-PATCH === */
    #settingsPanel .settings-subpage-back,
    #settingsPanel .settings-back-row,
    #settingsPanel .settings-back-btn,
    .settings-subpage-back,
    .settings-back-row,
    .settings-back-btn {
      min-height: 56px !important;
      height: 56px !important;
      padding-top: 0 !important;
      padding-bottom: 4px !important;
      /* optical lift: sits slightly higher between dividers */
      display: flex !important;
      align-items: center !important;
      box-sizing: border-box !important;
    }

    #settingsPanel .settings-subpage-back>*,
    #settingsPanel .settings-back-row>*,
    #settingsPanel .settings-back-btn>*,
    .settings-subpage-back>*,
    .settings-back-row>*,
    .settings-back-btn>* {
      transform: translateY(-2px);
    }

    /* Fallback for inline-created Back to Settings rows */
    #settingsPanel [onclick*="Settings"][class*="back"],
    .settings-panel [onclick*="Settings"][class*="back"] {
      padding-top: 0 !important;
      padding-bottom: 4px !important;
      align-items: center !important;
    }


    /* ===================== MOBILE POLISH PATCH V2 - SAFE SIDEBAR =====================
     CSS-only responsive layer. Keeps the existing sidebar/nav behaviour intact.
     No provider, memory, import/export, image-generation, or scenario logic touched.
  ================================================================================ */
    @media (max-width: 860px) {
      :root {
        --topbar-h: 48px;
        --mobile-gutter: 14px;
        --sidebar-w: 56px;
      }

      html,
      body {
        width: 100%;
        min-width: 0;
        overflow: hidden;
        overscroll-behavior: none;
        -webkit-text-size-adjust: 100%;
      }

      #app {
        display: flex !important;
        flex-direction: row !important;
        width: 100vw !important;
        height: 100dvh !important;
        min-height: 100dvh !important;
        overflow: hidden !important;
      }

      #sidebar,
      #sidebar.collapsed {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        bottom: auto !important;
        left: auto !important;
        width: 56px !important;
        min-width: 56px !important;
        max-width: 56px !important;
        height: 100dvh !important;
        padding: 0 !important;
        flex: 0 0 56px !important;
        flex-direction: column !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        border-right: 1px solid rgba(255, 255, 255, 0.08) !important;
        border-top: 0 !important;
        background: var(--bg-panel) !important;
        z-index: 20 !important;
      }

      #sidebar .sidebar-logo,
      #sidebar.collapsed .sidebar-logo {
        height: 52px !important;
        padding: 0 !important;
        justify-content: center !important;
        flex: 0 0 52px !important;
      }

      #sidebar .sidebar-logo img {
        width: 38px !important;
        height: 38px !important;
        margin: 0 !important;
      }

      #sidebar .sidebar-logo-text,
      #sidebar .sidebar-collapse-btn,
      #sidebar .sidebar-section-label,
      #sidebar .chat-history-list,
      #sidebar .music-player,
      #sidebar .user-info,
      #sidebar .nav-label,
      #sidebar.collapsed .sidebar-logo-text,
      #sidebar.collapsed .sidebar-collapse-btn,
      #sidebar.collapsed .sidebar-section-label,
      #sidebar.collapsed .chat-history-list,
      #sidebar.collapsed .music-player,
      #sidebar.collapsed .user-info,
      #sidebar.collapsed .nav-label {
        display: none !important;
      }

      #sidebar .sidebar-nav,
      #sidebar.collapsed .sidebar-nav {
        width: 100% !important;
        padding: 8px 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
        align-items: stretch !important;
        overflow: visible !important;
        flex-shrink: 0 !important;
      }

      #sidebar .nav-item,
      #sidebar.collapsed .nav-item {
        width: 100% !important;
        height: 48px !important;
        min-height: 48px !important;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 0 !important;
        border-right: 3px solid transparent !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
        color: var(--text-secondary) !important;
        overflow: visible !important;
      }

      #sidebar .nav-item.active,
      #sidebar.collapsed .nav-item.active {
        border-right-color: var(--accent) !important;
        background: linear-gradient(90deg, rgba(232, 98, 26, 0.12), rgba(232, 98, 26, 0.04)) !important;
        color: var(--accent) !important;
      }

      #sidebar .nav-item svg,
      #sidebar .nav-item .material-symbols-outlined {
        width: 22px !important;
        height: 22px !important;
        font-size: 22px !important;
        flex: 0 0 auto !important;
      }

      #sidebar .sidebar-user-area,
      #sidebar.collapsed .sidebar-user-area {
        margin-top: auto !important;
        padding: 10px 0 12px !important;
        border-top: 1px solid var(--border) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
      }

      #sidebar .user-avatar,
      #sidebar.collapsed .user-avatar {
        width: 36px !important;
        height: 36px !important;
        font-size: 13px !important;
      }

      #main {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        width: auto !important;
        height: 100dvh !important;
        padding-bottom: 0 !important;
        overflow: hidden !important;
      }

      #topbar {
        height: 48px !important;
        padding: 0 10px !important;
        gap: 8px !important;
      }

      .topbar-search {
        max-width: none !important;
        min-width: 0 !important;
      }

      .topbar-search input {
        height: 34px !important;
        font-size: 13px !important;
        border-radius: 16px !important;
        padding-right: 10px !important;
      }

      .topbar-actions {
        gap: 4px !important;
        flex-shrink: 0 !important;
      }

      .topbar-btn,
      .chat-topbar-btn,
      .chat-topbar-icon-btn {
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
      }

      .topbar-avatar {
        width: 32px !important;
        height: 32px !important;
      }

      .view.active {
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
      }

      #view-home,
      #view-scenarios,
      #view-create,
      #view-create-hub,
      #view-personas,
      #view-personas-hub,
      #view-characters-original,
      #view-scenario-detail,
      #view-settings,
      #view-edit-char,
      #view-ai-rules,
      #view-import-export,
      #view-model-settings,
      #view-continuity,
      #view-memory,
      #view-lore-hub {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
      }

      .home-content,
      .scenarios-content,
      .personas-content,
      .characters-content,
      .creator-content,
      .create-hub-content,
      .scenario-detail-content,
      .settings-content,
      .memory-content,
      .lore-hub-content,
      .continuity-content {
        width: 100% !important;
        max-width: none !important;
        padding-left: var(--mobile-gutter) !important;
        padding-right: var(--mobile-gutter) !important;
        padding-top: 16px !important;
        padding-bottom: 120px !important;
      }

      .section-header,
      .personas-header,
      .scenarios-content .section-header {
        gap: 12px !important;
        align-items: center !important;
        margin-bottom: 14px !important;
      }

      .section-header h3,
      .scenarios-content .section-header h3,
      .featured-header h2,
      .personas-header h2 {
        font-size: 16px !important;
        line-height: 1.2 !important;
      }

      .featured-banner {
        height: 380px !important;
      }

      .featured-banner-content {
        padding: 0 32px 36px !important;
      }

      .featured-banner-title {
        font-size: clamp(26px, 5vw, 42px) !important;
        letter-spacing: 2px !important;
        margin-bottom: 10px !important;
      }

      .featured-banner-desc {
        font-size: 13px !important;
        margin-bottom: 18px !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 3 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
      }

      .scenario-detail-hero {
        height: 360px !important;
      }

      .scenario-detail-header {
        padding: 0 20px 28px !important;
      }

      .scenario-detail-title {
        font-size: 24px !important;
      }

      .scenario-detail-desc {
        font-size: 12px !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 3 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
      }

      .scenario-detail-body {
        padding: 20px 0 !important;
      }

      .featured-btn-start, .featured-btn-details {
        font-size: 14px !important;
        padding: 11px 20px !important;
      }

      .featured-nav-btn {
        opacity: 1 !important;
        width: 32px !important;
        height: 32px !important;
        background: rgba(0, 0, 0, 0.52) !important;
      }

      .featured-dots {
        display: none !important;
      }

      .scenario-grid,
      #storyCharactersList,
      .story-card-section-grid,
      .persona-grid,
      .personas-grid,
      .characters-grid,
      .settings-grid,
      .model-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
      }

      .scenario-card {
        gap: 9px !important;
      }

      .scenario-card-img {
        border-radius: 12px !important;
      }

      .scenario-card-menu-btn {
        display: flex !important;
        width: 34px !important;
        height: 34px !important;
        background: rgba(0, 0, 0, 0.62) !important;
      }

      /* Creator Layout Stacking */
      .creator-main-row {
        flex-direction: column !important;
        gap: 16px !important;
      }

      .creator-left-col {
        width: 100% !important;
      }

      .creator-right-col {
        width: 100% !important;
      }

      .creator-bottom-actions {
        bottom: 64px !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
        background: var(--bg-panel) !important;
        border-top: 1px solid var(--border) !important;
        margin-left: calc(-1 * var(--mobile-gutter)) !important;
        margin-right: calc(-1 * var(--mobile-gutter)) !important;
        width: calc(100% + 2 * var(--mobile-gutter)) !important;
      }

      .personas-header {
        flex-wrap: wrap !important;
        gap: 10px !important;
      }

      .personas-header>div {
        flex-wrap: wrap !important;
        gap: 6px !important;
      }

      .char-modal-flex-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
      }

      .character-section-title-text {
        white-space: normal !important;
        line-height: 1.3 !important;
      }


      .scenario-card-title {
        font-size: 15px !important;
        -webkit-line-clamp: 2 !important;
      }

      .scenario-card-desc {
        font-size: 12px !important;
        -webkit-line-clamp: 2 !important;
      }

      .create-hub-content {
        gap: 14px !important;
      }

      .create-hub-title {
        font-size: 20px !important;
        margin-bottom: 2px !important;
      }

      .create-hub-card {
        height: 150px !important;
        border-radius: 15px !important;
      }

      .create-hub-card-label {
        left: 16px !important;
        bottom: 14px !important;
        font-size: 21px !important;
      }

      .create-hub-card-tag {
        top: 12px !important;
        right: 14px !important;
        font-size: 11px !important;
      }

      #chat-topbar {
        height: 48px !important;
        padding: 0 8px !important;
        gap: 8px !important;
      }

      .chat-topbar-scenario-img {
        width: 34px !important;
        height: 34px !important;
      }

      .chat-topbar-info {
        min-width: 0 !important;
      }

      .chat-topbar-name {
        font-size: 12px !important;
      }

      .chat-topbar-sub,
      .chat-topbar-badge {
        display: none !important;
      }

      .chat-topbar-actions {
        gap: 2px !important;
        max-width: 54vw !important;
        overflow-x: auto !important;
        scrollbar-width: none !important;
      }

      .chat-topbar-actions::-webkit-scrollbar {
        display: none;
      }

      .persona-picker-btn {
        max-width: 104px !important;
        min-width: 0 !important;
        padding: 4px 8px 4px 5px !important;
      }

      .persona-picker-name {
        max-width: 58px !important;
      }

      #personaPickerMenu.open {
        left: 62px !important;
        right: 8px !important;
        width: auto !important;
        max-width: calc(100vw - 70px) !important;
        max-height: min(76vh, 520px) !important;
        flex-direction: column !important;
      }

      .picker-list-col,
      .picker-preview-col {
        width: 100% !important;
        max-width: none !important;
        border-right: 0 !important;
      }

      .picker-preview-col {
        max-height: 230px !important;
        border-top: 1px solid var(--border) !important;
      }

      .picker-preview-hero {
        height: 95px !important;
      }

      .memory-card {
        margin: 10px var(--mobile-gutter) !important;
        border-radius: 13px !important;
      }

      .memory-card-header {
        padding: 12px !important;
        gap: 10px !important;
        align-items: flex-start !important;
      }

      .memory-card-header-right {
        flex-wrap: wrap !important;
        justify-content: flex-end !important;
      }

      .story-card,
      .char-card {
        border-radius: 12px !important;
      }

      .story-card[style*="row"],
      .story-card {
        flex-direction: column !important;
        gap: 10px !important;
      }

      .story-card-image {
        width: 100% !important;
        height: auto !important;
        min-width: 0 !important;
        aspect-ratio: 16 / 9 !important;
      }

      .char-card {
        flex-direction: row !important;
      }

      .char-card-image {
        width: 96px !important;
        height: 118px !important;
      }

      .creator-bottom-actions,
      .personaModal-footer,
      .charModal-footer,
      .scModal-footer,
      .cropModal-footer,
      .memEditModal-footer {
        gap: 10px !important;
        flex-wrap: wrap !important;
      }

      .creator-bottom-actions .btn-primary,
      .creator-bottom-actions .btn-secondary,
      .personaModal-footer .btn-primary,
      .personaModal-footer .btn-secondary,
      .charModal-footer .btn-primary,
      .charModal-footer .btn-secondary,
      .charModal-footer .btn-danger,
      .scModal-footer .btn-primary,
      .scModal-footer .btn-secondary,
      .scModal-footer .btn-danger {
        min-height: 40px !important;
        justify-content: center !important;
        flex: 1 1 auto !important;
      }

      #personaModal,
      #charModal,
      #scModal,
      #memEditModal,
      #cropModal,
      #settingsPanel,
      .modal,
      .settings-panel {
        width: calc(100vw - 72px) !important;
        max-width: calc(100vw - 72px) !important;
        max-height: 92dvh !important;
        border-radius: 16px !important;
      }

      .personaModal-header,
      .charModal-header,
      .scModal-header,
      .memEditModal-header {
        padding: 18px !important;
      }

      .personaModal-body,
      .charModal-body,
      .scModal-body,
      .memEditModal-body {
        padding: 18px !important;
        gap: 16px !important;
      }

      .persona-avatar-upload {
        width: min(170px, 58vw) !important;
        height: min(170px, 58vw) !important;
      }

      input,
      textarea,
      select,
      button {
        font-size: 16px;
      }
    }

    @media (max-width: 480px) {
      :root {
        --mobile-gutter: 12px;
        --sidebar-w: 52px;
      }

      #sidebar,
      #sidebar.collapsed {
        width: 52px !important;
        min-width: 52px !important;
        max-width: 52px !important;
        flex-basis: 52px !important;
      }

      #sidebar .nav-item,
      #sidebar.collapsed .nav-item {
        height: 46px !important;
        min-height: 46px !important;
      }

      #sidebar .nav-item svg,
      #sidebar .nav-item .material-symbols-outlined {
        width: 21px !important;
        height: 21px !important;
        font-size: 21px !important;
      }

      .home-content,
      .scenarios-content,
      .personas-content,
      .creator-content,
      .create-hub-content,
      .settings-content,
      .memory-content,
      .lore-hub-content,
      .continuity-content {
        padding-left: 12px !important;
        padding-right: 12px !important;
      }

      .featured-banner {
        min-height: 196px !important;
        height: 58vw !important;
      }

      .featured-banner-title {
        font-size: clamp(20px, 7vw, 27px) !important;
      }

      .featured-banner-desc {
        -webkit-line-clamp: 2 !important;
        margin-bottom: 10px !important;
      }

      .create-hub-card {
        height: 132px !important;
      }

      .char-card-image {
        width: 84px !important;
        height: 108px !important;
      }

      #personaModal,
      #charModal,
      #scModal,
      #memEditModal,
      #cropModal,
      #settingsPanel,
      .modal,
      .settings-panel {
        width: calc(100vw - 64px) !important;
        max-width: calc(100vw - 64px) !important;
      }
    }

    /* Sampling Parameters Modal */
    #samplingParamsModal {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 9998;
      align-items: center;
      justify-content: center;
      pointer-events: auto;
    }

    #samplingParamsModal.active {
      display: flex;
    }

    #samplingParamsBackdrop {
      position: absolute;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      backdrop-filter: blur(4px);
      z-index: 0;
    }

    #samplingParamsContainer {
      position: relative;
      z-index: 10;
      width: 100%;
      max-width: 900px;
      height: 85vh;
      background: #09090b;
      border: 1px solid #27272a;
      border-radius: 16px;
      display: flex;
      flex-direction: column;
      box-shadow: 0 0 50px -12px rgba(0, 0, 0, 0.8);
      pointer-events: auto;
    }

    #samplingParamsHeader {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20px 32px;
      border-bottom: 1px solid #27272a;
      background: #09090b;
    }

    #samplingParamsContent {
      flex: 1;
      overflow-y: auto;
      padding: 32px;
    }

    #samplingParamsContent::-webkit-scrollbar {
      width: 8px;
    }

    #samplingParamsContent::-webkit-scrollbar-track {
      background: transparent;
    }

    #samplingParamsContent::-webkit-scrollbar-thumb {
      background: #27272a;
      border-radius: 4px;
    }

    #samplingParamsContent::-webkit-scrollbar-thumb:hover {
      background: #3f3f46;
    }

    #samplingParamsFooter {
      padding: 20px 32px;
      border-top: 1px solid #27272a;
      background: #09090b;
      display: flex;
      gap: 12px;
      justify-content: flex-end;
    }

    .sampling-modal-btn {
      padding: 10px 20px;
      border-radius: 8px;
      border: 1px solid #27272a;
      background: #18181b;
      color: #e4e4e7;
      font-size: 13px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;
    }

    .sampling-modal-btn:hover {
      background: #27272a;
      border-color: #3f3f46;
    }

    .sampling-modal-btn.primary {
      background: white;
      color: black;
      border-color: white;
    }

    .sampling-modal-btn.primary:hover {
      background: #e4e4e7;
      border-color: #e4e4e7;
    }

    /* Range slider styling */
    input[type="range"] {
      -webkit-appearance: none;
      appearance: none;
    }

    input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: white;
      cursor: pointer;
      box-shadow: 0 0 4px rgba(255, 255, 255, 0.3);
    }

    input[type="range"]::-moz-range-thumb {
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: white;
      cursor: pointer;
      border: none;
      box-shadow: 0 0 4px rgba(255, 255, 255, 0.3);
    }

    input[type="range"]::-webkit-slider-runnable-track {
      background: transparent;
      border: none;
    }

    input[type="range"]::-moz-range-track {
      background: transparent;
      border: none;
    }

    /* Global AI Rules Modal */
    #aiRulesModal {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 9998;
      align-items: center;
      justify-content: center;
      pointer-events: auto;
    }

    #aiRulesModal.active {
      display: flex;
    }

    #aiRulesBackdrop {
      position: absolute;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      backdrop-filter: blur(4px);
      z-index: 0;
    }

    #aiRulesContainer {
      position: relative;
      z-index: 10;
      width: 100%;
      max-width: 900px;
      height: 85vh;
      background: #09090b;
      border: 1px solid #27272a;
      border-radius: 16px;
      display: flex;
      flex-direction: column;
      box-shadow: 0 0 50px -12px rgba(0, 0, 0, 0.8);
      pointer-events: auto;
    }

    #aiRulesHeader {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20px 32px;
      border-bottom: 1px solid #27272a;
      background: #09090b;
    }

    #aiRulesContent {
      flex: 1;
      overflow-y: auto;
      padding: 32px;
      display: flex;
      flex-direction: column;
    }

    #aiRulesContent::-webkit-scrollbar {
      width: 8px;
    }

    #aiRulesContent::-webkit-scrollbar-track {
      background: transparent;
    }

    #aiRulesContent::-webkit-scrollbar-thumb {
      background: #27272a;
      border-radius: 4px;
    }

    #aiRulesContent::-webkit-scrollbar-thumb:hover {
      background: #3f3f46;
    }

    #aiRulesFooter {
      padding: 20px 32px;
      border-top: 1px solid #27272a;
      background: #09090b;
      display: flex;
      gap: 12px;
      justify-content: space-between;
    }

    .ai-rules-textarea {
      flex: 1;
      background: #18181b;
      border: 1px solid #27272a;
      border-radius: 8px;
      padding: 16px;
      color: #e4e4e7;
      font-family: inherit;
      font-size: 14px;
      line-height: 1.6;
      resize: none;
      outline: none;
    }

    .ai-rules-textarea:focus {
      border-color: #3f3f46;
      background: #1a1a1d;
    }

    .ai-rules-textarea::placeholder {
      color: #71717a;
    }

    /* ── Settings Modal (two-column, FictionLab-style) ──────── */
    #accountModal {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 10000;
      align-items: center;
      justify-content: center;
      padding: 16px;
      background: rgba(0,0,0,0.75);
      backdrop-filter: blur(6px);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s;
    }
    #accountModal.active { display: flex; opacity: 1; pointer-events: auto; }

    .sm-box {
      position: relative;
      display: flex;
      width: min(880px, 100%);
      height: min(620px, 90vh);
      background: #141414;
      border: 1px solid #2a2a2a;
      border-radius: 16px;
      overflow: hidden;
      box-shadow: 0 20px 60px rgba(0,0,0,0.7);
    }

    /* Left sidebar */
    .sm-sidebar {
      width: 200px;
      flex-shrink: 0;
      background: #0f0f0f;
      border-right: 1px solid #222;
      display: flex;
      flex-direction: column;
      overflow-y: auto;
    }
    .sm-sidebar-user {
      padding: 20px 16px 14px;
      border-bottom: 1px solid #222;
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .sm-sidebar-av {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      background: #333;
      border: 2px solid #444;
      flex-shrink: 0;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 13px;
      font-weight: 700;
      color: var(--accent);
    }
    .sm-sidebar-av img { width: 100%; height: 100%; object-fit: cover; }
    .sm-sidebar-name { font-size: 13px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .sm-sidebar-handle { font-size: 11px; color: #555; }

    .sm-nav { flex: 1; padding: 8px 0; }
    .sm-nav-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 10px 16px;
      font-size: 13px;
      font-weight: 500;
      color: #888;
      cursor: pointer;
      transition: color 0.15s, background 0.15s;
      border-radius: 0;
    }
    .sm-nav-item:hover { color: #ccc; background: rgba(255,255,255,0.04); }
    .sm-nav-item.active { color: #fff; background: rgba(250,130,17,0.12); border-left: 3px solid var(--accent); }
    .sm-nav-item svg { flex-shrink: 0; }

    .sm-sidebar-footer { padding: 12px 16px 16px; border-top: 1px solid #222; }
    .sm-logout-btn {
      width: 100%;
      background: transparent;
      border: 1px solid #3a2020;
      border-radius: 8px;
      padding: 8px;
      color: #e55;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.2s;
    }
    .sm-logout-btn:hover { background: rgba(220,50,50,0.1); border-color: #e55; }

    /* Right content panel */
    .sm-content {
      flex: 1;
      overflow-y: auto;
      padding: 28px 32px 32px;
    }
    .sm-section { display: none; }
    .sm-section.active { display: block; }
    .sm-section-title {
      font-size: 20px;
      font-weight: 700;
      color: #fff;
      margin: 0 0 24px;
    }
    .sm-divider { height: 1px; background: #222; margin: 20px 0; }
    .sm-group-label {
      font-size: 11px;
      font-weight: 700;
      color: #555;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      margin-bottom: 10px;
    }

    /* Close button */
    .sm-close {
      position: absolute;
      top: 14px;
      right: 14px;
      background: none;
      border: none;
      color: #666;
      font-size: 20px;
      cursor: pointer;
      width: 28px;
      height: 28px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 6px;
      transition: color 0.15s, background 0.15s;
      z-index: 2;
    }
    .sm-close:hover { color: #fff; background: rgba(255,255,255,0.08); }

    /* Banner */
    .sm-banner-zone {
      height: 100px;
      border-radius: 10px;
      border: 2px dashed #2e2e2e;
      background: linear-gradient(135deg, #1a0a00, #2d1200, #1a0500);
      background-size: cover;
      background-position: center;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      margin-bottom: 16px;
      transition: border-color 0.2s;
      position: relative;
      overflow: hidden;
    }
    .sm-banner-zone:hover { border-color: var(--accent); }
    .sm-banner-zone-label {
      font-size: 12px;
      color: #555;
      pointer-events: none;
      background: rgba(0,0,0,0.5);
      padding: 4px 10px;
      border-radius: 6px;
    }

    /* Avatar row */
    .sm-avatar-row {
      display: flex;
      align-items: center;
      gap: 16px;
      margin-bottom: 20px;
    }
    .sm-avatar-wrap { position: relative; width: 72px; height: 72px; cursor: pointer; flex-shrink: 0; }
    .sm-avatar-circle {
      width: 72px;
      height: 72px;
      border-radius: 50%;
      background: #333;
      border: 2px solid #444;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      font-size: 22px;
      font-weight: 700;
      color: var(--accent);
      transition: border-color 0.2s;
    }
    .sm-avatar-circle img { width: 100%; height: 100%; object-fit: cover; }
    .sm-avatar-overlay {
      position: absolute;
      inset: 0;
      border-radius: 50%;
      background: rgba(0,0,0,0.55);
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.2s;
      color: #fff;
      font-size: 18px;
    }
    .sm-avatar-wrap:hover .sm-avatar-overlay { opacity: 1; }
    .sm-avatar-wrap:hover .sm-avatar-circle { border-color: var(--accent); }
    .sm-avatar-upload-btn {
      background: #1e1e1e;
      border: 1px solid #333;
      border-radius: 8px;
      padding: 8px 14px;
      color: #ccc;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      display: block;
      margin-bottom: 8px;
      transition: all 0.2s;
    }
    .sm-avatar-upload-btn:hover { border-color: var(--accent); color: #fff; }

    /* Form fields */
    .sm-field { margin-bottom: 14px; }
    .sm-label {
      display: block;
      font-size: 11px;
      font-weight: 700;
      color: #555;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      margin-bottom: 6px;
    }
    .sm-input {
      width: 100%;
      background: #111;
      border: 1px solid #2a2a2a;
      border-radius: 8px;
      padding: 10px 12px;
      color: #e8e8e8;
      font-size: 14px;
      font-family: inherit;
      outline: none;
      box-sizing: border-box;
      transition: border-color 0.2s;
    }
    .sm-input:focus { border-color: #555; }
    .sm-textarea { resize: none; min-height: 80px; }
    .sm-char-count { text-align: right; font-size: 11px; color: #555; margin-top: 4px; }
    .sm-fields-row { display: flex; gap: 10px; }
    .sm-fields-row .sm-field { flex: 1; }

    /* Save button */
    .sm-save-btn {
      background: var(--accent);
      color: #fff;
      border: none;
      border-radius: 8px;
      padding: 10px 22px;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      margin-top: 8px;
      transition: background 0.2s;
    }
    .sm-save-btn:hover { background: #e07310; }

    /* Mature content slider */
    .sm-slider-wrap { margin-bottom: 6px; }
    .sm-slider {
      width: 100%;
      accent-color: var(--accent);
      cursor: pointer;
      height: 4px;
    }
    .sm-slider-track-labels {
      display: flex;
      justify-content: space-between;
      font-size: 10px;
      color: #555;
      margin-top: 4px;
    }
    .sm-slider-desc { font-size: 12px; color: #888; margin-top: 8px; min-height: 32px; }

    /* Import/Export grid */
    .sm-io-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px;
    }
    .sm-io-btn {
      background: #1a1a1a;
      border: 1px solid #2a2a2a;
      border-radius: 8px;
      padding: 10px 8px;
      font-size: 12px;
      font-weight: 600;
      color: #aaa;
      cursor: pointer;
      text-align: center;
      transition: all 0.2s;
    }
    .sm-io-btn:hover { border-color: var(--accent); color: #fff; }

    /* Model cards */
    .sm-model-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
      margin-bottom: 4px;
    }
    .sm-model-card {
      position: relative;
      border-radius: 10px;
      overflow: hidden;
      cursor: pointer;
      border: 2px solid transparent;
      transition: border-color 0.2s, transform 0.15s;
      aspect-ratio: 16/9;
    }
    .sm-model-card:hover { transform: translateY(-2px); }
    .sm-model-card.selected { border-color: var(--accent); }
    .sm-model-card-bg {
      position: absolute;
      inset: 0;
      background-size: cover;
      background-position: center;
    }
    .sm-model-card-overlay {
      position: absolute;
      inset: 0;
      background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.2) 60%);
    }
    .sm-model-card-body {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      padding: 8px 10px;
    }
    .sm-model-card-tier {
      display: inline-block;
      font-size: 9px;
      font-weight: 800;
      letter-spacing: 1px;
      padding: 2px 6px;
      border-radius: 4px;
      margin-bottom: 3px;
    }
    .sm-model-card-tier.free { background: rgba(255,255,255,0.15); color: #ccc; }
    .sm-model-card-tier.pro { background: rgba(250,130,17,0.3); color: #fa8211; }
    .sm-model-card-tier.ultra { background: rgba(138,89,255,0.3); color: #b78fff; }
    .sm-model-card-name { font-size: 13px; font-weight: 700; color: #fff; }
    .sm-model-card-desc { font-size: 10px; color: rgba(255,255,255,0.6); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .sm-model-card-locked {
      position: absolute;
      top: 6px;
      right: 6px;
      background: rgba(0,0,0,0.6);
      border-radius: 4px;
      padding: 2px 5px;
      font-size: 9px;
      color: #fa8211;
      font-weight: 700;
    }

    /* Toggle rows */
    .sm-toggle-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px 0;
      border-bottom: 1px solid #1e1e1e;
    }
    .sm-toggle-label { font-size: 13px; font-weight: 500; color: #ddd; }
    .sm-toggle-sub { font-size: 11px; color: #555; margin-top: 2px; }
    .sm-switch { position: relative; display: inline-block; width: 38px; height: 22px; }
    .sm-switch input { opacity: 0; width: 0; height: 0; }
    .sm-switch-slider {
      position: absolute;
      inset: 0;
      background: #333;
      border-radius: 11px;
      cursor: pointer;
      transition: background 0.2s;
    }
    .sm-switch-slider:before {
      content: '';
      position: absolute;
      width: 16px;
      height: 16px;
      left: 3px;
      bottom: 3px;
      background: #fff;
      border-radius: 50%;
      transition: transform 0.2s;
    }
    .sm-switch input:checked + .sm-switch-slider { background: var(--accent); }
    .sm-switch input:checked + .sm-switch-slider:before { transform: translateX(16px); }

    /* Response length pills */
    .sm-pills { display: flex; gap: 6px; }
    .sm-pill {
      flex: 1;
      padding: 8px;
      background: #1a1a1a;
      border: 1px solid #2a2a2a;
      border-radius: 8px;
      color: #888;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      text-align: center;
      transition: all 0.15s;
    }
    .sm-pill:hover { border-color: #444; color: #ccc; }
    .sm-pill.active { background: rgba(250,130,17,0.15); border-color: var(--accent); color: #fff; }

    /* Subscription tier card */
    .sm-tier-card {
      background: linear-gradient(135deg, #1a1a1a, #111);
      border: 1px solid #2a2a2a;
      border-radius: 12px;
      padding: 20px;
      margin-bottom: 12px;
    }
    .sm-tier-badge {
      display: inline-block;
      padding: 3px 10px;
      border-radius: 6px;
      font-size: 11px;
      font-weight: 800;
      letter-spacing: 1px;
      text-transform: uppercase;
      margin-bottom: 8px;
    }
    .sm-tier-badge.free { background: rgba(255,255,255,0.1); color: #aaa; }
    .sm-tier-badge.pro { background: rgba(250,130,17,0.2); color: #fa8211; }
    .sm-tier-badge.ultra { background: rgba(138,89,255,0.2); color: #b78fff; }

    /* Mobile */
    @media (max-width: 600px) {
      .sm-box { flex-direction: column; height: min(95vh, 700px); width: 100%; }
      .sm-sidebar { width: 100%; flex-direction: row; border-right: none; border-bottom: 1px solid #222; overflow-x: auto; overflow-y: hidden; }
      .sm-sidebar-user { display: none; }
      .sm-nav { display: flex; flex-direction: row; padding: 4px; }
      .sm-nav-item { padding: 8px 12px; white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
      .sm-nav-item.active { border-left: none; border-bottom-color: var(--accent); }
      .sm-sidebar-footer { display: none; }
      .sm-content { padding: 16px; }
      .sm-model-grid { grid-template-columns: repeat(2, 1fr); }
      .sm-io-grid { grid-template-columns: repeat(2, 1fr); }
    }

    #accountBackdrop {
      position: absolute;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      backdrop-filter: blur(4px);
      z-index: 0;
    }

    #accountContainer {
      position: relative;
      z-index: 10;
      width: 100%;
      max-width: 600px;
      max-height: 85vh;
      background: #09090b;
      border: 1px solid #27272a;
      border-radius: 16px;
      display: flex;
      flex-direction: column;
      box-shadow: 0 0 50px -12px rgba(0, 0, 0, 0.8);
      pointer-events: auto;
    }

    #accountHeader {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20px 24px;
      border-bottom: 1px solid #27272a;
      background: #09090b;
      border-top-left-radius: 16px;
      border-top-right-radius: 16px;
    }

    /* Image Generation Modal */
    #imageGenModal {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 9998;
      align-items: center;
      justify-content: center;
      pointer-events: auto;
    }

    #imageGenModal.active {
      display: flex;
    }

    #imageGenBackdrop {
      position: absolute;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      backdrop-filter: blur(4px);
      z-index: 0;
    }

    #imageGenContainer {
      position: relative;
      z-index: 10;
      width: 100%;
      max-width: 900px;
      max-height: 85vh;
      background: #09090b;
      border: 1px solid #27272a;
      border-radius: 16px;
      display: flex;
      flex-direction: column;
      box-shadow: 0 0 50px -12px rgba(0, 0, 0, 0.8);
      pointer-events: auto;
      overflow: hidden;
    }

    #imageGenHeader {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20px 32px;
      border-bottom: 1px solid #27272a;
      background: #09090b;
    }

    #imageGenContent {
      flex: 1;
      overflow-y: auto;
      padding: 32px;
      display: flex;
      flex-direction: column;
      gap: 24px;
    }

    #imageGenContent::-webkit-scrollbar {
      width: 8px;
    }

    #imageGenContent::-webkit-scrollbar-track {
      background: transparent;
    }

    #imageGenContent::-webkit-scrollbar-thumb {
      background: #27272a;
      border-radius: 4px;
    }

    #imageGenContent::-webkit-scrollbar-thumb:hover {
      background: #3f3f46;
    }

    #imageGenFooter {
      padding: 20px 32px;
      border-top: 1px solid #27272a;
      background: #09090b;
      display: flex;
      gap: 12px;
      justify-content: flex-end;
    }

    .image-gen-section {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .image-gen-label {
      font-size: 11px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      color: #71717a;
    }

    .image-gen-desc {
      font-size: 13px;
      color: #a1a1aa;
      margin-top: -4px;
    }

    .image-gen-input {
      width: 100%;
      padding: 12px 16px;
      background: #18181b;
      border: 1px solid #27272a;
      border-radius: 8px;
      color: #e4e4e7;
      font-family: inherit;
      font-size: 14px;
      transition: all 0.2s;
      outline: none;
    }

    .image-gen-input:hover {
      border-color: #3f3f46;
    }

    .image-gen-input:focus {
      border-color: #52525b;
      background: #1a1a1d;
    }

    .image-gen-textarea {
      width: 100%;
      padding: 12px 16px;
      background: #18181b;
      border: 1px solid #27272a;
      border-radius: 8px;
      color: #e4e4e7;
      font-family: inherit;
      font-size: 14px;
      line-height: 1.5;
      resize: vertical;
      min-height: 100px;
      outline: none;
      transition: all 0.2s;
    }

    .image-gen-textarea:hover {
      border-color: #3f3f46;
    }

    .image-gen-textarea:focus {
      border-color: #52525b;
      background: #1a1a1d;
    }

    .image-gen-dropdown {
      width: 100%;
      padding: 12px 16px;
      background: #18181b;
      border: 1px solid #27272a;
      border-radius: 8px;
      color: #e4e4e7;
      font-family: inherit;
      font-size: 14px;
      transition: all 0.2s;
      outline: none;
      cursor: pointer;
      appearance: none;
      -webkit-appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 14px center;
      padding-right: 40px;
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .image-gen-dropdown:hover {
      border-color: #3f3f46;
    }

    .image-gen-dropdown:focus {
      border-color: #52525b;
      background: #1a1a1d;
    }

    .image-gen-dropdown option {
      background: #18181b;
      color: #e4e4e7;
    }

    /* Modal Layering Fixes */
    .auth-overlay, .modal-overlay {
      position: fixed !important;
      top: 0; left: 0; right: 0; bottom: 0;
      width: 100vw; height: 100vh;
      background: rgba(0,0,0,0.85) !important;
      backdrop-filter: blur(8px);
      z-index: 10000 !important;
      display: none;
      align-items: center;
      justify-content: center;
    }
    .auth-overlay.active, .modal-overlay.active {
      display: flex !important;
    }
    /* Specific Auth/Profile Modal Layout */
    .auth-modal {
      position: relative;
      z-index: 10001;
      width: 400px;
      max-width: 90vw;
      max-height: 90vh;
      overflow-y: auto;
      background: #141414;
      border: 1px solid #2d2d2d;
      border-radius: 20px;
      padding: 32px;
      box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8);
    }
    
    #editProfileModal .profile-edit-content {
      position: relative;
      z-index: 10001;
      width: 500px;
      max-width: 90vw;
      max-height: 90vh;
      overflow-y: auto;
      background: #141414;
      border: 1px solid #2d2d2d;
      border-radius: 20px;
      padding: 32px;
    }

/* ── Block 3 ──────────────────────────────────────────────── */
    @keyframes imgOrbit {
      to {
        transform: rotate(360deg);
      }
    }

    @keyframes imgBrushSpin {

      0%,
      100% {
        transform: rotate(-12deg);
      }

      50% {
        transform: rotate(12deg);
      }
    }

    @keyframes imgGlowPulse {

      0%,
      100% {
        opacity: 0.5;
        transform: scale(0.9);
      }

      50% {
        opacity: 1;
        transform: scale(1.1);
      }
    }

    @keyframes imgStroke1 {

      0%,
      100% {
        opacity: 0;
      }

      30%,
      70% {
        opacity: 0.75;
      }
    }

    @keyframes imgStroke2 {

      0%,
      100% {
        opacity: 0;
      }

      30%,
      70% {
        opacity: 0.6;
      }
    }

    @keyframes imgSplat {

      0%,
      100% {
        opacity: 0;
        transform: scale(0);
      }

      40%,
      60% {
        opacity: 0.8;
        transform: scale(1);
      }
    }

    #imgGenOverlay.active {
      opacity: 1 !important;
      pointer-events: auto !important;
    }

    /* Profile View Layout */
    /* ── Full-width profile page ── */
    .profile-banner-wrap {
      background: linear-gradient(135deg, #1a0a00, #2d1200, #1a0500);
      background-size: cover;
      background-position: center;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .profile-banner-spacer {
      height: 140px;
    }

    .profile-hero {
      display: flex;
      align-items: flex-end;
      gap: 20px;
      padding: 0 32px 20px;
      flex-wrap: wrap;
    }

    .profile-hero-avatar {
      width: 110px;
      height: 110px;
      border-radius: 50%;
      border: 4px solid #181818;
      background: var(--accent);
      margin-top: -55px;
      overflow: hidden;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 36px;
      font-weight: 700;
      color: #fff;
    }

    .profile-hero-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .profile-hero-info {
      flex: 1;
      min-width: 0;
      padding-top: 12px;
    }

    .profile-name-large {
      font-size: 22px;
      font-weight: 800;
      color: #fff;
      margin: 0 0 4px;
    }

    .profile-hero-meta {
      font-size: 13px;
      color: rgba(255,255,255,0.85);
    }

    .profile-hero-meta span {
      color: #fff;
      font-weight: 600;
    }

    .profile-bio {
      font-size: 13px;
      color: rgba(255,255,255,0.85);
      line-height: 1.5;
    }

    .profile-social-link {
      display: flex;
      align-items: center;
      gap: 6px;
      color: rgba(255,255,255,0.8);
      text-decoration: none;
      font-size: 13px;
      transition: color 0.2s;
    }

    .profile-social-link:hover { color: var(--accent); }

    /* Profile sections */
    .profile-section-block { margin-bottom: 32px; }

    /* ── Shared page heading style (gradient text, big) ──── */
    .page-heading {
      font-family: var(--font-display);
      font-size: 28px;
      font-weight: 800;
      background: linear-gradient(90deg, #fff 0%, var(--accent) 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      letter-spacing: -0.5px;
      line-height: 1.1;
    }

    /* ── Profile Overview (carousel rows) ─────────────────── */
    .profile-ov-section { margin-bottom: 36px; }
    .profile-ov-section-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
    .profile-ov-section-title {
      font-family: var(--font-display);
      font-size: 28px;
      font-weight: 800;
      background: linear-gradient(90deg, #fff 0%, var(--accent) 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      letter-spacing: -0.5px;
    }
    /* Carousel */
    .profile-ov-grid {
      display: flex;
      gap: 14px;
      overflow-x: auto;
      padding-bottom: 10px;
      scrollbar-width: none;
    }
    .profile-ov-grid::-webkit-scrollbar { display: none; }
    .profile-ov-grid .showcase-card {
      flex-shrink: 0;
      width: 320px;
      aspect-ratio: 3/2;
    }

    .profile-section-head { display:flex; align-items:center; gap:10px; margin-bottom:12px; }
    .profile-section-name { font-size:15px; font-weight:700; color:var(--text-primary); }
    .profile-section-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
    .profile-section-actions { margin-left:auto; display:flex; gap:6px; }
    .profile-section-action-btn { background:none; border:1px solid var(--border); border-radius:6px; color:var(--text-dim); font-size:11px; padding:2px 8px; cursor:pointer; }
    .profile-section-action-btn:hover { color:var(--text-primary); border-color:var(--border-light); }
    .profile-section-strip { display:flex; gap:14px; overflow-x:auto; padding-bottom:8px; scrollbar-width:thin; scrollbar-color:var(--border) transparent; }
    .profile-section-strip::-webkit-scrollbar { height:3px; }
    .profile-section-strip::-webkit-scrollbar-thumb { background:var(--border); border-radius:2px; }
    .profile-section-card { flex-shrink:0; width:160px; cursor:pointer; border-radius:10px; overflow:hidden; background:var(--bg-card); border:1px solid var(--border); transition:transform 0.15s,border-color 0.15s; }
    .profile-section-card:hover { transform:translateY(-2px); border-color:var(--accent); }
    .profile-section-card-img { width:160px; height:100px; object-fit:cover; display:block; background:linear-gradient(135deg,#1a1a2e,#16213e); }
    .profile-section-card-body { padding:8px 10px; }
    .profile-section-card-title { font-size:12px; font-weight:600; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
    .profile-section-card-badge { font-size:9px; color:var(--text-dim); margin-top:2px; }
    .profile-add-section-bar { display:flex; align-items:center; gap:10px; margin-bottom:24px; }

    /* Notification bell */
    @keyframes bellGlow {
      0%,100% { box-shadow: 0 0 0 0 rgba(232,98,26,0); }
      50%      { box-shadow: 0 0 12px 4px rgba(232,98,26,0.55); }
    }
    .notif-bell {
      position: relative;
      cursor: pointer;
      padding: 9px;
      border-radius: 10px;
      color: var(--text-dim);
      background: none;
      border: none;
      transition: color 0.2s, background 0.2s;
    }
    .notif-bell svg { width: 24px; height: 24px; }
    .notif-bell:hover {
      color: var(--accent);
      background: rgba(232,98,26,0.1);
    }
    .notif-bell.has-unread {
      color: var(--accent);
      animation: bellGlow 2s ease-in-out infinite;
    }
    .notif-badge { position:absolute; top:1px; right:1px; background:var(--accent); color:#fff; font-size:9px; font-weight:800; min-width:15px; height:15px; border-radius:8px; display:flex; align-items:center; justify-content:center; padding:0 3px; pointer-events:none; }
    .notif-panel { position:fixed; top:54px; right:16px; width:340px; max-height:480px; background:var(--bg-panel); border:1px solid var(--border-light); border-radius:12px; box-shadow:0 12px 40px rgba(0,0,0,0.5); z-index:200; display:flex; flex-direction:column; overflow:hidden; }
    .notif-panel-head { padding:14px 16px 10px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
    .notif-panel-title { font-size:14px; font-weight:700; color:var(--text-primary); }
    .notif-panel-body { flex:1; overflow-y:auto; }
    .notif-item { display:flex; gap:10px; padding:12px 16px; border-bottom:1px solid var(--border); cursor:pointer; transition:background 0.15s; }
    .notif-item:hover { background:rgba(255,255,255,0.03); }
    .notif-item.unread { background:rgba(232,98,26,0.06); }
    .notif-item-icon { width:32px; height:32px; border-radius:50%; background:rgba(232,98,26,0.15); display:flex; align-items:center; justify-content:center; flex-shrink:0; font-size:14px; }
    .notif-item-body { flex:1; min-width:0; }
    .notif-item-text { font-size:12px; color:var(--text-primary); line-height:1.4; }
    .notif-item-time { font-size:10px; color:var(--text-dim); margin-top:3px; }

    .profile-tabs-bar {
      display: flex;
      gap: 0;
      padding: 0 32px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
      overflow-x: auto;
      scrollbar-width: none;
      -webkit-overflow-scrolling: touch;
    }
    .profile-tabs-bar::-webkit-scrollbar { display: none; }
    @media (max-width: 600px) {
      .profile-tabs-bar { padding: 0 12px; }
      #profileTabContent { padding: 16px !important; }
    }

    .profile-tab {
      padding: 14px 20px;
      font-size: 13px;
      font-weight: 600;
      color: var(--text-dim);
      cursor: pointer;
      border-bottom: 2px solid transparent;
      margin-bottom: -1px;
      transition: all 0.2s;
      white-space: nowrap;
    }

    .profile-tab:hover { color: #fff; }

    .profile-tab.active {
      color: #fff;
      border-bottom-color: var(--accent);
    }

    /* ── Character Gallery ─────────────────────────────────────── */
    .char-gallery-wrap {
      display: flex;
      flex-direction: column;
      gap: 20px;
    }

    .char-gallery-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .char-gallery-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
      gap: 16px;
      padding: 4px;
    }

    .char-gallery-card {
      position: relative;
      border-radius: 12px;
      overflow: visible;
      cursor: default;
      background: var(--bg-card);
      border: 1px solid var(--border);
      transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    }

    .char-gallery-card:hover {
      transform: translateY(-3px);
      border-color: var(--accent);
      box-shadow: 0 6px 24px rgba(0,0,0,0.4);
    }

    .char-gallery-img {
      width: 100%;
      aspect-ratio: 3/4;
      overflow: hidden;
      border-radius: 11px 11px 0 0;
      background: linear-gradient(135deg, #1a1a2e, #16213e);
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
    }

    .char-gallery-img img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .char-gallery-img-placeholder {
      opacity: 0.25;
    }

    .char-gallery-card-actions {
      position: absolute;
      top: 6px;
      right: 6px;
      display: flex;
      gap: 4px;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.15s;
    }

    .char-gallery-card:hover .char-gallery-card-actions {
      opacity: 1;
      pointer-events: auto;
    }

    .char-gallery-action-btn {
      width: 26px;
      height: 26px;
      border-radius: 50%;
      background: rgba(0,0,0,0.75);
      border: 1px solid rgba(255,255,255,0.15);
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      font-size: 11px;
    }

    .char-gallery-action-btn:hover { background: rgba(239,68,68,0.8); border-color: transparent; }

    .char-gallery-body {
      padding: 10px 12px 12px;
    }

    .char-gallery-name {
      font-weight: 700;
      font-size: 13px;
      color: var(--text-primary);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 6px;
    }

    .char-gallery-scenarios {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      margin-bottom: 6px;
    }

    .char-gallery-scenario-pill {
      font-size: 10px;
      padding: 2px 7px;
      border-radius: 20px;
      background: rgba(var(--accent-rgb,229,100,40), 0.15);
      color: var(--accent);
      border: 1px solid rgba(var(--accent-rgb,229,100,40), 0.3);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 100%;
    }

    .char-gallery-assign-btn {
      font-size: 10px;
      color: var(--text-dim);
      background: none;
      border: 1px dashed rgba(255,255,255,0.15);
      border-radius: 20px;
      padding: 2px 8px;
      cursor: pointer;
      transition: border-color 0.15s, color 0.15s;
    }

    .char-gallery-assign-btn:hover { border-color: var(--accent); color: var(--accent); }

    .char-gallery-add-card {
      border: 2px dashed rgba(255,255,255,0.12);
      border-radius: 12px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 8px;
      cursor: pointer;
      aspect-ratio: 3/4;
      color: var(--text-dim);
      font-size: 12px;
      transition: border-color 0.2s, color 0.2s;
    }

    .char-gallery-add-card:hover { border-color: var(--accent); color: var(--accent); }

    /* Scenario assign dropdown */
    .char-scenario-dropdown {
      position: absolute;
      bottom: calc(100% + 4px);
      left: 0;
      right: 0;
      background: var(--bg-secondary, #1e1e2e);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 6px 0;
      z-index: 200;
      box-shadow: 0 8px 24px rgba(0,0,0,0.5);
      max-height: 200px;
      overflow-y: auto;
    }

    .char-scenario-dropdown-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 7px 12px;
      font-size: 12px;
      cursor: pointer;
      color: var(--text-secondary);
      transition: background 0.1s;
    }

    .char-scenario-dropdown-item:hover { background: rgba(255,255,255,0.05); }

    .char-scenario-dropdown-item input[type=checkbox] {
      accent-color: var(--accent);
      width: 13px;
      height: 13px;
      flex-shrink: 0;
    }

    /* Character picker modal */
    .char-picker-modal {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.7);
      z-index: 1000;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s;
    }

    .char-picker-modal.active {
      opacity: 1;
      pointer-events: auto;
    }

    .char-picker-box {
      background: var(--bg-secondary, #1e1e2e);
      border: 1px solid var(--border);
      border-radius: 16px;
      width: 540px;
      max-width: 95vw;
      max-height: 80vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    .char-picker-header {
      padding: 18px 20px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .char-picker-title {
      font-weight: 700;
      font-size: 15px;
    }

    .char-picker-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
      gap: 12px;
      padding: 16px;
      overflow-y: auto;
    }

    .char-picker-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 6px;
      padding: 10px 8px;
      border-radius: 10px;
      cursor: pointer;
      border: 2px solid transparent;
      transition: border-color 0.15s, background 0.15s;
      text-align: center;
    }

    .char-picker-item:hover { background: rgba(255,255,255,0.05); }
    .char-picker-item.selected { border-color: var(--accent); background: rgba(var(--accent-rgb,229,100,40),0.1); }
    .char-picker-item.already-added { opacity: 0.4; cursor: not-allowed; }

    .char-picker-avatar {
      width: 72px;
      height: 72px;
      border-radius: 50%;
      overflow: hidden;
      background: rgba(255,255,255,0.06);
      border: 2px solid rgba(255,255,255,0.1);
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .char-picker-avatar img { width: 100%; height: 100%; object-fit: cover; }

    .char-picker-name {
      font-size: 11px;
      font-weight: 600;
      color: var(--text-primary);
      line-height: 1.3;
    }

    .char-picker-footer {
      padding: 14px 20px;
      border-top: 1px solid var(--border);
      display: flex;
      justify-content: flex-end;
      gap: 10px;
    }

    /* Moving Line Carousel */
    .moving-line-container {
      width: 100%;
      overflow: hidden;
      position: relative;
      padding: 20px 0;
    }

    .moving-line-track {
      display: flex;
      gap: 20px;
      width: max-content;
      animation: scroll 40s linear infinite;
    }

    .moving-line-track:hover {
      animation-play-state: paused;
    }

    @keyframes scroll {
      0% { transform: translateX(0); }
      100% { transform: translateX(-50%); }
    }

    .carousel-card {
      width: 320px;
      height: 190px;
      border-radius: 14px;
      overflow: hidden;
      position: relative;
      flex-shrink: 0;
      cursor: pointer;
      border: 1px solid var(--border);
      transition: transform 0.3s, border-color 0.2s, box-shadow 0.2s;
      box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    }

    .carousel-card:hover {
      transform: scale(1.04) translateY(-2px);
      border-color: var(--accent);
      box-shadow: 0 8px 28px rgba(0,0,0,0.45);
    }

    .carousel-card img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .carousel-card-overlay {
      position: absolute;
      inset: 0;
      background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.2) 60%, transparent 100%);
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      padding: 14px;
    }

    .carousel-card-name {
      font-size: 15px;
      font-weight: 700;
      color: #fff;
      text-shadow: 0 1px 4px rgba(0,0,0,0.6);
      line-height: 1.3;
    }

    .carousel-card-creator {
      font-size: 11px;
      color: rgba(255,255,255,0.65);
      margin-top: 3px;
    }

    .community-heading {
      display: flex;
      flex-direction: column;
      gap: 5px;
    }

    .community-heading-main {
      font-family: var(--font-display);
      font-size: 28px;
      font-weight: 800;
      background: linear-gradient(90deg, #fff 0%, var(--accent) 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      letter-spacing: -0.5px;
      line-height: 1;
    }

    .community-heading-sub {
      font-size: 13px;
      color: #ffffff;
      font-weight: 400;
    }

    /* Community search bar */
    .community-search-row {
      display: flex;
      align-items: center;
      gap: 10px;
      margin-top: 16px;
    }

    .community-search-wrap {
      position: relative;
      flex: 1;
      max-width: 420px;
    }

    .community-search-wrap svg {
      position: absolute;
      left: 12px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-dim);
      pointer-events: none;
    }

    .community-search-input {
      width: 100%;
      padding: 9px 14px 9px 36px;
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text-primary);
      font-size: 13px;
      outline: none;
      transition: border-color 0.2s;
    }

    .community-search-input:focus {
      border-color: var(--accent);
    }

    .community-search-input::placeholder {
      color: var(--text-dim);
    }

    /* Genre row sections */
    .genre-row-section {
      margin-top: 28px;
    }

    .genre-row-header {
      display: flex;
      align-items: baseline;
      gap: 10px;
      margin-bottom: 14px;
    }

    .genre-row-title {
      font-family: var(--font-display);
      font-size: 16px;
      font-weight: 700;
      color: var(--text-primary);
    }

    .genre-row-count {
      font-size: 11px;
      color: var(--text-dim);
    }

    .genre-row-strip {
      display: flex;
      gap: 16px;
      overflow-x: auto;
      padding-bottom: 10px;
      scrollbar-width: thin;
      scrollbar-color: var(--border) transparent;
    }

    .genre-row-strip::-webkit-scrollbar {
      height: 4px;
    }

    .genre-row-strip::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 2px;
    }

    /* Showcase layout */
    .showcase-spotlight {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 14px;
      margin-top: 20px;
    }

    .showcase-card {
      position: relative;
      aspect-ratio: 3/2;
      border-radius: 12px;
      overflow: hidden;
      cursor: pointer;
      background: #1a1a2e;
      transition: transform 0.2s, box-shadow 0.2s;
    }

    .showcase-card:hover {
      transform: translateY(-3px);
      box-shadow: 0 12px 32px rgba(0,0,0,0.5);
    }

    .showcase-card img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
      transition: transform 0.3s;
    }

    .showcase-card:hover img {
      transform: scale(1.04);
    }

    .showcase-card-overlay {
      position: absolute;
      inset: 0;
      background: linear-gradient(to top, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.2) 55%, transparent 100%);
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      padding: 14px;
    }

    .showcase-card-tags {
      display: flex;
      gap: 5px;
      flex-wrap: wrap;
      margin-bottom: 6px;
    }

    .showcase-card-name {
      font-size: 14px;
      font-weight: 700;
      color: #fff;
      line-height: 1.3;
      margin-bottom: 4px;
    }

    .showcase-card-desc {
      font-size: 11px;
      color: rgba(255,255,255,0.72);
      line-height: 1.4;
      margin-bottom: 5px;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .showcase-card-creator {
      font-size: 10px;
      color: rgba(255,255,255,0.5);
    }

    .showcase-card-creator:hover {
      color: rgba(255,255,255,0.85);
    }

    .showcase-section-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin: 28px 0 12px;
    }

    .showcase-section-title {
      font-size: 15px;
      font-weight: 700;
      color: var(--text-primary);
    }

    .showcase-browse-btn {
      background: none;
      border: none;
      color: var(--accent);
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      padding: 0;
    }

    .showcase-browse-btn:hover {
      opacity: 0.8;
    }

    .showcase-new-row {
      display: flex;
      gap: 14px;
      overflow-x: auto;
      padding-bottom: 10px;
      scrollbar-width: thin;
      scrollbar-color: var(--border) transparent;
    }

    .showcase-new-row::-webkit-scrollbar { height: 4px; }
    .showcase-new-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

    @media (max-width: 700px) {
      .showcase-spotlight {
        grid-template-columns: repeat(2, 1fr);
      }
    }

    @media (max-width: 480px) {
      .showcase-spotlight {
        grid-template-columns: 1fr;
      }
    }

    /* ── Home genre tabs ──────────────────────────────────── */
    .home-genre-tabs {
      display: flex;
      gap: 8px;
      overflow-x: auto;
      padding: 4px 0 12px;
      scrollbar-width: none;
      margin-bottom: 4px;
    }
    .home-genre-tabs::-webkit-scrollbar { display: none; }
    .home-genre-tab {
      flex-shrink: 0;
      padding: 7px 16px;
      border-radius: 20px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      border: 1px solid var(--border);
      background: transparent;
      color: var(--text-dim);
      transition: background 0.15s, color 0.15s, border-color 0.15s;
      white-space: nowrap;
    }
    .home-genre-tab:hover { color: #fff; border-color: rgba(255,255,255,0.3); }
    .home-genre-tab.active {
      background: #fff;
      color: #111;
      border-color: #fff;
    }

    /* ── Home cards grid ──────────────────────────────────── */
    .home-cards-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 14px;
    }
    @media (max-width: 700px) { .home-cards-grid { grid-template-columns: repeat(2, 1fr); } }
    @media (max-width: 420px) { .home-cards-grid { grid-template-columns: 1fr; } }

    /* Larger text on home grid cards */
    .home-cards-grid .showcase-card-name { font-size: 16px; }
    .home-cards-grid .showcase-card-desc { font-size: 12px; }
    .home-cards-grid .showcase-card-creator { font-size: 11px; color: rgba(255,255,255,0.6); }
    .home-cards-grid .showcase-card-overlay { padding: 18px; }

    /* ── Home bottom bar ──────────────────────────────────── */
    .home-bottom-bar {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 12px;
      margin-top: 28px;
      padding-top: 24px;
      border-top: 1px solid var(--border);
    }
    .home-bottom-btn {
      display: flex;
      align-items: center;
      gap: 7px;
      padding: 10px 22px;
      border-radius: 8px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: opacity 0.15s;
    }
    .home-bottom-btn:hover { opacity: 0.85; }
    .home-bottom-btn-primary { background: var(--accent); color: #fff; border: none; }
    .home-bottom-btn-secondary { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
    .home-bottom-sep { color: var(--text-dim); font-size: 13px; }

    /* Explore view */
    #view-explore {
      overflow-y: auto;
    }

    .explore-content {
      max-width: 1100px;
      margin: 0 auto;
      width: 100%;
      padding: 32px 24px 40px;
    }

    .explore-header {
      margin-bottom: 24px;
    }

    .explore-title {
      font-family: var(--font-display);
      font-size: 28px;
      font-weight: 800;
      margin-bottom: 16px;
      background: linear-gradient(90deg, #fff 0%, var(--accent) 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      letter-spacing: -0.5px;
    }

    .explore-search-row {
      display: flex;
      gap: 10px;
      align-items: center;
      flex-wrap: nowrap;
    }

    .explore-search-wrap {
      position: relative;
      flex: 1;
      min-width: 0;
    }

    .explore-search-wrap svg {
      position: absolute;
      left: 12px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-dim);
      pointer-events: none;
    }

    .explore-search-input {
      width: 100%;
      padding: 10px 14px 10px 38px;
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text-primary);
      font-size: 14px;
      outline: none;
      transition: border-color 0.2s;
    }

    .explore-search-input:focus { border-color: var(--accent); }
    .explore-search-input::placeholder { color: var(--text-dim); }

    .explore-sort-select {
      padding: 10px 14px;
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text-primary);
      font-size: 13px;
      outline: none;
      cursor: pointer;
      width: auto;
      min-width: 130px;
      flex-shrink: 0;
    }

    /* Category-based explore filter */
    .explore-cats-bar {
      display: flex;
      gap: 6px;
      flex-wrap: wrap;
      margin-top: 14px;
      align-items: center;
    }
    @media (max-width: 700px) {
      .explore-cats-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 6px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
      }
      .explore-cats-bar::-webkit-scrollbar { display: none; }
      .explore-cat-btn { flex-shrink: 0; }
    }

    .explore-cat-btn {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 5px 12px;
      border-radius: 20px;
      border: 1px solid var(--border);
      background: var(--bg-card);
      color: var(--text-dim);
      font-size: 12px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.18s;
      user-select: none;
      white-space: nowrap;
    }

    .explore-cat-btn:hover {
      border-color: var(--accent);
      color: var(--text-primary);
    }

    .explore-cat-btn.active {
      background: rgba(232,98,26,0.15);
      border-color: var(--accent);
      color: var(--accent);
      font-weight: 600;
    }

    .explore-cat-btn.has-selected {
      border-color: var(--accent2);
      color: var(--accent2);
      background: rgba(46,189,217,0.1);
    }

    .explore-cat-btn .cat-count {
      font-size: 10px;
      background: var(--accent2);
      color: #000;
      border-radius: 8px;
      padding: 1px 5px;
      font-weight: 700;
      line-height: 1.4;
    }

    .explore-tag-strip {
      display: flex;
      gap: 6px;
      flex-wrap: wrap;
      margin-top: 8px;
      padding: 10px 12px;
      background: rgba(255,255,255,0.03);
      border: 1px solid var(--border);
      border-radius: 8px;
      animation: fadeIn 0.15s ease;
    }

    .explore-active-tags-row {
      display: flex;
      gap: 6px;
      flex-wrap: wrap;
      margin-top: 8px;
      min-height: 0;
    }

    .explore-active-tag {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 3px 8px 3px 10px;
      border-radius: 20px;
      background: rgba(46,189,217,0.15);
      border: 1px solid rgba(46,189,217,0.4);
      color: var(--accent2);
      font-size: 11px;
      font-weight: 600;
      cursor: pointer;
    }

    .explore-active-tag:hover { background: rgba(46,189,217,0.25); }
    .explore-active-tag svg { opacity: 0.7; }

    .explore-clear-all {
      font-size: 11px;
      color: var(--text-dim);
      background: none;
      border: none;
      cursor: pointer;
      padding: 4px 6px;
      border-radius: 4px;
      align-self: center;
    }
    .explore-clear-all:hover { color: var(--text-primary); }

    .explore-filter-bar {
      display: none; /* legacy — replaced by .explore-cats-bar */
    }

    .explore-results-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
      gap: 20px;
      margin-top: 20px;
      padding: 4px;
    }
    @media (max-width: 600px) {
      .explore-results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
      }
    }
    @media (max-width: 360px) {
      .explore-results-grid {
        grid-template-columns: 1fr;
      }
    }

    .explore-card {
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: 12px;
      overflow: hidden;
      cursor: pointer;
      transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    }

    .explore-card:hover {
      transform: translateY(-3px);
      box-shadow: 0 8px 28px rgba(0,0,0,0.45);
    }

    .explore-card-img {
      width: 100%;
      aspect-ratio: 16/9;
      overflow: hidden;
      background: linear-gradient(135deg, #1a1a2e, #16213e);
      position: relative;
    }

    .explore-card-img img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .explore-card-body {
      padding: 14px;
    }

    .explore-card-title {
      font-weight: 700;
      font-size: 14px;
      margin-bottom: 4px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .explore-card-desc {
      font-size: 12px;
      color: var(--text-dim);
      line-height: 1.5;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      margin-bottom: 10px;
    }

    .explore-card-meta {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 11px;
      color: var(--text-dim);
    }

    .explore-card-creator {
      font-weight: 500;
      color: var(--text-secondary);
    }

    .explore-load-more {
      margin-top: 28px;
      text-align: center;
    }

    .explore-empty {
      text-align: center;
      padding: 60px 20px;
      color: var(--text-dim);
    }

    .explore-empty svg {
      margin-bottom: 12px;
      opacity: 0.4;
    }

    .genre-filter-bar {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-bottom: 12px;
      margin-top: 14px;
    }

    .genre-pill {
      padding: 4px 12px;
      border-radius: 20px;
      border: 1px solid var(--border);
      background: var(--bg-card);
      color: var(--text-dim);
      font-size: 12px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.18s;
      user-select: none;
    }

    .genre-pill:hover {
      border-color: var(--accent);
      color: var(--text-primary);
    }

    .genre-pill.active {
      background: rgba(46,189,217,0.15);
      border-color: var(--accent2);
      color: var(--accent2);
      font-weight: 600;
    }

    /* Tags shown on explore cards */
    .explore-card-tag {
      font-size: 10px;
      font-weight: 600;
      background: rgba(255,255,255,0.07);
      border: 1px solid rgba(255,255,255,0.12);
      color: var(--text-dim);
      padding: 2px 6px;
      border-radius: 20px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 80px;
    }
    @media (max-width: 600px) {
      .explore-card-tag { font-size: 9px; padding: 1px 5px; max-width: 60px; }
      .explore-card-title { font-size: 12px; }
      .explore-card-desc { display: none; }
      .explore-card-body { padding: 10px; }
    }


