/* =========================================
   モード切り替えタブ
   ========================================= */
.mode-tabs {
    display: flex;
    gap: 8px;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    padding: 6px;
    border-radius: 14px;
    margin: 0 auto 2rem;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.08);
    border: 1px solid var(--border-color);
    max-width: 500px;
}

.mode-tab {
    flex: 1;
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    font-family: inherit;
}

.mode-tab.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.mode-tab:hover:not(.active) {
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary);
}

.mode-section {
    display: none;
}

.mode-section.active {
    display: block;
}

/* =========================================
   微調整モード：パネル
   ========================================= */
.adjust-panel {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.adjust-panel.hidden {
    display: none;
}

.adjust-panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* =========================================
   スライダー
   ========================================= */
.adjust-sliders {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.adjust-slider-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.adjust-slider-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.adjust-slider-value {
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.adjust-slider-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 3px;
    outline: none;
}

.adjust-slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.adjust-slider-row input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid white;
}

/* =========================================
   ボタン（小サイズ）
   ========================================= */
.adjust-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 1.2rem;
}

.btn-primary-sm,
.btn-secondary-sm,
.btn-accent-sm {
    font-family: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary-sm {
    background: var(--accent-gradient);
    color: white;
}

.btn-primary-sm:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(99, 102, 241, 0.3);
}

.btn-secondary-sm {
    background: rgba(99, 102, 241, 0.08);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.btn-secondary-sm:hover {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
}

.btn-accent-sm {
    background: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);
    color: white;
}

.btn-accent-sm:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(168, 85, 247, 0.3);
}

.adjust-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 12px;
    line-height: 1.6;
}

/* =========================================
   9マスグリッド
   ========================================= */
.adjust-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* 列数は JS から adjustState.cols に応じて動的に上書き */
    gap: 12px;
    margin-top: 1rem;
}

.adjust-cell {
    position: relative;
    aspect-ratio: 1;
    padding: 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    overflow: hidden;
    border: 2px solid var(--border-color);
    background-color: #ffffff;
    background-image:
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.adjust-cell:hover {
    border-color: var(--primary);
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

/* ブルーバック確認モード */
.adjust-grid.blue-bg .adjust-cell {
    background-color: #8EABC0;
    background-image: none;
}

.blue-bg-btn.active {
    background: #8EABC0;
    color: white;
    border-color: #7090a8;
}

.adjust-cell canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.adjust-cell-number {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.9);
    padding: 1px 6px;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.adjust-cell-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 0 2px white, 0 2px 4px rgba(99, 102, 241, 0.4);
    display: none;
}

.adjust-cell.adjusted .adjust-cell-dot {
    display: block;
}

/* =========================================
   モーダル
   ========================================= */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.active {
    display: flex;
}

.modal-overlay .modal {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.5rem;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary);
}

.close-btn {
    background: rgba(99, 102, 241, 0.1);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    transition: all 0.15s ease;
}

.close-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
}

.preview-wrap {
    background-color: #ffffff;
    background-image:
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 14px 14px;
    background-position: 0 0, 0 7px, 7px -7px, -7px 0px;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.preview-wrap canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.modal-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 1.2rem;
}

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

.modal-actions button {
    flex: 1;
}

/* =========================================
   モバイル
   ========================================= */
@media (max-width: 600px) {
    .mode-tab {
        font-size: 0.8rem;
        padding: 10px 8px;
    }

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

    .adjust-cell-number {
        font-size: 0.65rem;
    }
}
