/* ========== リセット & ベース ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* ゆるま湯データラボ カラーパレット（nurumayudatalab.com準拠） */
    --primary-orange: #ff9a5a;
    --primary-orange-light: #ffb380;
    --primary-orange-dark: #ff7e2f;
    --accent-orange: #ffd4a3;
    --bg-orange-light: #fff5eb;
    --text-dark: #333333;
    --text-light: #666666;
    --border-color: #ffd4a3;
    --white: #ffffff;
    --shadow: rgba(255, 154, 90, 0.2);
    --header-height: 96px;
    
    /* グラデーションカラー */
    --gradient-start: #fff8f0;
    --gradient-mid: #ffe8d8;
    --gradient-end: #ffd4a3;
}

body {
    font-family: 'Noto Sans JP', sans-serif;
    background: linear-gradient(135deg, var(--gradient-start) 0%, var(--gradient-mid) 50%, var(--gradient-end) 100%);
    color: var(--text-dark);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent; /* タップハイライト除去 */
}

/* ========== アプリコンテナ ========== */
.app-container {
    max-width: 100vw;
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100); /* iOS対応 */
    display: flex;
    flex-direction: column;
    background: var(--white);
}

/* ========== ヘッダー ========== */
.app-header {
    background: linear-gradient(135deg, var(--primary-orange) 0%, var(--primary-orange-dark) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 12px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.5px;
    flex: 1;
}

.btn-menu {
    background: rgba(255,255,255,0.25);
    color: white;
    border: 2px solid rgba(255,255,255,0.5);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    min-width: 44px;
    min-height: 44px;
    margin-right: 12px;
}

.btn-menu:active {
    transform: scale(0.95);
    background: rgba(255,255,255,0.35);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.save-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: white;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.save-indicator.show {
    opacity: 1;
}

.save-indicator i {
    font-size: 16px;
}

.btn-settings {
    background: rgba(255,255,255,0.25);
    color: white;
    border: 2px solid rgba(255,255,255,0.5);
    padding: 10px;
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    min-width: 44px;
    min-height: 44px;
}

.btn-settings:active {
    transform: scale(0.95);
    background: rgba(255,255,255,0.35);
}

.btn-export {
    background: rgba(255,255,255,0.25);
    color: white;
    border: 2px solid white;
    padding: 10px 16px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    transition: all 0.3s ease;
    min-height: 44px;
    white-space: nowrap;
}

.btn-export:active {
    transform: scale(0.95);
    background: rgba(255,255,255,0.35);
}

.btn-export:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ========== ヘッダーズームコントロール ========== */
.zoom-controls-header {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.15);
    padding: 6px 14px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.zoom-btn-header {
    background: transparent;
    color: white;
    border: none;
    padding: 6px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    transition: all 0.2s ease;
}

.zoom-btn-header:hover {
    background: rgba(255, 255, 255, 0.2);
}

.zoom-btn-header:active {
    transform: scale(0.9);
}

.zoom-value-header {
    font-size: 13px;
    font-weight: 600;
    color: white;
    letter-spacing: 0.4px;
    min-width: 48px;
    text-align: center;
}

.zoom-slider-container-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-slider-header {
    width: 120px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.zoom-slider-header::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: all 0.2s ease;
}

.zoom-slider-header::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.zoom-slider-header::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: all 0.2s ease;
}

.zoom-slider-header::-moz-range-thumb:hover {
    transform: scale(1.2);
}

.zoom-value-header {
    font-size: 12px;
    font-weight: 600;
    color: white;
    min-width: 42px;
    text-align: center;
}

/* ========== ズーム倍率インジケーター（一時表示） ========== */
.zoom-indicator {
    position: fixed;
    top: 120px;
    right: 20px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    z-index: 10000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.zoom-indicator i {
    margin-right: 8px;
    color: var(--primary-orange);
}

.zoom-indicator.show {
    display: block;
    opacity: 1;
}

/* モバイル対応：ズームインジケーター位置調整 */
@media (max-width: 768px) {
    .zoom-indicator {
        top: 80px;
        right: 10px;
        font-size: 14px;
        padding: 10px 16px;
    }
}

/* モバイル対応：ズームコントロールを非表示 */
@media (max-width: 768px) {
    /* スマホモードでページ全体のスクロール禁止 */
    body {
        overflow: hidden;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }

    .app-container {
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        overflow: hidden;
    }

    .app-header {
        width: 100%;
        box-sizing: border-box;
        border-radius: 0;
        padding: calc(12px + env(safe-area-inset-top, 0px))
                 calc(16px + env(safe-area-inset-right, 0px))
                 12px
                 calc(16px + env(safe-area-inset-left, 0px));
        top: env(safe-area-inset-top, 0px);
        flex-wrap: nowrap;
        justify-content: flex-start;
        column-gap: 12px;
    }

    .app-header h1 {
        font-size: 18px;
        gap: 8px;
        min-width: 0;
        flex: 0 0 auto;
    }

    .zoom-controls-header {
        display: none;
    }

    .btn-menu {
        padding: 8px 10px;
        min-width: 40px;
        min-height: 40px;
        margin-right: 8px;
        font-size: 16px;
    }

    .header-actions {
        gap: 8px;
        flex: 1 0 auto;
        min-width: min-content;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .header-actions > * {
        flex-shrink: 0;
    }

    .header-actions::-webkit-scrollbar {
        display: none;
    }

    .btn-settings,
    .btn-undo {
        padding: 8px;
        min-width: 40px;
        min-height: 40px;
        font-size: 14px;
    }

    .btn-export {
        padding: 8px 10px;
        font-size: 0; /* テキストを非表示 */
        gap: 0;
        min-height: 40px;
        min-width: 40px;
        border-radius: 12px;
    }

    .btn-export i {
        font-size: 16px;
    }

    /* エクスポートボタンのテキストをスマホで非表示 */
    .btn-export span {
        display: none;
    }

    .save-indicator {
        font-size: 11px;
    }
}

.mobile-mode .app-container {
    max-width: min(430px, 100%);
    margin: 0 auto;
    box-shadow: 0 0 30px rgba(255, 154, 90, 0.12);
    border-radius: 24px;
    overflow: hidden;
}

.mobile-mode .app-header {
    border-radius: 0;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-light);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.btn-close:active {
    background: rgba(0,0,0,0.05);
}

/* ========== メインコンテンツ ========== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-orange-light);
}

/* ========== キャンバスコンテナ ========== */
#canvasContainer {
    position: relative;
    width: 100%;
    min-height: 400px;
    /* ★Bug6 Fix: Remove fixed 60vh height - will be set dynamically by JavaScript */
    /* REMOVED: height: 60vh; */
    /* REMOVED: height: calc(var(--vh, 1vh) * 60); */
    background: #e0e0e0; /* グレー背景で作業領域を広く見せる */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    overflow: auto; /* スクロール可能にしてキャンバス全体を表示 */
    border-bottom: 2px solid var(--border-color);
    padding: 24px 20px 32px; /* キャンバス周りのスペースを適度に */
    /* Bug7修正: 初期表示のちらつき防止 */
    opacity: 0;
    transition: opacity 0.25s ease-in-out;
}

#canvasContainer.initialized {
    opacity: 1;
}

.canvas-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
    position: relative;
}

