@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");

* {
    margin: 0px;
    padding: 0px;
    color: rgb(229, 229, 229);
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --bg-start: #0c0f14;
    --bg-end: #06080b;
    --panel: rgba(18, 22, 30, 0.92);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-soft: rgba(235, 245, 255, 0.92);
    --text-softer: rgba(235, 245, 255, 0.58);
    --accent: #3aa7ff;
    --accent-strong: #6bc0ff;
    --accent-soft: rgba(58, 167, 255, 0.18);
    --accent-ink: #0e1320;
    --glow: rgba(58, 167, 255, 0.18);
    --mac-close: #ff5f56;
    --mac-minimize: #ffbd2e;
    --mac-maximize: #27c93f;
}

html, body {
    height: 100%;
}

body {
    min-height: 100vh;
    background: 
        radial-gradient(circle at 10% 10%, rgba(58, 167, 255, 0.12), transparent 45%),
        radial-gradient(circle at 90% 0%, rgba(76, 255, 221, 0.08), transparent 40%),
        radial-gradient(circle at 10% 90%, rgba(58, 167, 255, 0.06), transparent 45%),
        linear-gradient(180deg, var(--bg-start), var(--bg-end));
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    line-height: 1.4;
    padding: 1.5rem !important;
}

.page-shell {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    border-radius: 16px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(26px);
    -webkit-backdrop-filter: blur(26px);
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    min-height: 600px;
}

.app-header {
    background: rgba(12, 15, 20, 0.85);
    padding: 14px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-header-inner {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.brand-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    flex-shrink: 0;
    font-weight: 800;
    color: var(--accent-strong);
    line-height: 0.9;
}

.brand-logo span {
    font-size: 20px;
    letter-spacing: 2px;
    margin-right: -2px;
}

.brand-logo small {
    margin-top: 2px;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 7px;
    color: rgba(107, 192, 255, 0.8);
    margin-right: -7px;
}

.brand-copy {
    flex: 1;
    min-width: 0;
}

.brand-title-link {
    color: #fff;
    text-decoration: none;
    font-size: 17px;
    font-weight: 600;
    display: block;
}

.brand-title-link:hover {
    color: var(--accent-strong);
}

.brand-copy p {
    color: var(--text-soft);
    font-size: 12px;
    margin: 2px 0;
}

.brand-credit {
    color: var(--text-softer);
    font-size: 11px;
    line-height: 1.3;
}

.brand-credit a {
    color: var(--text-soft);
    text-decoration: none;
}

.brand-credit a:hover {
    color: #fff;
}

.device-badge {
    background: var(--accent);
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    box-shadow: 0 2px 8px var(--accent-soft);
}

/* Header - macOS styled */
.header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    background: rgba(36, 38, 46, 0.6);
    border-bottom: 1px solid rgba(0, 0, 0, 0.5);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
    min-height: 80px;
}

.macos-traffic {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.mac-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
}

.mac-dot.close { background-color: var(--mac-close); }
.mac-dot.minimize { background-color: var(--mac-minimize); }
.mac-dot.maximize { background-color: var(--mac-maximize); }
.mac-dot.close:hover { filter: brightness(1.2); }
.mac-dot.minimize:hover { filter: brightness(1.2); }
.mac-dot.maximize:hover { filter: brightness(1.2); }

.brand-block {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}

.brand-title {
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.brand-title:hover {
    color: var(--accent-strong);
}

.brand-subtitle {
    color: var(--text-soft);
    font-size: 0.8rem;
    margin: 0;
}

.brand-attribution {
    color: var(--text-softer);
    font-size: 0.7rem;
    margin: 0;
    line-height: 1.3;
}

.brand-attribution a {
    color: var(--text-soft);
    text-decoration: none;
}

.brand-attribution a:hover {
    color: #fff;
    text-decoration: underline;
}

.header-links {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.header-links a {
    font-size: 0.8rem;
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.06);
    text-decoration: none;
    transition: all 150ms ease;
    border: 1px solid rgba(255, 255, 255, 0.05);
    white-space: nowrap;
}

.header-links a:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.device-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: 1rem;
    padding: 0.5rem 0.85rem;
    border-radius: 10px;
    background: rgba(10, 132, 255, 0.15);
    border: 1px solid rgba(10, 132, 255, 0.3);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.device-switch:hover {
    background: rgba(10, 132, 255, 0.25);
    border-color: rgba(10, 132, 255, 0.5);
}

.device-switch label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.device-switch select {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 6px;
    padding: 0.3rem 1.75rem 0.3rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 700;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1em;
}

.device-switch select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.app-footer {
    padding: 1rem 1.5rem;
    text-align: center;
    border-top: 1px solid var(--panel-border);
    margin-top: auto;
    flex-shrink: 0;
}

/* Main content area (Modern IDE Layout) */
.main.layout-modern {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(350px, 1fr) 400px 320px;
    gap: 1.25rem;
    padding: 1.25rem;
    overflow: hidden; /* Prevent main scroll, let columns scroll */
    min-height: 0; /* Important for nested scrolling */
}

/* Layout Columns */
.layout-col {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-height: 0;
    background: rgba(12, 15, 20, 0.4);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
}

.panel-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    color: var(--text-softer);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 0.25rem;
    flex-shrink: 0;
}

