        :root {
            --bg: #000000;
            --card-bg: #1e1e1e;
            --pill-bg: #333;
            --text-main: #eee;
            --text-dim: #666;
            --card-default-bg: #1e1e1e;
            --card-default-text: #eee;
            --card-default-secondary: #666;
            --card-preset-blue-bg: #31527A;
            --card-preset-blue-text: #F3F6FA;
            --card-preset-blue-secondary: #C8D4E2;
            --card-preset-teal-bg: #2F666C;
            --card-preset-teal-text: #F3F6FA;
            --card-preset-teal-secondary: #C5D9DB;
            --card-preset-green-bg: #536C4C;
            --card-preset-green-text: #F3F6FA;
            --card-preset-green-secondary: #CCD8C8;
            --card-preset-orange-bg: #8A5B33;
            --card-preset-orange-text: #F8F4EE;
            --card-preset-orange-secondary: #E6D4C3;
            --card-preset-red-bg: #7A3F43;
            --card-preset-red-text: #FAF3F4;
            --card-preset-red-secondary: #E3C9CC;
            --card-preset-purple-bg: #5F4D74;
            --card-preset-purple-text: #F5F2FA;
            --card-preset-purple-secondary: #D8D0E6;
            --card-preset-yellow-bg: #8A7438;
            --card-preset-yellow-text: #F5F2FA;
            --card-preset-yellow-secondary: #D8D0E6;
            --accent: #4caf50;
            --reject: #ff453a;
            --gold: #ffd700;
            --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            --controls-height: 120px;
            --top-bar-row-height: 48px;
            --top-bar-icon-button-size: 48px;
            --top-bar-icon-size: 34px;
            --bottom-nav-height: 48px;
            --bottom-nav-collapsed-size: 48px;
            --bottom-nav-toggle-gap: 4px;
            --bottom-nav-toggle-size: calc(var(--bottom-nav-collapsed-size) - (var(--bottom-nav-toggle-gap) * 2));
            --bottom-nav-gap: 10px;
            --bottom-nav-side-padding: 20px;
            --bottom-nav-bottom-padding: calc(10px + env(safe-area-inset-bottom, 0px));
            --controls-offset-bottom: calc(var(--bottom-nav-height) + var(--bottom-nav-gap) + var(--bottom-nav-bottom-padding));
            --controls-reserve: calc(var(--controls-height) + var(--bottom-nav-height) + var(--bottom-nav-gap) + var(--bottom-nav-bottom-padding));
        }

        html {
            height: 100%;
            overflow: hidden;
            background-color: var(--bg);
        }

        body {
            background-color: var(--bg);
            color: var(--text-main);
            font-family: var(--font);
            margin: 0;
            min-height: 100vh;
            height: 100dvh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            user-select: none;
            -webkit-tap-highlight-color: transparent;
        }

        header {
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            z-index: 10;
            flex-shrink: 0;
            height: var(--top-bar-row-height);
            box-sizing: content-box;
        }
        
        .brand {
            display: flex;
            align-items: center;
            line-height: 0;
        }

        .brand-logo {
            display: block;
            width: auto;
            height: 24px;
            opacity: 0.4;
        }
        
        .icon-btn {
            background: none;
            border: none;
            color: var(--text-main);
            cursor: pointer;
            width: var(--top-bar-icon-button-size);
            height: var(--top-bar-icon-button-size);
            padding: 6px;
            line-height: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            box-sizing: border-box;
        }

        .icon-btn svg {
            width: var(--top-bar-icon-size);
            height: var(--top-bar-icon-size);
            display: block;
        }

        .menu-btn {
            margin-right: -10px;
        }

        .menu-btn svg {
            fill: currentColor;
        }

        #stage {
            flex: 1;
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
            perspective: 1000px;
            padding: 20px 20px var(--controls-reserve);
            transform: translateZ(0);
        }

        /* STATES */
        .system-msg {
            text-align: center; color: #666; animation: fadeIn 1s ease;
            position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 90%;
            font-size: 1rem; font-weight: 500;
            z-index: 0; pointer-events: none;
        }
        
        .err-technical {
            display: block; margin-top: 8px; 
            font-family: monospace; font-size: 0.75rem; 
            color: #333; 
        }

        .empty-state {
            text-align: center; color: #444; animation: fadeIn 0.5s ease;
            margin-top: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80%;
            z-index: 0;
        }
        .empty-state h2 { margin: 0 0 15px 0; font-size: 1.6rem; color: #eee; font-weight: 700; }
        .empty-state p { margin: 0; color: #888; font-size: 1rem; line-height: 1.5; }
        
        @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

        /* CARD */
        .card {
            background: var(--card-current-bg, var(--card-bg));
            color: var(--card-current-text, var(--text-main));
            width: 100%;
            max-width: 340px;
            height: 55vh;
            border-radius: 24px;
            padding: 30px;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            position: absolute;
            box-shadow: 0 15px 50px rgba(0,0,0,0.9);
            border: 1px solid #333;
            will-change: transform, opacity;
            transform-origin: 50% 100%;
            -webkit-user-select: none;
            user-select: none;
        }

        .card.active { cursor: grab; z-index: 100; }
        .card.editing { z-index: 200; border-color: #555; box-shadow: 0 20px 60px rgba(0,0,0,0.9); transition: none; }
        .card.stacked { pointer-events: none; filter: brightness(0.92); border-top: 1px solid #666; }
        .card-char-counter {
            position: absolute;
            top: -22px;
            right: 4px;
            font-size: 0.72rem;
            line-height: 1;
            font-weight: 700;
            letter-spacing: 0.02em;
            color: rgba(255,255,255,0.45);
            pointer-events: none;
            user-select: none;
        }

        .card-char-counter.is-over-limit {
            color: #ff453a;
        }

        .card-char-counter.is-flashing {
            color: #ff453a;
        }

        .card.animate { transition: transform 0.3s ease-out, opacity 0.3s ease; }
        .card.spring { transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
        .card.reveal { animation: cardReveal 0.24s ease-out both; }
        .card-text { font-size: 1.5rem; line-height: 1.5; font-weight: 600; pointer-events: auto; width: 100%; word-wrap: break-word; white-space: pre-wrap; -webkit-user-select: none; user-select: none; color: var(--card-current-text, var(--text-main)); }

        .card-action-button {
            margin-top: 22px;
            max-width: 100%;
            width: auto;
            min-height: 38px;
            padding: 8px 18px;
            border: 1px solid rgba(255,255,255,0.22);
            border-radius: 20px;
            background: rgba(255,255,255,0.08);
            color: var(--card-current-text, var(--text-main));
            font: inherit;
            font-size: 0.88rem;
            line-height: 1.2;
            font-weight: 650;
            text-align: center;
            cursor: pointer;
            pointer-events: auto;
            touch-action: manipulation;
            transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
        }

        .card-action-button:active {
            transform: scale(0.96);
            background: rgba(255,255,255,0.14);
            border-color: rgba(255,255,255,0.36);
        }
        
        .link-pill {
            display: inline-flex; align-items: center; vertical-align: middle; max-width: 90%;
            background: rgba(255,255,255,0.08); padding: 4px 12px 4px 8px; border-radius: 50px;
            color: var(--card-current-text, var(--text-main)); text-decoration: none; font-size: 0.85rem; font-weight: 500;
            margin: 2px 4px 2px 0; border: 1px solid rgba(255,255,255,0.12); box-shadow: none;
            cursor: pointer; user-select: none;
        }
        .link-pill[contenteditable="false"] { user-select: none; cursor: default; }
        .link-icon { margin-right: 6px; color: var(--card-current-secondary, var(--text-dim)); font-size: 1rem; }
        .link-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }

        .card-input-div {
            font-size: 1.5rem; line-height: 1.5; font-weight: 600;
            color: var(--card-current-text, var(--text-main)); background: transparent; border: none;
            width: 100%; height: 100%; text-align: center; outline: none; 
            font-family: inherit; padding: 0; margin: 0; overflow-y: auto; white-space: pre-wrap;
            -webkit-user-select: text;
            user-select: text;
        }
        .card-input-div:empty::before { content: attr(data-placeholder); color: var(--card-current-secondary, #444); display: block; }
        .card-input-div a { color: inherit; text-decoration: none; pointer-events: none; }
        .card-input-div.is-over-limit { color: #ffb0aa; }

        @keyframes cardReveal {
            from {
                opacity: 0;
                transform: translateY(10px) scale(0.985);
            }
            to {
                opacity: 1;
                transform: translateY(0) scale(1);
            }
        }

        .card-meta {
            margin-top: 30px; font-size: 0.8rem; color: var(--card-current-secondary, var(--text-dim));
            text-transform: uppercase; letter-spacing: 1px; pointer-events: none;
            display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%;
        }
        
        .promo-badge {
            display: inline-flex; align-items: baseline; justify-content: center; gap: 6px;
            color: var(--card-current-secondary, #d4d4d4);
            border: 1px solid currentColor;
            background: transparent;
            padding: 7px 16px; border-radius: 20px; text-decoration: none; font-weight: 700; font-size: 0.75rem;
            letter-spacing: 0.5px; transition: transform 0.1s, opacity 0.1s; cursor: pointer; pointer-events: auto; touch-action: manipulation;
        }
        .promo-badge:active { 
            opacity: 0.8;
            transform: scale(0.95); 
        }
        .promo-badge svg { width: 0.85em; height: 0.85em; display: inline-block; fill: currentColor; transform: translateY(1px); }

        .promo-hint {
            font-size: 0.65rem; color: var(--card-current-secondary, #555); font-weight: 500; letter-spacing: 0.5px;
            opacity: 0.8;
            margin-top: 0; 
        }

        .card-btn-wrapper {
            width: 60px; height: 60px;
            display: flex; align-items: center; justify-content: center;
            pointer-events: auto; z-index: 100; cursor: pointer;
            touch-action: manipulation;
        }

        .card-icon {
            width: 22px; height: 22px; border-radius: 50%; background: transparent;
            display: flex; justify-content: center; align-items: center;
            opacity: 1; transition: transform 0.1s, background 0.1s;
        }

        .icon-delete { border: 2px solid var(--reject); color: var(--reject); }
        .card-btn-wrapper:active .icon-delete { background: var(--reject); color: #1e1e1e; transform: scale(0.9); }
        .icon-save { border: 2px solid var(--accent); color: var(--accent); }
        .card-btn-wrapper:active .icon-save { background: var(--accent); color: #1e1e1e; transform: scale(0.9); }
        .card-btn-wrapper.is-disabled {
            cursor: default;
            pointer-events: none;
        }
        .card-btn-wrapper.is-disabled .icon-save {
            border-color: #4b4b4b;
            color: #4b4b4b;
            opacity: 0.65;
        }

        .card-copy {
            position: absolute;
            top: 16px;
            right: 16px;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            pointer-events: auto;
            cursor: pointer;
            z-index: 120;
            touch-action: manipulation;
        }

        .icon-copy {
            width: 18px;
            height: 18px;
            color: var(--card-current-text, var(--text-main));
            opacity: 0.25;
            transition: opacity 0.2s ease, transform 0.1s ease;
        }
        
        .icon-copy svg {
            width: 100%;
            height: 100%;
            display: block;
            color: var(--card-current-text, var(--text-main));
            pointer-events: none;
        }

        .card-copy:hover .icon-copy {
            opacity: 0.4;
        }

        .card-copy:active .icon-copy {
            transform: scale(0.95);
            opacity: 0.8;
        }

        .copy-label {
            position: absolute;
            right: 32px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 0.65rem;
            letter-spacing: 0.3px;
            color: var(--card-current-text, var(--text-main));
            opacity: 0;
            white-space: nowrap;
            pointer-events: none;
            transition: opacity 0.2s ease;
        }

        .card-copy.show-copied .copy-label {
            opacity: 0.45;
        }

        /* CONTROLS */
        .controls {
            position: fixed;
            left: 0;
            right: 0;
            bottom: var(--controls-offset-bottom);
            height: var(--controls-height);
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 30px;
            padding: 0 20px;
            box-sizing: border-box;
            transition: opacity 0.2s ease;
            z-index: 1000;
            pointer-events: none;
        }
        .controls.hidden { opacity: 0; pointer-events: none; }

        .bottom-nav {
            position: fixed;
            left: 0;
            right: 0;
            bottom: 0;
            padding: 0 var(--bottom-nav-side-padding) var(--bottom-nav-bottom-padding);
            box-sizing: border-box;
            z-index: 950;
            pointer-events: none;
        }

        .bottom-nav-shell {
            position: relative;
            display: flex;
            align-items: center;
            width: fit-content;
            height: var(--bottom-nav-height);
            max-width: min(560px, calc(100vw - (var(--bottom-nav-side-padding) * 2)));
            margin: 0 auto;
            box-sizing: border-box;
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 999px;
            background: rgba(17,17,17,0.82);
            box-shadow: 0 12px 30px rgba(0,0,0,0.35);
            backdrop-filter: blur(18px);
            -webkit-backdrop-filter: blur(18px);
            overflow: hidden;
            pointer-events: auto;
            transform: translateX(0);
            transform-origin: left center;
            transition:
                width 0.4s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
                border-color 0.25s ease,
                background 0.25s ease,
                box-shadow 0.3s ease;
        }

        .bottom-nav-shell::before,
        .bottom-nav-shell::after {
            content: "";
            position: absolute;
            top: 0;
            bottom: 0;
            width: 30px;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease;
        }

        .bottom-nav-shell::before {
            left: 0;
            background: linear-gradient(90deg, rgba(17,17,17,0.96) 0%, rgba(17,17,17,0) 100%);
        }

        .bottom-nav-shell::after {
            right: 0;
            background: linear-gradient(270deg, rgba(17,17,17,0.96) 0%, rgba(17,17,17,0) 100%);
        }

        .bottom-nav-shell.has-left-overflow::before,
        .bottom-nav-shell.has-right-overflow::after {
            opacity: 1;
        }

        .bottom-nav-shell.is-collapsed {
            width: var(--bottom-nav-collapsed-size);
            height: var(--bottom-nav-collapsed-size);
            margin-left: 0;
            margin-right: auto;
            overflow: visible;
            transform: translateX(0);
            border-color: rgba(255,255,255,0.12);
            background: rgba(15,15,15,0.92);
            box-shadow: 0 14px 32px rgba(0,0,0,0.48);
        }

        .bottom-nav-shell.is-collapsed::before,
        .bottom-nav-shell.is-collapsed::after {
            opacity: 0;
        }

        .bottom-nav-precollapsed .bottom-nav-shell {
            width: var(--bottom-nav-collapsed-size);
            height: var(--bottom-nav-collapsed-size);
            margin-left: 0;
            margin-right: auto;
            overflow: visible;
            transform: translateX(0);
            transition: none;
        }

        .bottom-nav-precollapsed .bottom-nav-shell::before,
        .bottom-nav-precollapsed .bottom-nav-shell::after {
            opacity: 0;
        }

        .bottom-nav-viewport {
            flex: 0 1 auto;
            min-width: 0;
            overflow: hidden;
            transition:
                opacity 0.28s ease,
                transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
        }

        .bottom-nav-shell.is-collapsed .bottom-nav-viewport {
            flex: 0 0 0;
            width: 0;
            opacity: 0;
            transform: translateX(-24px);
            pointer-events: none;
        }

        .bottom-nav-precollapsed .bottom-nav-viewport {
            flex: 0 0 0;
            width: 0;
            opacity: 0;
            transform: translateX(-24px);
            pointer-events: none;
            transition: none;
        }

        .bottom-nav-scroll {
            display: flex;
            align-items: center;
            gap: 8px;
            min-height: var(--bottom-nav-height);
            padding: 5px 8px 5px 18px;
            overflow-x: auto;
            overflow-y: hidden;
            scroll-snap-type: x proximity;
            scroll-padding-left: 18px;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior-x: contain;
            scrollbar-width: none;
            touch-action: pan-x;
        }

        .bottom-nav-scroll::-webkit-scrollbar {
            display: none;
        }

        .bottom-nav-scroll.is-demo-scrolling {
            scroll-snap-type: none;
        }

        .bottom-nav-link {
            flex: 0 0 auto;
            position: relative;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-height: 34px;
            padding: 0 13px;
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 999px;
            background: rgba(255,255,255,0.04);
            color: #d5d5d5;
            font: inherit;
            font-size: 0.82rem;
            font-weight: 500;
            line-height: 1;
            letter-spacing: 0.01em;
            white-space: nowrap;
            cursor: pointer;
            scroll-snap-align: start;
            transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
        }

        .bottom-nav-label {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            line-height: 1;
        }

        .bottom-nav-emoji {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 0.95em;
            line-height: 1;
            transform: translateY(-0.5px);
        }

        .bottom-nav-link:active {
            background: rgba(255,255,255,0.1);
            border-color: rgba(255,255,255,0.16);
            color: #f2f2f2;
        }

        .bottom-nav-badge-dot {
            position: absolute;
            top: -3px;
            right: -3px;
            width: 9px;
            height: 9px;
            border-radius: 999px;
            background: #ff3b30;
            box-shadow: 0 0 0 2px rgba(17,17,17,0.94);
            pointer-events: none;
        }

        .bottom-nav-toggle-badge {
            opacity: 0;
            transform: scale(0.7);
            transition: opacity 0.2s ease, transform 0.2s ease;
        }

        .bottom-nav-toggle.has-badge .bottom-nav-toggle-badge {
            opacity: 0;
        }

        .bottom-nav-shell.is-collapsed .bottom-nav-toggle.has-badge .bottom-nav-toggle-badge,
        .bottom-nav-precollapsed .bottom-nav-toggle.has-badge .bottom-nav-toggle-badge {
            opacity: 1;
            transform: scale(1);
        }

        .bottom-nav-toggle {
            position: relative;
            flex: 0 0 auto;
            width: var(--bottom-nav-toggle-size);
            height: var(--bottom-nav-toggle-size);
            margin: 0 var(--bottom-nav-toggle-gap) 0 0;
            border: none;
            border-radius: 999px;
            background: rgba(255,255,255,0.05);
            color: #d7d7d7;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition:
                background 0.2s ease,
                color 0.2s ease,
                transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
        }

        .bottom-nav-shell.is-collapsed .bottom-nav-toggle {
            position: absolute;
            inset: var(--bottom-nav-toggle-gap);
            width: auto;
            height: auto;
            margin: 0;
            background: rgba(255,255,255,0.08);
        }

        .bottom-nav-precollapsed .bottom-nav-toggle {
            position: absolute;
            inset: var(--bottom-nav-toggle-gap);
            width: auto;
            height: auto;
            margin: 0;
            background: rgba(255,255,255,0.08);
            transition: none;
        }

        .bottom-nav-toggle:active {
            background: rgba(255,255,255,0.12);
            transform: scale(0.96);
        }

        .bottom-nav-toggle-icon {
            position: absolute;
            inset: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition:
                opacity 0.2s ease,
                transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
        }

        .bottom-nav-toggle-icon svg {
            width: 16px;
            height: 16px;
            display: block;
            fill: none;
            stroke: currentColor;
            stroke-width: 1.9;
            stroke-linecap: round;
            stroke-linejoin: round;
        }

        .bottom-nav-toggle-emoji {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 15px;
            line-height: 1;
            transform: translateY(-0.5px);
        }

        .bottom-nav-toggle-close {
            opacity: 1;
            transform: scale(1) rotate(0deg);
        }

        .bottom-nav-toggle-orbit {
            opacity: 0;
            transform: scale(0.7) rotate(-14deg);
        }

        .bottom-nav-shell.is-collapsed .bottom-nav-toggle-close {
            opacity: 0;
            transform: scale(0.72) rotate(18deg);
        }

        .bottom-nav-shell.is-collapsed .bottom-nav-toggle-orbit {
            opacity: 1;
            transform: scale(1) rotate(0deg);
        }

        .bottom-nav-precollapsed .bottom-nav-toggle-close {
            opacity: 0;
            transform: scale(0.72) rotate(18deg);
            transition: none;
        }

        .bottom-nav-precollapsed .bottom-nav-toggle-orbit {
            opacity: 1;
            transform: scale(1) rotate(0deg);
            transition: none;
        }

        .btn {
            border-radius: 50%; border: 1px solid #333;
            background: #111; color: var(--text-main); 
            cursor: pointer; display: flex; justify-content: center; align-items: center;
            transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            z-index: 1001; pointer-events: auto; 
            -webkit-user-select: none; touch-action: manipulation;
            box-shadow: 0 10px 20px rgba(0,0,0,0.5);
        }
        
        .btn-main { width: 70px; height: 70px; font-size: 1.8rem; }
        .btn-add { width: 50px; height: 50px; color: #555; border-color: #222; background: transparent; box-shadow: none; }
        .btn-add svg {
            width: 22px;
            height: 22px;
            display: block;
            stroke: currentColor;
            stroke-width: 2.2;
            stroke-linecap: round;
            fill: none;
        }
        .btn.hidden-btn { opacity: 0; transform: scale(0.5); pointer-events: none; }
        
        .btn-yes:active,
        .btn-yes.is-pressed { border-color: var(--accent); color: var(--accent); background: #222; transform: scale(0.95); }
        .btn-no:active,
        .btn-no.is-pressed { border-color: var(--reject); color: var(--reject); background: #222; transform: scale(0.95); }
        .btn-add:active,
        .btn-add.is-pressed { color: #fff; border-color: #fff; background: #222; transform: scale(0.95); box-shadow: 0 0 15px rgba(255,255,255,0.1); }

        /* DRAG & DROP OVERLAY */
        #dragOverlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0, 0, 0, 0.85);
            z-index: 5000;
            display: flex; flex-direction: column; justify-content: center; align-items: center;
            pointer-events: none; opacity: 0; transition: opacity 0.2s;
            backdrop-filter: blur(5px);
        }
        #dragOverlay.active { opacity: 1; pointer-events: auto; }
        .drag-box {
            width: 80%; height: 60%;
            border: 2px dashed var(--accent);
            border-radius: 24px;
            display: flex; flex-direction: column; justify-content: center; align-items: center;
            color: var(--accent);
            background: rgba(76, 175, 80, 0.1);
        }
        .drag-text { margin-top: 20px; font-size: 1.2rem; font-weight: 600; text-align: center; }
        .drag-icon { font-size: 3rem; }

        /* LIBRARY & MODALS */
        .library-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg); z-index: 2000; display: flex; flex-direction: column; transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
        .library-overlay.open { transform: translateY(0); }
        
        .lib-header { 
            padding: 15px 20px; 
            display: flex; justify-content: space-between; align-items: center; 
            border-bottom: 1px solid #222; flex-shrink: 0; 
            height: var(--top-bar-row-height); box-sizing: content-box;
        }
        
        .lib-title { font-size: 1.5rem; font-weight: 800; line-height: 1; display: flex; align-items: center; min-height: var(--top-bar-row-height); }
        
        .lib-actions { display: flex; align-items: center; }
        .lib-refresh {
            background: none; border: none; color: var(--text-dim);
            display: flex; align-items: center; justify-content: center;
            padding: 8px; cursor: pointer; transition: color 0.2s;
            margin-right: -5px; 
        }
        .lib-refresh:active { color: var(--text-main); }
        .lib-refresh:disabled {
            opacity: 0.35;
            cursor: default;
            pointer-events: none;
        }
        .lib-refresh svg { width: 20px; height: 20px; fill: currentColor; }
        @keyframes spin { 100% { transform: rotate(360deg); } }
        .icon-spin svg { animation: spin 1s linear infinite; }

        .lib-close {
            margin-right: -10px;
            align-self: center;
        }

        .lib-close svg {
            fill: none;
            stroke: currentColor;
            width: 36px;
            height: 36px;
            stroke-width: 2.7;
            stroke-linecap: round;
            transform: none;
        }

        .lib-content { flex: 1; overflow-y: auto; padding: 20px; -webkit-overflow-scrolling: touch; }
        .lib-footer { padding: 20px; background: var(--bg); border-top: 1px solid #222; flex-shrink: 0; }
        
        .lib-section-header { 
            display: flex; justify-content: space-between; align-items: center; 
            margin-bottom: 15px; 
        }
        
        .lib-subtitle { 
            font-size: 0.8rem; text-transform: uppercase; 
            color: var(--text-dim); letter-spacing: 1px; font-weight: 700; 
            margin: 0;
        }
        
        .lib-footer .lib-subtitle { margin-bottom: 15px; }
        
        .deck-list { display: flex; flex-direction: column; gap: 10px; }
        .deck-item { background: var(--card-bg); padding: 0 15px; height: 70px; border-radius: 12px; border: 1px solid #333; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
        .deck-info { display: flex; flex-direction: column; gap: 4px; }
        .deck-name { font-weight: 600; font-size: 1rem; }
        .deck-count { font-size: 0.8rem; color: #666; }
        .deck-action { color: var(--reject); font-size: 1.2rem; cursor: pointer; padding: 10px; display: flex; align-items: center; justify-content: center; height: 100%; }
        .deck-placeholder { width: 40px; } 
        .add-deck-btn { width: 100%; padding: 15px; border: 1px dashed #444; border-radius: 12px; color: var(--text-dim); background: transparent; font-size: 0.9rem; cursor: pointer; margin-bottom: 15px; transition: 0.2s; flex-shrink: 0; }
        .add-deck-btn:active { background: #222; color: #fff; border-color: #666; }
        .data-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
        .action-btn { background: #1a1a1a; border: 1px solid #444; color: var(--text-main); padding: 15px; border-radius: 12px; font-size: 0.9rem; cursor: pointer; text-align: center; }
        .action-btn:active { background: #333; }
        .backup-restore-note { margin: 14px 2px 0; font-size: 0.84rem; line-height: 1.45; color: var(--text-dim); }
        .inline-action-btn { padding: 0; border: none; background: none; color: var(--text-main); font: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
        .inline-action-btn:active { color: #fff; }

        .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); backdrop-filter: blur(10px); display: none; justify-content: center; align-items: center; z-index: 3000; opacity: 0; transition: opacity 0.2s; will-change: opacity; }
        .modal.open { display: flex; opacity: 1; }
        .modal-content { background: #1a1a1a; padding: 25px; border-radius: 24px; width: 85%; max-width: 320px; border: 1px solid #333; box-shadow: 0 20px 60px rgba(0,0,0,0.9); transform: scale(0.95); transition: transform 0.2s; text-align: center; }
        .modal.open .modal-content { transform: scale(1); }
        .modal-title { font-size: 1.1rem; font-weight: bold; margin-bottom: 10px; color: #fff; }
        .modal-desc { font-size: 0.9rem; color: #aaa; margin-bottom: 25px; line-height: 1.4; }
        .modal-input { width: 100%; background: #000; border: 1px solid #333; color: white; padding: 12px; border-radius: 8px; font-size: 1rem; box-sizing: border-box; margin-bottom: 20px; outline: none; }
        .modal-actions { display: flex; gap: 10px; }
        .modal-actions-single { justify-content: center; }
        .modal-actions-single .modal-btn { max-width: 140px; }
        .modal-btn { flex: 1; padding: 12px; border-radius: 12px; border: none; font-size: 1rem; font-weight: 600; cursor: pointer; }
        .btn-cancel { background: #3a3a3a; color: #fff; }
        .btn-confirm { background: var(--accent); color: #000; }
        .btn-confirm-delete { background: var(--reject); color: #fff; }

        .console-link { position: fixed; bottom: calc(var(--controls-reserve) + 10px); left: 10px; color: #333; font-size: 0.7rem; text-decoration: none; cursor: pointer; z-index: 200; }
        .console-link[hidden] { display: none; }
        #debugConsole { position: fixed; bottom: 0; left: 0; width: 100%; height: 40vh; background: #0a0a0a; border-top: 1px solid #333; display: none; flex-direction: column; z-index: 4000; font-family: monospace; padding: 10px; box-sizing: border-box; color: #0f0; }
        .debug-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #222; }
        
        .debug-btn {
            background: #333; color: #fff; border: 1px solid #555; padding: 0 10px; 
            cursor: pointer; font-size: 0.8rem;
        }
        .debug-btn:active { background: #555; }
        .debug-btn.is-active { background: #0b4f28; border-color: #178547; color: #caffdc; }

        @media (max-width: 768px) {
            #stage {
                padding: 20px;
                margin-bottom: var(--controls-reserve);
            }

        }
    