.canvas-slot {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center; /* ★Bug_report_canvas_size 追加: 垂直方向も中央配置 */
    padding: 50px 60px 50px 50px; /* ★Bug_report_canvas_size 修正: ズーム時のはみ出しを許容 */
    overflow: visible; /* ★Bug_report_canvas_size 追加: ズーム時の表示確保 */
}

/* PC版のみコントロールパネル用のpadding - 常時適用してレイアウト安定化 */
body.desktop-mode #canvasContainer {
    padding-left: 210px;
    padding-right: 210px;
}

/* Bug修正: Fabric.jsが作成する全canvas要素に背景を適用 */
.canvas-slot canvas,
.canvas-slot .lower-canvas,
.canvas-slot .upper-canvas {
    touch-action: none;
    /* CSS背景を強制適用（Fabric.jsのDOM変換後も有効） */
    background: #ffffff !important;
    /* キャンバス出力範囲の影を強調 - 出力範囲が明確に分かる */
    box-shadow:
        0 0 0 2px rgba(255, 154, 90, 0.8), /* オレンジの枠線で出力範囲を明確化 */
        0 0 0 3px rgba(0,0,0,0.1),
        0 4px 12px rgba(0,0,0,0.15),
        0 8px 24px rgba(0,0,0,0.2),
        0 16px 48px rgba(0,0,0,0.15);
    border-radius: 2px;
    margin: auto; /* 中央配置を確実に */
}

/* Bug修正: アクティブなcanvasのスタイル（lower-canvasのみ影を適用） */
.canvas-slot.active canvas,
.canvas-slot.active .lower-canvas {
    box-shadow:
        0 0 0 2px rgba(255, 154, 90, 1),
        0 0 0 4px rgba(255, 154, 90, 0.32),
        0 8px 24px rgba(0, 0, 0, 0.25);
}

/* Bug修正: upper-canvasは透明背景で影なし（選択枠のみ表示） */
.canvas-slot .upper-canvas {
    background: transparent !important;
    box-shadow: none !important;
}

.canvas-slot-toolbar {
    position: absolute;
    top: 12px;
    left: 100%;
    margin-left: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 3;
    transform: none;
}

.canvas-slot:hover .canvas-slot-toolbar,
.canvas-slot.active .canvas-slot-toolbar,
.canvas-slot:focus-within .canvas-slot-toolbar {
    opacity: 1;
    pointer-events: auto;
}

