:root {
    --primary: #4f46e5;
    --primary-glow: rgba(79, 70, 229, 0.2);
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --accent: #0891b2;
    --glass: rgba(255, 255, 255, 0.8);
    --border: rgba(0, 0, 0, 0.08);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', 'Noto Sans KR', sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.glass-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.05), transparent),
        radial-gradient(circle at 80% 70%, rgba(34, 211, 238, 0.05), transparent);
    z-index: -1;
}

header {
    padding: 1.5rem 5%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.modal-content {
    background: #ffffff;
    color: var(--text);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: 24px;
    padding: 2.5rem;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

input,
select,
textarea {
    background: #f1f5f9;
    color: var(--text);
    border: 1px solid var(--border);
}

.rich-editor {
    background: #ffffff;
    color: #1e293b;
}

.editor-container {
    background: #ffffff;
    border: 1px solid var(--border);
}

.editor-toolbar {
    background: #f8fafc;
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -1px;
}

.logo span {
    color: var(--primary);
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    transition: 0.3s;
    font-size: 0.95rem;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
    text-shadow: 0 0 10px var(--primary-glow);
}

.btn-write {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.7rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-write:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
}

main {
    max-width: 1200px;
    margin: 4rem auto;
    padding: 0 5%;
}

.hero {
    text-align: center;
    margin-bottom: 5rem;
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    line-height: 1.2;
}

.hero mark {
    background: none;
    color: var(--accent);
}

.hero p {
    color: var(--text-muted);
    font-size: 1.2rem;
    max-width: 700px;
    margin: 0 auto;
}

.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 2rem;
}

.article-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 2rem;
    border-radius: 24px;
    transition: 0.4s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.article-card:hover {
    transform: translateY(-10px);
    background: rgba(30, 41, 59, 0.9);
    border-color: var(--primary);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.category-tag {
    display: inline-block;
    padding: 0.4rem 1rem;
    background: var(--glass);
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--accent);
    border: 1px solid var(--border);
}

.card-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    background: var(--glass);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.4rem;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-icon.btn-delete:hover {
    background: #ef4444;
    border-color: #ef4444;
}

.article-card h3 {
    font-size: 1.4rem;
    margin-bottom: 1rem;
    line-height: 1.4;
}

.article-card p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 2rem;
}

.content-preview {
    background: rgba(15, 23, 42, 0.3);
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 1rem;
    min-height: 100px;
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.6;
    overflow-y: auto;
}

/* List View Styles */
.list-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2rem;
    margin-top: 3rem;
}

.list-header {
    display: grid;
    grid-template-columns: 1fr 180px;
    padding: 1rem;
    border-bottom: 2px solid var(--text-muted);
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.85rem;
}

.article-row {
    display: grid;
    grid-template-columns: 1fr 180px;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
    transition: 0.3s;
    cursor: pointer;
    align-items: center;
}

.article-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

.article-row .title-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.article-row .article-title {
    font-size: 1.1rem;
    color: var(--text);
    font-weight: 500;
}

.article-row .article-title:hover {
    color: var(--accent);
}

