* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: #111827;
    color: #e5e7eb;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
textarea {
    font: inherit;
}

.container {
    width: min(1200px, calc(100% - 32px));
    margin: 24px auto 48px;
}

/* --------------------------------------------------
   Header
-------------------------------------------------- */

.app-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
}

.app-header h1 {
    margin: 0 0 6px;
    font-size: 28px;
}

.app-header p {
    margin: 0;
    color: #9ca3af;
}

.bits-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #9ca3af;
    font-size: 14px;
}

.bits-control select {
    min-width: 110px;
    padding: 8px 10px;
    border: 1px solid #374151;
    border-radius: 6px;
    background: #1f2937;
    color: #f9fafb;
}

/* --------------------------------------------------
   Toolbar
-------------------------------------------------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.toolbar button {
    padding: 8px 14px;
    border: 1px solid #374151;
    border-radius: 6px;
    background: #1f2937;
    color: #f9fafb;
    cursor: pointer;
}

.toolbar button:hover:not(:disabled) {
    background: #374151;
}

.toolbar button:disabled {
    opacity: 0.45;
    cursor: default;
}

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

.editor-panel,
.panel,
.debug {
    border: 1px solid #374151;
    border-radius: 8px;
    background: #1f2937;
}

.editor-panel {
    overflow: hidden;
}

.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;

    padding: 10px 14px;

    border-bottom: 1px solid #374151;
    background: #111827;
}

.editor-info {
    display: flex;
    gap: 16px;
    color: #9ca3af;
    font-size: 13px;
}

/*
 * EDITORNS EXAKTA GRID
 *
 * 15px font
 * 23px rad
 * 1rem toppadding
 *
 * Samma värden används överallt.
 */

.code-editor {
    --editor-font-size: 15px;
    --editor-line-height: 23px;
    --editor-padding: 1rem;

    display: flex;

    height: 420px;
    overflow: hidden;

    font-family: "Courier New", Courier, monospace;
    font-size: var(--editor-font-size);
    line-height: var(--editor-line-height);
}

/* --------------------------------------------------
   Line numbers
-------------------------------------------------- */

.line-numbers {
    flex: 0 0 64px;

    height: 100%;

    padding-top: var(--editor-padding);

    overflow: hidden;

    background: #172033;
    border-right: 1px solid #374151;

    font-family: inherit;
    font-size: var(--editor-font-size);
    line-height: var(--editor-line-height);

    user-select: none;
}

.line-number {
    position: relative;

    display: block;

    width: 100%;
    height: var(--editor-line-height);

    margin: 0;
    padding: 0 12px 0 28px;

    border: 0;
    border-radius: 0;

    background: transparent;
    color: #6b7280;

    font-family: inherit;
    font-size: var(--editor-font-size);
    font-weight: normal;
    line-height: var(--editor-line-height);

    text-align: right;

    cursor: pointer;
    appearance: none;
}

.line-number:hover {
    background: #263247;
    color: #d1d5db;
}

.line-number span {
    display: block;

    height: var(--editor-line-height);

    margin: 0;
    padding: 0;

    font: inherit;
    line-height: var(--editor-line-height);
}

/*
 * BREAKPOINT
 *
 * Pricken ligger relativt till själva raden.
 * Därför följer den automatiskt med när raden flyttas.
 */

.line-number.breakpoint::before {
    content: "";

    position: absolute;

    left: 8px;
    top: 50%;

    width: 10px;
    height: 10px;

    transform: translateY(-50%);

    border-radius: 50%;

    background: #e53935;
}

/* --------------------------------------------------
   Code area
-------------------------------------------------- */

.code-area {
    position: relative;

    flex: 1;

    min-width: 0;
    height: 100%;

    overflow: hidden;
}

/*
 * Highlight-lagret och textarea måste ha
 * exakt samma typografi och padding.
 */

.highlight,
#source {
    position: absolute;

    top: 0;
    left: 0;

    width: 100%;
    height: 100%;

    margin: 0;
    padding: var(--editor-padding);

    border: 0;

    font-family: "Courier New", Courier, monospace;
    font-size: var(--editor-font-size);
    line-height: var(--editor-line-height);

    letter-spacing: normal;
    tab-size: 4;
    white-space: pre;

    overflow: auto;
}

/* Highlight-lager */

.highlight {
    z-index: 1;

    pointer-events: none;

    background: #111827;
    color: #d1d5db;

    overflow: hidden;
}

/* Textarea */

#source {
    z-index: 2;

    resize: none;

    background: transparent;
    color: transparent;

    caret-color: #f9fafb;

    outline: none;

    overflow: auto;
}

/*
 * Markera aktuell instruktion.
 */

.highlight .current-instruction {
    background: rgba(252, 252, 68, 0.55);
    border-radius: 2px;
}

/*
 * Matchande [ och ]
 */

.highlight .matching-bracket {
    background: rgba(255, 50, 50, 0.55);
    border-radius: 2px;
}

/* --------------------------------------------------
   IO
-------------------------------------------------- */

.workspace {
    display: grid;

    grid-template-columns: minmax(0, 1fr) 320px;

    gap: 16px;

    align-items: stretch;
}

.io-panel {
    display: flex;
    flex-direction: column;

    gap: 16px;

    min-width: 0;
}

.io-panel .panel {
    flex: 1;

    min-height: 0;

    display: flex;
    flex-direction: column;
}

.io-panel .panel textarea {
    flex: 1;

    min-height: 0;

    resize: none;
}

.panel {
    padding: 14px;
}