.btn-canvas-action {
    appearance: none;
    border: none;
    background: rgba(38, 38, 38, 0.6);
    color: #ffffff;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.btn-canvas-action:hover,
.btn-canvas-action:focus-visible {
    background: rgba(255, 154, 90, 0.95);
    outline: none;
}

.btn-canvas-action:active {
    transform: scale(0.94);
}

.btn-canvas-action i {
    font-size: 14px;
    pointer-events: none;
}

.btn-add-canvas {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary-orange-light) 0%, var(--primary-orange) 100%);
    color: white;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(255, 154, 90, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-height: 44px;
}

.btn-add-canvas i {
    font-size: 15px;
}

.btn-add-canvas span {
    font-size: 14px;
}

.btn-add-canvas:active {
    transform: scale(0.97);
    box-shadow: 0 3px 12px rgba(255, 154, 90, 0.24);
}

/* ========== キャンバス追加/削除ボタンを一時的に非表示 ========== */
.btn-add-canvas,
.delete-canvas-btn {
    display: none !important;
}

.inline-controls-panel {
    display: none;
    flex-direction: column;
    gap: 16px;
    margin-top: 24px;
    padding: 18px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 154, 90, 0.25);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.inline-controls-panel.active {
    display: flex;
}

.image-controls-panel,
.text-controls-panel {
    width: 100%;
}

body.desktop-mode .inline-controls-panel {
    padding: 20px;
}

/* ★ Bug8 Fix: Independent Controls Container */
/* Controls are NOW siblings of tool-panels, not children */
/* This allows them to be visible regardless of which tab is active */
.controls-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

/* Controls container inherits all positioning from toolbar */
/* Individual control panels manage their own visibility via .active class */

/* PC版：画像パネルのコントロールサイズ改善 */
body.desktop-mode .image-controls-panel .control-group.compact {
    margin-bottom: 12px;
}

body.desktop-mode .image-controls-panel .control-group label {
    font-size: 12px;
}

body.desktop-mode .image-controls-panel .value {
    font-size: 12px;
}

body.desktop-mode .image-controls-panel input[type="range"] {
    width: 100%;
    margin: 4px 0;
}

body.desktop-mode .image-controls-panel .btn-stack .btn-secondary,
body.desktop-mode .image-controls-panel .btn-full {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 12.5px;
}

body.desktop-mode .image-controls-panel .image-controls-section h4 {
    font-size: 11px;
    margin-top: 8px;
}

.image-controls-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.image-controls-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.image-controls-header .btn-icon,
.text-controls-header .btn-icon {
    min-height: 32px;
    min-width: 32px;
    padding: 6px;
    border-radius: 12px;
}

.image-controls-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.image-controls-primary {
    margin-top: 4px;
}

.image-controls-primary .btn-full {
    font-weight: 600;
}

.image-controls-section h4 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

.image-controls-panel .control-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.image-controls-panel .control-group label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-light);
}

.image-controls-panel .control-group.compact label span:first-child {
    display: flex;
    align-items: center;
    gap: 6px;
}

.image-controls-panel .value {
    font-weight: 600;
    color: var(--text-dark);
    font-size: 13px;
}

.btn-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-stack .btn-secondary,
.image-controls-panel .btn-full {
    width: 100%;
    min-height: 34px;
    padding: 8px 12px;
    font-size: 12.5px;
}

.btn-stack .btn-secondary i,
.image-controls-panel .btn-full i {
    margin-right: 6px;
}

body.desktop-mode .text-controls-panel {
    padding: 20px;
    gap: 16px;
}

/* PC版：テキストパネルのコントロールグループ改善 */
body.desktop-mode .text-controls-panel .control-group {
    display: grid;
    grid-template-columns: 100px 1fr;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 14px;
}

body.desktop-mode .text-controls-panel .control-group.compact {
    margin-bottom: 12px;
}

/* PC版：テキストグリッドの改善 */
body.desktop-mode .text-controls-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* PC版：セクションタイトル */
body.desktop-mode .text-controls-panel .text-controls-section > label:first-child {
    font-weight: 600;
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* PC版：コントロールサイズと可読性改善 */
body.desktop-mode .text-controls-panel select,
body.desktop-mode .text-controls-panel input[type="text"],
body.desktop-mode .text-controls-panel input[type="number"],
body.desktop-mode .text-controls-panel textarea {
    min-height: 34px;
    font-size: 13px;
    padding: 8px 10px;
}

body.desktop-mode .text-controls-panel input[type="range"] {
    width: 100%;
    margin: 4px 0;
}

/* PC版：ボタンサイズとスペーシング */
body.desktop-mode .text-controls-panel .btn-chip {
    min-width: 36px;
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
    flex: 0 1 auto;
}

body.desktop-mode .text-controls-panel .btn-stack {
    gap: 8px;
}

body.desktop-mode .text-controls-panel .btn-stack .btn-secondary {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 13px;
}

/* PC版：カラー入力の改善 */
body.desktop-mode .text-controls-panel .color-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

body.desktop-mode .text-controls-panel .color-inputs .color-chip {
    width: 36px;
    height: 36px;
}

body.desktop-mode .text-controls-panel .color-inputs input[type="text"] {
    flex: 1;
    min-width: 0;
    font-size: 12px;
}

/* PC版：チェックボックスの改善 */
body.desktop-mode .text-controls-panel .checkbox-label.small {
    font-size: 12px;
    gap: 8px;
    margin-top: 6px;
}

body.desktop-mode .text-controls-panel .checkbox-label.small input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

/* 上記で統合済み */

.text-controls-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.text-controls-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.text-controls-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.text-controls-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.text-controls-panel textarea {
    min-height: 60px;
    font-size: 14px;
    line-height: 1.5;
}

.text-controls-panel .color-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
}

