/* カスタムプロパティをレイヤー化して構造化 */
@layer base, theme, components, utilities;

@layer base {
    :root {
        /* 基本寸法とレイアウト定数 */
        --space-3xs: 0.125rem; /* 2px */
        --space-2xs: 0.25rem; /* 4px */
        --space-xs: 0.5rem; /* 8px */
        --space-sm: 0.75rem; /* 12px */
        --space-md: 1rem; /* 16px */
        --space-lg: 1.25rem; /* 20px */
        --space-xl: 1.5rem; /* 24px */
        --space-2xl: 2rem; /* 32px */
        --space-3xl: 2.5rem; /* 40px */
        --space-4xl: 3rem; /* 48px */

        /* 境界線とボーダー */
        --border-width-thin: 1px;
        --border-width-thick: 2px;
        --border-radius-sm: 0.375rem;
        --border-radius-md: 0.5rem;
        --border-radius-lg: 0.75rem;
        --border-radius-full: 9999px;

        /* タイポグラフィスケール（モジュラースケール 1.25） */
        --font-size-xs: 0.8rem; /* 12.8px */
        --font-size-sm: 0.875rem; /* 14px */
        --font-size-base: 1rem; /* 16px */
        --font-size-lg: 1.125rem; /* 18px */
        --font-size-xl: 1.25rem; /* 20px */
        --font-size-2xl: 1.5625rem; /* 25px */
        --font-size-3xl: 1.953rem; /* 31.25px */

        /* 行高 */
        --line-height-tight: 1.2;
        --line-height-normal: 1.5;
        --line-height-relaxed: 1.7;

        /* Z-index管理 */
        --z-dropdown: 1000;
        --z-sticky: 1020;
        --z-fixed: 1030;
        --z-modal-backdrop: 1040;
        --z-modal: 1050;
        --z-popover: 1060;
        --z-tooltip: 1070;
        --z-toast: 1080;
    }
}

@layer theme {
    :root {
        --bg: #0a0f1c;
        --surface: #0f172a;
        --elev: #1a1f3a;
        --elev-2: #1e2548;
        --text: #f1f5f9;
        --text-secondary: #cbd5e1;
        --muted: #8896ab;
        --line: #2a3441;
        --line-subtle: #1e2936;
        --brand: #06b6d4;
        --brand-hover: #0891b2;
        --brand-2: #8b5cf6;
        --brand-gradient: linear-gradient(135deg, #06b6d4 0%, #8b5cf6 100%);
        --accent: #f59e0b;
        --success: #10b981;
        --danger: #ef4444;
        --warning: #f59e0b;
        --ring: rgba(6, 182, 212, 0.2);
        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
        --shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
        --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.25);
        --shadow-brand: 0 8px 32px rgba(6, 182, 212, 0.2);
        /* Optical nudge for select icons (tweak 0px~2px as needed) */
        --select-icon-nudge-y: 1px;
    }
}

