/* ==========================================================================
   CSS Variables & Themes
   ========================================================================== */

:root {
    --solid: #000000;
    --bg: #0f1117;
    --panel: #1a1a1a;
    --elev: #151a22;
    --text: #e6edf3;
    --muted: #8b949e;
    --border: #2b313b;
    --green: #22c55e;
    --keyword-color: #ffffff; /* updated from editor theme */
    --red: #ff7b72;
    --warning: #ffd700;
    
    --radius: 14px;
    --radius-xs: 8px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    --gap: 14px;
    --splitter-h: 8px;
    --topbar-h: 45px;
    --bottombar-h: 45px;
    --bar-min: 22px;
}

.light {
    --solid: #ffffff;
    --bg: #f6f8fa;
    --panel: #ffffff;
    --elev: #f6f8fa;
    --text: #24292f;
    --muted: #57606a;
    --border: #d0d7de;
    --green: #009d00;
    --keyword-color: #000000; /* updated from editor theme */
    --red: #d73a49;
    --warning: #ce8600;
}

/* ==========================================================================
   Global Reset & Base Styles
   ========================================================================== */

* {
    box-sizing: border-box;
}

/* remove blue focus outline */
*:focus { outline: none; }
*:focus-visible { outline: none; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
}

/* ==========================================================================
   Main Layout
   ========================================================================== */

.app {
    height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding: var(--gap);
}

/* ==========================================================================
   Workspace & Layout System
   ========================================================================== */

#workspace {
    display: flex;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* layout orientation */
#workspace.layout-vertical   { flex-direction: column; }
#workspace.layout-horizontal { flex-direction: row; }

/* shrink panes */
#editorPane, #consolePane { 
    display: flex; 
    flex-direction: column; 
    min-width: 0; 
    min-height: 0; 
    flex: 0 0 0;
    position: relative;
    z-index: 0;
}

/* add gap between splitter and console in horizontal layout */
#workspace.layout-horizontal #consolePane {
    margin-left: var(--gap);
}

/* ==========================================================================
   Splitter
   ========================================================================== */

#splitter { 
    box-sizing: border-box; 
    margin: 0; 
    position: relative;
    z-index: 100;
    background: var(--splitter-bg, rgba(127,127,127,.25));
    flex: 0 0 var(--splitter-h);
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* grip dots on splitter */
#splitter::before {
    content: '';
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 2px;
    width: 24px;
    height: 6px;
    background-image:
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px),
        radial-gradient(circle, var(--text) 0.75px, transparent 0.5px);
    background-size: 3px 3px;
    background-position: 
        0px 0px, 3px 0px, 6px 0px, 9px 0px, 12px 0px, 15px 0px, 18px 0px, 21px 0px,
        0px 3px, 3px 3px, 6px 3px, 9px 3px, 12px 3px, 15px 3px, 18px 3px, 21px 3px;
    opacity: 0.6;
}
/* rotate dots in horizontal layout */
#workspace.layout-horizontal #splitter::before {
    transform: rotate(90deg);
}

#splitter:active, #splitter:focus { 
    outline: none; 
    border-width: 0; 
}

#splitter:hover {
    background: #3e444f;
}

/* orientation */
#workspace.layout-vertical #splitter {
    height: var(--splitter-h);
    width: 100%;
    cursor: row-resize;
}
#workspace.layout-horizontal #splitter {
    width: var(--splitter-h);
    height: 100%;
    cursor: col-resize;
}

/* While dragging, avoid text selection and keep the resize cursor */
body.dragging {
    user-select: none;
    cursor: row-resize !important;
}

/* ==========================================================================
   Utility Bar
   ========================================================================== */

.utilitybar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
}

.utilitybar .controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.utilitybar .utility-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Examples button */
.btn.examples {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 14px;
    color: var(--text);
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    transition: all 0.2s ease;
    cursor: pointer;
}
.btn.examples:hover {
    background: var(--hover);
}

/* Info button */
.btn.info {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 14px;
    color: var(--text);
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    transition: all 0.2s ease;
    cursor: pointer;
}
.btn.info:hover {
    background: var(--hover);
}

