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

:root {
    color-scheme: dark;
    --bg-start: #1c1c1e;
    --bg-end: #000000;
    --panel: rgba(44, 44, 46, 0.85);
    --panel-border: rgba(255, 255, 255, 0.15);
    --text-soft: #ebebf5;
    --text-softer: rgba(235, 235, 245, 0.6);
    --accent: #0A84FF;
    --accent-strong: #409CFF;
    --accent-soft: rgba(10, 132, 255, 0.15);
    --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(106, 168, 255, 0.08), transparent 40%),
        linear-gradient(180deg, var(--bg-start), var(--bg-end));
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.4;
    padding: 1.5rem !important;
}

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

.app-header {
    background: #242626;
    padding: 12px 20px;
    border-bottom: 1px solid #000;
}

.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);
    line-height: 0.9;
}

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

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

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

.brand-title-link {
    color: #fff;
    text-decoration: none;
    font-size: 16px;
    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-copy .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;
}

/* 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.8rem;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
    transition: all 150ms ease;
    border: 1px solid rgba(255, 255, 255, 0.04);
    white-space: nowrap;
}

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

/* Main content area */
.main {
    flex: 1;
    display: grid;
    grid-template-columns: 240px 1fr 1fr;
    grid-template-areas:
        "a d f"
        "a d c"
        "a e c"
        "a e g";
    gap: 1rem;
    padding: 1rem;
    overflow: auto;
}

/* Grid areas */
#registers-flags, .registers-flags {
    grid-area: a;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.controls-container {
    grid-area: d;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 400px;
}

#assembler-container {
    grid-area: e;
    overflow-y: auto;
}

.memory-edit-container {
    grid-area: f;
    min-height: 45px;
    margin-top: 1.5rem;
}

#memory-container {
    grid-area: c;
    overflow-y: auto;
    max-height: 600px;
}

/* Panel styling for interior blocks */
.table-container, .code-container, .registers-container, .flags-container {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.table-container {
    background: rgba(0, 0, 0, 0.2);
}

/* 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.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    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.05);
    padding: 0.4rem;
    vertical-align: middle;
}

.table-dark thead th {
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    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(255, 255, 255, 0.08) !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 1px 2px rgba(0, 0, 0, 0.2);
    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(0, 0, 0, 0.35);
}

.editor-gutter,
#track {
    width: 40px;
    padding: 0.5rem 0.5rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, 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: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, 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;
}

.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);
}

/* 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 {
        grid-template-columns: 200px 1fr;
        grid-template-areas:
            "a d"
            "a d"
            "a e"
            "f f"
            "c c"
            "g g";
    }

    .memory-edit-container {
        margin-top: 0;
    }
}

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

    .page-shell {
        border-radius: 8px;
        min-height: auto;
    }

    .app-header {
        padding: 0.75rem;
    }

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

    .header-links {
        width: 100%;
        gap: 0.25rem;
    }

    .header-links a {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }

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

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

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

    .main {
        grid-template-columns: 1fr;
        grid-template-areas:
            "d"
            "e"
            "a"
            "f"
            "c"
            "g";
        gap: 0.75rem;
        padding: 0.75rem;
        overflow: visible;
    }

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

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

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

    .memory-edit-container {
        min-height: 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: #0A84FF;
    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: #409CFF !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: #1a1c24;
    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: #0A84FF !important;
    background: rgba(255, 255, 255, 0.08) !important;
}

#ai-send-btn:hover {
    background: #409CFF !important;
    box-shadow: 0 2px 8px rgba(10, 132, 255, 0.3);
}

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

#ai-explain-btn:hover,
#ai-tutor-btn:hover {
    background: rgba(10, 132, 255, 0.3) !important;
    box-shadow: inset 0 0 8px rgba(10, 132, 255, 0.2);
}

.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);
    }
}