@layer theme {
    [data-theme="light"] {
        --bg: #fafbfc;
        --surface: #ffffff;
        --elev: #ffffff;
        --elev-2: #f8fafc;
        --text: #0f172a;
        --text-secondary: #374151;
        --muted: #6b7280;
        --line: #e5e7eb;
        --line-subtle: #f3f4f6;
        --brand: #0891b2;
        --brand-hover: #0e7490;
        --brand-2: #7c3aed;
        --brand-gradient: linear-gradient(135deg, #0891b2 0%, #7c3aed 100%);
        --accent: #d97706;
        --success: #059669;
        --danger: #dc2626;
        --warning: #d97706;
        --ring: rgba(8, 145, 178, 0.15);
        --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
        --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
        --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
        --shadow-brand: 0 4px 24px rgba(8, 145, 178, 0.15);
    }

    /* ライトテーマでの滑らかな背景グラデーション */
    [data-theme="light"] html {
        background:
            /* ライトテーマ用のメイングラデーション: スクロール全体に対応 */ linear-gradient(
                135deg,
                rgba(8, 145, 178, 0.04) 0%,
                rgba(124, 58, 237, 0.03) 35%,
                rgba(217, 119, 6, 0.02) 65%,
                transparent 100%
            ),
            /* 補完的な放射グラデーション */
                radial-gradient(
                    ellipse 1800px 1000px at 20% 25%,
                    rgba(8, 145, 178, 0.025),
                    transparent 70%
                ),
            radial-gradient(
                ellipse 1600px 900px at 80% 75%,
                rgba(124, 58, 237, 0.02),
                transparent 70%
            ),
            var(--bg);
        /* 背景をコンテンツと一緒にスクロールさせる */
        background-attachment: scroll;
        /* 背景サイズをページ全体に適用 */
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }

    /* ライトテーマのbodyは透明に */
    [data-theme="light"] body {
        background: transparent;
    }
}
@layer base {
    /* Modern CSS Reset with enhanced typography */
    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

    html {
        block-size: 100%;
        /* ページ全体の背景グラデーション設定 */
        background:
            /* メイングラデーション: スクロール全体に対応 */ linear-gradient(
                135deg,
                rgba(6, 182, 212, 0.06) 0%,
                rgba(139, 92, 246, 0.04) 35%,
                rgba(245, 158, 11, 0.02) 65%,
                transparent 100%
            ),
            /* 補完的な放射グラデーション: より大きく柔らかく */
                radial-gradient(
                    ellipse 2000px 1200px at 15% 20%,
                    rgba(6, 182, 212, 0.03),
                    transparent 70%
                ),
            radial-gradient(
                ellipse 1800px 1000px at 85% 80%,
                rgba(139, 92, 246, 0.025),
                transparent 70%
            ),
            /* ベースカラー */ var(--bg);
        /* 背景をコンテンツと一緒にスクロールさせる */
        background-attachment: scroll;
        /* 背景サイズをページ全体に適用 */
        background-size: 100% 100%;
        background-repeat: no-repeat;
        /* スムーズスクロール（ユーザー設定を尊重） */
        scroll-behavior: smooth;
        /* 2025: テキストサイズ調整を防ぐ */
        -webkit-text-size-adjust: none;
        text-size-adjust: none;
    }

    body {
        /* コンテンツ高さに応じて背景を調整 */
        min-block-size: 100vh;
        min-height: 100vh; /* フォールバック */
        margin: 0;
        /* 背景は透明に - htmlから継承 */
        background: transparent;
        color: var(--text);
        font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
            "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "YuGothic", Meiryo,
            "Noto Sans JP", sans-serif;
        font-size: var(--font-size-base);
        font-weight: 400;
        line-height: var(--line-height-relaxed);
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        letter-spacing: -0.011em;
        /* 2025: オーバースクロール制御 */
        overscroll-behavior: none;
    }

    /* 2025: Accessible selection colors with oklch */
    ::selection {
        background: oklch(from var(--brand) l c h / 0.35);
        color: var(--text);
    }

    /* 2025: 改善されたフォーカス管理 */
    :focus-visible {
        outline: var(--border-width-thick) solid var(--brand);
        outline-offset: var(--space-3xs);
        border-radius: var(--border-radius-sm);
    }

    /* Respect reduced motion preferences - 2025年版 */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation: none !important;
            transition: none !important;
        }

        html {
            scroll-behavior: auto !important;
        }
    }

    /* レスポンシブ背景グラデーション最適化 */
    @media (max-width: 768px) {
        html {
            background:
                /* モバイル向け: よりシンプルで軽いグラデーション */ linear-gradient(
                    135deg,
                    rgba(6, 182, 212, 0.04) 0%,
                    rgba(139, 92, 246, 0.02) 50%,
                    transparent 100%
                ),
                radial-gradient(
                    ellipse 1200px 800px at 50% 30%,
                    rgba(6, 182, 212, 0.02),
                    transparent 80%
                ),
                var(--bg);
            /* モバイルでもスクロール幅に対応 */
            background-attachment: scroll;
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }

        /* ライトテーマ - モバイル */
        [data-theme="light"] html {
            background: linear-gradient(
                    135deg,
                    rgba(8, 145, 178, 0.03) 0%,
                    rgba(124, 58, 237, 0.015) 50%,
                    transparent 100%
                ),
                radial-gradient(
                    ellipse 1000px 600px at 50% 30%,
                    rgba(8, 145, 178, 0.015),
                    transparent 80%
                ),
                var(--bg);
            /* ライトテーマ・モバイルでもスクロール幅に対応 */
            background-attachment: scroll;
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }
    }

    @media (min-width: 1400px) {
        html {
            background:
                /* 大画面向け: より豊かなグラデーション */ linear-gradient(
                    135deg,
                    rgba(6, 182, 212, 0.08) 0%,
                    rgba(139, 92, 246, 0.06) 30%,
                    rgba(245, 158, 11, 0.03) 60%,
                    rgba(16, 185, 129, 0.02) 85%,
                    transparent 100%
                ),
                radial-gradient(
                    ellipse 2400px 1400px at 10% 15%,
                    rgba(6, 182, 212, 0.04),
                    transparent 75%
                ),
                radial-gradient(
                    ellipse 2200px 1200px at 90% 85%,
                    rgba(139, 92, 246, 0.035),
                    transparent 75%
                ),
                var(--bg);
            /* 大画面でもスクロール幅に対応 */
            background-attachment: scroll;
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }

        /* ライトテーマ - 大画面 */
        [data-theme="light"] html {
            background: linear-gradient(
                    135deg,
                    rgba(8, 145, 178, 0.06) 0%,
                    rgba(124, 58, 237, 0.045) 30%,
                    rgba(217, 119, 6, 0.025) 60%,
                    rgba(5, 150, 105, 0.015) 85%,
                    transparent 100%
                ),
                radial-gradient(
                    ellipse 2200px 1200px at 15% 20%,
                    rgba(8, 145, 178, 0.03),
                    transparent 75%
                ),
                radial-gradient(
                    ellipse 2000px 1000px at 85% 80%,
                    rgba(124, 58, 237, 0.025),
                    transparent 75%
                ),
                var(--bg);
            /* ライトテーマ・大画面でもスクロール幅に対応 */
            background-attachment: scroll;
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }
    }
}

@layer components {
    /* 2025: コンテナクエリ対応のレスポンシブコンテナ */
    .container {
        container-type: inline-size;
        max-inline-size: 960px;
        margin-inline: auto;
        padding-inline: var(--space-lg);
    }

    /* 2025: 論理プロパティを使用したユーティリティ */
    .text-start {
        text-align: start;
    }
    .text-center {
        text-align: center;
    }
    .text-end {
        text-align: end;
    }

    .block-start-auto {
        margin-block-start: auto;
    }
    .block-end-auto {
        margin-block-end: auto;
    }
    .inline-start-auto {
        margin-inline-start: auto;
    }
    .inline-end-auto {
        margin-inline-end: auto;
    }
}

