/**
 * main.css
 * 전역 스타일, 레이아웃, CSS 리셋
 */

/* CSS Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border-radius: 0 !important;
    font-weight: normal !important;
}

/* CSS 변수 (색상 팔레트) */
/* CSS 변수 (색상 팔레트) - Pixel Theme */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #ef4444;
    --danger-color: #dc2626;
    --bg-dark: #1a1a1a;
    --bg-light: #262626;
    --bg-panel: #333333;
    --border-color: #000000;
    --text-primary: #ffffff;
    --text-secondary: #a3a3a3;
    --shadow: rgba(0, 0, 0, 0.5);
    --pixel-border: 1px solid var(--border-color);
}

.selection-marquee {
    position: fixed;
    border: 1px dashed var(--primary-color);
    background-color: rgba(59, 130, 246, 0.2);
    pointer-events: none;
    z-index: 9999;
}

@font-face {
    font-family: 'Cafe24ProUp';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2507-1@1.0/Cafe24PROUP.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

/* 기본 스타일 */
body {
    font-family: 'Cafe24ProUp', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
    color: var(--text-primary);
    background-color: var(--bg-dark);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    image-rendering: pixelated;

    /* Disable selection and dragging globally */
    user-select: none;
    -webkit-user-drag: none;
}

/* Enable selection for inputs and text areas */
input,
textarea,
[contenteditable="true"] {
    user-select: text;
}

/* Specifically disable image dragging */
img {
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: none;
    /* Prevents context menu and dragging */
}

button {
    font-family: 'Cafe24ProUp', sans-serif;
    color: var(--text-primary);
}

input,
select,
textarea {
    font-family: 'Cafe24ProUp', sans-serif;
    color: #ffffff;
    background-color: #222;
}

/* 레이아웃 */
#toolbar {
    flex-shrink: 0;
}

#main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    gap: 1px;
    background-color: var(--border-color);
}

/* 패널 공통 스타일 */
#assets-panel,
#editor-panel,
#preview-panel {
    background-color: var(--bg-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}



/* 오른쪽 영역 (Preview + Timeline 컨테이너) */
#right-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--border-color);
    gap: 0;
}

.resizer {
    background-color: var(--border-color);
    transition: background-color 0.2s;
    z-index: 10;
}

.resizer:hover,
.resizer.resizing {
    background-color: var(--primary-color);
}

.resizer-v {
    width: 2px;
    cursor: col-resize;
}

.resizer-h {
    height: 2px;
    cursor: row-resize;
}

/* Assets 패널 (왼쪽) */
#assets-panel {
    width: 240px;
    flex-shrink: 0;
    border-right: none;
    background-color: var(--bg-light);
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    /* Fixed height for alignment */
    padding: 0 10px;
    background-color: var(--bg-dark);
    color: white;
    border-bottom: 1px solid var(--border-color);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: normal;
    color: #ffffff;
}

.panel-icon-btn {
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    border: 1px solid #000;
    color: white;
}

.panel-icon-btn .material-symbols-outlined {
    font-size: 18px;
}

.panel-icon-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.panel-icon-btn:active:not(:disabled) {
    transform: translateY(2px);
}

.panel-icon-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--border-color);
}

#asset-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.asset-item {
    display: flex;
    flex-direction: row;
    /* Horizontal layout */
    align-items: center;
    margin-bottom: 5px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 0;
    cursor: grab;
    gap: 10px;
    /* Space between image and text */
    background-color: var(--bg-panel);
    user-select: none;
    /* Disable text selection */
}

.asset-item:hover {
    background-color: #444;
    border-color: var(--primary-color);
}

.asset-item:active {
    cursor: grabbing;
}

.asset-item.selected {
    background-color: var(--primary-color);
    border-color: #ffffff;
}

.asset-item.selected .asset-name {
    color: #ffffff;
}

.asset-thumbnail {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border: 1px solid var(--border-color);
    background-color: #333;
    /* Transparent Checkerboard Pattern */
    background-image:
        linear-gradient(45deg, #444 25%, transparent 25%),
        linear-gradient(-45deg, #444 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #444 75%),
        linear-gradient(-45deg, transparent 75%, #444 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
    pointer-events: none;
    /* Prevent image dragging */
    flex-shrink: 0;
}

.asset-name {
    font-size: 11px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
    /* Prevent text selection/dragging */
}



/* Editor 패널 (하단 - Timeline) */
#editor-panel {
    height: 360px;
    flex-shrink: 0;
    min-height: 100px;
    border-top: none;
    display: flex;
    flex-direction: column;
}

#timeline-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background-color: #222;
    /* Darker track bg */
    display: flex;
    flex-direction: row;
}

#timeline-canvas {
    flex: 1;
    cursor: crosshair;
    display: block;
}

/* Volume Meter */
#volume-meter-container {
    width: 80px;
    height: 100%;
    background-color: #151515;
    /* Distinct dark background */
    border-left: 1px solid #000;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 10px;
    /* Add breathing room */
    gap: 5px;
    /* Separate scale and bar */
}

.volume-meter-scale {
    width: 24px;
    height: 90%;
    /* Slight vertical padding effect */
    position: relative;
    border-right: 1px solid #333;
    /* Divider line */
}

