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

:root {
    --bg: #1a1a2e;
    --bg-secondary: #16213e;
    --accent: #e94560;
    --text: #eee;
    --text-muted: #888;
    --border: #333;
    --success: #4ade80;
    --error: #f87171;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.splash {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 50;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.splash.splash-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash.error .splash-spinner {
    display: none;
}

.splash-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem 2.5rem;
    border-radius: 14px;
    border: 1px solid rgba(233, 69, 96, 0.35);
    background: rgba(22, 33, 62, 0.9);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    text-align: center;
}

.splash-title {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.splash-spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(238, 238, 238, 0.18);
    border-top-color: var(--accent);
    animation: splash-spin 0.9s linear infinite;
}

.splash-status {
    font-size: 0.95rem;
    color: var(--text);
}

.splash-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.hidden {
    display: none !important;
}

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

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

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

.status-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.2rem;
}

.status {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.status-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status.ready {
    color: var(--success);
}

.status.error {
    color: var(--error);
}

.status.error {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 8px;
    border: 1px solid rgba(248, 113, 113, 0.6);
    background: rgba(248, 113, 113, 0.18);
}

.status.error + .status-hint {
    color: #fca5a5;
}

.splash.error .splash-status {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 8px;
    border: 1px solid rgba(248, 113, 113, 0.6);
    background: rgba(248, 113, 113, 0.18);
    color: var(--error);
}

main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    min-height: 0;
    overflow: hidden;
}

main.repl-mode {
    grid-template-columns: 1fr;
}

@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
    main.repl-mode {
        grid-template-rows: 1fr;
    }
}

.editor-pane,
.output-pane {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-height: 0;
    overflow: hidden;
}

.repl-pane {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-height: 0;
}

.repl-body {
    flex: 1;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    font-weight: 500;
}

.controls {
    display: flex;
    gap: 0.5rem;
}

select,
button {
    font-family: inherit;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

select {
    background: var(--bg);
    color: var(--text);
}

button {
    background: var(--accent);
    color: white;
    border: none;
    font-weight: 500;
    transition: opacity 0.15s;
}

button:hover:not(:disabled) {
    opacity: 0.9;
}

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

#clear-btn,
.toggle-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

#clear-btn:hover,
.toggle-btn:hover {
    border-color: var(--text-muted);
}

.toggle-btn.active {
    color: var(--text);
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.15);
}

.repl-toggle.active {
    border-color: var(--text-muted);
    background: transparent;
}

/* Editor with syntax highlighting overlay */
.editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#highlight-layer,
#code {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 1rem;
    margin: 0;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    tab-size: 4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: auto;
}

#highlight-layer {
    background: var(--bg);
    color: var(--text);
    pointer-events: none;
    z-index: 1;
}

#code {
    background: transparent;
    color: transparent;
    caret-color: var(--text);
    border: none;
    resize: none;
    outline: none;
    z-index: 2;
}

/* Syntax highlighting colors */
.hl-keyword { color: #c792ea; }
.hl-string { color: #c3e88d; }
.hl-number { color: #f78c6c; }
.hl-boolean { color: #ff9cac; }
.hl-constant { color: #89ddff; }
.hl-operator { color: #89ddff; }
.hl-punctuation { color: #89ddff; }
.hl-identifier { color: #eee; }
.hl-function { color: #82aaff; }
.hl-decorator { color: #c792ea; font-style: italic; }
.hl-property { color: #f07178; }
.hl-comment { color: #676e95; font-style: italic; }
.hl-regex { color: #89ddff; }
.hl-path { color: #c3e88d; }
.hl-unit { color: #ffcb6b; }
.hl-type { color: #ffcb6b; }
.hl-subject { color: #82aaff; font-weight: bold; }
.hl-implicit_subject { color: #f78c6c; font-weight: bold; font-size: 1.1em; line-height: 1; }
.hl-selector { color: #89ddff; }
.hl-hook { color: #c792ea; }
/* Line wrappers */
.hl-line {
    display: block;
    margin-left: -1rem;
    padding-left: 1rem;
}

.hl-line-error {
    background: rgba(248, 113, 113, 0.1);
    box-shadow: inset 3px 0 0 var(--error);
}

.hl-error {
    color: #f07178;
    background: rgba(248, 113, 113, 0.25);
    text-decoration: wavy underline;
    text-decoration-color: var(--error);
    border-radius: 2px;
}

.output-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#output {
    flex: 1;
    height: 0;
    min-height: 0;
    padding: 1rem;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

#repl-transcript {
    height: 100%;
    padding: 1rem;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    cursor: text;
}

.repl-line {
    display: block;
    white-space: pre-wrap;
}

.repl-line-input,
.repl-line-live {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.repl-input-wrap {
    position: relative;
    flex: 1;
    min-width: 1ch;
    min-height: 1.5em;
}

.repl-input-hl,
.repl-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    display: block;
    white-space: pre-wrap;
}

.repl-input-hl {
    color: var(--text);
    pointer-events: none;
    min-height: 1.5em;
    width: 100%;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.repl-input-hl .hl-line,
.repl-line .hl-line {
    margin-left: 0;
    padding-left: 0;
}

.repl-line-meta-output {
    color: var(--text-muted);
    font-style: italic;
    border-left: 2px solid rgba(136, 136, 136, 0.45);
    padding-left: 0.5rem;
    margin-left: -0.5rem;
}

.repl-suggestions {
    margin: 0.25rem 0 0.25rem 2.5ch;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    overflow: hidden;
}

.repl-suggestion {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.6rem;
    cursor: pointer;
}

.repl-suggestion:hover,
.repl-suggestion.selected {
    background: rgba(233, 69, 96, 0.15);
}

.repl-suggest-cmd {
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    color: var(--text);
}

.repl-suggest-desc {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.repl-prompt {
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    color: var(--text-muted);
}

.repl-input {
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    font-size: 0.875rem;
    color: transparent;
    caret-color: var(--text);
    outline: none;
    white-space: pre-wrap;
    width: 100%;
    line-height: 1.5;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    resize: none;
    overflow: hidden;
    word-break: break-word;
}

.repl-line-input {
    color: var(--text);
}

.repl-line-output {
    color: var(--text);
}

.repl-line-error {
    color: var(--error);
}

.repl-input.disabled {
    opacity: 0.6;
}

#output.error {
    color: var(--error);
}

.traceback {
    margin: 0 1rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text);
}

.traceback summary {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
    user-select: none;
}

.traceback[open] summary {
    color: var(--text);
}

#traceback-text {
    padding: 0.75rem 0.75rem 0.9rem;
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    border-top: 1px solid var(--border);
}

.traceback.hidden {
    display: none;
}

footer {
    padding: 1rem 2rem;
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}

footer a {
    color: var(--text);
    text-decoration: none;
}

footer a:visited {
    color: var(--text);
}

footer a:hover {
    text-decoration: underline;
}

.sep {
    margin: 0 0.5rem;
}

/* Loading spinner for run button */
button.loading {
    position: relative;
    color: transparent;
}

button.loading::after {
    content: "";
    position: absolute;
    width: 1rem;
    height: 1rem;
    top: 50%;
    left: 50%;
    margin-left: -0.5rem;
    margin-top: -0.5rem;
    border: 2px solid white;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
}

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

/* Game controls */
#game-controls {
    display: flex;
    gap: 0.5rem;
}

#start-game-btn {
    background: #4ade80;
}

#stop-game-btn {
    background: #f87171;
}

/* Monospace output for game board */
#output.game-output {
    font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
    font-size: 1rem;
    line-height: 1.2;
    letter-spacing: 0.05em;
}