.text-controls-panel .color-chip {
    width: 36px;
    height: 36px;
    padding: 2px;
    border: 1px solid rgba(45, 45, 45, 0.3); /* 白でも視認できる枠線 */
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0.45));
    cursor: pointer;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.8),
        0 1px 2px rgba(0, 0, 0, 0.08);
}

.text-controls-panel .color-chip:focus-visible {
    outline: 2px solid var(--primary-orange);
    outline-offset: 3px;
}

.text-controls-panel .color-chip::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

.text-controls-panel .color-chip::-webkit-color-swatch-wrapper {
    padding: 0;
}

.text-controls-panel .color-chip::-moz-color-swatch {
    border: none;
    border-radius: 6px;
}

.text-controls-panel .color-inputs input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 12.5px;
}

.text-effects-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.effects-toggle {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.effect-controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(255, 245, 235, 0.55);
    border: 1px solid rgba(255, 154, 90, 0.18);
    transition: opacity 0.2s ease;
}

.effect-controls.is-disabled {
    opacity: 0.35;
    pointer-events: none;
}

.effect-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--text-light);
}

.effect-control label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    color: var(--text-dark);
}

.effect-control .value {
    font-size: 11px;
    color: var(--text-light);
    margin-left: 8px;
}

.effect-control input[type="range"] {
    width: 100%;
}

.effects-typography {
    display: grid;
    gap: 10px;
}

.effects-typography .effect-control {
    background: rgba(255, 245, 235, 0.55);
    border-radius: 12px;
    border: 1px solid rgba(255, 154, 90, 0.18);
    padding: 8px 10px;
}

.btn-chip-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-chip {
    flex: 1;
    min-width: 34px;
    padding: 7px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255, 154, 90, 0.3);
    background: rgba(255, 245, 235, 0.8);
    color: var(--text-light);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-chip i {
    font-size: 12px;
}

.btn-chip.active {
    background: linear-gradient(135deg, var(--primary-orange) 0%, var(--primary-orange-dark) 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 6px 16px rgba(255, 154, 90, 0.32);
}

.checkbox-label.small {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-light);
}

.checkbox-label.small input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

@media (max-width: 768px) {
    /* スマホモード: ツールバーを上、キャンバスを下に配置 */
    /* column-reverseで順序を逆転（desktop-modeでも強制適用） */
    .main-content,
    body.desktop-mode .main-content,
    body.mobile-mode .main-content {
        flex-direction: column-reverse !important;
    }

    /* ツールバーの高さを固定 */
    .toolbar {
        height: 40vh;
        height: calc(var(--vh, 1vh) * 40);
        max-height: 40vh;
        max-height: calc(var(--vh, 1vh) * 40);
        min-height: 250px;
    }

    /* キャンバスエリアの高さを固定（ヘッダー + ツールバー分を引く） */
    #canvasContainer {
        /* ★Bug6 Fix: Remove fixed height calculations - managed by JavaScript */
        /* REMOVED: height: calc(60vh - var(--header-height, 96px)); */
        /* REMOVED: height: calc(var(--vh, 1vh) * 60 - var(--header-height, 96px)); */
        min-height: 200px;
        /* REMOVED: max-height: calc(60vh - var(--header-height, 96px)); */
        /* REMOVED: max-height: calc(var(--vh, 1vh) * 60 - var(--header-height, 96px)); */
        position: relative;
        padding: 16px;
    }

    .text-controls-grid {
        grid-template-columns: 1fr;
    }
}

/* ========== ツールバー ========== */
.toolbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 154, 90, 0.2);
    box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 14px 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    max-height: 32vh;
    max-height: calc(var(--vh, 1vh) * 32);
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
}

.tool-tabs {
    display: flex;
    gap: 6px;
    background: transparent;
    position: sticky;
    top: 0;
    z-index: 10;
    padding-bottom: 2px;
}

.tool-tab {
    flex: 1;
    padding: 7px 9px;
    background: rgba(255, 245, 235, 0.72);
    border: 1px solid rgba(255, 154, 90, 0.22);
    border-radius: 999px;
    color: var(--text-light);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.35px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.2s ease;
    min-height: 40px;
}

