/* =============================================================================
   Sigil Playground - Styles
   Interactive code editor and execution environment
   ============================================================================= */

/* --- Theme Variables --- */

:root {
    /* Dark theme (default) */
    --color-background: #050507;
    --color-surface: #0a0a0d;
    --color-surface-raised: #111114;
    --color-border: #1a1a1f;
    --color-text: #e8e8ec;
    --color-text-muted: #707078;
    --color-primary: #14A088;
    --color-primary-hover: #1AB89D;

    /* Editor specific */
    --editor-bg: #0a0a0d;
    --editor-gutter-bg: #0a0a0d;
    --editor-line-number: #707078;
}

[data-theme="light"] {
    --color-background: #f5f5f7;
    --color-surface: #ffffff;
    --color-surface-raised: #e8e8ec;
    --color-border: #d0d0d8;
    --color-text: #1a1a1f;
    --color-text-muted: #6c6c76;
    --color-primary: #0E6B5C;
    --color-primary-hover: #14A088;

    /* Editor specific */
    --editor-bg: #fafafa;
    --editor-gutter-bg: #f0f0f2;
    --editor-line-number: #999;
}

/* --- Base Layout --- */

.playground-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--color-background);
    color: var(--color-text);
}

/* --- Header --- */

.playground-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.playground-brand {
    display: flex;
    align-items: center;
}

.playground-logo-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--color-text);
}

.playground-logo-icon {
    width: 32px;
    height: 32px;
}

.playground-logo-text {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
}

.playground-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* --- Example Selector --- */

.example-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.example-dropdown {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--color-background);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    min-width: 180px;
}

.example-dropdown:hover {
    border-color: var(--color-primary);
}

.example-dropdown:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(20, 160, 136, 0.2);
}

/* --- Buttons --- */

.btn-run {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid transparent;
}

.btn-ghost:hover {
    background: var(--color-surface-raised);
    color: var(--color-text);
}

/* --- Main Content Area --- */

.playground-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- Resize Handle --- */

.resize-handle {
    width: 6px;
    background: var(--color-border);
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    transition: background-color 0.15s;
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--color-primary);
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 1px;
}

.playground-main.resizing {
    cursor: col-resize;
    user-select: none;
}

.playground-main.resizing * {
    pointer-events: none;
}

/* --- Editor Panel --- */

.editor-panel {
    width: 50%;
    min-width: 300px;
    max-width: calc(100% - 300px);
    display: flex;
    flex-direction: column;
    border-right: none;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.panel-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.file-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: var(--color-background);
    border-radius: 4px;
    font-size: 0.875rem;
}

.file-tab.active {
    background: var(--color-primary);
    background: rgba(20, 160, 136, 0.15);
    color: var(--color-primary);
}

.file-name {
    font-family: 'JetBrains Mono', monospace;
}

/* --- Editor Status --- */

.editor-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.status-dot.status-idle {
    background: var(--color-text-muted);
}

.status-dot.status-compiling {
    background: #f9e2af;
    animation: pulse 1s infinite;
}

.status-dot.status-success {
    background: #a6e3a1;
}

.status-dot.status-error {
    background: #f38ba8;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

/* --- Code Editor Container --- */

.editor-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: var(--editor-bg);
    position: relative;
}

/* --- Line Numbers Gutter --- */

.line-gutter {
    flex-shrink: 0;
    padding: 1rem 0;
    padding-right: 1rem;
    background: var(--editor-gutter-bg);
    border-right: 1px solid var(--color-border);
    text-align: right;
    user-select: none;
    overflow: hidden;
    min-width: 50px;
}

.line-number {
    height: 1.5em;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    color: var(--editor-line-number);
    padding-right: 0.75rem;
}

/* --- Code Wrapper --- */

.code-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* --- Syntax Highlight Layer --- */

.highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
    overflow: auto;
    pointer-events: none;
    background: transparent;
    color: #e8e8ec;
}

.highlight-layer code {
    display: block;
    min-height: 100%;
}

/* --- Code Input (Transparent Textarea) --- */

.code-input {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
    overflow: auto;
    background: transparent;
    color: transparent;
    caret-color: var(--color-primary);
    border: none;
    outline: none;
    resize: none;
    z-index: 1;
}

.code-input::selection {
    background: rgba(20, 160, 136, 0.3);
}

.code-input::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.code-input::-webkit-scrollbar-track {
    background: transparent;
}

.code-input::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.code-input::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* --- Syntax Highlighting Classes (legacy) --- */

