/* リセット & 基本スタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #00BFFF 0%, #1E90FF 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
    width: 100%;
}

/* ヘッダー */
header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    min-height: 70px;
    width: 100%;
    box-sizing: border-box;
}

.header-left .app-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-left .app-icon {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-left .title-text {
    display: flex;
    flex-direction: column;
}

.header-left h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #00BFFF 0%, #1E90FF 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0 0 0.2rem 0;
}

.header-left .subtitle {
    color: #666;
    font-size: 0.85rem;
    margin: 0;
}

.version {
    font-size: 0.75rem;
    color: #888;
    background: rgba(0, 191, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
    border: 1px solid rgba(0, 191, 255, 0.2);
}

.header-right {
    display: flex;
    align-items: center;
}

.header-right .status-info {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.header-right .status-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.header-right .status-label {
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 0.2rem;
    font-weight: 500;
}

.header-right .status-value {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    background: #f0f9ff;
    border: 1px solid #e0f2fe;
    border-radius: 12px;
    color: #0369a1;
    min-width: 50px;
}

.header-right .status-value.active {
    background: #dcfce7;
    border-color: #bbf7d0;
    color: #166534;
}

/* メインコンテナ */
.container {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 2rem;
    box-sizing: border-box;
    width: 100%;
}

/* キャンバスコンテナ */
.canvas-container {
    position: relative;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    aspect-ratio: 4/3;
    min-height: 500px;
    /* モバイル対策：固定サイズでスクロール影響を軽減 */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

#drawingCanvas, #handCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#handCanvas {
    pointer-events: none;
    z-index: 2;
}

#segmentationCanvas {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 200px;
    height: 150px;
    max-width: calc(100% - 20px);
    max-height: calc(100% - 20px);
    border-radius: 10px;
    border: 2px solid white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 3;
    transform: scaleX(-1);
}

/* コントロールパネル */
.controls {
    background: white;
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.control-group h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* モードボタン */
.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: #f5f5f5;
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    color: #666;
}

.mode-btn svg {
    fill: currentColor;
}

.mode-btn:hover {
    background: #e8e8e8;
}

.mode-btn.active {
    background: linear-gradient(135deg, #00BFFF 0%, #1E90FF 100%);
    color: white;
    border-color: transparent;
}

/* ペンコントロール */
.pen-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.color-picker label {
    display: block;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.color-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.color-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: #00BFFF;
    box-shadow: 0 0 0 3px rgba(0, 191, 255, 0.2);
}

.size-control {
    margin-top: 1rem;
}

.size-control label {
    display: block;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.5rem;
}

#brushSize {
    width: 100%;
    -webkit-appearance: none;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
}

#brushSize::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00BFFF 0%, #1E90FF 100%);
    cursor: pointer;
}

#brushSize::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00BFFF 0%, #1E90FF 100%);
    cursor: pointer;
    border: none;
}

/* アクションボタン */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    color: #666;
}

.action-btn svg {
    fill: currentColor;
}

.action-btn:hover {
    background: #f5f5f5;
    border-color: #00BFFF;
    color: #00BFFF;
}


/* パーティクルエフェクト */
.particle {
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
    animation: particle-float 2s ease-out forwards;
}

@keyframes particle-float {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

/* レスポンシブデザイン */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr;
    }
    
    .controls {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 1rem;
    }
    
    #segmentationCanvas {
        width: 150px;
        height: 112px;
    }
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        min-height: auto;
    }
    
    .header-left {
        text-align: center;
    }
    
    .header-right .status-info {
        justify-content: center;
        gap: 1rem;
    }
    
    .header-right .status-item {
        flex-direction: row;
        gap: 0.5rem;
        align-items: center;
    }
    
    .header-right .status-label {
        margin-bottom: 0;
        font-size: 0.75rem;
    }
    
    .header-right .status-value {
        font-size: 0.75rem;
        padding: 0.15rem 0.4rem;
        min-width: 40px;
    }
    
    /* モバイル向け縦長レイアウト */
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        gap: 1.5rem;
        margin: 1rem 0.33rem; /* 左右マージンを1/3に縮小 */
        max-width: none;
    }
    
    /* モバイルでキャンバスを縦長に */
    .canvas-container {
        aspect-ratio: 3/4; /* 縦長比率 */
        min-height: 60vh; /* ビューポートの60%を使用 */
        max-height: 70vh; /* 最大70%に制限 */
        order: 1;
    }
    
    /* コントロールパネルを下に配置 */
    .controls {
        order: 2;
        padding: 1rem;
        border-radius: 15px;
    }
}