.panel>label {
    display: block;

    margin-bottom: 8px;

    color: #d1d5db;
    font-size: 14px;
    font-weight: 600;
}

.panel textarea {
    display: block;

    width: 100%;
    min-height: 140px;

    padding: 10px;

    border: 1px solid #374151;
    border-radius: 6px;

    background: #111827;
    color: #f9fafb;

    font-family: "Courier New", Courier, monospace;
    font-size: 14px;
    line-height: 1.5;

    resize: vertical;
}

.panel textarea:focus {
    outline: 1px solid #6b7280;
}

/* --------------------------------------------------
   Debugger
-------------------------------------------------- */

.debug {
    margin-top: 16px;
    padding: 14px;
}

.debug-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    margin-bottom: 14px;
}

.debug-header h2 {
    margin: 0;
    font-size: 18px;
}

#status {
    color: #9ca3af;
    font-size: 14px;
}

.debug-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;

    margin-bottom: 18px;
}

.debug-grid>div {
    padding: 10px;

    border: 1px solid #374151;
    border-radius: 6px;

    background: #111827;
}

.debug-grid span {
    display: block;

    margin-bottom: 4px;

    color: #9ca3af;
    font-size: 12px;
}

.debug-grid strong {
    font-family: "Courier New", Courier, monospace;
    font-size: 16px;
}

/* --------------------------------------------------
   Memory
-------------------------------------------------- */

.debug>label {
    display: block;

    margin-bottom: 8px;

    color: #d1d5db;
    font-size: 14px;
    font-weight: 600;
}

.memory {
    display: flex;
    gap: 4px;

    max-width: 100%;

    padding: 10px;

    overflow-x: auto;

    border: 1px solid #374151;
    border-radius: 6px;

    background: #111827;
}

.memory-cell {
    flex: 0 0 52px;

    display: flex;
    flex-direction: column;
    align-items: center;

    padding: 6px;

    border: 1px solid #374151;
    border-radius: 4px;

    background: #1f2937;

    text-align: center;

    font-family: "Courier New", Courier, monospace;
}

.memory-cell.current {
    border-color: #9ca3af;
    background: #374151;
}

.memory-address {
    display: block;

    margin-bottom: 4px;

    color: #9ca3af;
    font-size: 11px;
}

.memory-value {
    display: block;

    color: #f9fafb;
    font-size: 15px;
}

/* --------------------------------------------------
   Responsive
-------------------------------------------------- */

@media (max-width: 800px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .io-panel {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

/*
 * ============================================================
 * INSTRUKTIONER
 * ============================================================
 */

.instructions {
    margin-top: 16px;
    padding: 0;
    overflow: hidden;
}

.instructions-header {
    padding: 20px 20px 12px;
}

.instructions-header h2 {
    margin: 0;
}


/*
 * Språkflikar
 */

.instruction-tabs {
    display: flex;
    gap: 4px;
    padding: 0 20px;
    border-bottom: 1px solid #374151;
    overflow-x: auto;
}

.instruction-tab {
    flex: 0 0 auto;
    margin: 0;
    padding: 10px 16px;
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 6px 6px 0 0;
    background: transparent;
    color: #9ca3af;
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.instruction-tab:hover {
    background: #1f2937;
    color: #f3f4f6;
}

.instruction-tab.active {
    border-bottom-color: #60a5fa;
    background: #1f2937;
    color: #ffffff;
}


/*
 * Innehållet är scrollbar.
 */

.instruction-content {
    max-height: 500px;
    overflow-y: auto;
    padding: 20px;
}

.instruction-language {
    display: none;
}

.instruction-language.active {
    display: block;
}


/*
 * Text
 */

.instruction-language h3 {
    margin-top: 24px;
    margin-bottom: 10px;
}

.instruction-language h3:first-child {
    margin-top: 0;
}

.instruction-language p {
    max-width: 900px;
    line-height: 1.6;
}

.instruction-language li {
    margin-bottom: 8px;
    line-height: 1.5;
}


/*
 * Kod
 */

.instruction-language code {
    padding: 2px 5px;
    border-radius: 4px;
    background: #111827;
    color: #e5e7eb;
    font-family: "Courier New", Courier, monospace;
}

.instruction-language pre {
    margin: 12px 0;
    padding: 14px 16px;
    overflow-x: auto;
    border-radius: 6px;
    background: #111827;
}

.instruction-language pre code {
    padding: 0;
    background: transparent;
}


/*
 * Kommando-tabell
 */

.instruction-table {
    width: 100%;
    max-width: 900px;
    border-collapse: collapse;
    margin: 12px 0 20px;
}

.instruction-table th,
.instruction-table td {
    padding: 9px 12px;
    border-bottom: 1px solid #374151;
    text-align: left;
    vertical-align: top;
}

.instruction-table th {
    background: #172033;
    color: #f3f4f6;
}

.instruction-table td:first-child {
    width: 100px;
    font-family: "Courier New", Courier, monospace;
    font-weight: bold;
    font-size: 1.1rem;
}

.instruction-table tr:hover td {
    background: #172033;
}


/*
 * Mobil
 */

@media (max-width: 800px) {
    .instruction-content {
        max-height: 600px;
        padding: 16px;
    }

    .instructions-header {
        padding: 16px 16px 10px;
    }

    .instruction-tabs {
        padding: 0 16px;
    }

    .instruction-tab {
        padding: 9px 12px;
    }

    .instruction-table th,
    .instruction-table td {
        padding: 8px;
    }
}