:root {
    --bg: #ffffff;
    --text: #000000;
    --border: #e0e0e0;
    --surface: #f5f5f5;
    --accent: #000000;
    --accent-text: #ffffff;
    --dim: #666666;
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --stats-bg: #f0f0f0;
}

[data-theme="dark"] {
    --bg: #000000;
    --text: #ffffff;
    --border: #333333;
    --surface: #111111;
    --accent: #ffffff;
    --accent-text: #000000;
    --dim: #888888;
    --modal-overlay: rgba(255, 255, 255, 0.15);
    --stats-bg: #1a1a1a;
}

* { 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent;
}

button:focus, 
input:focus, 
textarea:focus, 
.select-preset-btn:focus,
.option-label:focus-within {
    outline: none;
}

button:focus-visible, 
input:focus-visible, 
textarea:focus-visible, 
.select-preset-btn:focus-visible,
.option-label input:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

body {
    margin: 0;
    font-family: "Google Sans Flex", sans-serif;
    background-color: var(--bg);
    color: var(--text);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    border-bottom: 1px solid var(--border);
}

.logo { font-weight: 600; font-size: 14px; letter-spacing: -0.02em; }

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 34px;
}

.nav-btn:hover { border-color: var(--text); }

main {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 40px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

header h1 {
    font-size: clamp(32px, 5vw, 48px);
    line-height: 1.1;
    font-weight: 500;
    margin: 0;
    letter-spacing: -0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.stats-container { display: flex; justify-content: center; }

.stats-box {
    background: var(--stats-bg);
    padding: 8px 16px;
    border-radius: 99px;
    font-family: "Google Sans Flex";
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
}

#global-stats { font-weight: 700; }

.controls-bar {
    display: flex;
    justify-content: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 24px;
}

.select-preset-btn {
    display: flex;
    align-items: stretch;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    min-width: 260px;
    overflow: hidden;
}

.select-preset-btn:hover {
    background: transparent; 
    border-color: var(--text);
}

.btn-label {
    background: var(--surface);
    font-size: 11px;
    font-weight: 700;
    color: var(--dim);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 12px 16px;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
}

.btn-value {
    font-size: 14px;
    font-weight: 600;
    padding: 12px 16px;
    flex-grow: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.options-wrapper { margin-bottom: 10px; }

.options-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.option-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 6px;
    transition: background 0.2s, border-color 0.2s;
    justify-content: flex-start;
}

.option-label:hover {
    background: var(--surface);
    border-color: var(--text);
}

.option-label input[type="checkbox"] {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 1px solid var(--dim);
    border-radius: 3px;
    display: grid;
    place-content: center;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.option-label input[type="checkbox"]::before {
    content: "";
    width: 8px;
    height: 8px;
    transform: scale(0);
    transition: 0.1s transform ease-in-out;
    background-color: var(--bg);
    transform-origin: center;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.option-label input[type="checkbox"]:checked {
    border-color: var(--text);
    background-color: var(--text);
}

.option-label input[type="checkbox"]:checked::before { transform: scale(1); }

.editor-container {
    display: flex;
    flex: 1;
    border: 1px solid var(--border);
    min-height: 400px;
    border-radius: 8px;
}

.divider-vertical { width: 1px; background: var(--border); }

.editor-pane { flex: 1; display: flex; flex-direction: column; }

.pane-header {
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 54px;
    min-height: 54px;
}

.pane-header span {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--dim);
    line-height: 1;
}

.header-spacer { height: 28px; width: 1px; }

#copy-btn {
    background: var(--text);
    color: var(--bg);
    border: none;
    font-family: inherit;
    font-size: 11px;
    padding: 0 14px;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 4px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#copy-btn:hover { opacity: 0.9; }

textarea {
    flex: 1;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 24px;
    font-family: "Google Sans Flex", monospace;
    font-size: 15px;
    line-height: 1.6;
    resize: none;
    cursor: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12.5 4.5V20.5M10 4.5H15M10 20.5H15' stroke='%236B7280' stroke-width='1' /%3E%3C/svg%3E") 12 12, text;
    caret-color: #6b7280; 
}

textarea:focus { outline: none; background: var(--surface); }

footer {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    border-top: 1px solid var(--border);
    padding-top: 30px;
    font-size: 12px;
    color: var(--dim);
    text-align: center;
}

footer a { color: var(--text); text-decoration: none; font-weight: 500; }

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-content {
    background: var(--bg);
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 { margin: 0; font-size: 18px; font-weight: 600; }

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--dim);
    padding: 0 8px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.info-item {
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.info-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.info-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
}

.info-desc {
    font-size: 13px;
    color: var(--dim);
    line-height: 1.5;
}

.preset-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 20px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.preset-card:hover {
    background: var(--surface);
    border-color: var(--text);
}

.p-title {
    font-weight: 700;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 12px;
}

.p-desc { 
    font-size: 13px; 
    color: var(--text); 
    line-height: 1.5; 
    opacity: 0.9;
    margin-bottom: 16px;
}

.p-best { 
    font-size: 12px; 
    color: var(--dim); 
    font-style: italic; 
}

@media (max-width: 768px) {
    main { padding: 20px; gap: 24px; }
    nav { padding: 15px 20px; }
    
    header h1 { 
        white-space: normal; 
        font-size: 32px;
        line-height: 1.2;
    }
    
    .select-preset-btn { width: 100%; }
    
    .options-grid { grid-template-columns: repeat(2, 1fr); }
    
    .editor-container {
        flex-direction: column;
        border: none;
        gap: 20px;
        background: transparent;
    }
    
    .divider-vertical { display: none; }
    
    .editor-pane {
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--bg);
    }
}