/* MSU x366 Emulator - Styles adapted from MTMC */

:root {
    --pdp-blue: #243571;
    --pdp-light-blue: #3286ce;
    --pdp-beige: #fdfddc;
    --pdp-white: #f1f1f6;
    --pdp-off-white: #F0EBCD;
    --console-primary: #ffcc00;
    --console-background: #35291c;
}

html {
    overscroll-behavior: none;
}

body {
    margin: 0;
    overscroll-behavior: none;
    background-color: #c3c3c3;
    overflow-x: hidden;
}

main {
    display: grid;
    grid-template-columns: 470px 458px 1fr;
    grid-gap: 4px;
}

/* LEFT COLUMN */
#left {
    grid-template-rows: auto auto minmax(0, 1fr);
    display: grid;
    grid-gap: 4px;
    height: 100dvh;
    max-height: 100dvh;
    min-width: 470px;
    max-width: 470px;
}

/* CENTER COLUMN */
#center {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    grid-gap: 4px;
    height: 100dvh;
    max-height: 100dvh;
    min-width: 450px;
    max-width: 450px;
}

/* RIGHT COLUMN */
#fs {
    max-width: calc(100dvw - 938px);
    background-color: var(--pdp-white);
    height: calc(100dvh - 10px);
    max-height: calc(100dvh - 10px);
}

/* PANEL BASE */
.panel {
    border-radius: 4px;
    padding: 4px;
    background-color: var(--pdp-white);
    color: var(--pdp-blue);
    border: 1px solid rgba(0, 0, 0, 0.36);
}

.panel > div {
    background-color: var(--pdp-white);
    color: black;
}

/* CONTROL PANEL */
#controls {
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

#controls > * > * {
    margin: 4px;
}

#control-header {
    background-color: var(--pdp-blue);
    color: var(--pdp-white);
    font-family: monospace;
    font-size: 32px;
    padding: 4px 24px;
    margin-left: 0;
    margin-right: 0;
}

#control-header span {
    display: inline-block;
    margin-top: -6px;
    margin-bottom: -6px;
    padding: 4px 8px;
    font-weight: bold;
    font-size: 38px;
    border-right: 4px solid white;
    border-left: 4px solid white;
}

#control-header span:not(:first-child) {
    border-left: none;
}

#control-secondary {
    background-color: var(--pdp-light-blue);
    color: var(--pdp-white);
    font-family: monospace;
    font-size: 18px;
    font-style: italic;
    text-align: center;
    padding: 4px 4px;
    margin-left: 0;
    margin-right: 0;
}

#control-buttons {
    text-align: right;
}

/* Unified button styling - system default */
button,
select {
    font-family: system-ui, -apple-system, sans-serif;
    cursor: pointer;
}

/* REGISTER PANEL */
#register-table {
    width: 100%;
    padding: 8px;
    border-radius: 8px;
    font-family: monospace;
    background-color: black;
    color: var(--pdp-off-white);
}

#register-table td {
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0;
}

/* BLINKENLIGHTS */
.blinken {
    display: inline-block;
    margin-right: 2px;
    height: 6px;
    width: 6px;
    border-radius: 6px;
    padding: 3px;
}

.blinken.on {
    background-color: red;
}

.blinken.off {
    background-color: #5c0119;
}

.blinken.space {
    margin-right: 8px;
}

/* MEMORY PANEL */
#memory-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#memory-panel > div {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-grow: 1;
    min-height: 0;
}

#memory-header {
    font-family: monospace;
    font-weight: bold;
    font-size: 16px;
    padding: 4px;
    flex-shrink: 0;
}

.memory {
    font-family: monospace;
    overflow-y: auto;
    overflow-x: hidden;
    flex-grow: 1;
    min-height: 0;
}

.memory td {
    align-content: center;
    overflow: hidden;
}

.mem-highlight {
    box-shadow: inset 0 0 10px purple;
}

/* Memory cell colors based on type */
.mem-stack {
    background-color: rgba(0, 255, 255, 0.2);  /* Cyan - stack */
    font-weight: bold;
}

