* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

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

h1,
h2,
h3 {
    margin: 0 0 4px 0;
    font-weight: 600;
}

p {
    margin: 4px 0;
    font-size: 12px;
    color: #9ca3af;
}

#app {
    display: flex;
    height: 100vh;
}

.left-panel,
.right-panel {
    flex: 1;
    padding: 12px 16px;
    overflow: hidden;
}

.left-panel {
    border-right: 1px solid #1f2937;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.memory-section {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.memory-container {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border-radius: 4px;
    border: 1px solid #374151;
    background: #020617;
}

.memory-caption {
    margin-top: 4px;
}

#memory-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 10px;
}

#memory-table th,
#memory-table td {
    border: 1px solid #1f2937;
    padding: 2px 3px;
    text-align: center;
    white-space: nowrap;
}

#memory-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #111827;
}

#memory-table th.row-header {
    background: #111827;
    position: sticky;
    left: 0;
    z-index: 1;
}

.current-pointer {
    background: #f97316 !important;
    color: #111827;
    font-weight: 700;
}

.controls-section {
    flex: 0 0 auto;
    padding: 8px 10px;
    border-radius: 4px;
    border: 1px solid #374151;
    background: #020617;
}

.buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

button {
    appearance: none;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    background: #2563eb;
    color: #e5e7eb;
}

button:hover {
    background: #1d4ed8;
}

button:active {
    background: #1e40af;
}

.settings label {
    display: block;
    font-size: 12px;
    margin: 4px 0 2px;
}

.settings select,
.settings input[type="number"] {
    width: 100%;
    padding: 4px 6px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid #4b5563;
    background: #020617;
    color: #e5e7eb;
}

.settings .checkbox-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 6px 0;
    font-size: 12px;
    color: #e5e7eb;
}

.ascii-section {
    flex: 0 0 35%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ascii-container {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border-radius: 4px;
    border: 1px solid #374151;
    background: #020617;
}

#ascii-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

#ascii-table th,
#ascii-table td {
    border: 1px solid #1f2937;
    padding: 2px 4px;
    text-align: center;
}

.editor-section {
    flex: 1 1 55%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* CodeMirror editor area */
.editor-section .CodeMirror {
    flex: 1;
    min-height: 0;
    border-radius: 4px;
    border: 1px solid #374151;
    background: #020617;
    font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
    font-size: 13px;
}

.editor-section .CodeMirror-scroll {
    min-height: 0;
}

.io-section {
    flex: 1 1 45%;
    display: flex;
    gap: 12px;
    min-height: 0;
}

.command-bar {
    padding: 6px 0 10px;
}

.command-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.command-btn {
    appearance: none;
    border: 1px solid #4b5563;
    background: #020617;
    color: #e5e7eb;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
}

.command-btn:hover {
    border-color: #2563eb;
    color: #93c5fd;
}

.command-btn:active {
    background: #111827;
    border-color: #1d4ed8;
}

.io-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

textarea {
    width: 100%;
    resize: vertical;
    background: #020617;
    color: #e5e7eb;
    border-radius: 4px;
    border: 1px solid #374151;
    padding: 8px;
    font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
    font-size: 13px;
}

#code {
    flex: 1;
    min-height: 0;
}

#input {
    flex: 1;
    min-height: 0;
}

#output {
    flex: 1;
    min-height: 0;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #374151;
    background: #020617;
    font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
    font-size: 13px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.section-header-row small {
    font-size: 11px;
    color: #9ca3af;
}

.editor-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-button {
    appearance: none;
    border: 1px solid #4b5563;
    background: #020617;
    color: #e5e7eb;
    border-radius: 6px;
    padding: 6px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-button:hover {
    border-color: #2563eb;
    color: #93c5fd;
}

.icon-button:active {
    background: #111827;
    border-color: #1d4ed8;
}

.memory-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #9ca3af;
}

.toggle-pill {
    padding: 2px 8px;
    border-radius: 9999px;
    border: 1px solid #4b5563;
    background: #020617;
    font-size: 11px;
    color: #e5e7eb;
    cursor: pointer;
}

.toggle-pill.active {
    background: #22c55e;
    border-color: #16a34a;
    color: #0f172a;
    font-weight: 600;
}

.editor-header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.editor-tabs-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.editor-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    min-width: 0;
}

.editor-tab {
    padding: 2px 8px 2px 10px;
    border-radius: 10px;
    border: 1px solid #4b5563;
    background: #020617;
    font-size: 11px;
    color: #e5e7eb;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.editor-tab.active {
    background: #2563eb;
    border-color: #1d4ed8;
}

.tab-title {
    line-height: 1.2;
}

.tab-rename {
    appearance: none;
    border: none;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    border-radius: 6px;
    cursor: pointer;
}

.tab-rename:hover {
    background: #1f2937;
}

.tab-rename svg {
    display: block;
}

.tab-add {
    width: 32px;
    height: 32px;
}

.cm-current-instruction {
    background: rgba(56, 189, 248, 0.25);
    border-bottom: 1px solid #22d3ee;
}