.tool-tab i {
    font-size: 15px;
}

.tool-tab.active {
    background: linear-gradient(135deg, var(--primary-orange) 0%, var(--primary-orange-dark) 100%);
    border-color: transparent;
    color: white;
    box-shadow: 0 8px 20px rgba(255, 154, 90, 0.32);
}

.tool-panel {
    display: none;
    padding: 12px 4px 4px;
    animation: fadeIn 0.25s ease;
}

.tool-panel.active {
    display: block;
}

.tool-panel h3 {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 12px;
}

.image-url-import {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.image-url-import.is-loading {
    pointer-events: none;
    opacity: 0.6;
}

.image-url-import.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid rgba(255, 154, 90, 0.3);
    border-top-color: var(--primary-orange);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.image-url-row {
    display: flex;
    gap: 8px;
}

.image-url-row input[type="url"] {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 13px;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.image-url-row input[type="url"]:focus {
    border-color: var(--primary-orange);
    box-shadow: 0 0 0 3px rgba(255, 154, 90, 0.25);
    outline: none;
}

.image-url-row .btn-secondary {
    flex-shrink: 0;
    padding: 0 14px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.image-url-hint {
    font-size: 11.5px;
    color: var(--text-light);
    padding-left: 4px;
}

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

/* ========== コントロール ========== */
.control-group {
    margin-bottom: 18px;
}

.control-group label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.control-group label i {
    margin-right: 6px;
    color: var(--primary-orange);
    font-size: 15px;
}

.control-group .value {
    color: var(--primary-orange);
    font-weight: 600;
    font-size: 13px;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, var(--accent-orange), var(--primary-orange));
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-orange);
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(255, 154, 90, 0.35);
    border: 3px solid white;
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-orange);
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 3px 8px rgba(255, 154, 90, 0.35);
}

textarea,
select,
input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 14px;
    font-family: 'Noto Sans JP', sans-serif;
    transition: all 0.3s ease;
    min-height: 40px; /* タッチ対応 */
}

textarea:focus,
select:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-orange);
    box-shadow: 0 0 0 3px rgba(255, 154, 90, 0.1);
}

textarea {
    resize: vertical;
    min-height: 64px;
}

select {
    cursor: pointer;
    background: white;
}

/* ========== カラーピッカー ========== */
.color-picker-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

input[type="color"] {
    width: 60px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    background: white;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 6px;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

.color-picker-group input[type="text"] {
    flex: 1;
    text-transform: uppercase;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-light);
    margin-left: auto;
    padding: 8px;
    min-height: 44px; /* タッチ対応 */
}

.checkbox-label input[type="checkbox"] {
    width: 22px;
    height: 22px;
    cursor: pointer;
    accent-color: var(--primary-orange);
}

/* ========== ボタングループ ========== */
.btn-group {
    display: flex;
    gap: 10px;
}

.btn-icon {
    flex: 1;
    padding: 14px;
    background: var(--bg-orange-light);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-light);
    transition: all 0.3s ease;
    min-height: 50px; /* タッチ対応 */
}

.btn-icon:active,
.btn-icon.active {
    background: var(--primary-orange);
    color: white;
    border-color: var(--primary-orange);
    transform: scale(0.95);
}

/* ========== ボタンスタイル ========== */
.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    min-height: 52px; /* タッチ対応 */
}

.btn-full {
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-orange) 0%, var(--primary-orange-dark) 100%);
    color: white;
    box-shadow: 0 6px 16px var(--shadow);
}

.btn-primary:active {
    transform: scale(0.97);
    box-shadow: 0 3px 10px var(--shadow);
}

.btn-secondary {
    background: var(--bg-orange-light);
    color: var(--text-dark);
    border: 2px solid var(--border-color);
}

.btn-secondary:active {
    background: var(--accent-orange);
}

.btn-danger {
    background: #ff5252;
    color: white;
    box-shadow: 0 6px 16px rgba(255, 82, 82, 0.3);
}

.btn-danger:active {
    transform: scale(0.97);
    box-shadow: 0 3px 10px rgba(255, 82, 82, 0.3);
}

/* ========== テンプレート ========== */
.tool-panel h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--border-color);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}

/* ロゴグリッドは常に2列固定 */
.logo-grid {
    grid-template-columns: repeat(2, 1fr) !important;
}

.template-btn {
    padding: 10px 12px;
    background: linear-gradient(135deg, white 0%, var(--bg-orange-light) 100%);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    min-height: 54px;
}

.template-btn i {
    font-size: 20px;
    color: var(--primary-orange);
}

.template-btn:active {
    transform: scale(0.96);
    background: linear-gradient(135deg, var(--primary-orange) 0%, var(--primary-orange-dark) 100%);
    color: white;
    border-color: var(--primary-orange);
}

.template-btn:active i {
    color: white;
}

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