.mem-current {
    background-color: rgba(255, 255, 0, 0.3);  /* Yellow - current PC */
    color: red;
    font-weight: bold;
}

.mem-code {
    background-color: rgba(173, 216, 230, 0.3);  /* Light blue - code */
}

.mem-data {
    background-color: rgba(255, 182, 193, 0.3);  /* Light pink - data */
}

.mem-heap {
    background-color: rgba(144, 238, 144, 0.3);  /* Light green - heap */
}

.mem-hover-highlight {
    box-shadow: 0 0 0 3px orange, inset 0 0 0 2px orange !important;
    z-index: 10;
    position: relative;
}

/* DISPLAY PANEL */
#display {
    background-color: #dbd9d6;
    padding: 16px;
    user-select: none;
    -webkit-user-select: none;
}

#display-wrapper {
    text-align: center;
    padding: 28px 16px;
    background-color: #918e93;
    border: 1px solid dimgray;
    border-radius: 8px 8px 32px 8px;
    box-shadow: inset rgb(0, 0, 0, .2) 1px 1px 1px 1px;
}

#display-canvas {
    width: 320px;
    height: 288px;
    border: 1px solid dimgray;
    border-radius: 2px;
    background: black;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    filter: blur(0.65px) contrast(1.05);
}

/* GAME BOY CONTROLS */
#gameboy-controls {
    padding: 12px 20px 20px 20px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto;
    gap: 20px;
    align-items: center;
    background-color: #dbd9d6;
    border-radius: 0 0 8px 8px;
}

/* D-Pad */
#dpad {
    position: relative;
    width: 80px;
    height: 80px;
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    align-self: center;
    margin-left: 20px;
}

.dpad-btn {
    position: absolute;
    background-color: #2a2a2a;
    border: none;
    cursor: pointer;
    transition: all 0.1s;
}

.dpad-btn:active {
    background-color: #1a1a1a;
}

.dpad-up {
    top: 0;
    left: 27px;
    width: 26px;
    height: 27px;
    border-radius: 3px 3px 0 0;
}

.dpad-down {
    bottom: 0;
    left: 27px;
    width: 26px;
    height: 27px;
    border-radius: 0 0 3px 3px;
}

.dpad-left {
    left: 0;
    top: 27px;
    width: 27px;
    height: 26px;
    border-radius: 3px 0 0 3px;
}

.dpad-right {
    right: 0;
    top: 27px;
    width: 27px;
    height: 26px;
    border-radius: 0 3px 3px 0;
}

/* Center piece of D-pad */
#dpad::before {
    content: '';
    position: absolute;
    top: 27px;
    left: 27px;
    width: 26px;
    height: 26px;
    background-color: #2a2a2a;
    z-index: -1;
}

/* Start/Select Buttons */
#start-select {
    display: flex;
    flex-direction: row;
    gap: 0;
    align-items: center;
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    align-self: center;
    margin-top: 50px;
}

.small-btn {
    padding: 2px 10px;
    background-color: #6a6a6a;
    border: 1px solid #4a4a4a;
    border-radius: 10px;
    color: #aaa;
    font-size: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
    text-transform: uppercase;
    box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.3);
    min-width: 48px;
    transform: rotate(-30deg);
}

.small-btn#btn-start {
    margin-left: -4px;
}

.small-btn:hover {
    background-color: #5a5a5a;
}

.small-btn:active {
    background-color: #3a3a3a;
}

/* A/B Buttons */
#ab-buttons {
    display: flex;
    gap: 16px;
    align-items: center;
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    align-self: center;
    margin-right: 20px;
}

.action-btn {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background-color: #8b2e3f;
    border: none;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3);
}

.action-btn:hover {
    background-color: #9b3e4f;
}

.action-btn:active {
    background-color: #7b2e3f;
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.4);
}

/* CONSOLE PANEL */
#console-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(0);
}

#console-panel > div {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-grow: 1;
    min-height: 0;
}

#console-header {
    font-family: monospace;
    font-weight: bold;
    font-size: 16px;
    padding: 4px;
    flex-shrink: 0;
}

