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

:root {
    --bg: #faf9f6;
    --bg-alt: #f5f4f1;
    --text: #1a1a1a;
    --text-muted: #6b6b6b;
    --accent: #c41e3a;
    --border: #d4d4d4;
    --border-dark: #1a1a1a;
    --surface: #ffffff;
}

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-family: 'Georgia', 'Times New Roman', serif;
}

body.modal-open {
    overflow: hidden;
}

/* Container for centered content */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Header */
header {
    background: var(--bg);
    padding: 1rem 0;
}

.header-logo {
    text-align: center;
    padding: 0.5rem 0;
}

.logo {
    font-family: 'Times New Roman', 'Georgia', serif;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.header-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding: 0.5rem 0;
}

/* Typography stepper controls */
.typo-controls {
    display: flex;
    gap: 1rem;
}

.typo-control {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.typo-label {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-right: 0.25rem;
}

.typo-btn {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 20px;
    height: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.typo-btn:hover {
    color: var(--accent);
}

.typo-value {
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 0.7rem;
    color: var(--text);
    min-width: 1.5rem;
    text-align: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.25rem;
    cursor: pointer;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

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

/* Main content */
main {
    padding: 2.5rem 0 3rem;
}

.type-row {
    display: grid;
    grid-template-columns: 1fr 180px;
    gap: 1.5rem;
    align-items: center;
    padding: 1.25rem 0;
}

.type-row:first-child {
    padding-top: 0.5rem;
}

.type-text {
    min-width: 0;
    word-wrap: break-word;
}

.type-text h1 {
    font-family: inherit;
    font-size: clamp(2.5rem, 5vw, 4rem);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--text);
}

.type-text h2 {
    font-family: inherit;
    font-size: clamp(1.25rem, 2.5vw, 1.75rem);
    font-weight: 400;
    font-style: italic;
    color: var(--text-muted);
    line-height: 1.3;
    letter-spacing: 0;
}

.type-text p {
    font-family: inherit;
    font-size: clamp(1rem, 1.25vw, 1.125rem);
    color: var(--text);
    max-width: 65ch;
    line-height: 1.7;
    letter-spacing: 0;
}

/* Markdown-style content */
.type-row-content .type-text {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.type-text h3 {
    font-family: inherit;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.type-text h4 {
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0.5rem 0 0 0;
}

.type-text ul,
.type-text ol {
    font-family: inherit;
    font-size: clamp(1rem, 1.25vw, 1.125rem);
    color: var(--text);
    padding-left: 1.5rem;
    margin: 0;
    line-height: 1.6;
}

.type-text li {
    margin: 0.25rem 0;
}

.type-text strong {
    font-weight: 600;
}

.type-text blockquote {
    font-family: inherit;
    font-size: clamp(1rem, 1.25vw, 1.125rem);
    color: var(--text-muted);
    border-left: 3px solid var(--border);
    padding-left: 1rem;
    margin: 0.5rem 0;
    font-style: italic;
    line-height: 1.6;
}

.type-control {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

/* Font selector button */
.font-selector {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.8rem;
    padding: 0.25rem 0;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.2s;
}

.font-selector:hover {
    border-color: var(--accent);
}

.font-selector .font-name {
    font-weight: 500;
}

/* Font loading state */
.font-loading {
    position: relative;
    opacity: 0.5;
}

.font-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -24px;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Toast */
.toast {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: var(--bg);
    padding: 0.6rem 1.25rem;
    font-size: 0.8rem;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1100;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    z-index: 1000;
}

.modal.open {
    opacity: 1;
    visibility: visible;
}

.modal.open .modal-content {
    transform: translateY(0);
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    backdrop-filter: blur(4px);
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: none;
    border-radius: 8px;
    width: 90%;
    max-width: 580px;
    max-height: 75vh;
    margin-top: 5vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    transform: translateY(10px);
    transition: transform 0.25s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 1rem;
}

.modal-title {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: var(--bg-alt);
    border: none;
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--border);
    color: var(--text);
}

/* Modal search */
.modal-search {
    padding: 0 1.5rem 1rem;
}

.modal-search input {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    width: 100%;
    background: var(--bg-alt);
    border: none;
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    padding: 0.7rem 1rem;
    outline: none;
    transition: box-shadow 0.2s;
}

.modal-search input:focus {
    box-shadow: 0 0 0 2px rgba(196, 30, 58, 0.2);
}

.modal-search input::placeholder {
    color: var(--text-muted);
}

/* Modal filters */
.modal-filters {
    padding: 0.5rem 1.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    border-bottom: 1px solid var(--bg-alt);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.filter-label {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.6rem;
    color: var(--text-muted);
    min-width: 40px;
}

.filter-btn {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.3rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.filter-btn:hover {
    background: var(--bg-alt);
    color: var(--text);
}

.filter-btn.active {
    background: var(--text);
    color: var(--surface);
}

/* Font list */
.modal-font-list {
    flex: 1;
    overflow-y: auto;
    background: var(--surface);
    padding: 0.5rem 0;
}

.font-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: background 0.1s;
    margin: 0 0.5rem;
    border-radius: 6px;
}

.font-item:hover {
    background: var(--bg-alt);
}

.font-item.selected {
    background: rgba(196, 30, 58, 0.08);
}

.font-item.selected::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    width: 3px;
    height: 24px;
    background: var(--accent);
    border-radius: 2px;
}

.font-preview {
    font-size: 1.1rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 1rem;
    color: var(--text);
}

.font-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 80px;
    text-align: right;
}

.font-name-ko {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text);
}

.font-meta {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.6rem;
    color: var(--text-muted);
}

.no-fonts {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Modal settings */
.modal-settings {
    padding: 0.75rem 1.5rem;
    background: var(--bg-alt);
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.setting-item label {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.setting-item select {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.75rem;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    outline: none;
}

.setting-item select:focus {
    border-color: var(--accent);
}

.setting-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 0 1.5rem;
    }

    header {
        padding: 0.75rem 0;
    }

    .logo {
        font-size: 1.8rem;
    }

    .header-controls {
        gap: 0.75rem;
    }

    .typo-controls {
        gap: 0.5rem;
    }

    /* Mobile: Font selector above text for each row */
    .type-row {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 1rem 0;
    }

    .type-row .type-control {
        order: -1;  /* Move control above text */
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }

    .type-row .type-text {
        order: 0;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .modal-filters {
        padding: 0.6rem 1rem;
    }

    .filter-group {
        gap: 0.3rem;
    }

    .filter-btn {
        padding: 0.2rem 0.5rem;
        font-size: 0.65rem;
    }

    .font-item {
        padding: 0.75rem 1rem;
    }

    .font-preview {
        font-size: 1rem;
    }

    .settings-row {
        gap: 0.75rem;
    }
}

/* Scrollbar styling */
.modal-font-list::-webkit-scrollbar {
    width: 8px;
}

.modal-font-list::-webkit-scrollbar-track {
    background: var(--bg-alt);
}

.modal-font-list::-webkit-scrollbar-thumb {
    background: var(--border);
}

.modal-font-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
