html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    text-align: center;
}

h1 {
    color: #1c1e21;
}

.upload-area {
    display: flex;
    gap: 30px;
    margin-bottom: 20px;
    padding-left: 20px;
}

.how-to-use {
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 10px 15px;
    text-align: left;
    margin: 20px; 
    background-color: #fff;
}

.how-to-use legend {
    padding: 0 5px;
    font-weight: bold;
    color: #555;
}

.how-to-use ul {
    padding-left: 20px;
    margin: 5px 0;
    font-size: 0.9em;
}

.how-to-use li {
    margin-bottom: 8px;
}

#preview-container {
    position: relative;
    max-width: 100%;
    margin: 20px auto;
    border: 2px dashed #ccc;
    min-width: 300px;
    width: fit-content; /* Allow container to shrink to content size */
}

#preview-canvas {
    display: block;
}

#bbox {
    position: absolute;
    border: 2px solid rgba(255, 0, 0, 0.7);
    cursor: move;
    box-sizing: border-box;
    display: none; /* Initially hidden */
}

.handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: rgba(255, 0, 0, 0.9);
    border: 1px solid white;
    border-radius: 50%;
}

.top-left { top: -6px; left: -6px; cursor: nwse-resize; }
.top-right { top: -6px; right: -6px; cursor: nesw-resize; }
.bottom-left { bottom: -6px; left: -6px; cursor: nesw-resize; }
.bottom-right { bottom: -6px; right: -6px; cursor: nwse-resize; }

#initial-spotlight-marker {
    position: absolute;
    border: 3px solid rgba(0, 123, 255, 0.9);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    display: none; /* Initially hidden */
    box-sizing: border-box;
    background-color: transparent;
}

#initial-spotlight-marker.dragging {
    cursor: grabbing;
}

#direction-arrow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px; /* 矢印の長さ */
    height: 2px; /* 矢印の太さ */
    background-color: white;
    transform-origin: center; /* 回転の中心を中央に設定 */
    transform: translate(-50%, -50%); /* 中央に配置 */
}

#direction-arrow::after {
    content: '';
    position: absolute;
    right: -5px; /* 矢印の先端 */
    top: -4px;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 8px solid white;
}

.controls {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 20px;
}

.control-group input[type="number"] {
    width: 60px;
    padding: 5px;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.description {
    font-size: 0.85em;
    color: #666;
    margin-top: 5px;
    margin-bottom: 5px;
    padding-left: 10px; /* Indent description */
}

.speed-control {
    justify-content: space-between;
}

.speed-control input[type="range"] {
    flex-grow: 0;
    width: 200px;
}

.optimization-controls {
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 20px 10px;
    margin: 10px;
}

.optimization-controls legend {
    padding: 0 5px;
    font-weight: bold;
    color: #555;
}

.slider-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 80%;
}

.slider-wrapper span {
    font-size: 0.8em;
    color: #777;
    white-space: nowrap;
}

input[type="range"] {
    flex-grow: 1;
    -webkit-appearance: none;
    height: 8px;
    background: #d3d3d3;
    outline: none;
    opacity: 0.7;
    -webkit-transition: .2s;
    transition: opacity .2s;
    border-radius: 5px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
}

#status {
    font-weight: bold;
    color: #007bff;
    min-height: 1.2em;
}

#result-container {
    margin-top: 20px;
    text-align: center;
}

#result-gif {
    max-width: 100%;
    border: 1px solid #ddd;
    background-color: white;
    display: block;
    margin: 0 auto 10px;
}

button {
    padding: 10px 20px;
    border-radius: 5px;
    border: none;
    font-size: 16px;
    cursor: pointer;
    background-color: #007bff;
    color: white;
    text-decoration: none;
    display: inline-block;
}

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

#save-gif {
    background-color: #28a745;
}

.number-input {
    width: 60px;
    padding: 5px;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-left: 10px;
}

/* Responsive Design for Mobile Devices */
@media (max-width: 768px) {
    body {
        margin: 10px;
        font-size: 16px; /* ベースのフォントサイズを少し上げる */
    }

    h2 {
        font-size: 1.5em;
    }

    .upload-area {
        flex-direction: column; /* 縦並びにする */
        gap: 15px;
        padding-left: 0;
        align-items: stretch; /* 幅を揃える */
    }

    .upload-box {
        width: 100%;
    }

    .how-to-use,
    .controls {
        /* Removed width: 95%; */
    }

    .controls {
        gap: 20px; /* コントロール間のスペースを調整 */
    }

    .control-group {
        flex-direction: column; /* ラベルと入力を縦並びに */
        align-items: flex-start; /* 左揃えに */
        gap: 8px;
    }

    .speed-control {
        flex-direction: row; /* スピードコントロールは横並びを維持 */
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }

    .speed-control input[type="range"] {
        width: 150px; /* スライダーの幅を調整 */
    }

    .optimization-controls .control-group {
        flex-direction: column;
        align-items: flex-start;
    }

    .slider-wrapper {
        flex-direction: column; /* スライダーとラベルを縦に */
        align-items: stretch;
        width: 100%;
        gap: 5px;
    }

    .slider-wrapper span {
        text-align: center; /* ラベルを中央揃えに */
    }

    input[type="range"] {
        width: 100%;
    }

    button {
        width: 100%;
        padding: 15px; /* ボタンを大きくしてタップしやすく */
        font-size: 1.1em;
    }

    #preview-container {
        width: 100%;
        height: auto;
        max-width: 100%;
    }

    /* #preview-canvas {
        width: 100%;
        height: auto;
    } */
}
