* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 10px;
    gap: 10px;
}

/* ヘッダー */
.header {
    background: white;
    padding: 8px 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    flex-shrink: 0;
}

.header-left h1 {
    color: #667eea;
    font-size: 20px;
    margin: 0;
}

.header-tools {
    display: flex;
    gap: 5px;
    flex: 1;
    justify-content: center;
}

.header-tool-btn {
    width: 50px;
    height: 50px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-tool-btn .icon {
    font-size: 28px;
}

.header-tool-btn:hover {
    background: #f5f5f5;
    border-color: #667eea;
}

.header-tool-btn.active {
    background: #667eea;
    border-color: #667eea;
}

.header-actions {
    display: flex;
    gap: 5px;
}

.header-action-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-action-btn .icon {
    font-size: 20px;
}

.header-action-btn:hover {
    background: #f5f5f5;
    border-color: #667eea;
}

/* ツールオプションパネル */
.tool-options {
    background: white;
    padding: 10px 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-height: 50px;
    flex-shrink: 0;
}

.tool-option-panel {
    display: flex;
    gap: 30px;
    align-items: center;
    flex-wrap: wrap;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.option-group label {
    font-size: 12px;
    color: #666;
    font-weight: 600;
    min-width: 50px;
}

.option-group input[type="range"] {
    width: 120px;
}

.option-group input[type="color"] {
    width: 40px;
    height: 40px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    cursor: pointer;
}

.option-group select {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    background: white;
    font-size: 12px;
    cursor: pointer;
}

.option-group span {
    font-size: 12px;
    color: #667eea;
    font-weight: bold;
    min-width: 30px;
}

.tool-hint {
    color: #999;
    font-size: 12px;
    margin: 0;
    font-style: italic;
}

/* 選択モードボタン */
.selection-mode-buttons {
    display: flex;
    gap: 5px;
}

.mode-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mode-btn .icon {
    font-size: 20px;
}

.mode-btn:hover {
    background: #f5f5f5;
    border-color: #667eea;
}

.mode-btn.active {
    background: #667eea;
    border-color: #667eea;
}

/* 色選択 */
#colorPicker {
    width: 35px;
    height: 35px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    cursor: pointer;
}

.color-presets {
    display: flex;
    gap: 4px;
}

.color-preset {
    width: 22px;
    height: 22px;
    border: 2px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.color-preset:hover {
    transform: scale(1.15);
    border-color: #667eea;
}

/* ブラシサイズ */
#brushSize {
    width: 80px;
}

#brushSizeValue {
    font-weight: bold;
    color: #667eea;
    font-size: 11px;
    min-width: 20px;
}

/* キャンバスワークスペース */
.canvas-workspace {
    flex: 1;
    display: flex;
    gap: 10px;
    overflow: hidden;
    min-height: 0;
}

/* キャンバスエリア */
.canvas-container {
    flex: 1;
    background: #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    position: relative;
    padding: 20px;
}

#mainCanvas {
    cursor: none;
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 0 0 2px #999;
    /* チェッカーボード背景（透明を表現） */
    background-image:
        linear-gradient(45deg, #cccccc 25%, transparent 25%),
        linear-gradient(-45deg, #cccccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #cccccc 75%),
        linear-gradient(-45deg, transparent 75%, #cccccc 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #ffffff;
    position: relative;
}

/* ブラシカーソル */
#brushCursor {
    position: fixed;
    pointer-events: none;
    border: 1px solid rgba(0, 0, 0, 0.8);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    display: none;
    /* 白い影を追加して黒い背景でも見える */
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.8),
        0 0 3px rgba(255, 255, 255, 0.5);
}

#brushCursor.square {
    border-radius: 0;
}

/* 選択ツール用の十字カーソル */
#crosshairCursor {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    display: none;
    /* カーソル全体にフィルターで影を追加 */
    filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.9))
            drop-shadow(0 0 2px rgba(255, 255, 255, 0.6));
}

#crosshairCursor::before,
#crosshairCursor::after {
    content: '';
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
}

#crosshairCursor::before {
    /* 縦線 */
    width: 1px;
    height: 20px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

#crosshairCursor::after {
    /* 横線 */
    width: 20px;
    height: 1px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* タイムライン */
