body {
    margin: 0;
    font-family: sans-serif;
}

/* 操作アイコンを画面上部中央に固定 */
.main-container {
    text-align: center;
    align-items: center;
    padding: 70px 12px 20px;
}

.buttons {
    position: absolute;
    top: 10px;
    left: 50%;
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateX(-50%);
}

.buttons img {
    width: 40px;
    cursor: pointer;
}

.buttons .delete-action {
    margin-left: 14px;
    padding-left: 14px;
    border-left: 1px solid #d8d2c8;
}

/* モバイルでは上部ツールバーを除いた高さに画像を収める */
@media (max-width: 599px) {
    body {
        overflow: hidden;
    }

    .image-area {
        vertical-align: top;
    }

    #baseImage {
        max-height: calc(100dvh - 90px);
        width: auto;
    }
}

.bottom-sheet {
    position: fixed;
    inset: 0;
    visibility: hidden;
    z-index: 10;
}

.bottom-sheet.is-open {
    visibility: visible;
}

.bottom-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 25, 30, 0.35);
    opacity: 0;
    transition: opacity 220ms ease;
}

.bottom-sheet-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
    background: #fffdf8;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(30, 30, 30, 0.18);
    transform: translateY(100%);
    transition: transform 260ms ease;
}

.bottom-sheet.is-open .bottom-sheet-backdrop {
    opacity: 1;
}

.bottom-sheet.is-open .bottom-sheet-panel {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 42px;
    height: 4px;
    margin: 0 auto 14px;
    border-radius: 2px;
    background: #c9c2b6;
}

.bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.bottom-sheet-header h2 {
    margin: 0;
    color: #332e29;
    font-size: 20px;
}

.sheet-close {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #eee9e0;
    color: #332e29;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.sheet-action {
    width: 100%;
    padding: 13px 16px;
    border: 0;
    border-radius: 8px;
    background: #007AFF;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}

.sheet-text-label {
    display: block;
    margin-bottom: 6px;
    color: #332e29;
}

#textInput {
    width: 100%;
    min-height: 92px;
    max-height: 30vh;
    padding: 10px;
    border: 1px solid #c9c2b6;
    border-radius: 8px;
    box-sizing: border-box;
    font: inherit;
    font-size: 16px;
    resize: vertical;
}

#applyText {
    margin-top: 10px;
}

.sheet-controls {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.sheet-control {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
    align-items: center;
    color: #332e29;
}

.sheet-control span {
    min-width: 3ch;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.sheet-control input[type="range"] {
    grid-column: 1 / -1;
    width: 100%;
}

.image-area {
    position: relative;
    display: inline-block;
}

/* 背景画像の表示サイズを基準にCanvasと選択枠を重ねる */
#baseImage {
    max-width: 100%;
    height: auto;
    display: block;
}

/* 実際の文字を描画する透明Canvas */
#textCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    touch-action: none;
    pointer-events: none;
}

/* 入力・確認モーダル共通のレイアウト */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 16px;
    box-sizing: border-box;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    z-index: 20;
}

.modal-content {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 400px;
    box-sizing: border-box;
}

.confirm-content p {
    margin: 0 0 16px;
    text-align: center;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
}

.confirm-buttons button {
    flex: 1;
    padding: 10px;
    font-size: 16px;
}

#textBoxes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* 未選択時は背景を隠さず、選択時だけ枠とハンドルを表示 */
.text-box {
    position: absolute;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
    cursor: move;
    touch-action: none;
    pointer-events: auto;
}

.text-box.active {
    border: 2px dashed rgba(190, 70, 30, 0.95);
}

.text-box::after {
    content: '';
    position: absolute;
    right: -7px;
    bottom: -7px;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(20, 80, 120, 0.9);
    background: #fff;
    box-sizing: border-box;
    display: none;
}

.text-box.active::after {
    display: block;
}

@media (min-width: 600px) {
    .bottom-sheet-panel {
        right: 50%;
        left: auto;
        width: min(440px, 100%);
        border-radius: 18px 18px 0 0;
        transform: translate(50%, 100%);
    }

    .bottom-sheet.is-open .bottom-sheet-panel {
        transform: translate(50%, 0);
    }
}