@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');

:root {
    /* PRETENDARD FONT */
    --font-sans: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif !important;

    /* Color palette (matching original) */
    --slate-50: rgb(248 250 252);
    --slate-100: rgb(241 245 249);
    --slate-200: rgb(226 232 240);
    --slate-400: rgb(148 163 184);
    --slate-500: rgb(100 116 139);
    --slate-600: rgb(71 85 105);
    --slate-800: rgb(30 41 59);
    --slate-900: rgb(15 23 42);

    --indigo-50: rgb(238 242 255);
    --indigo-600: rgb(79 70 229);
    --indigo-700: rgb(67 56 202);

    --emerald-50: rgb(236 253 245);
    --emerald-400: rgb(52 211 153);
    --emerald-600: rgb(5 150 105);

    --purple-600: rgb(147 51 234);
    --purple-700: rgb(126 34 206);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body,
.kswt-app,
.kswt-app * {
    font-family: var(--font-sans) !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body,
.kswt-app {
    background: var(--slate-50);
    color: var(--slate-800);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--slate-100);
}

::-webkit-scrollbar-thumb {
    background: var(--slate-200);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--slate-400);
}

/* ===== HEADER ===== */
.kswt-header {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--slate-100);
    position: sticky;
    top: 0;
    z-index: 40;
}

.kswt-header-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kswt-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.view-toggle {
    display: flex;
    background: var(--slate-100);
    padding: 0.25rem;
    border-radius: 0.75rem;
    gap: 0.25rem;
}

.view-toggle button {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 700;
    border: none;
    background: transparent;
    color: var(--slate-400);
    cursor: pointer;
    transition: all 0.2s;
}

.view-toggle button.active {
    background: white;
    color: var(--slate-900);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.kswt-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.kswt-avatar {
    width: 2.5rem;
    height: 2.5rem;
    background: var(--slate-900);
    color: white;
    border-radius: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.2rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.kswt-brand h1 {
    font-size: 1.25rem;
    font-weight: 800;
    margin: 0;
    padding: 0;
}

.kswt-brand p {
    font-size: 0.75rem;
    color: var(--slate-500);
    margin: 0;
}

/* ===== LAYOUT ===== */
.kswt-layout {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 2rem;
    align-items: start;
}

/* ===== MODE TOGGLE ===== */
.mode-toggle {
    display: flex;
    background: var(--slate-100);
    padding: 0.375rem;
    border-radius: 1rem;
    gap: 0.25rem;
}

.mode-toggle button {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 700;
    border: none;
    background: transparent;
    color: var(--slate-500);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.mode-toggle button.active {
    background: white;
    color: var(--slate-900);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.mode-toggle button span {
    font-size: 1rem;
}

/* ===== TABS ===== */
.kswt-tabs {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.kswt-tab {
    padding: 0.75rem 1.5rem;
    border-radius: 1rem;
    background: white;
    border: 1px solid var(--slate-200);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--slate-400);
    transition: all 0.2s;
}

.kswt-tab.active {
    background: var(--slate-900);
    color: white;
    border-color: var(--slate-900);
}

/* ===== FIELD GROUPS ===== */
.field-group {
    margin-bottom: 1.25rem;
}

.field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.field-header label {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--slate-700);
}

.badge {
    font-size: 0.875rem;
    font-weight: 800;
    color: var(--indigo-600);
    background: var(--indigo-50);
    padding: 0.25rem 0.625rem;
    border-radius: 0.375rem;
}

.range-slider {
    width: 100%;
    height: 8px;
    border-radius: 1rem;
    appearance: none;
    background: var(--slate-200);
    cursor: pointer;
    outline: none;
}

.range-slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--indigo-600);
    cursor: pointer;
}

.range-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--indigo-600);
    cursor: pointer;
    border: none;
}

/* ===== BUTTON GROUPS ===== */
.button-group {
    display: flex;
    gap: 0.5rem;
}

.button-group button {
    flex: 1;
    padding: 0.625rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid var(--slate-200);
    background: white;
    color: var(--slate-500);
    cursor: pointer;
    transition: all 0.2s;
}

.button-group button.active {
    background: var(--slate-900);
    color: white;
    border-color: var(--slate-900);
}

/* ===== PROGRESS ===== */
.progress-container {
    width: 100%;
    height: 12px;
    background: var(--slate-100);
    border-radius: 1rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--emerald-400);
    transition: width 0.3s ease;
    border-radius: 1rem;
}

/* ===== SIDEBAR ===== */
.kswt-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--slate-100);
}

