:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --background-color: #f5f6fa;
    --editor-bg: #ffffff;
    --output-bg: #2c3e50;
    --output-text: #ecf0f1;
    --help-bg: rgba(255, 255, 255, 0.98);
    --help-border: #e1e8ed;
    --panel-border: #dcdde1;
    --panel-header-bg: #f1f2f6;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--background-color);
    line-height: 1.4;
}

.container {
    width: 100%;
    padding: 0.5rem 0.5rem 0.25rem 0.5rem;
}

header {
    margin-bottom: 0.5rem;
    padding: 0 0.5rem;
}

h1 {
    color: var(--primary-color);
    margin: 0;
    margin-right: 1rem;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
}

.toolbar {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
    padding-bottom: 0.3rem;
}

button {
    padding: 0.3rem 0.7rem;
    background-color: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #2980b9;
}

.help-button {
    margin-left: auto;
}

.mode-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-right: 0.5rem;
    color: var(--primary-color);
}

.mode-selector label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
}

.mode-selector input[type="radio"] {
    width: 0.9rem;
    height: 0.9rem;
    cursor: pointer;
}

.prelude-toggle {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: 0.5rem;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.9rem;
}

.prelude-toggle input[type="checkbox"] {
    width: 0.9rem;
    height: 0.9rem;
    cursor: pointer;
}

main {
    display: flex;
    gap: 0.5rem;
    height: calc(100vh - 100px);
    margin-bottom: 30px;
}

.editor-container {
    flex: 1;
    position: relative;
    height: calc(100% - 28px);
    width: 100%;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Bottom panel for output and System F */
.bottom-panel {
    height: 27vh;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.tab-buttons {
    display: flex;
    background-color: var(--panel-header-bg);
    border-bottom: 1px solid var(--panel-border);
    height: 28px;
}

.tab-button {
    padding: 0.25rem 0.75rem;
    background: none;
    color: var(--primary-color);
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-button:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.tab-button.active {
    border-bottom: 2px solid var(--secondary-color);
    font-weight: 500;
}

.tab-content {
    flex: 1;
    position: relative;
}

.tab-pane {
    display: none;
    height: calc(100% - 28px);
    padding: 0;
}

.tab-pane.active {
    display: block;
}

.output-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    background-color: var(--output-bg);
    overflow: hidden;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#output {
    padding: 0.5rem;
    margin: 0;
    height: 100%;
    width: 100%;
    overflow: auto;
    color: var(--output-text);
    background-color: var(--output-bg);
    font-family: monospace;
    font-size: 0.85rem;
}

#systemf_editor {
    height: 100%;
    width: 100%;
}

#systemf_editor,
#1ml_editor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    font-size: 0.95rem;
    background-color: #1e1e1e;
    font-family: 'Fira Code', 'JetBrains Mono', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

#systemf_editor .ace_gutter {
    background: #1e1e1e;
    color: #858585;
    padding: 0.5rem 0;
    min-width: 3.5rem;
    width: auto !important;
    z-index: 1;
}

#systemf_editor .ace_gutter-cell {
    padding: 0 0.5rem;
    font-size: 0.9rem;
}

#systemf_editor .ace_scroller {
    left: 4em !important;
    padding: 0.5rem;
    overflow: auto !important;
}

#systemf_editor .ace_content {
    width: 100% !important;
    position: absolute;
    left: 0 !important;
}

#systemf_editor .ace_scrollbar {
    display: block;
    width: 12px;
}

#systemf_editor .ace_scrollbar-v {
    right: 0;
    bottom: 0;
}

#systemf_editor .ace_scrollbar-h {
    bottom: 0;
    left: 0;
}

#systemf_editor .ace_scrollbar-inner {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

#systemf_editor .ace_text-layer {
    width: 100% !important;
    padding-right: 1rem;
    color: #d4d4d4;
}

#systemf_editor .ace_line {
    white-space: pre !important;
    line-height: 1.5;
}

#systemf_editor .ace_cursor {
    border-left: 2px solid #a0a0a0;
}

#systemf_editor .ace_active-line {
    background: rgba(255, 255, 255, 0.07);
}

#systemf_editor .ace_selection {
    background: rgba(52, 152, 219, 0.3);
}

#systemf_editor .ace_keyword {
    color: #569cd6;
}

#systemf_editor .ace_string {
    color: #ce9178;
}

#systemf_editor .ace_constant {
    color: #4ec9b0;
}

#systemf_editor .ace_support.ace_function {
    color: #dcdcaa;
}

#systemf_editor .ace_comment {
    color: #6a9955;
    font-style: italic;
}

#systemf_editor .ace_indent-guide {
    background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYHB3d/8PAAOIAdULw8qMAAAAAElFTkSuQmCC) right repeat-y;
    opacity: 0.15;
}

#editor {
    width: 100%;
    height: 100%;
    font-size: 1rem;
}

.syntax-help {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 1200px;
    max-height: 85vh;
    background: var(--help-bg);
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    z-index: 1000;
    overflow-y: auto;
}

.syntax-help h2 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    font-size: 1.2rem;
}

.syntax-help h3 {
    color: var(--primary-color);
    margin: 0.5rem 0;
    font-size: 1rem;
}

.syntax-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

.syntax-help pre {
    background: #2d2d2d;
    border-radius: 4px;
    padding: 0.75rem;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem;
    overflow-x: auto;
    white-space: pre-wrap;
    color: #d4d4d4;
}

/* Syntax Highlighting */
.syntax-help pre .keyword {
    color: #569cd6;
}

.syntax-help pre .type {
    color: #4ec9b0;
}

.syntax-help pre .string {
    color: #ce9178;
}

.syntax-help pre .number {
    color: #b5cea8;
}

.syntax-help pre .comment {
    color: #6a9955;
    font-style: italic;
}

.syntax-help pre .function {
    color: #dcdcaa;
}

.syntax-help pre .operator {
    color: #d4d4d4;
}

.syntax-help pre .variable {
    color: #9cdcfe;
}

.close-button {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.close-button:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.hidden {
    display: none;
}

.attribution {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--help-bg);
    padding: 0.25rem;
    text-align: center;
    font-size: 0.8rem;
    border-top: 1px solid var(--help-border);
    height: 30px;
    z-index: 100;
}

.attribution a {
    color: var(--secondary-color);
    text-decoration: none;
}

.attribution a:hover {
    text-decoration: underline;
}

/* Three-panel layout */
.three-panel-layout {
    display: flex;
    gap: 0.5rem;
    height: 68vh;
    margin-bottom: 0.5rem;
}

.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.2rem 0.4rem;
    background-color: var(--panel-header-bg);
    border-bottom: 1px solid var(--panel-border);
    height: 28px;
}

.panel-header h2 {
    font-size: 0.9rem;
    margin: 0;
    color: var(--primary-color);
}

.small-button {
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
}

.example-buttons {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.example-buttons button {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
}

button#run,
button#clear {
    font-weight: 500;
}