.style-template-btn {
    padding: 20px 16px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.style-template-btn:active {
    transform: scale(0.96);
    border-color: var(--primary-orange);
    background: var(--bg-orange-light);
}

/* ========== Fabric.js カスタムスタイル ========== */
#canvasContainer .canvas-container {
    position: relative !important;
    left: 0 !important;
    top: 0 !important;
    margin: 0 auto !important;
    overflow: visible;  /* ★変更: キャンバス外も表示 */
}

/* Fabric.jsキャンバスコンテナ */
.canvas-container {
    position: relative;
    overflow: visible;  /* ズーム時に枠外も表示 */
}

/* Fabric.jsの下層キャンバス（静的コンテンツ） */
.lower-canvas {
    position: absolute !important;
    z-index: 10 !important;
}

/* Fabric.jsの上層キャンバス（インタラクティブ要素） */
.upper-canvas {
    position: absolute !important;
    z-index: 11 !important;
    border: none !important;
    pointer-events: auto !important;
}

.canvas-slot {
    position: relative;
}

/* ========== レスポンシブ ========== */
@media (min-width: 768px) {
    .app-container {
        max-width: 768px;
        margin: 0 auto;
        box-shadow: 0 0 40px rgba(255, 154, 90, 0.15);
    }

    .app-header h1 {
        font-size: 26px;
    }

    .btn-export {
        padding: 12px 24px;
        font-size: 16px;
    }

    .template-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .toolbar {
        max-height: none;
    }

    #canvasContainer {
        max-height: 70vh;
    }
}

body.desktop-mode .app-container {
    max-width: none;
    margin: 0;
    box-shadow: none;
}

body.desktop-mode .main-content {
    flex-direction: row;
    align-items: stretch;
}

body.desktop-mode #canvasContainer {
    flex: 1;
    height: calc(100vh - var(--header-height) - 40px);
    max-height: none;
    padding: clamp(24px, 4vw, 48px);
}

body.desktop-mode .toolbar {
    flex: 0 0 clamp(280px, 28vw, 360px);
    border-top: none;
    border-left: 1px solid rgba(255, 154, 90, 0.25);
    border-radius: 0;
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.08);
    height: calc(100vh - var(--header-height));
    max-height: none;
    overflow-y: auto;
    padding: 24px 20px;
    gap: 16px;
}

body.desktop-mode .template-grid,
body.desktop-mode .style-template-grid {
    grid-template-columns: repeat(2, 1fr);
}

body.toolbar-scroll-active #canvasContainer {
    overflow: hidden;
}

/* ========== アニメーション ========== */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.pulse {
    animation: pulse 0.6s ease;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.fa-spin {
    animation: spin 1s linear infinite;
}

/* ========== モバイル最適化 ========== */
.is-mobile .btn-icon,
.is-mobile .template-btn,
.is-mobile .style-template-btn {
    min-height: 56px; /* モバイルでさらに大きく */
}

.is-mobile .tool-tab {
    min-height: 76px;
}

.is-touch .btn-icon:hover,
.is-touch .template-btn:hover {
    /* タッチデバイスではhover効果を無効化 */
    transform: none;
}

/* iOS用の追加調整 */
.is-ios input,
.is-ios select,
.is-ios textarea {
    font-size: 16px; /* iOSの自動ズーム防止 */
}

/* ========== ローディング ========== */
.loading {
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    margin: -25px 0 0 -25px;
    border: 5px solid var(--accent-orange);
    border-top: 5px solid var(--primary-orange);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ========== プロジェクトメニュー ========== */
.project-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: 85%;
    max-width: 350px;
    height: 100vh;
    background: white;
    box-shadow: 4px 0 16px rgba(0,0,0,0.1);
    z-index: 200;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.project-menu.show {
    left: 0;
}

.project-menu-header {
    padding: 20px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-orange-light);
}

.project-menu-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.project-menu-actions {
    padding: 16px;
    border-bottom: 2px solid var(--border-color);
}

.project-count {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-orange-light);
    border-radius: 8px;
    font-size: 14px;
}

.project-count span {
    font-weight: 600;
    color: var(--primary-orange);
}

.project-count small {
    color: var(--text-light);
}

.project-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.no-projects {
    text-align: center;
    color: var(--text-light);
    padding: 40px 20px;
    font-size: 14px;
}

.project-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.project-item:active {
    transform: scale(0.98);
    background: var(--bg-orange-light);
}

.project-item.active {
    border-color: var(--primary-orange);
    background: var(--bg-orange-light);
}

.project-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f5f5f5;
}

.project-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.project-info {
    flex: 1;
    min-width: 0;
}

