/* ==========================================================================
   GALYM Arduino IDE — desktop-only theme aligned with main site (style.css).
   Uses the same green palette, light/dark tokens, and fonts as index.html
   (Golos Text + Manrope). Requires Web Serial + a real editor, so on
   touch-primary devices the whole app is swapped for a "use a computer"
   message instead of trying (and failing) to be usable on a phone.
   ========================================================================== */

/* ── Theme tokens (match style.css) ─────────────────────────────────────── */
:root {
    /* Light (default) — same as main site */
    --bg:        #ffffff;
    --bg-elev:   #f5f5f5;
    --bg-elev-2: #ededed;
    --accent:    #2D6A4F;
    --accent-hi: #1F4D38;
    --accent-soft: rgba(45, 106, 79, 0.12);
    --text:      #1B3A2F;
    --muted:     rgba(27, 58, 47, 0.65);
    --border:    rgba(45, 106, 79, 0.15);
    --glow:      rgba(45, 106, 79, 0.12);

    --success: #2ecc71;
    --error:   #e74c3c;
    --warn:    #e67e22;

    /* Fonts — same stack as index.html / style.css */
    --font-ui:   "Golos Text", "Inter", system-ui, sans-serif;
    --font-display: "Manrope", "Playfair Display", "Golos Text", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

    color-scheme: light;
}

/* Dark mode — same tokens as [data-theme="dark"] in style.css */
[data-theme="dark"] {
    --bg:        #0F1A15;
    --bg-elev:   #16231C;
    --bg-elev-2: #1C2C23;
    --accent:    #4CAF7D;
    --accent-hi: #79C99E;
    --accent-soft: rgba(76, 175, 125, 0.18);
    --text:      #EAF3EE;
    --muted:     rgba(234, 243, 238, 0.55);
    --border:    rgba(255, 255, 255, 0.08);
    --glow:      rgba(76, 175, 125, 0.22);

    --success: #34d399;
    --error:   #ff6b93;
    --warn:    #ffb454;

    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }

body.ide-page {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
}

/* ---------------------------------------------------------------------- */
/* Device gate — blocks touch-primary devices (phones/tablets), not just  */
/* narrow windows. Capability gate via (hover: none) and (pointer: coarse). */
/* IMPORTANT: robot_izbasar pre-check must use the same media features.   */
/* ---------------------------------------------------------------------- */
.mobile-block {
    display: none;
    height: 100dvh;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 1.5rem;
    gap: 0.9rem;
}
.mobile-block svg { color: var(--accent); margin-bottom: 0.4rem; }
.mobile-block h1 {
    font-family: var(--font-display);
    font-size: 1.15rem;
    margin: 0;
    font-weight: 800;
}
.mobile-block p {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    max-width: 32ch;
    line-height: 1.5;
}
.mobile-block-sub { color: var(--text) !important; font-weight: 600; }

.ide-shell { display: flex; }
.browser-warning:not([hidden]) { display: block; }

/* ---------------------------------------------------------------------- */
/* Auth gate — shown instead of the IDE shell when the visitor isn't      */
/* logged in. Same URL, no redirect. Toggled by app.js (checkSession())   */
/* via body.auth-blocked, after asking /api/session.                     */
/* ---------------------------------------------------------------------- */
.auth-block {
    display: none;
    height: 100dvh;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 1.5rem;
    gap: 0.9rem;
}
.auth-block svg { color: var(--accent); margin-bottom: 0.4rem; }
.auth-block h1 {
    font-family: var(--font-display);
    font-size: 1.15rem;
    margin: 0;
    font-weight: 800;
}
.auth-block p {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    max-width: 34ch;
    line-height: 1.5;
}
.auth-block-btn { margin-top: 0.4rem; text-decoration: none; }

body.auth-blocked .auth-block { display: flex; }
body.auth-blocked .ide-shell,
body.auth-blocked .browser-warning { display: none !important; }

/* While the initial /api/session check is in flight, show nothing rather
   than flashing the editor (or the login screen) for a frame. */
body.auth-checking .ide-shell,
body.auth-checking .auth-block,
body.auth-checking .browser-warning { display: none !important; }

@media (hover: none) and (pointer: coarse) {
    .mobile-block { display: flex; }
    .ide-shell { display: none !important; }
    .browser-warning { display: none !important; }
}

/* ---------------------------------------------------------------------- */
/* Browser support banner (Firefox/Safari lack Web Serial)                */
/* ---------------------------------------------------------------------- */
.browser-warning {
    background: rgba(230, 126, 34, 0.1);
    color: var(--warn);
    border-bottom: 1px solid rgba(230, 126, 34, 0.3);
    font-size: 0.8rem;
    padding: 0.55rem 1.2rem;
    text-align: center;
    font-family: var(--font-ui);
}

/* ---------------------------------------------------------------------- */
/* Shell                                                                   */
/* ---------------------------------------------------------------------- */
.ide-shell {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

.ide-topbar {
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 1vw, 1rem);
    padding: 0.65rem clamp(0.8rem, 2vw, 1.4rem);
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
}

.ide-brand {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: -0.01em;
}
.ide-brand span { color: var(--accent); }

.board-tag {
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid rgba(45, 106, 79, 0.25);
    border-radius: 999px;
    padding: 0.3rem 0.7rem;
    font-size: 0.74rem;
    font-weight: 700;
    font-family: var(--font-ui);
    white-space: nowrap;
}
[data-theme="dark"] .board-tag {
    border-color: rgba(76, 175, 125, 0.35);
    color: var(--accent-hi);
}