@layer components {
    /* 2025: Enhanced Header Design with container queries */
    .site-header {
        position: sticky;
        inset-block-start: 0;
        z-index: var(--z-sticky);
        backdrop-filter: saturate(180%) blur(20px);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        background: oklch(from var(--surface) l c h / 0.85);
        border-block-end: var(--border-width-thin) solid var(--line-subtle);
        box-shadow: var(--shadow-sm);
        margin-block-end: var(--space-2xl);
    }

    .header-inner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-lg);
        padding-block: var(--space-lg);
    }

    .header-left {
        display: flex;
        flex-direction: column;
        gap: var(--space-xs);
    }

    .header-right {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
    }

    .brand-wrap {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
    }

    .brand-logo {
        width: 32px;
        height: 32px;
        border-radius: 10px;
        background: var(--brand-gradient);
        box-shadow: var(--shadow-brand), inset 0 1px 0 rgba(255, 255, 255, 0.2);
        position: relative;
        overflow: hidden;
    }

    .brand-logo::after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(
            135deg,
            transparent 0%,
            rgba(255, 255, 255, 0.1) 50%,
            transparent 100%
        );
        animation: shimmer 3s ease-in-out infinite;
    }
}

@keyframes shimmer {
    0%,
    100% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
}

.brand {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    margin: 0;
    color: var(--muted);
    font-size: 0.925rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

/* Theme Toggle */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--elev);
    border: 1px solid var(--line);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.theme-toggle::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--brand-gradient);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.theme-toggle:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow), 0 0 0 3px var(--ring);
    transform: translateY(-1px);
}

.theme-toggle:hover::before {
    opacity: 0.1;
}

.theme-toggle:active {
    transform: translateY(0);
    transition: transform 0.1s ease;
}

.theme-toggle .icon-moon {
    display: none;
    position: relative;
    z-index: 1;
    font-size: 1.1rem;
}

.theme-toggle .icon-sun {
    position: relative;
    z-index: 1;
    font-size: 1.1rem;
}

/* Ensure inline SVG icons in the theme toggle have consistent sizing */
.theme-toggle svg {
    width: 20px;
    height: 20px;
    display: block;
    stroke: currentColor;
    fill: none;
}

[data-theme="light"] .theme-toggle .icon-sun {
    display: inline;
}
[data-theme="light"] .theme-toggle .icon-moon {
    display: none;
}
[data-theme="dark"] .theme-toggle .icon-sun {
    display: none;
}
[data-theme="dark"] .theme-toggle .icon-moon {
    display: inline;
}

/* Enhanced Footer */
.site-footer {
    border-top: 1px solid var(--line-subtle);
    padding: 24px 0;
    color: var(--muted);
    margin-top: 48px;
    background: color-mix(in oklch, var(--surface) 50%, transparent);
}

