/* ============================================================
   TransparentEditor - Photoshop風 背景透過ツール
   ============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-darkest:  #1a1a1e;
    --bg-dark:     #252529;
    --bg-mid:      #2e2e33;
    --bg-light:    #3a3a40;
    --bg-hover:    #44444b;
    --border:      #4a4a52;
    --border-light:#5c5c66;
    --text-primary:#e8e8ee;
    --text-secondary:#9898a8;
    --text-dim:    #66667a;
    --accent:      #4fc3f7;
    --accent-dark: #0288d1;
    --accent-green:#66bb6a;
    --accent-red:  #ef5350;
    --accent-orange:#ffa726;
    --tool-active: #4fc3f7;
    --radius:      6px;
    --radius-sm:   4px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans JP', sans-serif;
    font-size: 12px;
    background: var(--bg-darkest);
    color: var(--text-primary);
    overflow: hidden;
    user-select: none;
}

/* ============================================================
   App Layout
   ============================================================ */
.app-header {
    height: 46px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    gap: 12px;
    flex-shrink: 0;
    z-index: 100;
}

.app-body {
    display: flex;
    height: calc(100vh - 46px - 28px);
}

/* ============================================================
   Header
   ============================================================ */
.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.header-center {
    flex: 1;
    text-align: center;
}

.filename {
    font-size: 12px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-light);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

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

.btn-primary {
    background: var(--accent-dark);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: #0399d8;
    border-color: var(--accent);
}

.btn-success {
    background: #2e6b30;
    border-color: var(--accent-green);
    color: #fff;
}
.btn-success:hover:not(:disabled) {
    background: #367a38;
}

.btn-danger {
    background: #6b2e2e;
    border-color: var(--accent-red);
    color: #fff;
}
.btn-danger:hover:not(:disabled) {
    background: #7a3636;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg-light);
    border-color: var(--border);
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-lg {
    padding: 10px 24px;
    font-size: 14px;
}

/* ============================================================
   Toolbar
   ============================================================ */
.toolbar {
    width: 64px;
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    gap: 2px;
    overflow-y: auto;
    flex-shrink: 0;
}

.tool-group {
    padding: 6px 6px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tool-group:last-child {
    border-bottom: none;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 52px;
    height: 52px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 9px;
    font-family: inherit;
}

.tool-btn span {
    font-size: 9px;
    line-height: 1;
    letter-spacing: 0;
}

.tool-btn:hover {
    background: var(--bg-light);
    color: var(--text-primary);
    border-color: var(--border);
}

.tool-btn.active {
    background: var(--bg-mid);
    color: var(--tool-active);
    border-color: var(--tool-active);
}

/* ============================================================
   Canvas Area
   ============================================================ */
.canvas-area {
    flex: 1;
    background: var(--bg-darkest);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* チェッカーボードパターン（透過を示す） */
.canvas-area::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
        linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    pointer-events: none;
}

.drop-zone {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: transparent;
}

.drop-zone.drag-over .drop-zone-content {
    border-color: var(--accent);
    background: rgba(79, 195, 247, 0.05);
    transform: scale(1.02);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 60px;
    border: 2px dashed var(--border-light);
    border-radius: 16px;
    background: rgba(37, 37, 41, 0.9);
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}

.drop-zone-content svg {
    color: var(--text-dim);
}

.drop-zone-content h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.drop-zone-content p {
    font-size: 13px;
    color: var(--text-secondary);
}

.drop-zone-content .formats {
    font-size: 11px;
    color: var(--text-dim);
}

.canvas-container {
    position: relative;
    will-change: transform;
}

.canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
}

#mainCanvas {
    image-rendering: pixelated;
}

#overlayCanvas {
    cursor: crosshair;
    z-index: 5;
}

/* ============================================================
   Right Panel
   ============================================================ */
.panel-right {
    width: 210px;
    background: var(--bg-dark);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.panel-right::-webkit-scrollbar {
    width: 4px;
}
.panel-right::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.panel-section {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.panel-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-control {
    margin-bottom: 10px;
}

.panel-control label:not(.checkbox-label) {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

/* ============================================================
   Sliders
   ============================================================ */
.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-light);
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-dark);
    box-shadow: 0 0 0 1px rgba(79,195,247,0.4);
}

.slider::-webkit-slider-thumb:hover {
    background: #81d4fa;
}

.slider-value {
    min-width: 28px;
    text-align: right;
    color: var(--text-primary);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

/* ============================================================
   Checkboxes
   ============================================================ */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkbox-custom {
    width: 14px;
    height: 14px;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    background: var(--bg-light);
    position: relative;
    flex-shrink: 0;
    transition: all 0.15s;
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 0px;
    width: 6px;
    height: 9px;
    border: 2px solid #fff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}

/* ============================================================
   Info Panel
   ============================================================ */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    margin-bottom: 10px;
}

.info-item {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 7px;
}

.info-label {
    display: block;
    font-size: 9px;
    color: var(--text-dim);
    margin-bottom: 2px;
    text-transform: uppercase;
}

.info-value {
    display: block;
    font-size: 11px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.color-preview-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-preview {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background: #fff;
    flex-shrink: 0;
    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: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.hex-value {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: monospace;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-secondary);
}

.info-row span:last-child {
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* ============================================================
   Status Bar
   ============================================================ */
.status-bar {
    height: 28px;
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.zoom-btn {
    width: 20px;
    height: 20px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-light);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    transition: background 0.15s;
}

.zoom-btn:hover {
    background: var(--bg-hover);
}

.zoom-display {
    min-width: 46px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ============================================================
   Loading Overlay
   ============================================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 30, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    gap: 16px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-size: 14px;
    color: var(--text-secondary);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   Progress Bar (flood fill)
   ============================================================ */
.progress-bar-container {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 12px;
    z-index: 50;
    display: none;
}

.progress-bar {
    height: 4px;
    background: var(--bg-light);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.1s;
}

/* ============================================================
   Scroll
   ============================================================ */
.toolbar::-webkit-scrollbar {
    width: 3px;
}
.toolbar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
    .panel-right {
        width: 170px;
    }
}

@media (max-width: 700px) {
    .panel-right {
        display: none;
    }
}
