* {
    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.6;
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    padding-top: 20px;
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 15px;
    transform: scale(0.9);
    transform-origin: top center;
}

h1 {
    text-align: center;
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.8rem;
}

.preview-section h1 {
    margin-top: 0;
    margin-bottom: 5px;
}

.site-description {
    text-align: center;
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 15px;
}

.upload-section {
    text-align: center;
    margin-bottom: 20px;
}

.upload-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.upload-hint {
    margin-top: 10px;
    color: #666;
    font-size: 14px;
}

.upload-label {
    display: inline-block;
    padding: 12px 24px;
    background-color: #3498db;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    font-weight: 500;
}

.upload-label:hover {
    background-color: #2980b9;
}

#imageUpload {
    display: none;
}

.editor-section {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.controls {
    background-color: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.control-group input[type="text"],
.control-group select,
.control-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.control-group textarea {
    resize: vertical;
    font-family: inherit;
}

.control-group input[type="range"] {
    width: 70%;
    vertical-align: middle;
}

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

.control-group input[type="color"] {
    width: 50px;
    height: 35px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.color-input-group input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    font-family: monospace;
}

.control-group input[type="checkbox"] {
    margin-right: 8px;
}

.control-group small {
    display: block;
    margin-top: 5px;
    color: #888;
    font-size: 12px;
}

.preview-section {
    background-color: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    align-self: start;
    min-height: 350px;
    position: sticky;
    top: 20px;
}

.canvas-container {
    position: relative;
    width: 100%;
    max-width: 720px;
    aspect-ratio: 1280 / 670;
    border: 1px solid #e0e0e0;
    background-color: #f5f5f5;
    margin: 15px 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

body.drag-over::before {
    content: "";
    position: fixed;
    inset: 0;
    background-color: rgba(52, 152, 219, 0.15);
    border: 4px dashed #3498db;
    pointer-events: none;
    z-index: 9998;
}

body.drag-over::after {
    content: "ここに画像をドロップ";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(52, 152, 219, 0.95);
    color: white;
    padding: 20px 40px;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: 600;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 9999;
}

#canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: pointer;
    user-select: none;
}

#noImageMessage {
    position: absolute;
    color: #999;
    font-size: 18px;
    pointer-events: none;
}

.button-group {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 15px auto 0;
}

.download-btn, .copy-image-btn, .copy-url-btn {
    padding: 10px 25px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s;
}

.download-btn {
    background-color: #27ae60;
    color: white;
}

.download-btn:hover:not(:disabled) {
    background-color: #229954;
}

.download-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

.copy-image-btn {
    background-color: #f39c12;
    color: white;
}

.copy-image-btn:hover:not(:disabled) {
    background-color: #e67e22;
}

.copy-image-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

.copy-image-btn.copied {
    background-color: #27ae60;
}

.copy-url-btn {
    background-color: #3498db;
    color: white;
}

.copy-url-btn:hover {
    background-color: #2980b9;
}

.copy-url-btn.copied {
    background-color: #27ae60;
}

.clear-btn {
    padding: 12px 24px;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.clear-btn:hover {
    background-color: #c0392b;
}

.custom-size-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
}

.custom-size-inputs input[type="number"] {
    width: 100px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.custom-size-inputs span {
    color: #666;
    font-weight: 500;
}


.control-group {
    position: relative;
}

.eyedropper-btn {
    padding: 6px 8px;
    background-color: #17a2b8;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
    margin-left: 4px;
}

.eyedropper-btn:hover {
    background-color: #138496;
}

.eyedropper-btn.active {
    background-color: #28a745;
}

.canvas-eyedropper {
    cursor: crosshair !important;
}

.layer-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.layer-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background-color: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
    min-height: 32px;
}

.layer-item:hover {
    border-color: #3498db;
}

.layer-item.active {
    border-color: #3498db;
    background-color: #e8f4f8;
}

.layer-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    flex: 1;
    min-width: 0;
}

.layer-delete-btn {
    width: 20px;
    height: 20px;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
}

.layer-delete-btn:hover {
    background-color: #c0392b;
}

.layer-delete-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.add-layer-btn {
    width: 100%;
    padding: 6px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;
}

.add-layer-btn:hover {
    background-color: #2980b9;
}

/* 左右の位置・行揃えのセグメントコントロール */
.text-align-group {
    display: flex;
    gap: 4px;
}

/* 左右の位置と行揃えを1行に並べて縦スペースを節約 */
.layout-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.layout-controls .text-align-group {
    flex: 1 1 auto;
}

.control-group .text-align-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
    padding: 7px 4px;
    color: #666;
    background-color: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 5px;
    cursor: pointer;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    user-select: none;
}