#console {
    background: #1e1e1e;
    color: var(--console-primary);
    overflow-x: hidden;
    overflow-y: auto;
    word-break: break-all;
    margin: 0;
    padding: 8px;
    font-family: monospace;
    font-weight: bold;
    flex-grow: 1;
    position: relative;
}

#console-input-wrapper {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

#console-input {
    outline: none;
    visibility: visible;
    caret: var(--console-primary) block;
    background-color: #1e1e1e;
    font-family: monospace;
    font-weight: bold;
    font-size: 13px;
    color: var(--console-primary);
    border: none;
    margin: 0;
    padding: 0;
    flex-grow: 1;
}

#console-history div {
    white-space: pre-wrap;
    min-height: calc(1lh - 2px);
}

/* FILE SYSTEM / EDITOR */
.site {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#fs-header {
    font-family: monospace;
    font-weight: bold;
    font-size: 16px;
    padding: 4px;
    flex-shrink: 0;
    background-color: var(--pdp-white);
    position: relative;
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-btn {
    min-width: 24px;
    height: 24px;
    padding: 2px 4px;
    margin-right: 4px;
}

.file-dropdown .dropdown-btn,
.folder-dropdown .dropdown-btn {
    min-width: 16px;
    height: 16px;
    padding: 0px 2px;
    font-size: 10px;
    line-height: 1;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background-color: #c0c0c0;
    min-width: 160px;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
    border: 1px solid;
    border-color: #ffffff #000000 #000000 #ffffff;
    z-index: 1000;
}

.file-dropdown {
    position: relative;
}

.file-dropdown .dropdown-content {
    min-width: 120px;
}

.folder-dropdown {
    position: relative;
}

.folder-dropdown .dropdown-content {
    min-width: 160px;
}


.dropdown-content a {
    color: #000000;
    padding: 6px 12px;
    text-decoration: none;
    display: block;
    font-family: monospace;
    font-size: 12px;
}

.dropdown-content a:hover {
    background-color: #000080;
    color: #ffffff;
}

.dropdown.show .dropdown-content {
    display: block;
}

.editor-nav-bar {
    background-color: var(--pdp-white);
    padding: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}


.editor-nav-bar .title {
    color: #000000;
    flex-grow: 1;
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: bold;
}

/* View Containers */
.view-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
    overflow: visible; /* Changed from hidden - was clipping Monaco */
}

#explorer-view {
    overflow-y: hidden;
    overflow-x: visible;
}

/* File Explorer - Windows 98 Style */
#file-explorer {
    background-color: #ffffff;
    overflow-y: auto;
    overflow-x: visible;
    flex-grow: 1;
    border: 2px solid;
    border-color: #808080 #ffffff #ffffff #808080;
    margin: 4px;
}