.project-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-date {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

.project-actions {
    display: flex;
    gap: 6px;
}

.btn-icon-small {
    background: transparent;
    border: none;
    color: var(--text-light);
    font-size: 16px;
    cursor: pointer;
    padding: 8px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.btn-icon-small:active {
    background: rgba(0,0,0,0.05);
    color: var(--primary-orange);
}

/* ========== エクスポートダイアログ ========== */
.export-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.export-dialog {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.export-dialog-header {
    padding: 20px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-orange-light);
}

.export-dialog-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.export-dialog-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.export-preview {
    text-align: center;
    margin-bottom: 20px;
}

#exportPreviewCanvas {
    max-width: 100%;
    border: 2px solid var(--border-color);
    border-radius: 8px;
}

.export-info {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-light);
}

.export-info div {
    margin: 4px 0;
}

.export-options h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
}

.quality-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quality-option {
    display: flex;
    align-items: center;
    padding: 14px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.quality-option:active {
    transform: scale(0.98);
    background: var(--bg-orange-light);
}

.quality-option input[type="radio"] {
    margin-right: 12px;
    width: 20px;
    height: 20px;
    accent-color: var(--primary-orange);
    cursor: pointer;
}

.quality-option input[type="radio"]:checked + .quality-label {
    color: var(--primary-orange);
}

.quality-label {
    flex: 1;
}

.quality-label strong {
    display: block;
    font-size: 14px;
    margin-bottom: 4px;
}

.quality-label small {
    color: var(--text-light);
    font-size: 12px;
}

.export-dialog-footer {
    padding: 16px 20px;
    border-top: 2px solid var(--border-color);
    display: flex;
    gap: 10px;
    background: var(--bg-orange-light);
}

.export-dialog-footer .btn-secondary,
.export-dialog-footer .btn-primary {
    flex: 1;
}

/* ========== 設定ダイアログ ========== */
.settings-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    animation: fadeIn 0.3s ease;
}

.settings-dialog {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    animation: slideUp 0.3s ease;
}

/* スマホモード：設定ダイアログの最適化 */
@media (max-width: 768px) {
    .settings-dialog-overlay {
        padding: 8px;
        align-items: flex-start;
        padding-top: 60px; /* ヘッダーの下に表示 */
    }

    .settings-dialog {
        max-width: 100%;
        width: calc(100% - 16px);
        max-height: calc(90vh - 60px);
        margin: 0 auto;
        border-radius: 12px;
    }

    .settings-dialog-header {
        padding: 14px 16px;
    }

    .settings-dialog-header h3 {
        font-size: 16px;
    }

    .settings-dialog-body {
        padding: 16px;
    }

    .canvas-size-options {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .canvas-size-btn {
        padding: 12px 8px;
        font-size: 13px;
    }

    .canvas-size-btn strong {
        font-size: 14px;
    }

    .canvas-size-btn small {
        font-size: 11px;
    }

    .custom-size-input {
        gap: 6px;
    }

    .custom-size-input input {
        padding: 8px;
        font-size: 13px;
    }

    .settings-dialog-footer {
        padding: 12px 16px;
        gap: 8px;
    }

    .settings-group {
        margin-bottom: 18px;
    }

    .settings-group h4 {
        font-size: 14px;
        margin-bottom: 10px;
    }
}

.settings-dialog-header {
    padding: 20px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-orange-light);
}

.settings-dialog-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-dialog-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.settings-group {
    margin-bottom: 24px;
}

.settings-group h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
}

.canvas-size-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.canvas-size-btn {
    padding: 16px 12px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
}

.canvas-size-btn:active {
    transform: scale(0.98);
    background: var(--bg-orange-light);
}

.canvas-size-btn.active {
    border-color: var(--primary-orange);
    background: var(--bg-orange-light);
    color: var(--primary-orange);
}

.canvas-size-btn strong {
    display: block;
    font-size: 16px;
    margin-bottom: 4px;
}

.canvas-size-btn small {
    display: block;
    color: var(--text-light);
    font-size: 12px;
}

.custom-size-input {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
}

