/* APL Environment styles */

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

/* Side-by-side layout: editor left, REPL right */
#main-content.side-by-side {
    flex-direction: row;
}

/* Control bar */
.control-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--surface1);
    background: var(--mantle);
    flex-shrink: 0;
}

.btn {
    font-family: var(--mono);
    font-size: 13px;
    padding: 4px 12px;
    border: 1px solid var(--surface2);
    border-radius: 4px;
    cursor: pointer;
    background: var(--surface0);
    color: var(--text);
    transition: background 0.15s;
}

.btn:hover {
    background: var(--surface1);
}

.btn-reset {
    color: var(--red);
    border-color: var(--red);
}

.btn-upload {
    color: var(--blue);
    border-color: var(--blue);
}

.demo-select {
    font-family: var(--mono);
    font-size: 12px;
    padding: 3px 6px;
    background: var(--surface0);
    color: var(--text);
    border: 1px solid var(--surface2);
    border-radius: 4px;
    cursor: pointer;
}

/* REPL panel */
.repl-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    outline: none;
    position: relative;
}

.repl-panel:focus {
    outline: none;
}

.repl-output {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    background: var(--base);
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.5;
    color: var(--green);
    white-space: pre-wrap;
    word-break: break-all;
    scroll-behavior: smooth;
}

.repl-line {
    min-height: 1.5em;
}

.repl-input-line {
    display: inline;
}

.repl-prompt {
    color: var(--blue);
}

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

.repl-cursor {
    color: var(--text);
    animation: cursor-blink 1.06s step-end infinite;
}

/* Scroll-to-bottom indicator */
.scroll-to-bottom {
    position: absolute;
    bottom: 12px;
    left: 16px;
    font-family: var(--mono);
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid var(--surface2);
    border-radius: 4px;
    cursor: pointer;
    background: rgba(24, 24, 37, 0.9);
    color: var(--blue);
    z-index: 10;
}

.scroll-to-bottom:hover {
    background: var(--surface0);
    color: var(--text);
}

/* Hardware panel — floating bottom-right */
.hw-panel {
    position: absolute;
    bottom: 12px;
    right: 16px;
    background: rgba(24, 24, 37, 0.9);
    border: 1px solid var(--surface1);
    border-radius: 6px;
    padding: 10px 14px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--subtext0);
    z-index: 10;
    min-width: 140px;
}

.hw-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--overlay1);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.hw-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.hw-row:last-child {
    margin-bottom: 0;
}

.hw-label {
    color: var(--overlay2);
    min-width: 20px;
}

.hw-label-rx {
    margin-left: 8px;
}

/* D2 LED */
.hw-led {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.hw-led-on {
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
}

.hw-led-off {
    background: var(--surface0);
    border: 1px solid var(--surface1);
}

/* S2 switch */
.hw-switch {
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    user-select: none;
}

.hw-switch-on {
    background: var(--blue);
    color: var(--base);
}

.hw-switch-off {
    background: var(--surface0);
    color: var(--overlay1);
    border: 1px solid var(--surface1);
}

.hw-switch:hover {
    opacity: 0.85;
}

.hw-byte {
    font-size: 12px;
    color: var(--text);
}

/* Display mode toggle group */
.mode-group {
    display: inline-flex;
    gap: 0;
    margin-left: auto;
    margin-right: 80px;
}

.btn-mode {
    border-radius: 0;
    border-right-width: 0;
    padding: 4px 8px;
    font-size: 12px;
    min-width: 32px;
    text-align: center;
}

.btn-mode:first-child {
    border-radius: 4px 0 0 4px;
}

.btn-mode:last-child {
    border-radius: 0 4px 4px 0;
    border-right-width: 1px;
}

.btn-mode-active {
    background: var(--mauve);
    color: var(--base);
    border-color: var(--mauve);
}

/* APL keyword highlighting */
.apl-keyword {
    color: var(--mauve);
    font-weight: 600;
}

/* Help button */
.btn-help {
    color: var(--yellow);
    border-color: var(--yellow);
    font-weight: 700;
    min-width: 28px;
    text-align: center;
}

/* Index origin indicator */
.io-indicator {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--teal);
    border: 1px solid var(--surface1);
    border-radius: 4px;
    padding: 2px 6px;
    white-space: nowrap;
    opacity: 0.8;
    user-select: none;
}

/* Spacer to keep controls clear of the GitHub corner */
.corner-spacer {
    display: inline-block;
    width: 5ch;
    flex-shrink: 0;
}

