:root {
    --axy-bg: #1a1a2e;
    --axy-surface: #16213e;
    --axy-accent: #e94560;
    --axy-text: #eee;
    --axy-text-dim: #888;
    --axy-lcd-bg: #1b3a2a;
    --axy-lcd-text: #33ff66;
    --axy-led-on: #e94560;
    --axy-led-off: #333;
    --axy-btn: #2a2a4a;
    --axy-btn-active: #4a4a6a;
    --axy-key: #2d2d4d;
    --axy-key-text: #ddd;
    --axy-key-border: #444;
    --axy-highlight: rgba(233, 69, 96, 0.3);
}

* { box-sizing: border-box; }

body {
    background: var(--axy-bg);
    color: var(--axy-text);
    font-family: 'Courier New', monospace;
    margin: 0; padding: 0;
    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

button {
    font-family: 'Courier New', monospace;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ==================== Tabs ==================== */

.tab-bar {
    display: flex;
    justify-content: center;
    padding: 8px 12px 6px;
    background: var(--axy-surface);
}

.tab-group {
    display: inline-flex;
    border: 1px solid var(--axy-key-border);
    border-radius: 6px;
    overflow: hidden;
}

.tab-btn {
    padding: 7px 24px;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--axy-text-dim);
    background: transparent;
    border: none;
    border-right: 1px solid var(--axy-key-border);
    cursor: pointer;
    transition: color 0.1s, background 0.1s;
}

.tab-btn:last-child { border-right: none; }
.tab-btn:active { background: var(--axy-btn-active); }

.tab-btn.active {
    color: #fff;
    background: var(--axy-accent);
}

.tab-content {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 8px;
}

/* ==================== Shared Key ==================== */

.kb-row {
    display: flex;
    justify-content: center;
    gap: 3px;
    margin-bottom: 3px;
}

.kb-key {
    flex: 1;
    max-width: 40px;
    height: 40px;
    border-radius: 5px;
    border: 1px solid var(--axy-key-border);
    background: var(--axy-key);
    color: var(--axy-key-text);
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    flex-shrink: 0;
}
.kb-key:active { background: var(--axy-btn-active); }

/* Fixed-width modifier keys to prevent layout shift */
.kb-key.w15 { flex: 0 0 52px; max-width: 52px; }
.kb-key.w-mode { flex: 0 0 48px; max-width: 48px; font-size: 11px; }

.kb-key.accent {
    border-color: var(--axy-accent);
    color: var(--axy-accent);
}

.kb-key.active {
    border-color: var(--axy-accent);
    color: var(--axy-accent);
    background: rgba(233, 69, 96, 0.15);
}

.kb-key.dim { color: var(--axy-text-dim); font-size: 12px; }

.kb-bottom {
    display: flex;
    gap: 3px;
    margin-top: 3px;
}

.kb-space {
    flex: 1;
    height: 40px;
    border-radius: 5px;
    border: 1px solid var(--axy-key-border);
    background: var(--axy-key);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--axy-text-dim);
    font-size: 11px;
}
.kb-space:active { background: var(--axy-btn-active); }

/* ==================== Pad Tab ==================== */

.pad-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 2px;
}

.led-row { display: flex; gap: 5px; }
.led {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--axy-led-off);
}
.led.on { background: var(--axy-led-on); box-shadow: 0 0 6px var(--axy-led-on); }

.status-row { display: flex; gap: 6px; }
.status-display {
    font-size: 11px;
    padding: 2px 5px;
    background: var(--axy-surface);
    border: 1px solid var(--axy-key-border);
    border-radius: 3px;
    color: var(--axy-lcd-text);
}

.lcd {
    background: var(--axy-lcd-bg);
    border: 3px solid #2a4a3a;
    border-radius: 6px;
    padding: 8px 12px;
    margin: 8px 0;
    font-size: 15px;
    line-height: 1.4;
    color: var(--axy-lcd-text);
    min-height: 88px;
    white-space: pre;
    overflow: hidden;
    text-shadow: 0 0 8px rgba(51, 255, 102, 0.4);
}

.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    gap: 8px;
}

.btn-group-v { display: flex; flex-direction: column; gap: 5px; }

.ctrl-btn {
    width: 50px; height: 38px;
    border-radius: 8px;
    border: 2px solid var(--axy-key-border);
    background: var(--axy-btn);
    color: var(--axy-text);
    font-size: 12px; font-weight: bold;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.ctrl-btn:active { background: var(--axy-btn-active); }
.ctrl-btn.accent { border-color: var(--axy-accent); color: var(--axy-accent); }

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    gap: 2px;
}
.dpad-btn {
    border-radius: 6px;
    border: 2px solid var(--axy-key-border);
    background: var(--axy-btn);
    color: var(--axy-text);
    font-size: 16px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.dpad-btn:active { background: var(--axy-btn-active); }
.dpad-btn.empty { visibility: hidden; border: none; }

.keyboard { margin-top: 8px; }

/* ==================== IDE Tab ==================== */

.ide-editor {
    background: #111;
    border: 1px solid var(--axy-key-border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--axy-lcd-text);
    min-height: 72px;
    max-height: 110px;
    margin-bottom: 8px;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.5;
    overflow-y: auto;
}

.ide-cursor {
    display: inline;
    border-right: 2px solid var(--axy-lcd-text);
    animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { border-color: transparent; } }

.action-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1;
    padding: 7px 4px;
    border-radius: 5px;
    border: 1px solid var(--axy-key-border);
    background: var(--axy-btn);
    color: var(--axy-text);
    font-family: 'Courier New', monospace;
    font-size: 11px; font-weight: bold;
    cursor: pointer;
    text-align: center;
}
.action-btn:active { background: var(--axy-btn-active); }
.action-btn.primary { border-color: var(--axy-accent); color: var(--axy-accent); }