.explorer-header {
    background: linear-gradient(to bottom, #ffffff 0%, #dfdfdf 100%);
    border-bottom: 1px solid #808080;
    display: grid;
    grid-template-columns: 200px 80px 100px 50px;
    font-family: 'MS Sans Serif', Tahoma, sans-serif;
    font-size: 11px;
    font-weight: bold;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.explorer-header-cell {
    padding: 4px 6px;
    border-right: 1px solid #808080;
    border-bottom: 1px solid #808080;
    background: linear-gradient(to bottom, #ffffff 0%, #dfdfdf 100%);
    cursor: pointer;
}

.explorer-header-cell:active {
    background: linear-gradient(to bottom, #dfdfdf 0%, #ffffff 100%);
    border-style: inset;
}

.explorer-table {
    display: table;
    width: 100%;
    font-family: 'MS Sans Serif', Tahoma, sans-serif;
    font-size: 11px;
}

.explorer-row {
    display: grid;
    grid-template-columns: 200px 80px 100px 50px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px dotted #c0c0c0;
    position: relative;
    min-height: 20px;
}

.explorer-row:hover {
    background-color: #316AC5;
    color: white;
    min-height: 20px;
}

.explorer-row.selected {
    background-color: #0A246A;
    color: white;
    min-height: 20px;
}

.explorer-row.folder {
    font-weight: bold;
}

.explorer-cell {
    padding: 3px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.explorer-cell:last-child {
    overflow: visible;
}

.explorer-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    font-size: 14px;
}

.explorer-expand {
    width: 12px;
    flex-shrink: 0;
    font-size: 10px;
    cursor: pointer;
    user-select: none;
    display: inline-block;
    margin-right: 2px;
}

.explorer-actions {
    display: none;
    margin-left: auto;
    position: relative;
    overflow: visible;
}

.explorer-row:hover .explorer-actions {
    display: flex;
}

.explorer-delete {
    background-color: #c0c0c0;
    border: 1px solid;
    border-color: #ffffff #000000 #000000 #ffffff;
    color: #000000;
    cursor: pointer;
    font-size: 11px;
    padding: 1px 4px;
    font-weight: bold;
}

.explorer-row.selected .explorer-delete {
    background-color: #dfdfdf;
}

.explorer-delete:hover {
    background-color: #dfdfdf;
}

.explorer-delete:active {
    border-color: #000000 #ffffff #ffffff #000000;
}

/* Old textarea styles - REMOVED for Monaco */
/* Monaco handles all its own styling */

/* Binary Viewer */
#binary-viewer {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    font-family: monospace;
    font-size: 12px;
    padding: 8px;
    box-sizing: border-box;
    background-color: #ffffff;
}

#binary-viewer h3 {
    margin: 12px 0 6px 0;
    font-size: 14px;
    font-weight: bold;
    border-bottom: 1px solid #808080;
    padding-bottom: 2px;
}

#binary-viewer table {
    border-collapse: collapse;
    margin-bottom: 12px;
    width: 100%;
}

#binary-viewer th {
    background-color: #c0c0c0;
    border: 1px solid #808080;
    padding: 4px 8px;
    text-align: left;
    font-weight: bold;
}

#binary-viewer td {
    border: 1px solid #c0c0c0;
    padding: 4px 8px;
}

#binary-viewer .hex {
    font-family: monospace;
    color: #006400;
}

#binary-viewer .instruction {
    font-family: monospace;
    color: #000080;
}

#binary-viewer .address {
    font-family: monospace;
    color: #800000;
}

/* Image Viewer */
#image-view {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #ffffff;
    padding: 8px;
}