.control-group .text-align-option:hover {
    border-color: #3498db;
}

.control-group .text-align-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
}

.control-group .text-align-option:has(input[type="radio"]:checked) {
    border-color: #3498db;
    background-color: #e8f4f8;
    color: #2980b9;
}

.text-align-option svg {
    display: block;
}

/* 視覚的には隠すが読み上げには残すラベル */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.control-group .text-align-option:has(input[type="radio"]:focus-visible) {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

.stroke-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 6px;
}

.stroke-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    background-color: #f8f9fa;
    border-radius: 4px;
}

.stroke-item .stroke-width-input {
    flex: 1;
    min-width: 0;
}

.stroke-item .stroke-width-value {
    font-size: 12px;
    color: #666;
    min-width: 32px;
    text-align: right;
}

.stroke-item .stroke-color-input {
    width: 32px;
    height: 28px;
    padding: 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.stroke-delete-btn {
    width: 22px;
    height: 22px;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stroke-delete-btn:hover {
    background-color: #c0392b;
}

.add-stroke-btn {
    width: 100%;
    padding: 5px;
    background-color: #95a5a6;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

.add-stroke-btn:hover {
    background-color: #7f8c8d;
}

.add-stroke-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.font-dropdown {
    position: relative;
}

.font-dropdown-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: white;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    transition: border-color 0.2s;
}

.font-dropdown-trigger:hover,
.font-dropdown[data-open="true"] .font-dropdown-trigger {
    border-color: #3498db;
}

.font-dropdown-current {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.font-dropdown-arrow {
    margin-left: 8px;
    color: #999;
    font-size: 10px;
    flex-shrink: 0;
}

.font-dropdown[data-open="true"] .font-dropdown-arrow {
    transform: rotate(180deg);
}

.font-dropdown-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 400px;
    display: flex;
    flex-direction: column;
    padding: 4px;
}

.font-dropdown-panel[hidden] {
    display: none;
}

.font-dropdown-search {
    padding: 4px;
    border-bottom: 1px solid #eee;
    margin-bottom: 4px;
}

.font-dropdown-search input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.font-dropdown-search input:focus {
    outline: none;
    border-color: #3498db;
}

.font-dropdown-scroll {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.font-dropdown-load-local {
    margin-top: 4px;
    padding: 8px;
    background-color: #ecf0f1;
    color: #2c3e50;
    border: 1px dashed #bdc3c7;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

.font-dropdown-load-local:hover:not(:disabled) {
    background-color: #d5dbdb;
}

.font-dropdown-load-local:disabled {
    background-color: #f0f0f0;
    color: #999;
    cursor: not-allowed;
}

.font-dropdown-load-local[hidden] {
    display: none;
}

.font-dropdown-empty {
    padding: 16px;
    text-align: center;
    color: #999;
    font-size: 13px;
}

.font-dropdown-group-label {
    padding: 6px 8px 4px;
    font-size: 11px;
    color: #888;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.font-dropdown-item {
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.1s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.font-dropdown-item:hover,
.font-dropdown-item.highlighted {
    background-color: #e8f4f8;
}

.font-dropdown-item.selected {
    background-color: #d6eaf8;
    font-weight: 600;
}

.font-dropdown-item .font-check {
    color: #3498db;
    font-size: 14px;
    margin-left: 6px;
}

.history-section {
    background-color: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-top: 20px;
}

.history-section h2 {
    margin-bottom: 10px;
    color: #2c3e50;
    font-size: 1.1rem;
}

.history-list {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 10px 0;
}

.history-item {
    position: relative;
    min-width: 120px;
    max-width: 150px;
    padding: 15px;
    background-color: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.history-item:hover {
    border-color: #3498db;
    background-color: #e8f4f8;
}

.history-item-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    max-width: 100%;
}

.history-item-details {
    font-size: 12px;
    color: #666;
}

.history-item-date {
    font-size: 11px;
    color: #999;
    margin-top: 5px;
}

.history-delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.history-item:hover .history-delete-btn {
    display: flex;
}

.history-delete-btn:hover {
    background-color: #c0392b;
}

.history-list::-webkit-scrollbar {
    height: 8px;
}

.history-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.history-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

@media (max-width: 768px) {
    .editor-section {
        grid-template-columns: 1fr;
    }

    .controls {
        order: 2;
    }

    .preview-section {
        order: 1;
        position: static;
    }
    
    .button-group {
        flex-direction: column;
        align-items: center;
    }
    
    .download-btn, .copy-image-btn, .copy-url-btn {
        width: 180px;
    }
}