/* Issue report button */
.btn.issue-report {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: var(--radius-xs);
}

.btn.issue-report i {
    font-size: 12px;
}

/* ==========================================================================
   Editor Pane
   ========================================================================== */

#editorPane {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* topbar */
.topbar {
    flex: 0 1 var(--topbar-h);
    min-height: var(--bar-min);
    padding: 0;
    display: flex;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 8px;
    padding-top: 4px;
    padding-left: 12px;
    padding-right: 12px;
    overflow: hidden;
    container-type: size;
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* editor shell */
.editor {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#code {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

/* bottombar */
.bottombar {
    flex: 0 1 var(--bottombar-h);
    min-height: var(--bar-min);
    padding: 0 10px;
    font-size: 13px;
    margin: 0;
    width: 100%;
    display: flex;
    align-items: center;
    overflow: hidden;
    container-type: size;
}
.bottombar .info {
    display: flex;
    align-items: center;
    gap: 20px;
    min-width: 0;
}
.bottombar .info span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* collapse bars */
.topbar, .bottombar { 
    overflow: hidden; 
}

/* ==========================================================================
   Console
   ========================================================================== */

#consolePane {
    padding-top: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.run-container {
    display: flex;
    justify-content: flex-start;
    padding: 10px;
    flex-shrink: 0;
}

/* console layout */
.console {
    margin-top: 0;
    display: flex;
    flex-direction: row;
    height: 100%;
    min-height: 0;
    flex: 1 1 auto;
    background-color: black;
    overflow: hidden;
}

.console-sidebar {
    width: 40px;
    background-color: var(--elev);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    flex-shrink: 0;
    height: 100%;
    min-height: 0;
}

.console-controls {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.console-controls .btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.console-controls .btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.console-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}

.console,
.console-content { 
    min-height: 0; 
}

/* loading bar above console */
.console-loadingbar {
    height: 3px;
    background: var(--solid);
    width: 100%;
    flex: 0 0 auto;
    display: block;
}
.console-loadingbar.loading {
    background: var(--red); /* turns red while loading */
}

#console-viewport {
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 0;
    background-color: #000000;
    color: #ffffff;
    font-family: var(--mono);
    font-size: 13px;
    padding: 8px 12px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
}

.light #console-viewport {
    background-color: #ffffff;
    color: #000000;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    appearance: none;
    border: none;
    background: none;
    color: var(--text);
    padding: 8px 12px;
    cursor: pointer;
}

/* icon visibility */
.btn.mode i[hidden] {display: none;}

/* run/stop */
.btn.run {
    border: 2px solid var(--green);
    background: var(--panel);
    color: var(--green);
    font-weight: 600;
    padding: 8px 16px;
    transition: all 0.2s ease;
}
.btn.run:hover {
    background: var(--green);
    color: white;
}
.btn.stop {
    border: 2px solid var(--red);
    background: var(--panel);
    color: var(--red);
    font-weight: 600;
    padding: 8px 16px;
    transition: all 0.2s ease;
}
.btn.stop:hover {
    background: var(--red);
    color: white;
}

/* utiltiy bar */
.btn.settings,
.btn.download-editor,
.btn.mode {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}
.btn.mode i {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s ease;
}

/* topbar */

/* copy */
.btn.copy i {
    transition: transform 0.15s ease, opacity 0.15s ease;
}

/* close */
.btn.close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    transition: background 0.2s;
}

/* icon scaling */
.btn:hover i:not(.btn.mode i):not(.btn.layout i) {
    transform: scale(1.1);
    transition: transform 0.2s ease;
}
.btn.mode:hover i {
    transform: translate(-50%, -50%) scale(1.1);
    transition: transform 0.2s ease;
}

/* layout button */
.btn.layout:hover i.fa-rotate-90 {
    transform: scale(1.1) rotate(90deg);
    transition: transform 0.2s ease;
}
.btn.layout:hover i:not(.fa-rotate-90) {
    transform: scale(1.1);
    transition: transform 0.2s ease;
}

/* ==========================================================================
   Settings Panel
   ========================================================================== */

