/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #1e1e2e;
    --bg-secondary: #282840;
    --bg-surface: #313150;
    --text-primary: #e0e0f0;
    --text-secondary: #a0a0c0;
    --accent: #7c6ff7;
    --accent-hover: #9580ff;
    --border: #3a3a5c;
    --error: #ff6b8a;
    --success: #6bffa0;
    --font-mono: 'Consolas', 'D2Coding', 'Nanum Gothic Coding', monospace;
    --font-sans: 'Pretendard', 'Noto Sans KR', -apple-system, sans-serif;
    --header-height: 48px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

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

/* ===== Buttons ===== */
.btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font-sans);
}

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

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-export {
    font-size: 12px;
    padding: 4px 10px;
    font-weight: 600;
}

.btn-help {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    font-weight: 700;
    text-align: center;
}

/* ===== Main Layout ===== */
.main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-editor {
    width: 380px;
    min-width: 280px;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
}

.panel-preview {
    flex: 1;
    background: var(--bg-primary);
}

.panel-header {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.panel-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Editor ===== */
.editor {
    flex: 1;
    width: 100%;
    padding: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    tab-size: 2;
}

.editor::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

/* ===== Templates ===== */
.template-header {
    border-top: 1px solid var(--border);
}

.templates {
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    flex-shrink: 0;
}

.template-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font-sans);
}

.template-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ===== Error Box ===== */
.error-box {
    padding: 8px 12px;
    background: rgba(255, 107, 138, 0.1);
    border-top: 1px solid var(--error);
    color: var(--error);
    font-size: 13px;
    font-family: var(--font-mono);
    max-height: 80px;
    overflow-y: auto;
    flex-shrink: 0;
}

/* ===== Preview ===== */
.preview-area {
    flex: 1;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.jxgbox {
    border-radius: 8px;
    background: #fff;
}

/* JSXGraph override */
.jxgbox text {
    font-family: var(--font-sans) !important;
}

/* ===== Resize Handle ===== */
.resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    transition: background 0.15s;
    flex-shrink: 0;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--accent);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 560px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 16px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.7;
}

.modal-body h3 {
    color: var(--accent);
    margin: 16px 0 8px;
    font-size: 14px;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body pre {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    overflow-x: auto;
    color: var(--text-secondary);
}

/* ===== Utility ===== */
.hidden {
    display: none !important;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