.noscript-banner {
    margin: 8px auto 0;
    max-width: 960px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid color-mix(in oklch, var(--warning) 40%, var(--line));
    background: color-mix(in oklch, var(--warning) 18%, var(--surface));
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.footer-link {
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.footer-link:hover {
    color: var(--brand);
    background: color-mix(in oklch, var(--brand) 10%, transparent);
}

/* Card Design*/
.card {
    background: var(--elev);
    padding: var(--space-2xl);
    border-radius: var(--border-radius-lg);
    border: var(--border-width-thin) solid var(--line);
    box-shadow: var(--shadow);
    position: relative;
    /* ドロップダウンがカードの外へ展開されるため visible に変更 */
    overflow: visible;
    animation: slide-up 0.6s cubic-bezier(0.4, 0, 0.2, 1) both;
    container-type: inline-size;
}

/* コンテナクエリでカード内レイアウト調整 */
@container (max-width: 400px) {
    .card {
        padding: var(--space-lg);
    }
}

/* カードの状態管理 */
.card:has(.field:focus-within) {
    border-color: var(--brand);
    box-shadow: var(--shadow-brand);
}

/* カードが連続する場合に一定の隙間を付与 */
.card + .card {
    margin-block-start: var(--space-xl);
}

.card::before {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline: 0;
    block-size: 1px;
    background: var(--brand-gradient);
    opacity: 0.6;
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slide-up {
    from {
        transform: translateY(24px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.hero {
    margin-bottom: 24px;
    text-align: center;
    background: var(--elev-2);
    border: 1px solid var(--line-subtle);
}

.hero-title {
    margin: 0 0 12px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.3;
    color: var(--text);
}

.hero-text {
    margin: 0;
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 500;
    line-height: 1.6;
}

/* Subtitle style actually used in template */
.hero-sub {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 1rem;
}
/* index: hero head layout and mode switch */
.hero-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}
.mode-switch {
    display: flex;
    gap: 0.25rem;
}

/* Hide number input spinners (only where .no-spin is applied) */
input.no-spin[type="number"]::-webkit-outer-spin-button,
input.no-spin[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input.no-spin[type="number"] {
    -moz-appearance: textfield; /* Firefox */
    appearance: textfield;
}

/* Enhanced Form Design */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    animation-delay: 0.2s;
}

@media (max-width: 840px) {
    .form-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* フィールドラベルをモダンなデザインに */
label {
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--text);
    letter-spacing: -0.01em;
    /* ラベルとフィールドの関連性を視覚的に向上 */
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

/* 必須フィールドマーカー */
label[data-required]::after {
    content: "*";
    color: var(--danger);
    font-weight: 500;
}

.input-wrap {
    position: relative;
}

/* Iconified inputs */
.input-wrap.has-icon input,
.input-wrap.has-icon select {
    padding-inline-start: calc(var(--space-xl) + var(--space-sm));
    position: relative; /* keep below icon/suffix */
    z-index: 1;
}
.input-icon {
    position: absolute;
    inset-inline-start: var(--space-sm);
    inset-block-start: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
    font-size: 1.05rem;
    z-index: 2; /* above input */
}
.input-icon svg,
.btn-icon svg {
    inline-size: 18px;
    block-size: 18px;
    display: block;
    stroke: currentColor;
    fill: none;
}

/* Suffix eye toggle button inside inputs */
.input-suffix-btn {
    position: absolute;
    inset-inline-end: var(--space-sm);
    inset-block-start: 50%;
    transform: translateY(-50%);
    inline-size: 34px;
    block-size: 34px;
    border: none; /* 装飾なし */
    background: transparent; /* 装飾なし */
    color: var(--muted); /* アイコンはグレー */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
}
.input-suffix-btn:hover {
    background: transparent; /* 装飾なし */
    color: var(--muted);
}
.input-suffix-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}
.input-suffix-btn svg {
    inline-size: 18px;
    block-size: 18px;
    stroke: currentColor;
}

/* Input styling */
input[type="number"] {
    inline-size: 100%;
    padding: var(--space-sm) var(--space-4xl) var(--space-sm) var(--space-md);
    border: var(--border-width-thick) solid var(--line);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--border-radius-md);
    outline: none;
    font-size: var(--font-size-base);
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    accent-color: var(--brand);
}

input[type="number"]:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ring), var(--shadow);
    transform: translateY(-1px);
}

/* Text/Password Inputs */
input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--line);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    outline: none;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

/* Add space for suffix button */
.input-wrap.has-suffix input {
    padding-right: 48px;
}

/* Select (Dropdown) - Style aligned with inputs */
select {
    width: 100%;
    padding: 14px 48px 14px 16px; /* room for arrow */
    border: 1.5px solid var(--line);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    outline: none;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: pointer;
}

select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ring), var(--shadow);
    transform: translateY(-1px);
}

select:hover:not(:focus) {
    border-color: color-mix(in oklch, var(--brand) 60%, var(--line));
}

/* Custom arrow using the wrapper that already exists */
.input-wrap:has(select:not(.sr-only-select))::after {
    content: "";
    position: absolute;
    right: 14px;
    top: calc(50% + var(--select-icon-nudge-y));
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
    width: 18px;
    height: 18px;
    display: inline-block;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 18px 18px;
    /* chevron-down using currentColor */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' 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/svg%3E");
}
/* When custom select is active, hide the original leading .input-icon to avoid double icons */
.input-wrap:has(.select-custom:not([hidden])) .input-icon {
    display: none;
}

/* Hide native select visually when enhanced, keep for a11y/events */
.sr-only-select {
    position: absolute !important;
    inset: 0 auto auto 0 !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Custom select (modern dropdown) */
.select-custom {
    position: relative;
    z-index: 10000; /* 前面に */
}
.select-trigger {
    width: 100%;
    text-align: left;
    display: grid;
    grid-template-columns: 18px 1fr 18px; /* icon | label | caret */
    align-items: center;
    column-gap: 10px;
    padding: 14px 16px; /* uniform padding; grid handles icon/caret space */
    line-height: 1; /* stable vertical center basis */
    border: 1.5px solid var(--line);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    outline: none;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    box-sizing: border-box;
}
.select-trigger:hover {
    border-color: var(--brand);
}
.select-trigger:focus-visible {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ring), var(--shadow);
}
.select-leading {
    position: static;
    transform: translateY(var(--select-icon-nudge-y));
    color: var(--muted);
    font-size: 1.05rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.select-label {
    margin-left: 0; /* grid gap handles spacing */
}
.select-caret {
    position: static;
    transform: translateY(var(--select-icon-nudge-y));
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0; /* avoid baseline offset */
    width: 18px;
    height: 18px;
}
.select-caret svg {
    stroke: currentColor;
    display: block; /* align exact center in flex */
}
/* Ensure consistent sizing/alignment for select icons */
.select-leading svg,
.select-caret svg {
    width: 18px;
    height: 18px;
    display: block; /* remove baseline gap */
}
.select-list {
    position: absolute;
    z-index: 10001;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow: auto;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    border-radius: 12px;
    padding: 8px;
    font-size: 0.95rem;
}
.select-custom .select-list {
    display: none;
}
.select-custom.open .select-list {
    display: block;
}

/* ドロップダウン開時に親カードも最前面にする */
.card.raise {
    z-index: 10000;
}
.select-option {
    list-style: none;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text);
}
.select-option:hover {
    background: color-mix(in oklch, var(--brand) 10%, var(--surface));
}
.select-option[aria-selected="true"] {
    background: color-mix(in oklch, var(--brand) 18%, var(--surface));
    border: 1px solid color-mix(in oklch, var(--brand) 40%, var(--line));
}