.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-panel {
    padding: 0;
    min-width: 300px;
    max-width: 500px;
    background: var(--panel);
    border-radius: var(--radius);
}

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

.settings-header h3 {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 600;
}

.settings-content { padding: 20px; }

.setting-group { margin-bottom: 30px; }
.settings-content > .setting-group:last-child { margin-bottom: 0; } /* remove extra space */

/* Examples Overlay */
.examples-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.examples-panel {
    padding: 0;
    min-width: 300px;
    max-width: 500px;
    background: var(--panel);
    border-radius: var(--radius);
}

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

.examples-header h3 {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 600;
}

.examples-content { 
    padding: 20px; 
}
.examples-content .example-btn {
    margin-bottom: 12px;
}
.examples-content .example-btn:last-child {
    margin-bottom: 0;
}

/* example buttons */
.btn.example-btn {
    width: 100%;
    padding: 8px 12px; 
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn.example-btn:hover {
    background: var(--elev);
    border-color: var(--keyword-color);
}
.btn.example-btn:focus {
    outline: none;
    border-color: var(--keyword-color);
    box-shadow: var(--keyword-color);
}
.btn.example-btn i {
    font-size: 16px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

/* sliders */
.setting-group input[type="range"] {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    margin: 10px 0;
    position: relative;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    background: var(--keyword-color);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--panel);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
}

.setting-group input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--keyword-color);
    opacity: 0.8;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

.setting-group input[type="range"]::-webkit-slider-track {
    background: linear-gradient(to right, var(--keyword-color) 0%, var(--keyword-color) 50%, var(--border) 50%, var(--border) 100%);
    border-radius: 4px;
    height: 8px;
}

.setting-group input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: var(--keyword-color);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--panel);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
    transform: translateY(-2px); /* nudge to visual center in Firefox */
}

.setting-group input[type="range"]::-moz-range-thumb:hover {
    background: var(--keyword-color);
    opacity: 0.8;
    transform: translateY(-2px) scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

.setting-group input[type="range"]::-moz-range-track {
    background: linear-gradient(to right, var(--keyword-color) 0%, var(--keyword-color) 50%, var(--border) 50%, var(--border) 100%);
    border-radius: 4px;
    height: 8px;
    border: none;
}

/* slider container and tick marks */
.slider-container {
    position: relative;
    margin: 15px 0 5px 0;
}

.slider-ticks {
    display: flex;
    margin-top: 8px;
    position: relative;
}

.slider-ticks.tab-ticks {
    padding: 0 8px;
    justify-content: space-between;
}

.slider-ticks.font-ticks {
    padding: 0 6px;
    position: relative;
}

.slider-ticks.font-ticks .tick {
    position: absolute;
    transform: translateX(-50%);
}

/* position font ticks based on slider values */
.slider-ticks.font-ticks .tick:nth-child(1)  { left: 4%;     }  /* 6 */
.slider-ticks.font-ticks .tick:nth-child(2)  { left: 9.75%;  }  /* 8 */
.slider-ticks.font-ticks .tick:nth-child(3)  { left: 15.5%;  }  /* 10 */
.slider-ticks.font-ticks .tick:nth-child(4)  { left: 21.25%; }  /* 12 */
.slider-ticks.font-ticks .tick:nth-child(5)  { left: 27%;    }  /* 14 */
.slider-ticks.font-ticks .tick:nth-child(6)  { left: 32.75%; }  /* 16 */
.slider-ticks.font-ticks .tick:nth-child(7)  { left: 38.5%;  }  /* 18 */
.slider-ticks.font-ticks .tick:nth-child(8)  { left: 44.25%; }  /* 20 */
.slider-ticks.font-ticks .tick:nth-child(9)  { left: 50%;    }  /* 22 */
.slider-ticks.font-ticks .tick:nth-child(10) { left: 55.75%; }  /* 24 */
.slider-ticks.font-ticks .tick:nth-child(11) { left: 61.5%;  }  /* 26 */
.slider-ticks.font-ticks .tick:nth-child(12) { left: 67.25%; }  /* 28 */
.slider-ticks.font-ticks .tick:nth-child(13) { left: 73%;    }  /* 30 */
.slider-ticks.font-ticks .tick:nth-child(14) { left: 78.75%; }  /* 32 */
.slider-ticks.font-ticks .tick:nth-child(15) { left: 84.5%;  }  /* 34 */
.slider-ticks.font-ticks .tick:nth-child(16) { left: 90.25%; }  /* 36 */
.slider-ticks.font-ticks .tick:nth-child(17) { left: 96%;    }  /* 38 */

.slider-ticks .tick {
    font-size: 11px;
    color: var(--muted);
    font-weight: 500;
    position: relative;
    transition: color 0.2s ease;
}

.slider-ticks .tick:not(:empty) {
    cursor: pointer;
}

.slider-ticks .tick:not(:empty):hover {
    color: var(--keyword-color);
}

.slider-ticks .tick::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: 6px;
    background: var(--border);
}