.timeline {
    background: white;
    padding: 10px 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    max-height: 160px;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.timeline-header h3 {
    font-size: 14px;
    color: #666;
}

.frame-btn {
    padding: 8px 15px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: background 0.3s ease;
}

.frame-btn:hover {
    background: #5568d3;
}

.frame-btn.active {
    background: #5568d3;
    box-shadow: 0 0 0 2px #667eea;
}

/* オニオンスキンコントロール */
.onion-skin-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: #f5f5f5;
    border-radius: 5px;
}

.onion-skin-controls label {
    font-size: 11px;
    color: #666;
    font-weight: 600;
}

.onion-skin-controls input[type="range"] {
    width: 80px;
}

.onion-skin-controls span {
    font-size: 11px;
    color: #667eea;
    font-weight: bold;
    min-width: 25px;
}

.frames-container {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 0;
    flex: 1;
    min-height: 0;
}

.frame-item {
    min-width: 100px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    background: #f9f9f9;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    position: relative;
    touch-action: manipulation; /* タッチデバイスでダブルタップズームを無効化 */
}

.frame-item:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.frame-item.active {
    border-color: #667eea;
    background: #e8ebff;
    font-weight: bold;
}

.frame-item canvas {
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    background-image:
        linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
        linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
        linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.frame-item span {
    font-size: 11px;
    color: #666;
}

.frame-delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border: none;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    opacity: 0;
}

.frame-item:hover .frame-delete-btn {
    opacity: 1;
}

.frame-delete-btn:hover {
    background: #cc0000;
}

/* ズームコントロール */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 100;
}

.zoom-controls button {
    width: 32px;
    height: 32px;
    border: 1px solid #e0e0e0;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.zoom-controls button:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.zoom-controls span {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    min-width: 50px;
    text-align: center;
}

/* ナビゲーターパネル */
.navigator-panel {
    width: 220px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.navigator-header {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    margin-bottom: 10px;
}

.navigator-canvas-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
    cursor: crosshair;
}

#navigatorCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

#navigatorViewport {
    position: absolute;
    border: 2px solid #667eea;
    background: rgba(102, 126, 234, 0.1);
    pointer-events: none;
}

/* レイヤーパネル */
.layers-section {
    margin-top: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.layers-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.layers-header span {
    font-size: 13px;
    font-weight: 600;
    color: #666;
}

.add-layer-btn {
    width: 28px;
    height: 28px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.add-layer-btn:hover {
    background: #5568d3;
}

.layers-container {
    display: flex;
    flex-direction: column-reverse;
    gap: 5px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.layer-item {
    background: #f9f9f9;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 8px;
    cursor: move;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 55px;
}

.layer-item:hover {
    background: #f0f0f0;
    border-color: #667eea;
}

.layer-item.active {
    background: #e8ebff;
    border-color: #667eea;
}

.layer-item.dragging {
    opacity: 0.5;
}

.layer-item.drag-over {
    border-top: 3px solid #667eea;
}

.layer-thumbnail {
    width: 40px;
    height: 30px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: white;
    background-image:
        linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
        linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
        linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.layer-thumbnail canvas {
    max-width: 100%;
    max-height: 100%;
    image-rendering: auto;
}

.layer-visibility {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.layer-name {
    flex: 1;
    font-size: 12px;
    color: #666;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.layer-copy {
    width: 24px;
    height: 24px;
    border: none;
    background: #667eea;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.layer-copy:hover {
    background: #5568d3;
}

.layer-delete {
    width: 24px;
    height: 24px;
    border: none;
    background: #ff4444;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.layer-delete:hover {
    background: #cc0000;
}

/* 設定モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #f0f0f0;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    color: #667eea;
}

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: #f5f5f5;
    border-radius: 6px;
    cursor: pointer;
    font-size: 24px;
    color: #666;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #667eea;
    color: white;
}

.modal-body {
    padding: 20px;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #666;
    margin-bottom: 10px;
}

.setting-group input[type="number"] {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

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

.size-btn {
    padding: 12px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}

.size-btn:hover {
    border-color: #667eea;
    background: #f5f5ff;
}

.size-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.apply-btn {
    width: 100%;
    padding: 14px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: background 0.3s;
}

.apply-btn:hover {
    background: #5568d3;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .tool-section {
        min-width: auto;
    }

    .navigator-panel {
        display: none;
    }
}
