:root {
    /* Colors - Light Mode */
    --bg: #fafafa;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #ebebeb;
    --fg: #1a1a1a;
    --fg-secondary: #666666;
    --fg-tertiary: #999999;
    --accent: #000000;
    --accent-hover: #2a2a2a;
    --accent-soft: #f0f0f0;
    --border: #e5e5e5;
    --border-hover: #d4d4d4;

    /* Border Radius */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows - Light Mode */
    --shadow-xs: 0 1px 4px rgba(0, 0, 0, 0.02);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.04), 0 2px 6px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.05), 0 2px 10px rgba(0, 0, 0, 0.03);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    --font-serif: 'New York', 'Source Serif 4', Georgia, 'Times New Roman', Times, serif;
    --font-mono: 'SF Mono', Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;

    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);
    --ease-in: cubic-bezier(0.4, 0, 1, 1);

    /* Syntax Highlighting - Light Mode */
    --hl-comment: #75715E;
    --hl-tag: #F92672;
    --hl-attr: #547902;
    --hl-string: #987a00;
    --selection-bg: rgba(0, 0, 0, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Colors - Dark Mode */
        --bg: #1a1a1a;
        --bg-secondary: #0a0a0a;
        --bg-tertiary: #2a2a2a;
        --fg: #f0f0f0;
        --fg-secondary: #ababab;
        --fg-tertiary: #7a7a7a;
        --accent: #ffffff;
        --accent-hover: #e8e8e8;
        --accent-soft: #505050;
        --border: #303030;
        --border-hover: #404040;

        /* Shadows - Dark Mode */
        --shadow-xs: 0 1px 4px rgba(0, 0, 0, 0.15);
        --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.15);
        --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.3), 0 2px 10px rgba(0, 0, 0, 0.2);
        --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.35), 0 4px 16px rgba(0, 0, 0, 0.25);

        /* Syntax Highlighting - Dark Mode (One Dark Pro) */
        --hl-comment: #5C6370;
        --hl-tag: #E06C75;
        --hl-attr: #D19A66;
        --hl-string: #98C379;
        --selection-bg: rgba(255, 255, 255, 0.15);
    }
}

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

/* Text Selection */
::selection { background: var(--selection-bg); }
::-moz-selection { background: var(--selection-bg); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--border-hover); }