@media (max-width: 640px) {
    header {
        padding: 0.75rem;
    }
    
    .header-left .app-icon {
        width: 50px;
        height: 50px;
    }
    
    .header-left .app-title {
        gap: 0.75rem;
    }
    
    /* モバイル向けキャンバス追加最適化 */
    .canvas-container {
        min-height: 65vh; /* より縦長に */
        max-height: 75vh;
    }
    
    /* コントロールパネルのコンパクト化 */
    .controls {
        gap: 1rem;
        padding: 0.75rem;
    }
    
    .control-group {
        padding: 0.75rem;
    }
    
    .control-group h3 {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    /* ボタンとコントロールの最適化 */
    .mode-buttons {
        gap: 0.5rem;
    }
    
    .mode-btn {
        padding: 0.5rem;
        min-height: 50px;
    }
    
    .color-options {
        gap: 0.3rem;
    }
    
    .color-btn {
        width: 28px;
        height: 28px;
    }
    
    .action-buttons {
        gap: 0.5rem;
    }
    
    .action-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .header-left h1 {
        font-size: 1.5rem;
        margin-bottom: 0.1rem;
    }
    
    .header-left .subtitle {
        font-size: 0.8rem;
    }
    
    .header-right .status-info {
        gap: 0.75rem;
        flex-wrap: wrap;
    }
    
    .header-right .status-label {
        font-size: 0.7rem;
    }
    
    .header-right .status-value {
        font-size: 0.7rem;
        padding: 0.1rem 0.3rem;
        min-width: 35px;
    }
    
    .canvas-container {
        aspect-ratio: 4/3;
        min-height: 400px;
    }
    
    #segmentationCanvas {
        width: 120px;
        height: 90px;
        top: 8px;
        right: 8px;
    }
    
    .container {
        margin: 1rem 0.17rem; /* 左右マージンを1/3に縮小（0.5rem→0.17rem） */
        padding: 0 0.17rem; /* 左右パディングを1/3に縮小 */
        gap: 1rem;
    }
    
    .controls {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    header {
        padding: 0.5rem 0;
        margin: 0;
        width: 100vw;
        position: relative;
        left: 0;
        right: 0;
    }
    
    .header-right .status-info {
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    
    .header-right .status-item {
        justify-content: center;
        width: 100%;
    }
    
    .header-left .app-icon {
        width: 45px;
        height: 45px;
    }
    
    .header-left .app-title {
        gap: 0.5rem;
    }
    
    .header-left h1 {
        font-size: 1.3rem;
    }
    
    .container {
        padding: 0 0.33rem; /* 左右パディングを1/3に縮小 */
        margin: 0.5rem auto;
        width: calc(100% - 0.66rem); /* 全体幅から縮小されたパディング分を引く */
        max-width: none;
    }
    
    .canvas-container {
        aspect-ratio: 3/4; /* 小画面でも縦長維持 */
        min-height: 55vh; /* 小画面向け高さ調整 */
        max-height: 65vh;
        width: 100%;
        margin: 0;
    }
    
    .controls {
        width: 100%;
        margin: 0;
    }
    
    #segmentationCanvas {
        width: 80px;
        height: 60px;
        top: 5px;
        right: 5px;
    }
}

@media (max-width: 380px) {
    header {
        padding: 0.25rem 0;
        width: 100vw;
    }
    
    .header-left .app-icon {
        width: 40px;
        height: 40px;
    }
    
    .header-left .app-title {
        gap: 0.4rem;
    }
    
    .header-left h1 {
        font-size: 1.1rem;
    }
    
    .header-left .subtitle {
        font-size: 0.75rem;
    }
    
    .header-right .status-label {
        font-size: 0.65rem;
    }
    
    .header-right .status-value {
        font-size: 0.65rem;
        padding: 0.05rem 0.2rem;
        min-width: 30px;
    }
    
    .container {
        padding: 0 0.5rem;
        width: calc(100% - 1rem);
    }
    
    #segmentationCanvas {
        width: 70px;
        height: 52px;
    }
}