:root {
    --bg: #fafafa;
    --text: #333333;
    --card-bg: #ffffff;
    --border: #cccccc;
    --btn-bg: #0078ff;
    --btn-text: #ffffff;
    --btn-hover: #005fcc;
    --muted-btn-bg: #f5f7fa;
    --muted-btn-text: #1f2937;
    --danger-bg: #d14343;
    --danger-hover: #b83333;
}

html {
    font-size: 18px;
}

body.dark {
    --bg: #121212;
    --text: #f0f0f0;
    --card-bg: #1e1e1e;
    --border: #333333;
    --btn-bg: #2994ff;
    --btn-text: #ffffff;
    --btn-hover: #62b0ff;
    --muted-btn-bg: #2a2a2a;
    --muted-btn-text: #f0f0f0;
    --danger-bg: #e05a5a;
    --danger-hover: #f07070;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    padding: 1rem;
    max-width: 1120px;
    margin: 0 auto;
    transition: background 0.3s, color 0.3s;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 0.75rem;
}

textarea {
    width: 100%;
    min-height: 80px;
    margin-bottom: 1rem;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: vertical;
    background: var(--card-bg);
    color: var(--text);
    box-sizing: border-box;
}

textarea.long-editor {
    min-height: 300px;
}

.output {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.variant-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.variant-header h5 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

pre {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0.75rem 0 0;
}

button {
    background: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1.2;
}

button:hover {
    background: var(--btn-hover);
}

#tab-controls-container {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

#tab-controls-container .tab {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

#tab-controls-container .tab.active {
    background: var(--btn-bg);
    color: var(--btn-text);
    border-color: var(--btn-bg);
}

#text-formatter-input-container {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    padding: 0.5rem 0;
}

#text-editor-container .editor-split {
    display: grid;
    grid-template-columns: minmax(300px, 36%) minmax(0, 1fr);
    gap: 0.85rem;
    align-items: start;
}

#text-editor-container .editor-left {
    position: sticky;
    top: 0.5rem;
}

#text-editor-container .editor-group + .editor-group {
    margin-top: 0.9rem;
}

#text-editor-container .toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

#text-editor-container .toolbar .text-format {
    background: var(--muted-btn-bg);
    color: var(--muted-btn-text);
    border: 1px solid var(--border);
}

#text-editor-container .editor-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

#text-editor-container .section-title {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

#text-editor-container .scope-hint {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    opacity: 0.85;
    display: grid;
    gap: 0.15rem;
    min-height: 2.8rem;
}

#text-editor-container .scope-hint-line {
    margin: 0;
}

#text-editor-container .editor-right textarea.long-editor {
    min-height: 560px;
    margin-bottom: 0;
}

#text-editor-container .editor-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

#text-editor-container .editor-actions .text-format {
    background: var(--muted-btn-bg);
    color: var(--muted-btn-text);
    border: 1px solid var(--border);
}

#text-editor-container .editor-actions .danger {
    background: var(--danger-bg);
    color: #ffffff;
    border: 1px solid transparent;
}

#text-editor-container .editor-actions .danger:hover {
    background: var(--danger-hover);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

@media (max-width: 640px) {
    body {
        padding: 0.75rem;
    }

    #tab-controls-container {
        flex-wrap: wrap;
    }

    #text-editor-container .editor-split {
        grid-template-columns: 1fr;
    }

    #text-editor-container .editor-left {
        position: static;
    }

    #text-editor-container .editor-right textarea.long-editor {
        min-height: 320px;
    }

    #text-editor-container .editor-actions {
        grid-template-columns: 1fr;
    }

    #text-editor-container .editor-actions button {
        width: 100%;
    }
}

@media (max-width: 900px) {
    #text-editor-container .editor-split {
        grid-template-columns: 1fr;
    }

    #text-editor-container .editor-left {
        position: static;
    }
}