body {
    font-family: var(--font-sans);
    font-size: 15px;
    color: var(--fg);
    background: var(--bg-secondary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    letter-spacing: -0.01em;
}

/* App Container */
.app-container {
    display: grid;
    grid-template-columns: 400px 1fr;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Left Panel */
.left-panel {
    background: var(--bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.panel-header {
    padding: 32px 28px 24px;
    flex-shrink: 0;
}

.logo {
    font-family: var(--font-serif);
    font-size: 26px;
    font-weight: 600;
    color: var(--fg);
    letter-spacing: -0.03em;
    margin-bottom: 6px;
    line-height: 1.2;
}

.tagline {
    color: var(--fg-secondary);
    font-size: 13.5px;
    margin: 0;
    font-weight: 400;
}

.controls-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0 28px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Right Panel */
.right-panel {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-secondary);
    padding: 32px;
    gap: 32px;
}

/* Preview Section */
.preview-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    min-height: 0;
    padding: 40px;
}

/* Code Section */
.code-section {
    height: auto;
    flex-shrink: 0;
    position: relative;
}

.code-block {
    position: relative;
    background: var(--bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.code-content {
    margin: 0;
    padding: 24px 28px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    color: var(--fg);
    white-space: pre;
    overflow-x: auto;
    -webkit-user-select: text;
    user-select: text;
}

/* Syntax Highlighting */
.hl-comment { color: var(--hl-comment); }
.hl-tag { color: var(--hl-tag); font-weight: 600; }
.hl-attr { color: var(--hl-attr); }
.hl-string { color: var(--hl-string); }

.copy-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--fg-secondary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s var(--ease-out);
    z-index: 5;
}

.copy-btn:hover {
    background: var(--bg-tertiary);
    color: var(--fg);
}

.copy-btn.success {
    background: #10b981;
    color: #ffffff;
    border-color: #10b981;
}

/* Form Fields */
.field { display: flex; flex-direction: column; gap: 8px; }

/* Fieldset reset */
fieldset.field {
    border: none;
    padding: 0;
    margin: 0;
}

.label, legend.label {
    font-size: 11px;
    font-weight: 700;
    color: var(--fg-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="text"], textarea {
    width: 100%;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--fg);
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 12px 14px;
    outline: none;
    transition: all 0.15s var(--ease-out);
    -webkit-user-select: text;
    user-select: text;
}

input[type="text"]:focus, textarea:focus {
    background: var(--bg);
    border-color: var(--border);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { min-height: 80px; resize: none; }

.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }

.radio-group {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
    gap: 4px;
}

.radio {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s var(--ease-out);
    color: var(--fg-secondary);
}

.radio:hover { color: var(--fg); }
.radio input { position: absolute; opacity: 0; width: 0; }
.radio:has(input:checked) { background: var(--accent); color: var(--bg); }

.btn {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--bg);
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    padding: 0 20px;
    cursor: pointer;
    transition: all 0.15s var(--ease-out);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.98); }

/* Card */
.card {
    width: 700px;
    background: var(--bg);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transition: transform 0.2s var(--ease);
    will-change: transform;
}

.card-image {
    width: 100%;
    aspect-ratio: 1.91/1;
    object-fit: cover;
    display: block;
    background: var(--bg-secondary);
    margin-bottom: -1px;
}

.card-content { padding: 26px 30px 30px; }
.card-domain { font-size: 14px; color: var(--fg-secondary); margin-bottom: 8px; font-weight: 500; }
.card-title {
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.card-desc {
    font-size: 15px;
    color: var(--fg-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Summary variant */
.card.summary { display: flex; width: 750px; }
.card.summary .card-image { width: 180px; min-width: 180px; aspect-ratio: 1; margin-bottom: 0; margin-right: -1px; }
.card.summary .card-content { display: flex; flex-direction: column; justify-content: center; padding: 28px 32px; }

/* Toast */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    font-size: 13px;
    font-weight: 600;
    color: var(--bg);
    background: var(--fg);
    padding: 10px 20px;
    border-radius: 30px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s var(--ease-out);
    z-index: 1000;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========================================
   Mobile Layout Refactor (Natural Sequential Flow)
   ======================================== */
@media (max-width: 1023px) {
    body {
        overflow-y: auto;
        height: auto;
        background: var(--bg);
    }

    .app-container {
        display: flex;
        flex-direction: column;
        height: auto;
        width: 100%;
        overflow: visible;
    }

    /* 1. Form Section (Top) */
    .left-panel {
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow: visible;
        flex-shrink: 0;
        position: relative;
        box-shadow: 0 4px 20px rgba(0,0,0,0.04);
        z-index: 2;
        background: var(--bg);
    }

    .panel-header {
        padding: 32px 20px 16px;
        text-align: center;
        border-bottom: none;
    }

    .logo {
        font-size: 24px;
        margin-bottom: 4px;
    }

    .tagline {
        font-size: 13px;
        opacity: 0.75;
    }

    .controls-scroll {
        overflow: visible;
        padding: 0 20px 32px;
        gap: 20px;
    }

    /* 2. Preview & Code Section (Follows naturally) */
    .right-panel {
        height: auto;
        padding: 40px 20px 60px;
        gap: 48px;
        overflow: visible;
        background: var(--bg-secondary);
        flex: 1;
    }

    .preview-section {
        padding: 32px 20px;
        min-height: auto;
        overflow: visible;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Section Headings for mobile flow */
    .preview-section::before {
        content: "Preview";
        display: block;
        text-align: center;
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        color: var(--fg-tertiary);
        margin-bottom: 20px;
    }

    .code-section::before {
        content: "Code";
        display: block;
        text-align: center;
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        color: var(--fg-tertiary);
        margin-bottom: 16px;
    }

    /* Mobile: Copy button below code block */
    .copy-btn {
        position: relative;
        top: auto;
        right: auto;
        display: flex;
        width: 100%;
        max-width: 100%;
        margin: 12px auto 0;
        padding: 12px 16px;
        justify-content: center;
        font-size: 13px;
        background: var(--accent);
        color: var(--bg);
        border-color: var(--accent);
        border-radius: var(--radius);
        box-shadow: var(--shadow-sm);
    }

    .copy-btn:hover {
        background: var(--accent-hover);
        color: var(--bg);
    }

    .copy-btn:active {
        transform: scale(0.97);
    }

    .copy-btn svg {
        width: 14px;
        height: 14px;
    }

    .card {
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
        box-shadow: var(--shadow-md);
    }

    /* Mobile Summary Card: Keep horizontal layout, adjust size */
    .card.summary {
        display: flex;
        flex-direction: row;
        height: auto;
        width: 100%;
        max-width: 100%;
    }

    .card.summary .card-image {
        width: 140px;
        min-width: 140px;
        height: auto;
        aspect-ratio: 1;
        margin-right: -1px;
        margin-bottom: 0;
    }

    .card.summary .card-content {
        flex: 1;
        padding: 20px 22px;
    }

    /* 3. Code Section (Bottom) */
    .code-section {
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
    }

    .code-block {
        box-shadow: var(--shadow-sm);
        border-radius: var(--radius-md);
    }

    .code-content {
        font-size: 11.5px;
        padding: 18px 16px;
        line-height: 1.65;
    }

    /* Better touch targets */
    .btn, .radio {
        min-height: 44px;
    }

    input[type="text"], textarea {
        min-height: 42px;
        font-size: 15px;
        padding: 11px 13px;
    }

    .btn {
        width: 100%;
        margin-top: 8px;
        font-size: 15px;
        padding: 0 18px;
    }

    .input-group {
        flex-direction: column;
        gap: 10px;
    }

    .field {
        gap: 10px;
    }

    .label {
        font-size: 10.5px;
    }

    @media (hover: none) and (pointer: coarse) {
        .btn:active { transform: scale(0.97); }
    }
}

/* Smaller mobile devices */
@media (max-width: 480px) {
    .panel-header {
        padding: 24px 16px 12px;
    }

    .logo {
        font-size: 22px;
    }

    .tagline {
        font-size: 12px;
    }

    .controls-scroll {
        padding: 0 16px 24px;
        gap: 16px;
    }

    .right-panel {
        padding: 32px 16px 48px;
        gap: 40px;
    }

    .card {
        max-width: 100%;
        border-radius: var(--radius-md);
    }

    /* Smaller summary card on small screens */
    .card.summary .card-image {
        width: 120px;
        min-width: 120px;
    }

    .card.summary .card-content {
        padding: 18px 20px;
    }

    .card-content {
        padding: 20px 22px 22px;
    }

    .card-title {
        font-size: 19px;
    }

    .card-desc, input[type="text"], textarea {
        font-size: 14px;
    }

    .code-content {
        font-size: 11px;
        padding: 16px 14px;
    }

    .copy-btn {
        margin-top: 10px;
        padding: 11px 14px;
        font-size: 12.5px;
    }

    .copy-btn svg {
        width: 13px;
        height: 13px;
    }

    .preview-section::before,
    .code-section::before {
        font-size: 9.5px;
        margin-bottom: 16px;
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .panel-header {
        padding: 20px 14px 10px;
    }

    .logo {
        font-size: 20px;
    }

    .controls-scroll {
        padding: 0 14px 20px;
        gap: 14px;
    }

    .right-panel {
        padding: 28px 14px 40px;
        gap: 36px;
    }

    .card-title {
        font-size: 17px;
    }

    input[type="text"], textarea {
        font-size: 13.5px;
        padding: 10px 12px;
    }

    .btn {
        min-height: 42px;
        font-size: 14px;
    }

    .code-content {
        font-size: 10.5px;
        padding: 14px 12px;
    }
}

/* Landscape mobile optimization */
@media (max-width: 1023px) and (max-height: 600px) and (orientation: landscape) {
    .panel-header {
        padding: 20px 20px 12px;
    }

    .controls-scroll {
        padding: 0 20px 24px;
    }

    .right-panel {
        padding: 32px 20px 40px;
        gap: 32px;
    }

    .preview-section::before,
    .code-section::before {
        margin-bottom: 16px;
    }
}

/* Safe area support */
@supports (padding: env(safe-area-inset-bottom)) {
    .right-panel {
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
    }

    @media (max-width: 480px) {
        .right-panel {
            padding-bottom: calc(32px + env(safe-area-inset-bottom));
        }
    }
}