/* dropdowns */
.font-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    font-size: 14px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.font-select:hover {
    border-color: var(--keyword-color);
}

.font-select:focus {
    outline: none;
    border-color: var(--keyword-color);
    box-shadow: var(--keyword-color);
}

.font-select optgroup {
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--muted);
    padding: 4px 8px;
}

.btn.editortheme-changer {
    width: 100%;
    padding: 12px 16px;
    color: var(--keyword-color);
    background: var(--panel);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn.editortheme-changer:hover {
    background: var(--keyword-color);
    color: white;
}

.editortheme-section {
    margin-bottom: 30px;
}

.editortheme-section h4 {
    margin: 0 0 15px 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.editortheme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
}

.editortheme-button {
    padding: 10px 12px;
    border: 1px solid var(--border);
    background: var(--elev);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    border-radius: 4px;
}

.editortheme-button:hover {
    background: var(--panel);
    border-color: var(--keyword-color);
    color: var(--keyword-color);
}

.editortheme-button.active {
    background: var(--keyword-color);
    color: white;
    border-color: var(--keyword-color);
}

.editortheme-list-container {
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
    background: var(--elev);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.editortheme-category {
    margin-bottom: 20px;
}

.editortheme-category:last-child {
    margin-bottom: 0;
}

.editortheme-category-title {
    margin: 0 0 12px 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.editortheme-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.editortheme-item {
    padding: 8px 12px;
    background: var(--panel);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    position: relative;
}

.editortheme-item:hover {
    background: var(--elev);
    border-color: var(--keyword-color);
    color: var(--keyword-color);
}

.editortheme-item.selected {
    background: var(--keyword-color);
    color: white;
    border-color: var(--keyword-color);
}

.editortheme-item.selected::before {
    content: '✓';
    position: absolute;
    left: 8px;
    font-weight: bold;
    color: white;
}

.editortheme-item.selected {
    padding-left: 28px;
}

/* tour restart button */
.btn.replay-tour {
    width: 100%;
    padding: 8px 12px; 
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn.replay-tour:hover {
    background: var(--elev);
    border-color: var(--keyword-color);
}
.btn.replay-tour:focus {
    outline: none;
    border-color: var(--keyword-color);
    box-shadow: var(--keyword-color);
}
.btn.replay-tour i {
    font-size: 16px;
}

/* ==========================================================================
   Light Mode Overrides
   ========================================================================== */

.light #console-viewport {
    background-color: #ffffff;
    color: #24292f;
}

.light .console-prompt {
    background-color: #ffffff;
    color: #24292f;
}

.light .prompt-text .command-text {
    color: #24292f;
}

.light #console-viewport .line.stdin .command-text {
    color: #24292f;
}

.light .cursor {
    color: #24292f;
}

.light #console-viewport .cursor {
    background: #24292f;
}

/* ==========================================================================
   Utility Classes & States
   ========================================================================== */

#workspace { 
    min-height: 0; 
}

/* disable transitions during mode switching */
html.mode-switching *,
html.mode-switching *::before,
html.mode-switching *::after {
    transition: none !important;
    animation:  none !important;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
    text-align: center;
    padding: 8px;
    background: var(--bg);
    font-size: 11px;
    color: var(--muted);
    z-index: 0;
}
.footer i {
    vertical-align: middle;
}