/* Help overlay */
.help-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-dialog {
    background: var(--surface0);
    border: 1px solid var(--surface2);
    border-radius: 8px;
    max-width: 660px;
    width: 92vw;
    max-height: 80vh;
    overflow-y: auto;
    outline: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

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

.help-title {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.help-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.help-hint {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--overlay1);
}

.help-close-btn {
    background: none;
    border: none;
    color: var(--overlay1);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.help-close-btn:hover {
    color: var(--text);
}

.help-body {
    padding: 12px 16px;
}

.help-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
}

.help-table td {
    padding: 2px 8px 2px 0;
    vertical-align: top;
}

.help-section td {
    padding-top: 10px;
    font-weight: 700;
    font-size: 12px;
    color: var(--mauve);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.help-key {
    white-space: nowrap;
    color: var(--green);
    min-width: 80px;
}

.help-intro {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--subtext0);
    margin: 0 0 12px 0;
    line-height: 1.5;
}

.help-em {
    color: var(--text);
    font-weight: 600;
}

.help-col-header td {
    font-size: 11px;
    color: var(--overlay1);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-bottom: 4px;
}

.help-kw-table {
    margin-bottom: 4px;
}

.help-glyph {
    color: var(--mauve);
    white-space: nowrap;
    min-width: 50px;
}

.help-meaning {
    color: var(--subtext1);
}

.help-alias {
    color: var(--blue);
    white-space: nowrap;
    font-size: 12px;
}

.help-note {
    padding-top: 8px;
    font-style: italic;
    color: var(--subtext0);
    font-size: 12px;
}

/* Help tabs */
.help-tabs {
    display: flex;
    gap: 0;
}

.help-tab {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--overlay1);
    padding: 4px 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    user-select: none;
}

.help-tab:hover {
    color: var(--text);
}

.help-tab-active {
    color: var(--mauve);
    border-bottom-color: var(--mauve);
}

/* Tutorial tab */
.tutorial {
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
}

.tut-section {
    margin-bottom: 16px;
}

.tut-section:last-child {
    margin-bottom: 0;
}

.tut-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--mauve);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 0 4px 0;
}

.tut-desc {
    font-size: 12px;
    color: var(--subtext0);
    margin: 0 0 6px 0;
    line-height: 1.5;
}

.tut-examples {
    background: var(--base);
    border: 1px solid var(--surface1);
    border-radius: 4px;
    padding: 6px 10px;
}

.tut-example {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    min-height: 1.5em;
}

.tut-input {
    color: var(--green);
    white-space: pre;
}

.tut-output {
    color: var(--subtext1);
    text-align: right;
    white-space: pre;
    flex-shrink: 0;
}

.tut-example-group {
    margin-bottom: 1px;
}

.tut-example-group:last-child {
    margin-bottom: 0;
}

.tut-glyph-line {
    display: flex;
    align-items: baseline;
    padding-left: 3ch;
    opacity: 0.7;
}

.tut-glyph-prefix {
    color: var(--overlay1);
    font-size: 11px;
}

.tut-glyph-text {
    color: var(--mauve);
    white-space: pre;
}

.tut-ascii-hl {
    color: var(--green);
    font-weight: 600;
}

.tut-glyph-hl {
    color: var(--mauve);
    font-weight: 600;
}

/* Edit button */
.btn-edit {
    color: var(--green);
    border-color: var(--green);
}

.btn-edit-active {
    background: var(--green);
    color: var(--base);
    border-color: var(--green);
}

/* Panel divider — draggable handle between editor and REPL */
.panel-divider {
    flex: 0 0 5px;
    cursor: col-resize;
    background: var(--surface2);
    transition: background 0.15s;
}
.panel-divider:hover,
#main-content.dragging .panel-divider {
    background: var(--blue);
}
/* Disable text selection while dragging the divider */
#main-content.dragging,
#main-content.dragging * {
    user-select: none !important;
    -webkit-user-select: none !important;
    cursor: col-resize !important;
}

/* Editor panel — left side in side-by-side layout */
.editor-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--mantle);
    border-bottom: 1px solid var(--surface1);
}

.editor-title {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 700;
    color: var(--green);
}

.editor-spacer {
    flex: 1;
}

.btn-editor-run {
    color: var(--green);
    border-color: var(--green);
    font-weight: 700;
}

.btn-editor-run:hover {
    background: var(--green);
    color: var(--base);
}

.btn-editor-dl {
    color: var(--blue);
    border-color: var(--blue);
}

.btn-editor-new {
    color: var(--text);
    border-color: var(--surface2);
}

.btn-editor-close {
    color: var(--overlay1);
    border-color: var(--surface2);
    font-size: 16px;
    line-height: 1;
    padding: 2px 8px;
}

.btn-editor-close:hover {
    color: var(--red);
    border-color: var(--red);
}

.editor-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.editor-textarea {
    flex: 1;
    resize: none;
    background: var(--base);
    color: var(--text);
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.5;
    padding: 12px 16px;
    border: none;
    outline: none;
    white-space: pre;
    overflow-y: auto;
    tab-size: 4;
    min-height: 120px;
}

.editor-textarea::placeholder {
    color: var(--overlay0);
}

.editor-preview {
    flex: 0 0 40%;
    overflow-y: auto;
    padding: 12px 16px;
    background: var(--crust);
    border-left: 1px solid var(--surface1);
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.5;
    color: var(--green);
    white-space: pre-wrap;
    word-break: break-all;
}

.editor-preview-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--overlay1);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.editor-preview-line {
    min-height: 1.5em;
}

/* Cursor blink animation */
@keyframes cursor-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* Responsive: narrow viewports */
@media (max-width: 600px) {
    .control-bar {
        flex-wrap: wrap;
        padding: 6px 10px;
        gap: 6px;
    }

    .hw-panel {
        position: static;
        margin: 0 10px 8px;
        border-radius: 4px;
    }

    .repl-output {
        padding: 8px 10px;
        font-size: 13px;
    }
}

@media (max-width: 400px) {
    .btn {
        font-size: 12px;
        padding: 3px 8px;
    }

    .demo-select {
        font-size: 11px;
        width: 100%;
    }
}
