/**
 * Stamp Editor Styles
 */

/* オーバーレイ */
.stamp-editor-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* エディタ本体 */
.stamp-editor {
    width: 95vw;
    height: 95vh;
    max-width: 1600px;
    background: var(--bg, #1a1a1a);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ヘッダー */
.se-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--bg-darker, #111);
    border-bottom: 1px solid var(--border, #333);
}

.se-header-title {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text, #fff);
}

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

.se-btn-close {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted, #999);
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.se-btn-close:hover {
    background: var(--bg-hover, #333);
    color: var(--text, #fff);
}

/* ボタン共通 */
.se-btn {
    padding: 8px 16px;
    border: 1px solid var(--border, #444);
    background: var(--bg-darker, #222);
    color: var(--text, #fff);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.se-btn:hover:not(:disabled) {
    background: var(--bg-hover, #333);
}

.se-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.se-btn-primary {
    background: var(--accent, #4a90d9);
    border-color: var(--accent, #4a90d9);
}

.se-btn-primary:hover:not(:disabled) {
    background: var(--accent-hover, #5aa0e9);
}

.se-btn-danger {
    background: #c53030;
    border-color: #c53030;
}

.se-btn-danger:hover:not(:disabled) {
    background: #e53e3e;
}

.se-btn-block {
    display: block;
    width: 100%;
    margin-bottom: 8px;
}

/* ボディ（キャンバス + パレット） */
.se-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* キャンバスエリア */
.se-canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0a0a;
    padding: 20px;
    overflow: auto;
}

.se-image-container {
    position: relative;
    max-width: 100%;
    max-height: 100%;
}

.se-main-image {
    display: block;
    max-width: 100%;
    max-height: calc(95vh - 80px);
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

/* スタンプ・テキストレイヤー */
.se-stamps-layer,
.se-texts-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.se-stamp,
.se-text {
    pointer-events: auto;
    cursor: move;
    user-select: none;
}

.se-stamp img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.se-stamp.selected,
.se-text.selected {
    outline: 2px solid var(--accent, #4a90d9);
    outline-offset: 2px;
}

.se-text {
    white-space: pre-wrap;
    /* text-shadowはインラインスタイルで動的に設定 */
}

.se-text-input {
    background: rgba(0, 0, 0, 0.5);
    border: 1px dashed var(--accent, #4a90d9);
    outline: none;
    resize: both;
    padding: 4px 6px;
    min-width: 150px;
    min-height: 3.5em;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
}

/* パレット */
.se-palette {
    width: 280px;
    background: var(--bg-darker, #111);
    border-left: 1px solid var(--border, #333);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.se-palette-tabs {
    display: flex;
    border-bottom: 1px solid var(--border, #333);
}

.se-palette-tabs button {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    color: var(--text-muted, #999);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.se-palette-tabs button.active {
    color: var(--accent, #4a90d9);
    background: var(--bg, #1a1a1a);
    border-bottom: 2px solid var(--accent, #4a90d9);
}

.se-palette-content {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.se-palette-header {
    margin-bottom: 12px;
}

.se-palette-header label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted, #999);
    margin-bottom: 4px;
}

.se-palette-header select {
    width: 100%;
    padding: 8px;
    background: var(--bg, #1a1a1a);
    border: 1px solid var(--border, #444);
    border-radius: 6px;
    color: var(--text, #fff);
}

/* スタンプグリッド */
.se-stamp-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.se-stamp-item {
    aspect-ratio: 1;
    object-fit: contain;
    /* 透過画像の黒文字が見えるようチェッカーボード背景 */
    background-color: #e0e0e0;
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    cursor: pointer;
    padding: 4px;
    transition: all 0.2s;
}

.se-stamp-item:hover {
    border-color: var(--accent, #4a90d9);
    transform: scale(1.05);
}

/* テキストグリッド */
.se-text-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}

.se-text-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg, #1a1a1a);
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    color: var(--text, #fff);
    cursor: pointer;
    text-align: left;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.se-text-item:hover {
    border-color: var(--accent, #4a90d9);
}

.se-text-swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* 編集パネル */
.se-edit-panel {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border, #333);
}

.se-edit-panel h4 {
    font-size: 0.85rem;
    color: var(--text-muted, #999);
    margin: 0 0 12px;
}

.se-edit-row {
    margin-bottom: 10px;
}

.se-edit-row label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted, #999);
    margin-bottom: 4px;
}

.se-edit-row select,
.se-edit-row input[type="range"] {
    width: 100%;
}

.se-edit-row select {
    padding: 6px;
    background: var(--bg, #1a1a1a);
    border: 1px solid var(--border, #444);
    border-radius: 4px;
    color: var(--text, #fff);
}

.se-edit-row input[type="range"] {
    margin-top: 4px;
}

.se-edit-row span {
    font-size: 0.8rem;
    color: var(--text-muted, #999);
    margin-left: 8px;
}

/* Moveable カスタマイズ */
.moveable-control-box {
    --moveable-color: var(--accent, #4a90d9) !important;
    z-index: 100 !important;
}

.se-image-container .moveable-control-box {
    pointer-events: auto !important;
}

/* 選択中のスタンプ/テキストを最前面に */
.se-stamp.selected,
.se-text.selected {
    z-index: 10;
}

/* Warpモード */
.se-warp-toolbar {
    position: fixed;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-darker, #111);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 140px;
}

.se-warp-toolbar h4 {
    margin: 0 0 8px;
    font-size: 0.85rem;
    color: var(--text-muted, #999);
    text-align: center;
}

.se-warp-hint {
    margin: 0 0 12px;
    font-size: 0.75rem;
    color: var(--text-muted, #666);
    text-align: center;
    line-height: 1.4;
}

.se-warp-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Warpモード時のスタンプ */
.se-stamp.warp-target {
    outline: 2px dashed #9b59b6 !important;
    outline-offset: 2px;
}

/* 消しゴムモード */
.se-eraser-toolbar {
    position: fixed;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-darker, #111);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.se-eraser-toolbar h4 {
    margin: 0 0 8px;
    font-size: 0.85rem;
    color: var(--text-muted, #999);
    text-align: center;
}

.se-eraser-section {
    margin-bottom: 8px;
}

.se-eraser-section label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted, #999);
    margin-bottom: 4px;
}

.se-brush-shapes {
    display: flex;
    gap: 4px;
}

.se-brush-shape {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border, #444);
    background: var(--bg, #1a1a1a);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.se-brush-shape:hover {
    border-color: var(--accent, #4a90d9);
}

.se-brush-shape.active {
    border-color: var(--accent, #4a90d9);
    background: var(--accent, #4a90d9);
}

.se-brush-shape svg {
    width: 18px;
    height: 18px;
    fill: var(--text, #fff);
}

.se-eraser-toolbar input[type="range"] {
    width: 100%;
}

.se-eraser-toolbar .size-value {
    font-size: 0.75rem;
    color: var(--text-muted, #999);
    text-align: center;
}

.se-eraser-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border, #333);
}

/* 消しゴムモード時のスタンプ */
.se-stamp.eraser-target {
    outline: 2px dashed #ff6b6b !important;
    outline-offset: 2px;
    cursor: crosshair !important;
}

.se-stamp.eraser-target img {
    pointer-events: none;
}

/* 消しゴムカーソル */
.se-eraser-cursor {
    position: fixed;
    pointer-events: none;
    z-index: 10002;
    /* 枠線を内側に含めないと、円の外周が実際に消える範囲より border 分だけ大きくなる */
    box-sizing: border-box;
    border: 2px solid rgba(255, 107, 107, 0.8);
    background: rgba(255, 107, 107, 0.2);
    transform: translate(-50%, -50%);
}

.se-eraser-cursor.circle {
    border-radius: 50%;
}

.se-eraser-cursor.square {
    border-radius: 0;
}

/* 消しゴムモード時のオーバーレイ */
.stamp-editor-overlay.eraser-mode {
    cursor: none;
}

/* 消しゴムモード時のキャンバスエリア */
.se-canvas-area.eraser-mode {
    cursor: none;
}

/* スタンプのマスク適用 */
.se-stamp.has-mask img {
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

/* 自由入力モーダル */
.se-free-text-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10010;
    display: flex;
    align-items: center;
    justify-content: center;
}

.se-free-text-dialog {
    background: var(--bg, #1a1a1a);
    border: 1px solid var(--border, #333);
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.se-free-text-dialog h4 {
    margin: 0 0 16px;
    font-size: 1rem;
    color: var(--text, #fff);
}

.se-free-text-dialog textarea {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    background: var(--bg-darker, #111);
    border: 1px solid var(--border, #444);
    border-radius: 8px;
    color: var(--text, #fff);
    font-size: 1rem;
    line-height: 1.5;
    resize: vertical;
    font-family: inherit;
}

.se-free-text-dialog textarea:focus {
    outline: none;
    border-color: var(--accent, #4a90d9);
}

.se-free-text-dialog textarea::placeholder {
    color: var(--text-muted, #666);
}

.se-free-text-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .stamp-editor {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }

    .se-body {
        flex-direction: column;
    }

    .se-palette {
        width: 100%;
        height: 200px;
        border-left: none;
        border-top: 1px solid var(--border, #333);
    }

    .se-stamp-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}