.scale-mark {
    position: absolute;
    width: 100%;
    height: 1px;
    background-color: #444;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.scale-mark span {
    font-size: 9px;
    color: #888;
    margin-left: 2px;
}

/* Position scale marks (0dB at top, -60dB at bottom) */
.scale-mark[data-db="0"] {
    top: 0%;
}

.scale-mark[data-db="-6"] {
    top: 10%;
}

.scale-mark[data-db="-12"] {
    top: 20%;
}

.scale-mark[data-db="-18"] {
    top: 30%;
}

.scale-mark[data-db="-24"] {
    top: 40%;
}

.scale-mark[data-db="-36"] {
    top: 60%;
}

.scale-mark[data-db="-48"] {
    top: 80%;
}

.scale-mark[data-db="-60"] {
    top: 100%;
}

.volume-meter-bar {
    flex: 1;
    /* Take remaining width */
    height: 90%;
    /* Match scale height */
    background-color: #000;
    position: relative;
    overflow: hidden;
    border: 1px solid #333;
    border-radius: 2px;
}

.meter-gradient {
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    background: linear-gradient(to top,
            #00dc00 0%,
            /* Green: -60dB */
            #00dc00 70%,
            /* Green: -18dB */
            #eebb00 80%,
            /* Yellow: -12dB */
            #ff0000 90%,
            /* Red: -6dB */
            #ff0000 100%
            /* Red: 0dB */
        );
    z-index: 1;
    border-radius: 1px;
}

.meter-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Dynamically changed by JS */
    background-color: #000;
    /* Mask matches container background for "off" state look */
    z-index: 2;
    transition: height 0.05s ease-out;
    opacity: 1;
}

.meter-peak {
    position: absolute;
    left: 2px;
    right: 2px;
    height: 1px;
    background-color: #fff;
    opacity: 0;
    z-index: 3;
    transition: opacity 0.3s ease-out;
    pointer-events: none;
    box-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
}

/* Preview 패널 (상단) */
#preview-panel {
    flex: 1;
    min-height: 300px;
    display: flex;
    flex-direction: column;
}

#zoom-display {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding: 4px 8px;
    background-color: #222;
    border: 1px solid var(--border-color);
}

#preview-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
    position: relative;
    /* 투명 그리드 배경 (체커보드 패턴) */
    background-color: #1a1a1a;
    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;
}

#preview-display img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

#preview-display.empty::after {
    content: 'No frame selected';
    color: var(--text-secondary);
    font-style: italic;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* 인라인 렌더링 프로그래스 오버레이 */
#preview-rendering-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
}

.rendering-progress-container {
    background-color: var(--bg-panel);
    border: 2px solid var(--primary-color);
    padding: 30px 40px;
    min-width: 350px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.rendering-message {
    font-size: 16px;
    color: white;
    margin-bottom: 15px;
    font-family: 'Cafe24ProUp', sans-serif;
    min-height: 20px;
}

.rendering-progress-bar-container {
    width: 100%;
    height: 24px;
    background-color: #222;
    border: 1px solid #444;
    margin-bottom: 10px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.rendering-progress-bar {
    height: 100%;
    background: #3b82f6;
    width: 0%;
    transition: width 0.3s ease-out;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.3);
}

.rendering-progress-text {
    font-size: 13px;
    color: var(--text-secondary);
    font-family: 'Segoe UI', sans-serif;
    min-height: 18px;
}

/* 버튼 공통 스타일 */
button {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: normal;
    border: 1px solid black;
    border-radius: 0;
    cursor: pointer;
    transition: none;
    /* No smooth transition for pixel UI */
    background-color: var(--primary-color);
    color: white;
    box-shadow: inset 2px 2px 0px rgba(255, 255, 255, 0.4), inset -2px -2px 0px rgba(0, 0, 0, 0.4);
    text-shadow: 1px 1px 0 #000;
}

button:hover {
    background-color: var(--primary-hover);
}

button:active {
    transform: translateY(2px);
    box-shadow: inset 2px 2px 0px rgba(0, 0, 0, 0.4), inset -2px -2px 0px rgba(255, 255, 255, 0.1);
}

button:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    opacity: 0.6;
}

button.secondary {
    background-color: var(--secondary-color);
}

button.danger {
    background-color: var(--danger-color);
}

/* 입력 필드 공통 스타일 */
input[type="text"],
input[type="number"] {
    padding: 8px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: border-color 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* 유틸리티 클래스 */
.hidden {
    display: none !important;
}

/* 스크롤바 스타일 (Webkit) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background-color: var(--bg-light);
}

::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 0;
    border: 1px solid var(--bg-light);
}

::-webkit-scrollbar-thumb:hover {
    background-color: #95a5a6;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    background-color: #222;
    border: 1px solid #000;
    height: 20px;
    position: relative;
    margin: 20px 0;
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.progress-bar {
    height: 100%;
    background-color: var(--primary-color);
    width: 0%;
    transition: width 0.1s ease-out;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.2);
}

#dialog-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-51%, -50%);
    font-size: 10px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
    font-family: 'Pixelify Sans', sans-serif;
    white-space: nowrap;
}
