/* リセットとベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.5;
    font-size: 14px;
    height: 100vh;
    overflow: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 15px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ヘッダー */
header {
    text-align: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ddd;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
}

header p {
    color: #666;
    font-size: 0.9rem;
}

/* メインコンテンツ */
.main-content {
    display: flex;
    gap: 15px;
    flex: 1;
    min-height: 0;
    align-items: stretch;
}

/* コントロールパネル */
.control-panel {
    flex: 0 0 250px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
    overflow-y: auto;
}

.panel-section {
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.panel-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.panel-section h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
}

/* 行グループ（横並び配置用） */
.row-group {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.row-group .btn {
    margin-bottom: 0;
    flex: 1;
}

.row-group .input-group {
    flex: 1;
    margin-bottom: 0;
}

/* ボタン */
.btn {
    width: 100%;
    padding: 6px 10px;
    margin-bottom: 5px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.btn:hover:not(:disabled) {
    background-color: #2980b9;
}

.btn:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
}

.btn:last-child {
    margin-bottom: 0;
}

#resetBtn {
    background-color: #e74c3c;
    margin-top: 5px;
}

#resetBtn:hover:not(:disabled) {
    background-color: #c0392b;
}

/* 選択ツールボタン - アクティブ状態 */
.tool-btn.active {
    background-color: #27ae60;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tool-btn.active:hover:not(:disabled) {
    background-color: #229954;
}

/* 入力グループ */
.input-group {
    margin-bottom: 5px;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    color: #555;
    margin-bottom: 2px;
    font-weight: 500;
}

.input-group input[type="number"],
.input-group select {
    width: 100%;
    padding: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85rem;
}

.input-group input[type="number"]:disabled,
.input-group select:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

.input-group input[type="checkbox"] {
    margin-right: 4px;
    vertical-align: middle;
}

.input-group input[type="range"] {
    width: 100%;
    vertical-align: middle;
}

.input-group input[type="range"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* キャンバスエリア */
.canvas-area {
    flex: 1;
    min-width: 0;
    min-height: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.canvas-wrapper {
    flex: 1;
    min-height: 0;
    background:
        repeating-conic-gradient(#f0f0f0 0% 25%, white 0% 50%) 50% / 20px 20px;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: auto;
    display: flex;
}

.canvas-container {
    position: relative;
    margin: auto;
    line-height: 0;
}

.canvas-wrapper.drag-over {
    border-color: #3498db;
    background-color: #ecf8ff;
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
}

#mainCanvas {
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ステータスバー */
.status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.status {
    flex: 1;
    padding: 8px;
    background-color: #ecf0f1;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #555;
    min-height: 20px;
}

/* ズームラベル */
.zoom-label {
    padding: 8px 12px;
    background-color: #ecf0f1;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #555;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}

.zoom-label:hover {
    background-color: #d5dbde;
    color: #333;
}

/* トリミングオーバーレイ */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.crop-box {
    position: absolute;
    border: 2px solid #3498db;
    background-color: rgba(52, 152, 219, 0.1);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.crop-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #3498db;
    border: 1px solid white;
}

.crop-handle.nw {
    top: -4px;
    left: -4px;
    cursor: nw-resize;
}

.crop-handle.ne {
    top: -4px;
    right: -4px;
    cursor: ne-resize;
}

.crop-handle.sw {
    bottom: -4px;
    left: -4px;
    cursor: sw-resize;
}

.crop-handle.se {
    bottom: -4px;
    right: -4px;
    cursor: se-resize;
}

.crop-handle.n {
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    cursor: n-resize;
}

.crop-handle.s {
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    cursor: s-resize;
}

.crop-handle.w {
    top: 50%;
    left: -4px;
    transform: translateY(-50%);
    cursor: w-resize;
}

.crop-handle.e {
    top: 50%;
    right: -4px;
    transform: translateY(-50%);
    cursor: e-resize;
}

/* 選択キャンバス */
#selectionCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

/* レスポンシブ */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow: auto;
    }

    .container {
        height: auto;
    }

    .main-content {
        flex-direction: column;
        min-height: auto;
        align-items: stretch;
    }

    .control-panel {
        flex: none;
        width: 100%;
        max-height: none;
    }

    .canvas-wrapper {
        min-height: 300px;
    }

    /* モバイルではボタンを少し押しやすく */
    .btn {
        padding: 10px 12px;
    }
}