.comment { color: #707078; font-style: italic; }
.keyword { color: #C792EA; }
.type { color: #FFCB6B; }
.function { color: #82AAFF; }
.string { color: #C3E88D; }
.number { color: #F78C6C; }
.operator { color: #89DDFF; }
.morpheme { color: var(--color-primary); font-weight: 600; }
.native { color: #94e2d5; font-weight: 500; }
.ev-known { color: #4CAF50; }
.ev-uncertain { color: #FFC107; }
.ev-reported { color: #2196F3; }
.ev-paradox { color: #CE93D8; }

/* --- Athame Syntax Highlighting (Catppuccin Dark) --- */

.ath-keyword    { color: #cba6f7; }
.ath-type       { color: #89b4fa; }
.ath-function   { color: #89dceb; }
.ath-variable   { color: inherit; }
.ath-string     { color: #a6e3a1; }
.ath-number     { color: #fab387; }
.ath-comment    { color: #6c7086; font-style: italic; }
.ath-operator   { color: #89ddff; }
.ath-morpheme   { color: #f5c2e7; font-weight: 600; }
.ath-native     { color: #94e2d5; font-weight: 600; }
.ath-punctuation { color: #bac2de; }
.ath-bracket    { color: #cba6f7; }
.ath-error      { color: #f38ba8; text-decoration: wavy underline; }

/* Athame evidentiality markers */
.ath-evidence-known     { color: #a6e3a1; font-weight: 600; }
.ath-evidence-uncertain { color: #f9e2af; font-weight: 600; }
.ath-evidence-reported  { color: #89b4fa; font-weight: 600; }
.ath-evidence-paradox   { color: #f38ba8; font-weight: 600; }
.ath-bracket-match      { background: rgba(245, 194, 231, 0.2); border-radius: 2px; }

/* Light theme syntax highlighting */
[data-theme="light"] .comment { color: #6a737d; }
[data-theme="light"] .keyword { color: #d73a49; }
[data-theme="light"] .type { color: #6f42c1; }
[data-theme="light"] .function { color: #005cc5; }
[data-theme="light"] .string { color: #22863a; }
[data-theme="light"] .number { color: #e36209; }
[data-theme="light"] .operator { color: #d73a49; }
[data-theme="light"] .native { color: #0E6B5C; }
[data-theme="light"] .ev-known { color: #22863a; }
[data-theme="light"] .ev-uncertain { color: #b08800; }
[data-theme="light"] .ev-reported { color: #005cc5; }
[data-theme="light"] .ev-paradox { color: #6f42c1; }

/* Athame light theme */
[data-theme="light"] .ath-keyword    { color: #8839ef; }
[data-theme="light"] .ath-type       { color: #1e66f5; }
[data-theme="light"] .ath-function   { color: #209fb5; }
[data-theme="light"] .ath-string     { color: #40a02b; }
[data-theme="light"] .ath-number     { color: #fe640b; }
[data-theme="light"] .ath-comment    { color: #9ca0b0; font-style: italic; }
[data-theme="light"] .ath-operator   { color: #04a5e5; }
[data-theme="light"] .ath-morpheme   { color: #ea76cb; font-weight: 600; }
[data-theme="light"] .ath-native     { color: #179299; font-weight: 600; }
[data-theme="light"] .ath-punctuation { color: #4c4f69; }
[data-theme="light"] .ath-evidence-known     { color: #40a02b; }
[data-theme="light"] .ath-evidence-uncertain { color: #df8e1d; }
[data-theme="light"] .ath-evidence-reported  { color: #1e66f5; }
[data-theme="light"] .ath-evidence-paradox   { color: #d20f39; }
[data-theme="light"] .ath-bracket-match      { background: rgba(234, 118, 203, 0.15); }

[data-theme="light"] .highlight-layer {
    color: #24292e;
}

/* --- Theme Toggle Button --- */

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: all 0.15s ease;
}

.theme-toggle:hover {
    background: var(--color-surface-raised);
    color: var(--color-text);
    border-color: var(--color-primary);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

/* --- Output Panel --- */

.output-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
}

/* --- Preview Section --- */

.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.preview-content {
    flex: 1;
    padding: 1rem;
    background: var(--color-background);
    overflow: auto;
}

.preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-muted);
    text-align: center;
    gap: 0.5rem;
}

.preview-placeholder p {
    margin: 0;
}

.placeholder-hint {
    font-size: 0.85em;
    opacity: 0.7;
}

/* --- Console Section --- */

.console-section {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--color-border);
    max-height: 40%;
    min-height: 150px;
}

.console-header {
    flex-shrink: 0;
}

.console-output {
    flex: 1;
    margin: 0;
    padding: 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    background: var(--editor-bg);
    overflow: auto;
    min-height: 100px;
}

.console-line {
    margin-bottom: 0.25rem;
}

.console-info {
    color: var(--color-text);
}

.console-success {
    color: #a6e3a1;
}

.console-error {
    color: #f38ba8;
}

.console-warning {
    color: #f9e2af;
}

/* --- Footer --- */

.playground-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1.5rem;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.footer-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.version-badge {
    padding: 0.25rem 0.5rem;
    background: rgba(20, 160, 136, 0.15);
    color: var(--color-primary);
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.separator {
    color: var(--color-text-muted);
}

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

.footer-links {
    display: flex;
    gap: 1rem;
}

.footer-link {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-decoration: none;
}

.footer-link:hover {
    color: var(--color-primary);
}

/* --- Error State --- */

.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    text-align: center;
    padding: 2rem;
}

.error-state h2 {
    margin-bottom: 1rem;
    color: #f38ba8;
}

.error-state p {
    margin-bottom: 1.5rem;
    color: var(--color-text-muted);
}

.error-state button {
    padding: 0.75rem 1.5rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
}

/* --- Responsive --- */

@media (max-width: 1024px) {
    .playground-main {
        flex-direction: column;
    }

    .editor-panel {
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        max-height: 50%;
    }

    .output-panel {
        max-height: 50%;
    }
}

@media (max-width: 768px) {
    .playground-header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .playground-actions {
        width: 100%;
        justify-content: space-between;
    }

    .example-selector {
        flex: 1;
    }

    .example-dropdown {
        flex: 1;
        min-width: auto;
    }
}
