:root {
    /* Primary (brand accent) / secondary (code keyword) colors, overridable per theme
       via ?primaryLight=&secondaryLight=&primaryDark=&secondaryDark= query params. */
    --accent-dark: #4fd1c5;
    --cmd-dark: #7cc4ff;
    --accent-light: #0e9488;
    --cmd-light: #2b6cb0;

    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root, :root[data-theme="dark"] {
    --bg: #0f1420;
    --panel: #161c2b;
    --panel-2: #1b2333;
    --border: #263048;
    --fg: #d6def0;
    --muted: #8592ad;
    --accent: var(--accent-dark);
    --cmd: var(--cmd-dark);
    --error: #ff6b6b;
    --warn: #f5c451;
}

:root[data-theme="light"] {
    --bg: #f7f8fb;
    --panel: #ffffff;
    --panel-2: #eef1f6;
    --border: #dde3ee;
    --fg: #1b2333;
    --muted: #5b6478;
    --accent: var(--accent-light);
    --cmd: var(--cmd-light);
    --error: #d64545;
    --warn: #b3790a;
}

* { box-sizing: border-box; }
*, *::before, *::after { -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg);
    color: var(--fg);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

#topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    padding: 12px 18px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

#topbar .logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--accent);
    letter-spacing: 0.5px;
}

#topbar .tagline { color: var(--muted); font-size: 13px; }

#theme-toggle {
    margin-left: auto;
    align-self: center;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--fg);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

#theme-toggle:hover { border-color: var(--accent); }

#panes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    flex: 1;
    min-height: 0;
}

.pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: var(--bg);
}

.pane-header {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 34px;
    padding: 0 14px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--muted);
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
}

.pane-header .hint { text-transform: none; letter-spacing: 0; color: var(--muted); opacity: 0.8; }

.pane-header button {
    margin-left: auto;
    padding: 3px 10px;
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--fg);
    cursor: pointer;
}

.pane-header button:hover { border-color: var(--accent); color: var(--accent); }

/* Editor */
#editor {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.cm-editor { height: 100%; }
.cm-editor.cm-focused { outline: none; }

/* Diagnostics */
#diagnostics {
    height: 34%;
    min-height: 90px;
    overflow: auto;
    padding: 8px 0;
    font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
    font-size: 12.5px;
    background: var(--panel);
}

.diag-empty { padding: 6px 14px; color: var(--muted); }

.diag {
    padding: 6px 14px;
    border-left: 3px solid transparent;
    white-space: pre-wrap;
}

.diag.error { border-left-color: var(--error); color: #ffd7d7; }
.diag.warning { border-left-color: var(--warn); color: #f7e9c2; }
.diag .code { color: var(--muted); font-size: 11px; }

:root[data-theme="light"] .diag.error { color: #a11d1d; }
:root[data-theme="light"] .diag.warning { color: #6b4e00; }

/* Shell */
#shell-output {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 12px 14px;
    font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.line { margin: 0; }
.line.prompt-echo { color: var(--muted); }
.line.prompt-echo .p { color: var(--accent); }
.line.cmd { color: var(--cmd); }
.line.note { color: var(--muted); font-style: italic; }
.line.err { color: var(--error); }
.line.out { color: var(--fg); }

#shell-prompt-line {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    border-top: 1px solid var(--border);
    background: var(--panel);
    font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
    font-size: 13px;
}

#shell-prompt { color: var(--accent); font-weight: 600; flex-shrink: 0; }

#shell-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--fg);
    font: inherit;
}

#shell-input::placeholder { color: var(--muted); opacity: 0.7; }

@media (max-width: 780px) {
    #panes { grid-template-columns: 1fr; grid-template-rows: 3fr 2fr; }

    /* iOS zooms the page on focus of any input under 16px; keep it at 16px on touch-sized screens. */
    #shell-input { font-size: 16px; }

    #diagnostics { height: 28%; min-height: 70px; }
}

@media (max-width: 780px) and (orientation: landscape) {
    /* Short/landscape phones have width to spare but little height — stacking
       the panes would leave almost no room for either one, so keep them
       side by side instead. */
    #panes { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
}

@media (max-width: 560px) {
    #topbar { padding: 10px 14px; gap: 2px 10px; }
    #topbar .logo { font-size: 16px; }
    #topbar .tagline { font-size: 12px; flex-basis: 100%; }

    .pane-header { padding: 6px 10px; font-size: 11px; }

    #shell-output { padding: 10px; font-size: 13px; }

    #shell-prompt-line { padding: 8px 10px; }
}