/* Remove old grid areas, make elements flexible */
#registers-flags, .registers-flags {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
    overflow-y: auto;
}

.controls-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
    min-height: 250px;
}

#assembler-container {
    overflow-y: auto;
    max-height: 300px;
    flex-shrink: 0;
}

.memory-edit-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

#memory-container {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Panel styling for interior blocks */
.table-container, .code-container, .registers-container, .flags-container {
    background: rgba(8, 10, 14, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.table-container {
    background: rgba(8, 10, 14, 0.5);
}

/* Table styling */
table {
    text-align: center;
    font-size: 11px;
    margin-bottom: 0 !important;
    width: 100%;
}

table caption {
    caption-side: top;
    padding: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.35);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    text-align: left;
}

.table.table-striped.table-hover.table-dark {
    background: transparent !important;
}

.table-dark th, .table-dark td, .table-dark thead th {
    border-color: rgba(255, 255, 255, 0.06);
    padding: 0.4rem;
    vertical-align: middle;
}

.table-dark thead th {
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(255, 255, 255, 0.02) !important;
}

.table-hover tbody tr:hover {
    background-color: rgba(58, 167, 255, 0.12) !important;
}

.memory-cell {
    cursor: pointer;
    transition: background-color 120ms ease;
}

.memory-cell:hover {
    background-color: rgba(58, 167, 255, 0.18) !important;
}

/* Controls */
.controls-container .button-head {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: center;
}

.btn-sm {
    border-radius: 6px;
    font-weight: 500;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
    border: none !important;
    transition: opacity 150ms;
    cursor: pointer;
    padding: 0.4rem 0.8rem !important;
    font-size: 0.85rem !important;
}

.btn-sm:hover {
    opacity: 0.9;
}

/* Code editor */
.code-container {
    flex-direction: row;
    flex: 1;
    background: rgba(6, 8, 12, 0.55);
}

.editor-gutter,
#track {
    width: 40px;
    padding: 0.5rem 0.5rem;
    font-family: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.4);
    border-right: 1px solid var(--panel-border);
    text-align: right;
    color: var(--text-softer) !important;
    line-height: 1.5;
    resize: none;
    overflow: hidden;
    user-select: none;
}

.code-box {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.5rem 0.75rem;
    color: #e5e5e5;
    font-family: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;
    font-size: 12px;
    line-height: 1.5;
    resize: none;
    outline: none;
}

.code-box:focus {
    outline: none;
}

/* Memory edit input */
.memory-edit-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.memory-edit {
    width: 100%;
    padding: 0.6rem 1rem;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 8px;
    color: #fff;
    font-size: 0.85rem;
    transition: border-color 150ms;
}

.memory-edit:focus {
    outline: none;
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.memory-edit::placeholder {
    color: var(--text-softer);
}

.memory-hint {
    font-size: 11px;
    color: var(--text-softer);
}

#mem-dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 1200;
}

#mem-dialog-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

#mem-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -48%) scale(0.98);
    width: min(360px, calc(100vw - 32px));
    background: #1b1e26;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
    z-index: 1201;
}

#mem-dialog.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.mem-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.mem-dialog-header button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 16px;
}

.mem-dialog-body {
    padding: 14px;
    display: grid;
    gap: 10px;
}

.mem-address-label,
.mem-value-label {
    font-size: 11px;
    color: var(--text-softer);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.mem-address-value {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

#mem-value {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
}

#mem-value:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.mem-dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 6px;
    flex-wrap: wrap;
}

#mem-write-btn,
#mem-dialog-cancel {
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    max-width: 100%;
}

#mem-write-btn {
    background: var(--accent);
    color: #fff;
}

#mem-dialog-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Responsive design */
@media only screen and (max-width: 1200px) {
    .main.layout-modern {
        grid-template-columns: 1fr 350px;
        overflow: auto;
    }
    
    .layout-col {
        overflow: visible;
    }

    .layout-col-editor {
        grid-row: span 2;
    }
}