.kswt-section-title {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--slate-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.engine-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.engine-card {
    padding: 1rem;
    border-radius: 1rem;
    background: var(--slate-50);
    border: 2px solid transparent;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.engine-card.active.fast {
    background: var(--emerald-50);
    border-color: var(--emerald-600);
}

.engine-card.active.pro {
    background: rgb(245 243 255);
    border-color: var(--purple-600);
}

.engine-card.active.whisk {
    background: var(--indigo-50);
    border-color: var(--indigo-600);
}

.engine-card span {
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.engine-card .name {
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.125rem;
}

.engine-card .desc {
    font-size: 0.625rem;
    color: var(--slate-400);
    font-weight: 500;
}

/* ===== EDITOR ===== */
.editor-header {
    padding: 1.25rem 1.875rem;
    border-bottom: 1px solid var(--slate-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-header h2 {
    font-size: 1.125rem;
    font-weight: 800;
    margin: 0;
}

.char-count {
    font-size: 0.75rem;
    background: var(--slate-100);
    color: var(--slate-600);
    padding: 0.375rem 0.75rem;
    border-radius: 6.25rem;
    font-weight: 700;
}

.editor-body {
    padding: 1.5rem 1.875rem;
}

#kswt-script-input {
    width: 100%;
    height: 250px;
    background: var(--slate-50);
    border: 1px solid var(--slate-100);
    border-radius: 1rem;
    padding: 1.25rem;
    font-size: 1rem;
    line-height: 1.8;
    outline: none;
    font-family: var(--font-sans);
    resize: none;
}

.editor-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1.25rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 800;
    margin: 2.5rem 0 1.25rem;
    border-left: 4px solid var(--indigo-600);
    padding-left: 1rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 2.5rem 0 1.25rem;
}

.section-header .section-title {
    margin: 0;
}

/* ===== CHARACTERS ===== */
.kswt-characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.25rem;
}

.character-card {
    background: white;
    padding: 1rem;
    border-radius: 1.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--slate-50);
    display: flex;
    gap: 1rem;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.character-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.char-img-box {
    width: 72px;
    height: 72px;
    border-radius: 1.2rem;
    background: var(--slate-100);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.char-img-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.char-info {
    flex: 1;
}

.char-info h4 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.char-info p {
    font-size: 0.75rem;
    color: var(--slate-400);
    line-height: 1.4;
    margin-bottom: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== SCENES ===== */
.kswt-scenes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.scene-card {
    background: white;
    border-radius: 1.5rem;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--slate-50);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.scene-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.scene-img-box {
    position: relative;
    background: var(--slate-100);
    display: flex;
    align-items: center;
    justify-content: center;
}

.aspect-16-9 .scene-img-box {
    aspect-ratio: 16/9;
}

.aspect-9-16 .scene-img-box {
    aspect-ratio: 9/16;
}

.aspect-1-1 .scene-img-box {
    aspect-ratio: 1/1;
}

.scene-img-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scene-badge {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    padding: 0.25rem 0.625rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 900;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.scene-hover-actions {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 1rem;
}

.scene-card:hover .scene-hover-actions {
    opacity: 1;
}

.download-btn {
    width: 36px;
    height: 36px;
    border-radius: 0.75rem;
    background: white;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.download-btn:hover {
    transform: scale(1.1);
}

.scene-desc {
    padding: 1.25rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: rgb(51 65 85);
    font-weight: 500;
    min-height: 4.5em;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== MODAL ===== */
.kswt-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.kswt-modal-content {
    background: rgb(248 250 252);
    border-radius: 1.875rem;
    width: 100%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
}

.kswt-modal-body {
    display: grid;
    grid-template-columns: 1fr 420px;
    width: 100%;
    height: 90vh;
}

.kswt-modal-image-area {
    background: var(--slate-100);
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
    position: relative;
}

.canvas-container {
    background: white;
    border-radius: 1.25rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-container img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
}

.modal-floating-actions {
    position: absolute;
    bottom: 2.5rem;
    left: 50%;
    transform: translateX(-50%);
}

.kswt-modal-info-area {
    padding: 2.5rem;
    background: white;
    border-left: 1px solid var(--slate-100);
    overflow-y: auto;
    position: relative;
}

.kswt-close-modal {
    position: absolute;
    top: 1.875rem;
    right: 1.875rem;
    background: var(--slate-100);
    color: rgb(100 116 139);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    font-size: 1.25rem;
}

.modal-field {
    margin-bottom: 1.5rem;
}

.modal-field label {
    font-size: 0.75rem;
    font-weight: 800;
    color: rgb(148 163 184);
    text-transform: uppercase;
    margin-bottom: 0.75rem;
    display: block;
    letter-spacing: 0.05em;
}

.modal-field textarea {
    width: 100%;
    background: var(--slate-50);
    border: 1px solid var(--slate-200);
    border-radius: 1rem;
    padding: 1.25rem;
    font-size: 0.9rem;
    line-height: 1.7;
    min-height: 80px;
    outline: none;
    transition: all 0.2s;
    font-family: var(--font-sans);
}

.modal-field textarea:focus {
    border-color: var(--indigo-600);
    background: white;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.hist-thumb {
    aspect-ratio: 1;
    border-radius: 0.75rem;
    overflow: hidden;
    background: var(--slate-100);
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.hist-thumb.active {
    border-color: var(--indigo-600);
    box-shadow: 0 0 0 2px var(--indigo-50);
}

.hist-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== BUTTONS ===== */
.kswt-btn {
    font-family: var(--font-sans);
    font-weight: 700;
    border-radius: 0.75rem;
    padding: 0.75rem 1.5rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.kswt-btn.primary {
    background: var(--indigo-600);
    color: white;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

.kswt-btn.primary:hover {
    background: var(--indigo-700);
}

.kswt-btn.ghost {
    background: white;
    color: var(--slate-800);
    border: 1px solid var(--slate-200);
}

.kswt-btn.blur-bg {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
}

.dark-btn {
    background: var(--slate-900);
    color: white;
    font-weight: 700;
    padding: 0.625rem 1.5rem;
    border-radius: 0.75rem;
    border: none;
    cursor: pointer;
}

.kswt-btn-mini {
    padding: 0.375rem 0.875rem;
    border-radius: 6.25rem;
    font-size: 0.75rem;
    font-weight: 800;
    border: none;
    cursor: pointer;
}

.full-width {
    width: 100%;
}

/* ===== UTILITIES ===== */
.hidden {
    display: none !important;
}

.content-section {
    margin-top: 2rem;
}

.spinner,
.spinner-scene {
    width: 24px;
    height: 24px;
    border: 3px solid var(--slate-200);
    border-top-color: var(--indigo-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.placeholder,
.placeholder-scene {
    font-weight: 900;
    font-size: 1.5rem;
    color: var(--slate-400);
}

/* Status colors */
.bg-emerald-50 {
    background: var(--emerald-50);
}

.text-emerald-600 {
    color: var(--emerald-600);
}

.bg-indigo-50 {
    background: var(--indigo-50);
}

.text-indigo-600 {
    color: var(--indigo-600);
}

.bg-slate-100 {
    background: var(--slate-100);
}

.text-slate-400 {
    color: var(--slate-400);
}

.edit-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--slate-200);
    border-radius: 0.75rem;
    outline: none;
    font-family: var(--font-sans);
}

.tag {
    font-size: 0.75rem;
    background: var(--slate-100);
    color: var(--slate-500);
    padding: 0.25rem 0.625rem;
    border-radius: 0.375rem;
    font-weight: 800;
    display: inline-block;
    margin-bottom: 0.5rem;
}

.modal-header {
    margin-bottom: 1.5rem;
}

.history-section {
    margin-top: 1.5rem;
}

.modal-footer {
    margin-top: 2rem;
}

/* ===== MOBILE OPTIMIZATION ===== */
@media screen and (max-width: 768px) {
    .kswt-header-inner {
        padding: 0.75rem 1rem;
    }

    .kswt-brand h1 {
        font-size: 1rem;
    }

    .kswt-layout {
        display: flex;
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }

    .kswt-sidebar {
        width: 100%;
        order: 2;
        /* Move settings below editor on mobile */
    }

    .kswt-main {
        width: 100%;
        order: 1;
        /* Editor comes first on mobile */
    }

    #kswt-script-input {
        height: 200px;
        font-size: 0.875rem;
    }

    .kswt-characters-grid {
        grid-template-columns: 1fr;
    }

    .kswt-scenes-grid {
        grid-template-columns: 1fr;
    }

    .engine-grid {
        grid-template-columns: 1fr;
    }

    .character-card {
        padding: 0.75rem;
    }

    .kswt-modal-body {
        grid-template-columns: 1fr;
        height: auto;
        overflow-y: auto;
    }

    .kswt-modal-content {
        max-height: 95vh;
    }

    .kswt-modal-image-area {
        padding: 1rem;
    }

    .kswt-modal-info-area {
        border-left: none;
        border-top: 1px solid var(--slate-100);
        padding: 1.5rem;
    }
}