select.action-btn {
    flex: 0 0 auto;
    min-width: 80px;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 8px;
}

.error-bar {
    background: #e94560;
    color: #fff;
    padding: 5px 10px;
    font-size: 11px;
    border-radius: 4px;
    margin-bottom: 8px;
}

/* IDE keyboard mode tabs — fixed width to prevent layout shift */
.kb-mode-bar {
    display: flex;
    gap: 0;
    margin-bottom: 6px;
    border: 1px solid var(--axy-key-border);
    border-radius: 5px;
    overflow: hidden;
}

.kb-mode-tab {
    flex: 1;
    padding: 7px 0;
    text-align: center;
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--axy-text-dim);
    background: var(--axy-surface);
    border: none;
    border-right: 1px solid var(--axy-key-border);
    cursor: pointer;
    transition: color 0.1s, background 0.1s;
}
.kb-mode-tab:last-child { border-right: none; }
.kb-mode-tab:active { background: var(--axy-btn-active); }
.kb-mode-tab.active {
    color: #fff;
    background: var(--axy-accent);
}

/* Opcode grid */
.opcode-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    margin-bottom: 6px;
}

.op-key {
    height: 38px;
    border-radius: 5px;
    border: 1px solid var(--axy-key-border);
    background: var(--axy-btn);
    color: var(--axy-text);
    font-size: 10px; font-weight: bold;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.op-key:active { background: var(--axy-btn-active); }

/* Value hex grid */
.value-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    margin-bottom: 6px;
}

.hex-key {
    height: 40px;
    border-radius: 5px;
    border: 1px solid var(--axy-key-border);
    background: var(--axy-key);
    color: var(--axy-lcd-text);
    font-size: 15px; font-weight: bold;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.hex-key:active { background: var(--axy-btn-active); }

/* Register/directive row */
.reg-toggle-row {
    display: flex;
    gap: 3px;
    margin-bottom: 6px;
}

/* ==================== Memory Tab ==================== */

.mem-section { margin-bottom: 12px; }

.mem-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--axy-text-dim);
    margin-bottom: 3px;
}

.reg-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin-bottom: 12px;
}

.reg-box {
    background: var(--axy-surface);
    border: 1px solid var(--axy-key-border);
    border-radius: 6px;
    padding: 6px;
    text-align: center;
}

.reg-name {
    font-size: 9px;
    color: var(--axy-text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.reg-val {
    font-size: 16px;
    font-weight: bold;
    color: var(--axy-lcd-text);
    margin-top: 1px;
}

.mem-grid {
    display: grid;
    grid-template-columns: 24px repeat(16, 1fr);
    gap: 1px;
    font-size: 9px;
    line-height: 16px;
    background: var(--axy-surface);
    border: 1px solid var(--axy-key-border);
    border-radius: 4px;
    padding: 3px;
    overflow-x: auto;
}

.mem-addr {
    color: var(--axy-text-dim);
    text-align: right;
    padding-right: 3px;
    font-size: 8px;
}

.mem-cell { text-align: center; padding: 0 1px; border-radius: 2px; }
.mem-cell.zero { color: #333; }
.mem-cell.pc { background: var(--axy-highlight); color: var(--axy-accent); font-weight: bold; }
.mem-cell.nonzero { color: var(--axy-lcd-text); }

.stack-display {
    background: var(--axy-surface);
    border: 1px solid var(--axy-key-border);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 11px;
    color: var(--axy-lcd-text);
    min-height: 32px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.stack-item {
    background: #1a3a2a;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 10px;
}
.stack-item.top { background: var(--axy-accent); color: #fff; }

/* MMIO grid in Memory tab */
.mmio-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    margin-bottom: 12px;
}

.mmio-cell {
    background: var(--axy-surface);
    border: 1px solid var(--axy-key-border);
    border-radius: 4px;
    padding: 3px 2px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.mmio-name {
    font-size: 8px;
    color: var(--axy-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mmio-val {
    font-size: 12px;
    font-weight: bold;
    color: var(--axy-lcd-text);
}

/* ==================== Help Tab ==================== */

.help {
    padding-bottom: 24px;
}

.help-section {
    margin-bottom: 12px;
}

.help-title {
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--axy-accent);
    padding: 6px 0 4px;
    border-bottom: 1px solid var(--axy-key-border);
    margin-bottom: 4px;
}

.help-body {
    font-size: 11px;
    line-height: 1.5;
    color: var(--axy-text);
    margin: 0;
    padding: 4px 0;
    white-space: pre;
    overflow-x: auto;
}