#image-viewer {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* MOBILE RESPONSIVE */
@media only screen and (max-width: 768px) and (orientation: portrait) {
    html {
        overflow: hidden;
    }

    body {
        min-width: 100dvw;
        width: 100dvw;
        max-width: 100dvw;
        height: 100dvh;
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    main {
        grid-template-columns: 100dvw 100dvw 100dvw;
        grid-gap: 0px;
        overflow: auto;
        overscroll-behavior: none;
        scroll-snap-type: x mandatory;
        width: 100dvw;
        height: 100dvh;
        touch-action: manipulation;
    }

    #left, #center {
        min-width: 100dvw;
        width: 100dvw;
        max-width: 100dvw;
        min-height: 100dvh;
        height: 100dvh;
        max-height: 100dvh;
        scroll-snap-align: center;
    }

    #fs {
        min-width: calc(100dvw - 10px);
        width: calc(100dvw - 10px);
        max-width: calc(100dvw - 10px);
        min-height: calc(100dvh - 10px);
        height: calc(100dvh - 10px);
        max-height: calc(100dvh - 10px);
        overflow: hidden;
        scroll-snap-align: center;
    }

    #display {
        border: 0;
        padding: 0;
    }
}
/* Assembly Syntax Highlighting */
.asm-keyword { color: #569cd6; font-weight: bold; }
.asm-register { color: #4ec9b0; }
.asm-number { color: #b5cea8; }
.asm-string { color: #ce9178; }
.asm-comment { color: #6a9955; font-style: italic; }
.asm-label { color: #dcdcaa; font-weight: bold; }

/* Code Editor with Line Numbers */
.code-editor-container {
    display: flex;
    height: 100%;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    background: #1e1e1e;
    color: #d4d4d4;
}

/* Old custom editor .line-numbers styles - REMOVED for Monaco */
/* Monaco handles all line number styling internally */

.code-content {
    flex: 1;
    overflow: auto;
    padding: 10px;
    line-height: 1.5;
    white-space: pre;
    tab-size: 4;
}

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

.code-line.current-execution {
    background: #264f78;
}

.code-line.breakpoint-line {
    background: #5a1e1e;
}

/* Debug Controls */
.debug-controls {
    display: flex;
    gap: 5px;
    padding: 4px;
    background: #2d2d30;
    border-bottom: 1px solid #3e3e42;
}

.debug-controls button {
    font-family: monospace;
    font-size: 11px;
    padding: 3px 8px;
    background: #0e639c;
    color: white;
    border: 1px solid #0e639c;
    border-radius: 2px;
    cursor: pointer;
}

.debug-controls button:hover {
    background: #1177bb;
}

.debug-controls button:disabled {
    background: #3e3e42;
    color: #858585;
    cursor: not-allowed;
}

.debug-controls button.danger {
    background: #c9302c;
    border-color: #c9302c;
}

.debug-controls button.danger:hover {
    background: #d9534f;
}

/* Monaco Editor Customizations */
#editor-view {
    position: relative;
}

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

/* Override .site overflow for editor view to prevent clipping */
#fs {
    overflow: visible !important;
}

/* Remove padding from panel when editor is shown */
#fs.panel {
    padding: 0;
}

/* Restore padding for header */
#fs-header {
    margin: 4px;
}

/* Line numbers - make them brighter */
.monaco-editor .line-numbers {
    color: #c0c0c0 !important;
}

/* Glyph margin width fix */
.monaco-editor .margin-view-overlays {
    width: 20px !important;
}

/* Breakpoint styling */
.breakpoint-glyph {
    background: #d32f2f !important;
    width: 12px !important;
    height: 12px !important;
    border-radius: 50%;
    margin-left: 4px !important;
    margin-top: 4px !important;
}

/* Execution line highlighting */
.execution-line {
    background: rgba(255, 255, 0, 0.2) !important;
}

.execution-line-glyph {
    background: #ffeb3b !important;
    width: 12px !important;
    height: 12px !important;
    border-radius: 50%;
    margin-left: 4px !important;
    margin-top: 4px !important;
}

/* Expand button */
.expand-btn {
    min-width: 24px;
    height: 24px;
    padding: 2px 4px;
    margin: 0;
    vertical-align: middle;
}

/* Fullscreen modes */
main.console-fullscreen {
    grid-template-columns: 1fr !important;
    grid-gap: 0 !important;
}

main.console-fullscreen #left,
main.console-fullscreen #fs {
    display: none !important;
}

main.console-fullscreen #center {
    min-width: 100% !important;
    max-width: 100% !important;
    width: 100% !important;
    grid-gap: 0 !important;
}

main.console-fullscreen #console-panel {
    height: 100dvh !important;
}

main.console-fullscreen #display {
    display: none !important;
}

main.fs-fullscreen {
    grid-template-columns: 1fr !important;
    grid-gap: 0 !important;
}

main.fs-fullscreen #left,
main.fs-fullscreen #center {
    display: none !important;
}

main.fs-fullscreen #fs {
    width: 100% !important;
    max-width: 100% !important;
}

/* Mobile responsive layout */
@media (max-width: 950px) {
    html, body {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    main {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto auto auto;
        height: auto !important;
        min-height: auto !important;
        overflow: visible !important;
        grid-gap: 2px !important;
        padding: 2px !important;
    }

    #left {
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    #center {
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    #fs {
        max-width: 100% !important;
        height: 600px !important;
        max-height: 600px !important;
        overflow: visible !important;
    }

    .site {
        overflow: visible !important;
    }

    .panel {
        overflow: visible !important;
        padding: 2px !important;
        border-radius: 2px !important;
    }

    .panel > div {
        overflow: visible !important;
    }

    #fs-header, #console-header {
        padding: 2px !important;
    }

    #display-canvas {
        width: 100% !important;
        height: auto !important;
        max-width: 320px;
    }

    #console-panel {
        height: 400px;
    }

    #memory-panel {
        height: 400px;
    }
}