.ide-toolbar-actions { display: flex; gap: 0.5rem; margin-left: 0.5rem; }

/* Push status pill to the far right */
.status-pill { margin-left: auto; }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */
.ide-btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-elev-2);
    color: var(--text);
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.82rem;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.08s ease, opacity 0.15s ease, border-color 0.15s;
    white-space: nowrap;
}
.ide-btn:hover:not(:disabled) {
    background: var(--glow);
    border-color: var(--accent);
}
.ide-btn:active:not(:disabled) { transform: translateY(1px); }
.ide-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.ide-btn.ghost { background: transparent; }
.ide-btn.small { padding: 0.4rem 0.7rem; font-size: 0.74rem; border-radius: 6px; }

.ide-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.ide-btn.primary:hover:not(:disabled) {
    background: var(--accent-hi);
    border-color: var(--accent-hi);
}

.ide-btn.accent {
    background: transparent;
    border-color: var(--success);
    color: var(--success);
}
.ide-btn.accent:hover:not(:disabled) {
    background: rgba(46, 204, 113, 0.12);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-ui);
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    white-space: nowrap;
    color: var(--muted);
}
.status-pill i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}
.status-pill.online {
    color: var(--success);
    border-color: rgba(46, 204, 113, 0.35);
    background: rgba(46, 204, 113, 0.08);
}
.status-pill.online i { animation: pulse-dot 1.6s ease-in-out infinite; }
.status-pill.busy {
    color: var(--accent);
    border-color: rgba(45, 106, 79, 0.35);
    background: var(--accent-soft);
}
[data-theme="dark"] .status-pill.busy {
    color: var(--accent-hi);
    border-color: rgba(76, 175, 125, 0.4);
}
.status-pill.error {
    color: var(--error);
    border-color: rgba(231, 76, 60, 0.4);
    background: rgba(231, 76, 60, 0.08);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.5); }
    50%      { opacity: 0.6; box-shadow: 0 0 0 4px rgba(46, 204, 113, 0); }
}

/* ---------------------------------------------------------------------- */
/* Body: editor + monitor, side by side (desktop)                         */
/* ---------------------------------------------------------------------- */
.ide-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 6px var(--monitor-width, clamp(300px, 26vw, 460px));
}

.pane-splitter {
    background: var(--border);
    cursor: col-resize;
    position: relative;
}
.pane-splitter::after {
    content: "";
    position: absolute;
    inset: 0 -3px;
}
.pane-splitter:hover,
.pane-splitter:active {
    background: var(--accent);
}

.pane { display: flex; min-height: 0; min-width: 0; }
.pane-code { flex-direction: column; }
.editor-pane { flex: 1; min-height: 0; }

.pane-monitor {
    flex-direction: column;
    background: var(--bg-elev);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 24px -12px rgba(0, 0, 0, 0.12);
}
[data-theme="dark"] .pane-monitor {
    box-shadow: -8px 0 24px -12px rgba(0, 0, 0, 0.45);
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-ui);
    background: var(--bg-elev-2);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.pane-controls { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.pane-controls select {
    font-size: 0.72rem;
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-elev-2);
    color: var(--text);
    font-family: var(--font-ui);
}
.autoscroll {
    font-size: 0.68rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-family: var(--font-ui);
}

.monitor-output {
    flex: 1;
    margin: 0;
    padding: 0.7rem;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
    background: var(--bg);
}

/* ---------------------------------------------------------------------- */
/* Collapsible build log                                                  */
/* ---------------------------------------------------------------------- */
.ide-logbar {
    border-top: 1px solid var(--border);
    background: var(--bg-elev);
    max-height: clamp(120px, 16vh, 220px);
    overflow-y: auto;
    box-shadow: 0 -8px 24px -12px rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .ide-logbar {
    background: #0a120e;
    box-shadow: 0 -8px 24px -12px rgba(0, 0, 0, 0.5);
}
.ide-logbar summary {
    padding: 0.4rem 0.9rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    font-family: var(--font-ui);
}
.ide-logbar pre {
    margin: 0;
    padding: 0 1rem 0.7rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.55;
    white-space: pre-wrap;
    color: var(--muted);
}
.ide-logbar pre .err { color: var(--error); }
.ide-logbar pre .ok  { color: var(--success); }

/* ---------------------------------------------------------------------- */
/* Narrower desktop windows                                               */
/* ---------------------------------------------------------------------- */
@media (max-width: 1100px) {
    .ide-btn { padding: 0.45rem 0.7rem; font-size: 0.78rem; }
    .ide-brand { display: none; }
}

@media (max-width: 640px) {
    .ide-body {
        grid-template-columns: 1fr !important;
        grid-template-rows: 1fr 6px minmax(180px, 34vh);
    }
    .pane-splitter { cursor: row-resize; }
    .pane-monitor {
        border-left: none;
        border-top: 1px solid var(--border);
        box-shadow: 0 -8px 24px -12px rgba(0, 0, 0, 0.12);
    }
}

@media (min-width: 1700px) {
    .ide-body {
        grid-template-columns: minmax(0, 1400px) 6px var(--monitor-width, 460px);
        justify-content: center;
    }
}