/* Tokens imported via variables.css (linked from mc-script.html) */

        /* ── Reset & base ──────────────────────────────────────────────────── */
        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
        html, body {
            width: 100%; height: 100%;
            background: #0a0a14; color: #fff;
            font-family: 'Noto Sans JP', "Helvetica Neue", sans-serif;
            -webkit-font-smoothing: antialiased;
            touch-action: manipulation;
        }
        body {
            padding-top: env(safe-area-inset-top);
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
            padding-bottom: env(safe-area-inset-bottom);
            animation: pageLoad 200ms ease-out;
        }

        /* Scrollbar — dark theme */
        ::-webkit-scrollbar { width: 8px; height: 8px; }
        ::-webkit-scrollbar-track { background: var(--shirofes-black, #0c0c1a); }
        ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
        ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }
        * { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) var(--shirofes-black, #0c0c1a); }

        /* Custom checkboxes */
        input[type="checkbox"] {
            appearance: none;
            -webkit-appearance: none;
            width: 18px;
            height: 18px;
            border: 2px solid var(--border-color, #2a2a4a);
            border-radius: 4px;
            background: transparent;
            cursor: pointer;
            position: relative;
            vertical-align: middle;
            transition: background 0.15s, border-color 0.15s;
        }
        input[type="checkbox"]:checked {
            background: var(--shirofes-red, #E50012);
            border-color: var(--shirofes-red, #E50012);
        }
        input[type="checkbox"]:checked::after {
            content: '';
            position: absolute;
            left: 4px;
            top: 1px;
            width: 6px;
            height: 10px;
            border: solid #fff;
            border-width: 0 2px 2px 0;
            transform: rotate(45deg);
        }

        button:focus-visible, a:focus-visible, input:focus-visible {
            outline: 2px solid var(--shirofes-red);
            outline-offset: 3px;
            box-shadow: 0 0 0 4px rgba(229,0,18,0.18);
        }
        @media (prefers-reduced-motion: reduce) {
            *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
        }
        @keyframes pageLoad { from { opacity: 0; } to { opacity: 1; } }

        /* ── Stage picker overlay ────────────────────────────────────────── */
        #stagePicker {
            position: fixed; inset: 0; z-index: 200;
            background: #0a0a14;
            display: flex; flex-direction: column; align-items: center; justify-content: center;
            gap: 1.5rem; padding: 2rem;
        }
        #stagePicker h1 {
            font-size: 2rem; letter-spacing: 0.1em; color: var(--shirofes-red);
        }
        #stagePicker p {
            font-size: 1rem; font-family: 'Helvetica Neue', sans-serif; color: var(--text-secondary);
        }
        #stagePickerGrid {
            display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem;
            width: 100%; max-width: 420px;
        }
        .stage-pick-btn {
            background: #1a1a2e; border: 2px solid #333; border-radius: 8px;
            color: #fff; font-family: 'Noto Sans JP', sans-serif; font-size: 1.1rem;
            letter-spacing: 0.05em; padding: 1.1rem 0.75rem; text-align: center;
            cursor: pointer; -webkit-tap-highlight-color: transparent;
            transition: border-color 0.15s, background 0.15s; min-height: 44px;
        }
        .stage-pick-btn:active { border-color: var(--shirofes-red); background: #2a0008; }

        /* ── Main layout ───────────────────────────────────────────────────── */
        #scriptLayout {
            width: 100%; height: 100vh;
            display: flex; flex-direction: column;
        }

        /* ── Top bar ───────────────────────────────────────────────────────── */
        #topBar {
            flex: 0 0 auto;
            background: rgba(12,12,26,0.97); backdrop-filter: blur(12px);
            border-bottom: 2px solid var(--shirofes-red);
            padding: 0.75rem 1rem;
            display: flex; align-items: center; gap: 1rem;
            min-height: 56px;
        }
        #wordmark {
            font-size: 0.9rem; font-weight: 900; letter-spacing: 0.12em;
            color: var(--text-primary); flex-shrink: 0;
        }
        #stageName {
            flex: 1; text-align: center;
            font-size: 1rem; font-weight: 700; color: var(--text-secondary);
            text-transform: uppercase;
        }
        #viewModeGroup {
            display: flex; gap: 0.3rem; flex-shrink: 0;
        }
        .view-btn {
            background: rgba(255,255,255,0.08); border: 1px solid var(--border-color);
            border-radius: 4px; color: var(--text-secondary);
            font-size: 0.8rem; font-weight: 600; padding: 0.45rem 0.65rem;
            cursor: pointer; min-height: 44px; min-width: 44px;
            transition: background 0.15s, border-color 0.15s;
            -webkit-tap-highlight-color: transparent;
        }
        .view-btn.active {
            background: var(--shirofes-red); color: #fff; border-color: var(--shirofes-red);
        }
        .view-btn:active { opacity: 0.8; }

        #columnToggle, #liveBtn, #autoScrollBtn, #printBtn, #pdfBtn, .font-btn {
            background: rgba(255,255,255,0.08); border: 1px solid var(--border-color);
            border-radius: 4px; color: var(--text-secondary);
            font-size: 1rem; padding: 0.45rem 0.65rem; cursor: pointer;
            min-height: 44px; min-width: 44px; display: flex; align-items: center;
            justify-content: center;
            transition: background 0.15s; -webkit-tap-highlight-color: transparent;
        }
        #columnToggle svg, #liveBtn svg, #autoScrollBtn svg, #printBtn svg, #pdfBtn svg, #notesToggle svg {
            width: 20px;
            height: 20px;
            stroke-width: 1.8;
        }
        #columnToggle:active, #liveBtn:active, #autoScrollBtn:active, #printBtn:active, #pdfBtn:active, .font-btn:active { opacity: 0.8; }
        #autoScrollBtn.active {
            background: var(--info); color: #fff; border-color: var(--info);
        }
        #pdfBtn.generating {
            pointer-events: none; opacity: 0.5;
        }

        .font-btn {
            font-size: 0.9rem; font-weight: 700; padding: 0.45rem 0.5rem;
        }

        /* ── PDF generation overlay ──────────────────────────────────────── */
        #pdfOverlay {
            position: fixed; inset: 0; z-index: 300;
            background: rgba(0,0,0,0.85);
            display: none; flex-direction: column; align-items: center; justify-content: center;
            gap: 1rem; color: #fff;
        }
        #pdfOverlay.visible { display: flex; }
        #pdfOverlay .spinner {
            width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.2);
            border-top-color: var(--shirofes-red); border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }
        @keyframes spin { to { transform: rotate(360deg); } }
        #pdfOverlay p { font-size: 1rem; color: var(--text-secondary); }

        /* ── Column toggle panel ───────────────────────────────────────────── */
        #columnPanel {
            position: fixed; top: 56px; right: 1rem; z-index: 150;
            background: rgba(12,12,26,0.98); backdrop-filter: blur(12px);
            border: 1px solid var(--border-color); border-radius: 6px;
            padding: 0.75rem; min-width: 200px; display: none;
        }
        #columnPanel.open { display: block; }
        #columnPanel label {
            display: flex; align-items: center; gap: 0.5rem;
            font-size: 0.85rem; color: var(--text-secondary);
            padding: 0.4rem 0.5rem; cursor: pointer; margin: 0;
            -webkit-user-select: none; user-select: none;
        }
        #columnPanel input[type="checkbox"] {
            -webkit-appearance: none;
            appearance: none;
            width: 20px; height: 20px;
            border: 2px solid var(--border-color, #2a2a4a);
            border-radius: 4px;
            background: transparent;
            cursor: pointer;
            position: relative;
            vertical-align: middle;
            transition: background 0.15s, border-color 0.15s;
        }
        #columnPanel input[type="checkbox"]:checked {
            background: var(--shirofes-red, #E50012);
            border-color: var(--shirofes-red, #E50012);
        }
        #columnPanel input[type="checkbox"]:checked::after {
            content: '';
            position: absolute;
            left: 5px; top: 1px;
            width: 6px; height: 12px;
            border: solid #fff;
            border-width: 0 2px 2px 0;
            transform: rotate(45deg);
        }

        /* ── Connection status ─────────────────────────────────────────────── */
        #connDot {
            width: 8px; height: 8px; border-radius: 50%;
            background: var(--success); flex-shrink: 0;
            transition: background 0.3s;
        }
        #connDot.offline { background: var(--error); }

        /* ── Scripts scroll area + loading overlay ─────────────────────────── */
        #scriptsMain {
            flex: 1;
            min-height: 0;
            position: relative;
            display: flex;
            flex-direction: column;
        }
        #scriptsContainer {
            flex: 1; overflow-y: auto; overflow-x: hidden;
            padding: 0.75rem 1rem 6rem; max-width: 800px; margin: 0 auto; width: 100%;
            -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
        }
        #scriptsLoadingState {
            display: none;
            position: absolute;
            inset: 0;
            z-index: 5;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 1rem;
            background: rgba(10, 10, 20, 0.92);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            color: var(--text-secondary);
            text-align: center;
            padding: 1.5rem;
        }
        #scriptsLoadingState.visible { display: flex; }
        #scriptsLoadingState .spinner {
            width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.2);
            border-top-color: var(--shirofes-red); border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }
        #scriptsLoadingState p { font-size: 0.95rem; line-height: 1.5; max-width: 22rem; }

        /* ── Search bar ────────────────────────────────────────────────────── */
        #searchBar {
            position: sticky; top: 0; z-index: 15;
            background: var(--shirofes-black);
            border-bottom: 1px solid var(--border-color);
            padding: 0.7rem 1.1rem;
            display: flex; align-items: center; gap: 0.5rem;
        }
        #searchMeta {
            flex: 0 0 auto;
            min-width: 0;
            margin-right: 0.3rem;
        }
        .search-title {
            font-size: 0.75rem; font-weight: 800; letter-spacing: 0.06em;
            color: var(--text-primary); line-height: 1.2;
        }
        .search-hint {
            font-size: 0.75rem; color: var(--text-tertiary); line-height: 1.2;
            max-width: 24rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        }
        #searchInput {
            flex: 1; background: #1a1a2e; border: 1px solid var(--border-color);
            color: var(--text-primary); font-size: 0.95rem;
            padding: 0.45rem 0.75rem; border-radius: 4px;
            font-family: 'Helvetica Neue', sans-serif;
            min-height: 44px;
        }
        #searchInput::placeholder { color: var(--text-tertiary); }
        #searchClear {
            background: transparent; border: none; color: var(--text-secondary);
            font-size: 1.2rem; cursor: pointer; padding: 0.3rem;
            min-height: 44px; min-width: 44px; display: flex; align-items: center; justify-content: center;
            -webkit-tap-highlight-color: transparent;
            transition: color 0.15s;
        }
        #searchClear:active { color: var(--text-primary); }
        @media (max-width: 900px) {
            #searchBar { flex-wrap: wrap; gap: 0.45rem; }
            #searchMeta { flex: 1 1 100%; margin-right: 0; }
            .search-hint { max-width: none; white-space: normal; }
            #searchInput { flex: 1 1 auto; width: calc(100% - 52px); }
        }

        /* ── Empty state ───────────────────────────────────────────────────── */
        #emptyState {
            text-align: center; padding: 3rem 1.5rem;
            color: var(--text-tertiary); display: none;
        }
        #emptyState.visible { display: block; }
        #emptyState p { font-size: 1rem; line-height: 1.6; margin-top: 1rem; }

        /* ── Script section card ──────────────────────────────────────────── */
        .script-section {
            background: var(--shirofes-black-alt); border-left: 6px solid var(--border-color);
            border-radius: 6px; padding: 1.2rem; margin-bottom: 1rem;
            scroll-margin-top: 100px;
            transition: border-color 0.3s, box-shadow 0.3s;
        }
        .script-section.now-section {
            border-left-color: var(--warning); box-shadow: 0 0 16px rgba(245,158,11,0.4);
            animation: pulse-border 1.4s ease-in-out infinite;
        }
        @keyframes pulse-border {
            0%, 100% { box-shadow: 0 0 16px rgba(245,158,11,0.4); }
            50% { box-shadow: 0 0 24px rgba(245,158,11,0.7); }
        }

        /* Phase colors */
        .script-section.setup-phase { border-left-color: #555; }
        .script-section.checkin-phase { border-left-color: var(--info); }
        .script-section.prelim-phase { border-left-color: var(--warning); }
        .script-section.tournament-phase { border-left-color: var(--shirofes-red); }
        .script-section.complete-phase { border-left-color: var(--success); }

        .section-time {
            font-size: 0.75em; color: var(--text-tertiary); margin-bottom: 0.5rem;
            font-variant-numeric: tabular-nums;
        }
        .section-label {
            font-size: 1em; font-weight: 700; color: var(--text-primary);
            margin-bottom: 0.75rem;
        }
        .section-script {
            font-size: 1.1em; line-height: 1.6; color: var(--text-primary);
            margin-bottom: 0.75rem; white-space: pre-wrap; word-wrap: break-word;
        }
        .section-script.hidden { display: none; }

        /* ── Yomigana (reading hints) ──────────────────────────────────────── */
        .yomigana {
            font-size: 0.8em; color: var(--text-tertiary);
            margin-top: 0.3rem; margin-bottom: 0.6rem;
            font-weight: 400;
        }
        .yomigana.hidden { display: none; }

        /* ── Notes sections ────────────────────────────────────────────────── */
        .notes-toggle {
            font-size: 0.8em; color: var(--text-secondary); text-decoration: underline;
            cursor: pointer; padding: 0.3rem 0; margin-top: 0.5rem;
            -webkit-tap-highlight-color: transparent;
            background: transparent; border: none; font: inherit; text-align: left;
        }
        .notes-content {
            display: none; margin-top: 0.6rem; padding: 0.6rem 0.75rem;
            background: rgba(0,0,0,0.3); border-radius: 4px; border-left: 3px solid var(--text-tertiary);
            font-size: 0.9em; line-height: 1.5; color: var(--text-secondary);
        }
        .notes-content.visible { display: block; }

        /* ── Global notes toggle ─────────────────────────────────────────── */
        body.notes-hidden .notes-toggle { display: none !important; }
        body.notes-hidden .notes-content { display: none !important; }
        body.notes-visible .notes-content { display: block !important; }
        body.notes-visible .notes-toggle { display: none !important; }

        .elapsed-timer {
            font-size: 0.78em; color: var(--text-tertiary);
            font-variant-numeric: tabular-nums; margin-top: 0.35rem; font-weight: 500;
            display: flex; align-items: center; gap: 0.35rem;
        }
        .elapsed-timer.overtime {
            color: var(--warning);
        }
        .elapsed-timer.stale {
            color: var(--text-tertiary); opacity: 0.6;
        }

        .script-section.manual-now {
            border-left-color: var(--info); box-shadow: 0 0 12px rgba(59,130,246,0.4);
        }

        .battle-divider {
            position: sticky; top: 0; z-index: 10;
            padding: 0.6rem 0.75rem; margin: 1.2rem 0 0.6rem;
            border-top: 2px solid var(--shirofes-red);
            font-size: 0.85em; font-weight: 900;
            color: var(--shirofes-red); letter-spacing: 0.08em; text-transform: uppercase;
            background: #0a0a14;
        }

        /* ── 3-column grid layout for scripts ──────────────────────────────── */
        .script-section-grid {
            display: grid;
            grid-template-columns: 5rem 10rem 1fr;
            gap: 0 1rem;
            align-items: start;
        }
        .script-section-grid .section-time {
            font-variant-numeric: tabular-nums;
            white-space: nowrap;
        }
        .script-section-grid .section-label {
            margin-bottom: 0;
        }
        .script-section-grid .section-script-col {
            min-width: 0;
        }

        /* ── Done (past) sections ──────────────────────────────────────── */
        .script-section.done-section {
            opacity: 0.4; border-left-color: var(--border-color) !important;
            box-shadow: none !important; animation: none !important;
        }

        /* ── Live tracking active state ────────────────────────────────── */
        #liveBtn.active {
            background: var(--success); color: #fff; border-color: var(--success);
        }

        /* ── Print stylesheet ────────────────────────────────────────────── */
        /* ── Print: hide the SPA shell, show the injected print tree ────── */
        /* The JS buildPrintView() creates #shirofes-print-root with all     */
        /* inline styles — no flex, no viewport units, no overflow clips.    */
        @media print {
            html, body {
                height: auto !important;
                width: auto !important;
                min-height: 0 !important;
                overflow: visible !important;
                background: #fff !important;
                color: #000 !important;
                opacity: 1 !important;
                animation: none !important;
                position: static !important;
            }

            /* Hide the entire SPA shell */
            #scriptLayout, #stagePicker, #pdfOverlay {
                display: none !important;
            }

            /* The print tree is a flat block-layout div — just ensure it shows */
            #shirofes-print-root {
                display: block !important;
                visibility: visible !important;
                opacity: 1 !important;
            }

            @page {
                margin: 1.5cm;
                size: A4;
            }
        }