.custom-size-input input {
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

.settings-dialog-footer {
    padding: 16px 20px;
    border-top: 2px solid var(--border-color);
    display: flex;
    gap: 10px;
    background: var(--bg-orange-light);
}

.settings-dialog-footer .btn-secondary,
.settings-dialog-footer .btn-primary {
    flex: 1;
}

/* ========== 通知 ========== */
.notification {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    color: var(--text-dark);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 400;
    transition: bottom 0.3s ease;
    min-width: 280px;
    max-width: 90vw;
}

.notification.show {
    bottom: 20px;
}

.notification i {
    font-size: 20px;
}

.notification-success {
    border-left: 4px solid #4caf50;
}

.notification-success i {
    color: #4caf50;
}

.notification-error {
    border-left: 4px solid #f44336;
}

.notification-error i {
    color: #f44336;
}

.notification-info {
    border-left: 4px solid var(--primary-orange);
}

.notification-info i {
    color: var(--primary-orange);
}

/* ========== スクロールバーカスタマイズ ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-orange-light);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-orange);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-orange-dark);
}

/* ========== UI AUDIT FIXES (2025-10-22) ========== */
/* Mobile tap target fixes: all interactive elements must be ≥44x44px */
@media (max-width: 768px) {
  /* Fix header buttons to meet 44px minimum */
  .btn-menu,
  .btn-settings,
  .btn-export {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }

  /* Hide all text in header - icons only on mobile */
  .app-header h1 {
    font-size: 0 !important;
    width: auto;
    overflow: visible;
  }

  .app-header h1 i {
    font-size: 20px !important;
  }

  /* Hide FleMa text, keep icon */
  .app-header h1::after {
    content: none;
  }

  /* Export button - icon only */
  .btn-export {
    font-size: 0 !important;
  }

  .btn-export i {
    font-size: 16px !important;
  }

  .btn-export span {
    display: none !important;
  }

  /* Fix tool tabs height */
  .tool-tab {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 12px;
  }

  /* Fix project menu small icon buttons */
  .btn-icon-small {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }

  /* Fix close button */
  .btn-close {
    min-width: 44px;
    min-height: 44px;
  }

  /* Ensure text controls panel doesn't block entire view on mobile */
  .text-controls-panel,
  .image-controls-panel {
    max-height: 50vh;
    overflow-y: auto;
  }

  /* Add spacing between toolbar tabs on mobile */
  .tool-tabs {
    gap: 8px;
  }

  /* Improve button spacing in header */
  .header-actions {
    gap: 8px;
  }

  /* Compact header layout on mobile */
  .app-header {
    padding: 10px 12px;
    gap: 8px;
  }

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

  /* Hide save indicator on mobile */
  .save-indicator {
    display: none !important;
  }
}

/* Desktop-specific improvements */
body.desktop-mode .main-content {
  flex-direction: row !important;
  align-items: stretch !important;
}

body.desktop-mode #canvasContainer {
  flex: 1 !important;
  min-width: 0 !important;
  height: calc(100vh - var(--header-height)) !important;
  max-height: none !important;
}

body.desktop-mode .toolbar {
  flex: 0 0 clamp(280px, 28vw, 360px) !important;
  max-width: clamp(280px, 28vw, 360px) !important;
  height: calc(100vh - var(--header-height)) !important;
  max-height: none !important;
  overflow-y: auto !important;
  border-top: none !important;
  border-left: 1px solid rgba(255, 154, 90, 0.25) !important;
  border-radius: 0 !important;
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.08) !important;
  padding: 24px 20px !important;
}

/* Focus visibility for accessibility */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #2684ff;
  outline-offset: 2px;
}

/* Safe area insets for iOS notch and home indicator */
@supports (padding: env(safe-area-inset-top)) {
  .app-header {
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
  }

  .toolbar {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
}

/* Prevent horizontal overflow */
html,
body {
  overflow-x: hidden;
}

/* Improve text readability on mobile */
@media (max-width: 768px) {
  body {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
  }

  .tool-panel h3 {
    font-size: 14px;
  }

  .template-btn,
  .style-template-btn {
    font-size: 14px;
  }

  /* Improve control label sizes */
  .control-group label {
    font-size: 13px;
  }
}

/* ========== END UI AUDIT FIXES ==========  */

/* ========== 画像履歴パネル ========== */

.image-history-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

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

.image-history-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  margin: 0;
}

.image-history-header h3 i {
  color: #ff9a5a;
  font-size: 16px;
}

.image-history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
  padding: 4px;
}

.image-history-grid::-webkit-scrollbar {
  width: 6px;
}

.image-history-grid::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.image-history-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 154, 90, 0.3);
  border-radius: 3px;
}

.image-history-grid::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 154, 90, 0.5);
}

.image-history-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.05);
}

.image-history-item:hover {
  border-color: #ff9a5a;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(255, 154, 90, 0.3);
}

.image-history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-history-item-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: flex-end;
  padding: 6px;
}

.image-history-item:hover .image-history-item-overlay {
  opacity: 1;
}

.image-history-item-info {
  font-size: 10px;
  color: #ffffff;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%;
}

.image-history-item-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: rgba(244, 67, 54, 0.9);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 2;
}

.image-history-item:hover .image-history-item-delete {
  opacity: 1;
}

.image-history-item-delete:hover {
  background: #f44336;
  transform: scale(1.1);
}

.image-history-item-delete i {
  font-size: 12px;
}

.image-history-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: rgba(255, 255, 255, 0.4);
  text-align: center;
}

.image-history-empty i {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.3;
}

.image-history-empty p {
  font-size: 14px;
  margin: 0;
}

/* モバイル対応 */
@media (max-width: 768px) {
  .image-history-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    max-height: 300px;
  }

  .image-history-header h3 {
    font-size: 13px;
  }

  .image-history-item-info {
    font-size: 9px;
  }

  .image-history-item-delete {
    width: 20px;
    height: 20px;
  }

  .image-history-item-delete i {
    font-size: 10px;
  }
}

/* ========== END 画像履歴パネル ========== */