/* グループ見出し（科目） */
.select-group {
    list-style: none;
    padding: 8px 10px 6px;
    margin: 6px 6px 4px;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0.02em;
    border-top: 1px solid var(--line-subtle);
}

/* 科目別カラー（テーマ対応の控えめな帯） */
.select-group[data-subject] {
    border-radius: 8px;
    padding: 8px 10px 6px;
}
.select-group[data-subject^="英"] {
    /* 外国語 */
    background: color-mix(in oklch, var(--brand) 12%, transparent);
    color: color-mix(in oklch, var(--brand) 85%, var(--text));
}
.select-group[data-subject^="国"] {
    /* 国語 */
    background: color-mix(in oklch, var(--accent) 12%, transparent);
    color: color-mix(in oklch, var(--accent) 85%, var(--text));
}
.select-group[data-subject^="数"] {
    /* 数学 */
    background: color-mix(in oklch, var(--success) 12%, transparent);
    color: color-mix(in oklch, var(--success) 80%, var(--text));
}
.select-group[data-subject^="理"],
.select-group[data-subject^="化"],
.select-group[data-subject^="物"],
.select-group[data-subject^="生"] {
    /* 理系科目 */
    background: color-mix(in oklch, #22c55e 12%, transparent);
    color: color-mix(in oklch, #22c55e 80%, var(--text));
}
.select-group[data-subject^="社"],
.select-group[data-subject*="地"],
.select-group[data-subject*="歴"],
.select-group[data-subject*="公"] {
    /* 社会系科目 */
    background: color-mix(in oklch, #f43f5e 12%, transparent);
    color: color-mix(in oklch, #f43f5e 80%, var(--text));
}
.select-group[data-subject="その他"] {
    background: color-mix(in oklch, var(--muted) 10%, transparent);
    color: var(--muted);
}

input[type="text"]:focus,
input[type="password"]:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ring), var(--shadow);
    transform: translateY(-1px);
}

/* Alerts */
.alert {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: color-mix(in oklch, var(--danger) 15%, var(--surface));
    color: var(--text);
}

.alert.error {
    background: color-mix(in oklch, var(--danger) 22%, var(--surface));
    border-color: color-mix(in oklch, var(--danger) 40%, var(--line));
}

/* Generic Button (for <a> and others) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 12px;
    text-decoration: none;
    background: var(--elev);
    color: var(--text);
    border: 1px solid var(--line);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow), 0 0 0 3px var(--ring);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--line);
}

.btn-ghost {
    background: transparent;
    border: 1px solid transparent;
}

.btn-sm {
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.95rem;
}

/* Login Card */
.login-card {
    max-width: 420px;
    margin: 0 auto;
}
.login-title {
    margin: 0 0 8px;
    font-size: 1.4rem;
    font-weight: 700;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.login-subtitle {
    margin: 0 0 16px;
    color: var(--muted);
    font-weight: 500;
}

/* Brand ghost button (for header login/logout) */
.btn-ghost-brand {
    color: var(--brand);
    border-color: color-mix(in oklch, var(--brand) 50%, var(--line));
}
.btn-ghost-brand:hover {
    color: white;
    background: var(--brand-gradient);
    border-color: transparent;
    box-shadow: var(--shadow-brand), 0 0 0 3px var(--ring);
}
/* Active state for header nav buttons */
.btn-ghost-brand.is-active {
    color: white;
    background: var(--brand-gradient);
    border-color: transparent;
    box-shadow: var(--shadow-brand);
}
.btn-ghost-brand.is-active:hover {
    box-shadow: var(--shadow-brand), 0 0 0 3px var(--ring);
}

input[type="number"]:hover:not(:focus) {
    border-color: color-mix(in oklch, var(--brand) 60%, var(--line));
}

.suffix {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 500;
    pointer-events: none;
    z-index: 2; /* above input */
}

fieldset.field {
    border: 1.5px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

legend {
    padding: 0 12px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.925rem;
}

.help {
    color: var(--muted);
    font-size: 0.825rem;
    font-weight: 500;
    margin-top: 2px;
}
.radios {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 8px;
}

@media (max-width: 640px) {
    .radios {
        grid-template-columns: 1fr;
    }
}

.radio {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1.5px solid var(--line);
    background: var(--surface);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

/* 単語帳選択セクションの左右2カラムレイアウト */
/* 左右分割を確実にするためのフレックスフォールバック */
.series-grid {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    width: 100%;
}
.series-grid > fieldset {
    flex: 0 0 280px; /* 左の科目カラムを固定幅に */
    max-width: 320px;
}
.series-grid > .field {
    flex: 1 1 auto; /* 右の単語帳は可変 */
    min-width: 0; /* はみ出し対策 */
}

/* 対応ブラウザではグリッドでより安定させる */
@supports (display: grid) {
    .series-grid {
        display: grid;
        grid-template-columns: minmax(240px, 320px) 1fr;
    }
    .series-grid > fieldset,
    .series-grid > .field {
        width: auto;
    }
}

@media (max-width: 720px) {
    .series-grid {
        display: block; /* フォールバックと整合 */
    }
}

/* 科目ラジオを縦並びに美しく配置 */
.radios-vertical {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.radios-vertical .radio {
    display: flex;
    width: 100%;
    justify-content: flex-start;
}

.radio::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--brand-gradient);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.radio:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.radio:hover::before {
    opacity: 0.05;
}

.radio:has(input:checked) {
    border-color: var(--brand);
    background: color-mix(in oklch, var(--brand) 8%, var(--surface));
    box-shadow: var(--shadow-brand);
}

.radio:has(input:checked)::before {
    opacity: 0.1;
}

.radio input {
    accent-color: var(--brand);
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Custom radio mark */
.radio .r-mark {
    width: 18px;
    height: 18px;
    border-radius: 9999px;
    border: 2px solid color-mix(in oklch, var(--brand) 60%, var(--line));
    position: relative;
    flex: 0 0 auto;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    background: color-mix(in oklch, var(--surface) 90%, transparent);
}
.radio .r-mark::after {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 9999px;
    background: var(--brand-gradient);
    transform: scale(0);
    transition: transform 0.15s ease;
}
.radio:has(input:checked) .r-mark::after {
    transform: scale(1);
}
.radio .r-label {
    position: relative;
    z-index: 1;
}

/* 出題形式（direction）だけをセグメント風に */
.direction-radios {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 12px;
}
.direction-radios .radio {
    justify-content: center;
    gap: 12px;
    padding: 14px 18px;
    font-weight: 700;
}
.direction-radios .radio span {
    letter-spacing: 0.02em;
}
.direction-radios .radio:has(input:checked) {
    background: color-mix(in oklch, var(--brand) 14%, var(--surface));
}
.direction-radios .radio input {
    transform: scale(1.1);
}
@media (max-width: 640px) {
    .direction-radios {
        grid-template-columns: 1fr 1fr;
    }
}

.db-stats {
    display: block;
    font-size: 0.8em;
    color: var(--muted);
    margin-top: 2px;
    font-weight: 400;
}
.errors {
    background: color-mix(in oklch, var(--danger) 12%, var(--surface));
    color: var(--danger);
    padding: 16px;
    border-radius: 12px;
    margin: 12px 0;
    border: 1px solid color-mix(in oklch, var(--danger) 30%, var(--line));
    box-shadow: var(--shadow-sm);
    font-weight: 500;
}

.errors ul {
    margin: 0;
    padding-left: 16px;
}

.actions {
    margin-top: 12px;
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding-top: 8px;
}

/* PDF Preview */
.preview-overlay {
    position: fixed;
    inset: 0;
    background: color-mix(in oklch, black 55%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    z-index: 30000;
}

.preview-overlay.hidden {
    display: none;
}

.preview-dialog {
    width: min(1100px, 96vw);
    max-height: 92vh;
    background: var(--elev);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    padding: 16px;
    z-index: 32000;
}

body.no-scroll {
    overflow: hidden;
}

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

.preview-tabs {
    display: inline-flex;
    gap: 8px;
}

.preview-tabs .tab {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.preview-tabs .tab.active {
    border-color: var(--brand);
    box-shadow: var(--shadow-brand);
}

.preview-title {
    margin: 0;
    font-size: 1.1rem;
}

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

.preview-actions button {
    min-width: 120px;
    padding: 12px 20px;
}

.preview-body {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: var(--surface);
}

/* プレビュー: 左(iframe) + 右(設定) の2カラム */
.preview-split {
    display: grid;
    grid-template-columns: 1fr min(320px, 28vw);
    gap: 0;
    align-items: stretch;
}
.preview-main {
    border-inline-end: 1px solid var(--line);
}
.preview-sidebar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
    background: var(--elev-2);
}
.preview-sidebar-title {
    margin: 4px 2px 6px;
    font-size: 0.98rem;
    color: var(--text-secondary);
}
.settings-list {
    margin: 0;
    padding: 0;
}
.settings-row {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 8px;
    align-items: start;
    padding: 10px 8px;
    border-bottom: 1px dashed var(--line-subtle);
}
.settings-row:last-child {
    border-bottom: 0;
}
.settings-row dt {
    margin: 0;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.9rem;
}
.settings-row dd {
    margin: 0;
    color: var(--text);
    font-weight: 600;
}

@media (max-width: 840px) {
    .preview-sidebar {
        padding: 10px 12px 12px;
    }
}

#pdfFrame,
#pdfFrameQuiz,
#pdfFrameAnswers {
    width: 100%;
    max-width: 100%;
    height: min(75vh, 900px);
    border: 0;
    display: block;
    background: #fff;
}

.preview-hint {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

/* Recent Updates (index only) */
.ru-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}
.ru-header .hero-title {
    margin: 0;
}
.ru-list {
    list-style: none;
    margin: 0.25rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.4rem;
    position: relative;
}
.ru-item {
    display: block;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    position: relative;
    overflow: hidden;
}
.ru-item::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #22c55e, #38bdf8);
    opacity: 0.6;
}
.ru-item:hover {
    border-color: color-mix(in oklch, var(--line) 70%, #38bdf8 30%);
}
.ru-body {
    display: grid;
    gap: 0.2rem;
}
.ru-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}
.ru-date {
    color: var(--muted);
    font-size: 0.88rem;
}
.ru-title {
    font-size: 1rem;
}
.ru-tags {
    list-style: none;
    margin: 0.05rem 0 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}
.ru-tags.ru-inline {
    margin: 0;
}
.ru-chip {
    font-size: 0.72rem;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: var(--chip-bg, #f3f4f6);
    color: var(--chip-fg, #374151);
    border: 1px solid var(--line);
}
:root[data-theme="dark"] .ru-chip {
    --chip-bg: rgba(255, 255, 255, 0.06);
    --chip-fg: #d1d5db;
}
@media (min-width: 720px) {
    .ru-item {
        padding: 0.6rem 1rem;
    }
}

/* Enhanced Button Design */
.btn-primary,
button.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--brand-gradient);
    color: white;
    border: 0;
    padding: 16px 32px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-brand);
    position: relative;
    overflow: hidden;
    min-width: 180px;
    letter-spacing: -0.01em;
}

.btn-primary::before,
button.btn-primary::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.btn-primary:hover,
button.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(6, 182, 212, 0.3), 0 4px 16px rgba(139, 92, 246, 0.2);
}

.btn-primary:hover::before,
button.btn-primary:hover::before {
    opacity: 1;
}

.btn-primary:active,
button.btn-primary:active {
    transform: translateY(-1px);
    transition: transform 0.1s ease;
}

.btn-icon {
    font-size: 1.2rem;
    position: relative;
    z-index: 1;
}
.btn-icon .spin {
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn-primary span:not(.btn-icon),
button span:not(.btn-icon) {
    position: relative;
    z-index: 1;
}

/* Disabled button state: clearer gray monochrome */
.btn-primary:disabled,
button.btn-primary:disabled,
.btn-primary[aria-disabled="true"] {
    background: #6b7280; /* Gray 500 */
    background-image: none;
    color: #f3f4f6; /* near-white for contrast */
    border: 0;
    box-shadow: none;
    transform: none !important;
    cursor: not-allowed;
}

.btn-primary:disabled::before,
button.btn-primary:disabled::before,
.btn-primary[aria-disabled="true"]::before {
    content: none;
}

/* Keep brand look while loading even if disabled for safety */
.btn-primary.is-loading:disabled {
    background: var(--brand-gradient);
    color: #fff;
    box-shadow: var(--shadow-brand);
    cursor: wait;
}

/* Light Mode Enhancements */
[data-theme="light"] body {
    background: radial-gradient(
            ellipse 1400px 700px at 20% 10%,
            rgba(8, 145, 178, 0.06),
            transparent
        ),
        radial-gradient(ellipse 900px 500px at 80% 90%, rgba(124, 58, 237, 0.06), transparent),
        radial-gradient(ellipse 600px 400px at 50% 50%, rgba(217, 119, 6, 0.03), transparent),
        var(--bg);
}

/* Responsive Design Improvements */
@media (max-width: 640px) {
    .container {
        padding: 0 16px;
    }

    .card {
        padding: 24px 20px;
    }

    .hero-title {
        font-size: 1.5rem;
    }

    .header-inner {
        padding: 16px 0;
        gap: 12px;
        flex-wrap: wrap;
    }

    .brand {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.875rem;
        display: none; /* モバイルでは省略してコンパクトに */
    }

    .brand-wrap {
        flex-wrap: wrap;
    }

    .header-right {
        margin-left: auto;
    }

    .theme-toggle {
        width: 38px;
        height: 38px;
    }

    /* アクションボタンはフル幅で押しやすく */
    .actions {
        flex-direction: column;
        align-items: stretch;
    }
    .actions .btn-primary,
    .actions button {
        width: 100%;
        min-width: 0;
        padding: 14px 16px;
    }

    /* プレビュー操作を上部にまとめて見やすく */
    .preview-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .preview-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
    }
    .preview-actions button {
        width: 100%;
        min-width: 0;
        padding: 12px 16px;
    }

    .radios-vertical .radio {
        padding: 12px 14px;
    }

    /* プレビュー領域はやや低めにして操作部を確保 */
    #pdfFrame,
    #pdfFrameQuiz,
    #pdfFrameAnswers {
        height: 65vh;
    }

    /* カスタムセレクトのリスト高さを画面に収める */
    .select-list {
        max-height: min(50vh, 260px);
    }

    /* フッターは縦配置で中央寄せ */
    .footer-inner {
        flex-direction: column;
        gap: 6px;
        text-align: center;
    }
}

/* 右端固定の設定パネル */
.settings-fixed {
    display: none; /* デフォルトは非表示 */
    position: fixed;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    width: min(360px, 30vw);
    max-height: min(82vh, 920px);
    overflow: hidden;
    background: var(--elev);
    border: 1px solid var(--line);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0;
    z-index: 30500; /* overlay(30000) より前面 */
    backdrop-filter: saturate(140%) blur(6px);
}
.settings-fixed::before {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline: 0;
    block-size: 1px;
    background: var(--brand-gradient);
    opacity: 0.7;
}
/* プレビューオープン時のみ表示（:has使用） */
body:has(#previewSection:not(.hidden)) .settings-fixed {
    display: block;
}
@media (max-width: 1100px) {
    .settings-fixed {
        display: none; /* 画面が狭いときは非表示 */
    }
}

/* 固定パネル内の構造と見た目 */
.settings-fixed .preview-sidebar-title {
    position: sticky;
    top: 0;
    z-index: 1;
    margin: 0;
    padding: 12px 16px;
    background: color-mix(in oklch, var(--elev) 92%, transparent);
    border-bottom: 1px solid var(--line-subtle);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}
.settings-fixed .preview-sidebar-title::before {
    content: "";
    inline-size: 18px;
    block-size: 18px;
    background: var(--brand-gradient);
    border-radius: 6px;
    box-shadow: var(--shadow-brand);
}
.settings-fixed .settings-scroll {
    overflow: auto;
    max-height: calc(82vh - 52px);
    padding: 10px 12px 12px;
}
.settings-fixed .settings-list {
    padding: 0;
    margin: 0;
}
.settings-fixed .settings-row {
    padding: 12px 10px;
    border-bottom: 1px dashed var(--line-subtle);
    transition: background 0.15s ease, border-color 0.15s ease;
}
.settings-fixed .settings-row:hover {
    background: color-mix(in oklch, var(--brand) 8%, transparent);
    border-color: color-mix(in oklch, var(--brand) 30%, var(--line-subtle));
}
.settings-fixed .settings-row dt {
    color: var(--text-secondary);
}
.settings-fixed .settings-row dd {
    color: var(--text);
}

/* スクロール終端フェード */
.settings-fixed .settings-scroll::after {
    content: "";
    position: sticky;
    bottom: -1px;
    display: block;
    height: 18px;
    margin-top: -18px;
    background: linear-gradient(
        to bottom,
        transparent,
        color-mix(in oklch, var(--elev) 100%, transparent)
    );
}

/* さらに狭い端末での微調整 */
@media (max-width: 400px) {
    .brand {
        font-size: 1.1rem;
    }
    .preview-actions {
        grid-template-columns: 1fr;
    }
}

/* Additional utility classes */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus improvements for accessibility */
*:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
    position: absolute;
    left: 8px;
    top: -40px;
    padding: 10px 14px;
    background: var(--brand-gradient);
    color: #fff;
    border-radius: 10px;
    box-shadow: var(--shadow-brand);
    transition: top 0.15s ease;
    z-index: 100000;
}
.skip-link:focus {
    top: 8px;
}

/* Select search */
.select-search {
    position: absolute;
    z-index: 10002;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
    box-shadow: var(--shadow-lg);
}
.select-custom .select-search {
    display: none;
}
.select-custom.open .select-search {
    display: block;
}
.select-search input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1.5px solid var(--line);
    background: var(--elev-2);
    color: var(--text);
    font-size: 0.95rem;
}
.select-search input[type="text"]:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ring), var(--shadow-sm);
}