.article-row .article-date {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.editor-container {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.editor-toolbar {
    padding: 0.6rem 1rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.tool-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.4rem;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
}

.tool-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.tool-select.inline-select {
    background: #ffffff;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    width: auto;
    min-width: 65px;
    max-width: 100px;
}

.tool-select.inline-select:hover {
    border-color: var(--primary);
    color: var(--text);
}

.color-palette {
    display: flex;
    gap: 4px;
    align-items: center;
}

.color-btn {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: 0.2s;
}

.color-btn:hover {
    transform: scale(1.2);
    border-color: white;
}

.tool-btn.active {
    background: var(--primary);
    color: white;
}

.v-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 0.5rem;
}

.rich-editor {
    min-height: 300px;
    padding: 1.5rem;
    color: var(--text);
    outline: none;
    font-size: 1rem;
    line-height: 1.7;
    background: white;
}

.rich-editor:empty:before {
    content: attr(placeholder);
    color: var(--text-muted);
}

.editor-help {
    margin-top: 0.5rem;
    padding-left: 0.5rem;
}

/* Modal Content Variations */
.editor-modal {
    max-width: 900px;
}

.detail-modal {
    max-width: 1000px;
    padding: 3rem;
}

.form-row {
    display: flex;
    gap: 1.5rem;
}

.flex-1 {
    flex: 1;
}

.flex-2 {
    flex: 2;
}

/* Detail Page Styles */
.detail-title {
    font-size: 3rem;
    font-weight: 800;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.detail-meta {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 2rem;
}

.detail-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.detail-body {
    font-size: 1.2rem;
    line-height: 1.8;
}

.detail-files {
    margin-top: 3rem;
    padding: 1.5rem;
    background: var(--glass);
    border-radius: 12px;
}

.detail-actions {
    margin-top: 4rem;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.btn-edit-detail,
.btn-delete-detail {
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-edit-detail {
    background: var(--glass);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-delete-detail {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Attached Files List */
.attached-files {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--glass);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.btn-remove-file {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
}

.tool-link-inline {
    text-decoration: none;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.article-footer {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

/* Modal Styling */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

/* modal-content style already defined above, but we clean up the one at the bottom */
/* .modal-content at line 50 is the primary one */

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-muted);
}

.editor-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: var(--glass);
    border-radius: 8px;
    font-size: 0.85rem;
}

.editor-tools code {
    background: rgba(99, 102, 241, 0.2);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    color: var(--accent);
}

.tool-link {
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 600;
}

.tool-link:hover {
    text-decoration: underline;
}

input,
select,
textarea {
    width: 100%;
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 1rem;
}

textarea {
    resize: vertical;
}

.btn-submit {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: 0.3s;
}

.btn-submit:hover {
    background: #4f46e5;
}

footer {
    text-align: center;
    padding: 4rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

.loader {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--primary);
    font-weight: 600;
}

/* =========================================
   Mobile Optimization (max-width: 768px)
   ========================================= */
@media (max-width: 768px) {

    /* 1. Header & Navigation */
    header {
        padding: 1rem 5%;
        background: rgba(255, 255, 255, 0.95);
    }

    nav {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .logo {
        text-align: center;
        font-size: 1.3rem;
    }

    .nav-links {
        gap: 0.5rem;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 0.2rem;
        -webkit-overflow-scrolling: touch;
        /* Hide scrollbar */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .nav-links::-webkit-scrollbar {
        display: none;
    }

    .nav-links li {
        flex-shrink: 0;
    }

    .nav-links a {
        padding: 0.5rem 0.8rem;
        background: #f1f5f9;
        border-radius: 20px;
        font-size: 0.9rem;
        display: block;
    }

    .nav-links a.active {
        background: var(--primary);
        color: white;
        text-shadow: none;
    }

    /* 2. Floating Action Button (Write Button) */
    .btn-write {
        position: fixed;
        bottom: 2rem;
        right: 1.5rem;
        z-index: 1000;
        border-radius: 50%;
        width: 60px;
        height: 60px;
        padding: 0;
        justify-content: center;
        font-size: 0;
        /* Hide text */
        box-shadow: 0 4px 20px rgba(79, 70, 229, 0.5);
    }

    .btn-write i {
        width: 28px;
        height: 28px;
    }

    .btn-write::after {
        content: '';
        /* Ensure no extra spacing */
    }

    /* 3. Hero Section */
    .hero {
        margin-bottom: 3rem;
        margin-top: 1rem;
    }

    .hero h1 {
        font-size: 2.2rem;
    }

    .hero p {
        font-size: 1rem;
    }

    /* 4. List View */
    .list-container {
        padding: 1rem;
        margin-top: 2rem;
        border-radius: 16px;
    }

    .list-header {
        display: none;
        /* Hide header on mobile */
    }

    .article-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 1rem 0;
    }

    .article-row .title-area {
        font-size: 1rem;
        flex-wrap: wrap;
    }

    .article-row .article-date {
        font-size: 0.8rem;
        color: var(--text-muted);
    }

    /* 5. Modals */
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
        padding: 1.5rem;
    }

    .form-row {
        flex-direction: column;
        gap: 1rem;
    }

    .btn-close {
        font-size: 1.8rem;
    }

    /* Editor Toolbar scroll */
    .editor-toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 0.5rem;
    }

    .tool-btn {
        padding: 0.6rem;
    }

    /* Detail Page */
    .detail-title {
        font-size: 2rem;
    }

    .detail-actions {
        justify-content: space-between;
    }

    .btn-edit-detail,
    .btn-delete-detail {
        flex: 1;
        justify-content: center;
        padding: 1rem;
    }
}