@media only screen and (max-width: 768px) {
    body {
        padding: 0 !important;
    }

    .page-shell {
        border-radius: 0;
        min-height: 100vh;
        border: none;
    }

    .desktop-only-msg {
        display: inline-block !important;
    }

    .app-header {
        padding: 0.85rem;
    }

    .app-header-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .brand-logo {
        flex-direction: row;
        align-items: baseline;
        justify-content: flex-start;
        gap: 4px;
        margin-bottom: -4px;
    }
    
    .brand-logo span { font-size: 18px; }
    .brand-logo small { font-size: 12px; margin-top: 0; }

    .device-switch {
        margin-left: 0;
        width: 100%;
        justify-content: space-between;
    }

    .header-links {
        width: 100%;
        gap: 0.4rem;
        flex-wrap: wrap;
    }

    .header-links a {
        flex: 1;
        text-align: center;
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }

    .brand-title {
        font-size: 1rem;
    }

    .brand-subtitle {
        font-size: 0.75rem;
    }

    .brand-attribution {
        font-size: 0.65rem;
    }

    .main.layout-modern {
        grid-template-columns: 1fr;
        overflow: auto;
        padding: 0.75rem;
        gap: 1rem;
    }

    .layout-col-editor {
        grid-row: auto;
    }

    .controls-container {
        min-height: 360px;
    }

    #memory-container {
        max-height: 70vh;
    }

    .table-container {
        overflow-x: auto;
    }

    .code-box {
        min-height: 300px;
        font-size: 12px;
    }

    .editor-gutter,
    #track {
        width: 36px;
        min-height: 300px;
    }

    .btn-sm {
        flex: 1 1 calc(50% - 0.4rem);
    }

    .brand-copy p {
        font-size: 11px;
    }
}

/* AI Panel Styling */
#ai-panel-toggle {
    position: fixed;
    right: max(39px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 1000;
    width: auto;
    min-width: 112px;
    height: auto;
    min-height: 42px;
    padding: 10px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    pointer-events: auto;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}

#ai-panel-toggle:hover {
    background: var(--accent-strong) !important;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3);
}

#ai-panel {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(39px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: min(360px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    background: #121722;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    z-index: 119;
    transform: translateX(calc(100% + 39px));
    transition: transform 0.3s ease;
    box-shadow: -2px 0 16px rgba(0,0,0,0.5);
    overflow: hidden;
}

#ai-panel.open {
    transform: translateX(0);
}

#ai-chat-messages {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* AI Markdown Content Styling */
.ai-message-content p {
    margin-bottom: 0.5em;
}
.ai-message-content p:last-child {
    margin-bottom: 0;
}
.ai-message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    color: #ff9e64;
}
.ai-message-content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 8px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.ai-message-content pre code {
    background: transparent;
    padding: 0;
    color: #e5e5e5;
}
.ai-message-content ul, .ai-message-content ol {
    padding-left: 20px;
    margin-bottom: 0.5em;
}

#ai-input {
    transition: border-color 150ms, background-color 150ms;
}

#ai-input:focus {
    outline: none;
    border-color: var(--accent) !important;
    background: rgba(255, 255, 255, 0.08) !important;
}

#ai-send-btn:hover {
    background: var(--accent-strong) !important;
    box-shadow: 0 2px 8px var(--glow);
}

#ai-send-btn:active {
    transform: scale(0.95);
}

#ai-explain-btn:hover,
#ai-tutor-btn:hover {
    background: rgba(58, 167, 255, 0.3) !important;
    box-shadow: inset 0 0 8px var(--glow);
}

.phone-warning {
    display: none;
}

@media only screen and (max-width: 640px) {
    .phone-warning.show {
        position: fixed;
        inset: 12px 12px auto 12px;
        z-index: 200;
        display: flex;
        align-items: flex-start;
        gap: 12px;
        padding: 12px;
        background: #20242d;
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 8px;
        box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
    }

    .phone-warning strong {
        display: block;
        color: #fff;
        font-size: 13px;
        margin-bottom: 2px;
    }

    .phone-warning p {
        margin: 0;
        color: var(--text-soft);
        font-size: 12px;
        line-height: 1.35;
    }

    .phone-warning button {
        flex-shrink: 0;
        padding: 6px 10px;
        background: var(--accent);
        border: 0;
        border-radius: 6px;
        color: #fff;
        font-size: 12px;
        font-weight: 700;
    }

    #ai-panel-toggle {
        min-width: 112px;
        min-height: 42px;
        padding: 10px 16px;
        right: max(16px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
    }

    #ai-panel {
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        bottom: max(8px, env(safe-area-inset-bottom));
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
    }
}