/* Make the list attach to the search box seamlessly */
.select-custom .select-list {
    margin-top: 48px; /* height of search area incl. paddings */
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

@layer utilities {
    /* 2025: スペーシングユーティリティ（論理プロパティ） */
    .mt-xs {
        margin-block-start: var(--space-xs);
    }
    .mt-sm {
        margin-block-start: var(--space-sm);
    }
    .mt-md {
        margin-block-start: var(--space-md);
    }
    .mt-lg {
        margin-block-start: var(--space-lg);
    }
    .mt-xl {
        margin-block-start: var(--space-xl);
    }

    .mb-xs {
        margin-block-end: var(--space-xs);
    }
    .mb-sm {
        margin-block-end: var(--space-sm);
    }
    .mb-md {
        margin-block-end: var(--space-md);
    }
    .mb-lg {
        margin-block-end: var(--space-lg);
    }
    .mb-xl {
        margin-block-end: var(--space-xl);
    }

    .ml-xs {
        margin-inline-start: var(--space-xs);
    }
    .ml-sm {
        margin-inline-start: var(--space-sm);
    }
    .ml-md {
        margin-inline-start: var(--space-md);
    }
    .ml-lg {
        margin-inline-start: var(--space-lg);
    }
    .ml-xl {
        margin-inline-start: var(--space-xl);
    }

    .mr-xs {
        margin-inline-end: var(--space-xs);
    }
    .mr-sm {
        margin-inline-end: var(--space-sm);
    }
    .mr-md {
        margin-inline-end: var(--space-md);
    }
    .mr-lg {
        margin-inline-end: var(--space-lg);
    }
    .mr-xl {
        margin-inline-end: var(--space-xl);
    }

    /* 2025: Flexboxユーティリティ */
    .flex {
        display: flex;
    }
    .flex-col {
        flex-direction: column;
    }
    .flex-wrap {
        flex-wrap: wrap;
    }
    .justify-start {
        justify-content: flex-start;
    }
    .justify-center {
        justify-content: center;
    }
    .justify-end {
        justify-content: flex-end;
    }
    .justify-between {
        justify-content: space-between;
    }
    .items-start {
        align-items: flex-start;
    }
    .items-center {
        align-items: center;
    }
    .items-end {
        align-items: flex-end;
    }
    .items-stretch {
        align-items: stretch;
    }

    /* 2025: Gridユーティリティ */
    .grid {
        display: grid;
    }
    .grid-cols-1 {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
    .grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .gap-xs {
        gap: var(--space-xs);
    }
    .gap-sm {
        gap: var(--space-sm);
    }
    .gap-md {
        gap: var(--space-md);
    }
    .gap-lg {
        gap: var(--space-lg);
    }

    /* 2025: 視覚的ユーティリティ */
    .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .not-sr-only {
        position: static;
        width: auto;
        height: auto;
        padding: 0;
        margin: 0;
        overflow: visible;
        clip: auto;
        white-space: normal;
    }
}

/* 2025: View Transition API対応 */
@media (prefers-reduced-motion: no-preference) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 0.3s;
    }
}
