@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&display=swap');

/* Base */
body {
    background-color: #f4f4f4;
    font-family: 'IBM Plex Mono', monospace !important;
}

select, option, select:focus, option:hover {
    font-family: 'IBM Plex Mono', monospace;
}

#root {
    margin: 0 auto;
    padding: 0 1rem;
    width: 90%;
    height: 100vh;
}

/* Left workspace + Right execution panel */
#blocklyDiv,
.execution-panel {
    height: 100%;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px 20px;
}
.navbar .logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.navbar .logo img {
    height: 40px;
}

.navbar .logo h1 {
    font-size: 1em;
    font-weight: 600;
}

/* Columns */
.editor-panel {
    flex: 3;
}

.execution-panel {
    flex: 1;
    padding: 0 10px;
    background: #f4f4f4;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 350px;
    min-height: 0; /* allow inner flex children to shrink & scroll */
}

/* Buttons & inputs */
.program-dropdown {
    padding: 5px;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;
}

.run-button {
    border: 1px solid #dadce0;
    border-radius: 4px;
    box-sizing: border-box;
    color: #1a73e8;
    cursor: pointer;
    display: inline-block;
    font: 500 14px / 36px var(--font-family);
    padding: 0 12px;
    padding-top: 2px;
    width: 82px;
    height: 32px;
    font-weight: 450;
    font-size: 1em;
}

.run-button:hover {
    background: #e8f0fe;
    border: 1px solid #d2e3fc;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Give specific buttons sensible minimums */
#loadXmlButton {
    min-width: 145px;
}

#showShortcuts {
    min-width: 140px;
    min-height: 30px;
}

/* A11y helpers */
.visually-hidden,
.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Header row (Run + Program controls) */
.exec-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    flex: 0 0 auto; /* header uses intrinsic size */
}

/* keep Run at left; controls area on the right (or next row) */
.exec-header .program-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0; /* allow shrinking */
}

/* Responsive: put program controls on full-width next row for narrower screens */
@media (max-width: 1600px) {
    .exec-header .program-controls {
        order: 1;
        flex: 1 0 100%;
        width: 100%;
        margin-left: 0;
        gap: 10px;
        min-width: 0;
    }

    .program-controls .program-dropdown {
        flex: 0 1 auto;
        min-width: 220px;
    }

    .program-controls .run-button {
        margin-left: auto;
        flex: 0 0 auto;
        width: 150px;
    }
}

@media (max-width: 420px) {
    .exec-header .program-controls {
        flex-wrap: wrap;
    }

    .program-controls .program-dropdown,
    .program-controls .run-button {
        flex: 1 0 100%;
        width: 100%;
        margin-left: 0;
    }
}

/* Output container */
.output-container {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    border: 1px solid #ccc;
    background: #fff;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #eee;
    padding: 8px 10px;
    background: #fafafa;
}

.output-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.output-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 0;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.95em;
    line-height: 1.5;
}

.output-content:focus {
    outline: none;
}

.output-line {
    display: flex;
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f0;
}

.output-line:nth-child(odd) .output-line-content {
    background: #f9f9f9;
}

.output-line:nth-child(even) .output-line-content {
    background: #ffffff;
}

.output-line-number {
    flex: 0 0 28px;
    text-align: right;
    padding-right: 6px;
    padding-left: 6px;
    color: #666;
    background: #e8e8e8;
    user-select: none;
    border-right: 1px solid #ddd;
}

.output-line-content {
    flex: 1;
    padding-left: 15px;
    padding-right: 10px;
    color: #333;
    white-space: pre-wrap;
    word-break: break-word;
}

.output-line-focused {
    outline: 2px solid #1a73e8;
    outline-offset: -2px;
    background: #e3f2fd !important;
}

.output-line-focused .output-line-content {
    background: #e3f2fd !important;
}

/* Code container (scrollable content) */
.code-container {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    border: 1px solid #ccc;
    background: #fff;
    margin-top: 0;
    box-sizing: border-box;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #eee;
    padding: 8px 10px;
    background: #fafafa;
}

.code-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.program-dropdown--sm {
    font-size: 0.9rem;
    padding: 3px 6px;
}

/* the <pre> that shows code is the scroller */
.code-container > pre {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    border: none;
    font-size: 1em;
    font-family: 'IBM Plex Mono';
    padding: 10px;
}

pre.prettyprint {
    padding: 5px 10px !important;
}

/* Instruction Section */
.instruction {
    margin-top: 12px;
    border: 1px solid #d9d9d9;
    background: #fff;
    padding: 10px 12px;

    /* sizing & layout */
    flex: 0 1 50%;
    max-height: var(--instruction-max-height);
    overflow: hidden;

    display: flex;
    flex-direction: column;
}

.instruction[hidden] {
    display: none !important;
}

/* Sticky header */
#instructionHeader {
    margin: 0 0 6px 0;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
    padding-top: 2px;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
}

.instruction-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-start; /* no space-between */
}

.instruction-header-row > .instruction-title + * {
    margin-left: auto;
}

.instruction-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.instruction-pager {
    font-size: 0.9rem;
    color: #555;
    white-space: nowrap;
    text-align: center;
}

.instruction-nav {
    inline-size: 2rem;
    block-size: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fafafa;
    color: #333;
    cursor: pointer;
    user-select: none;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.instruction-nav:hover:not(:disabled) {
    background: #f3f3f3;
    border-color: #d2d2d2;
}

.instruction-nav:active:not(:disabled) {
    background: #ededed;
    border-color: #c8c8c8;
}

.instruction-nav:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.instruction-nav:focus-visible {
    outline: 2px solid #4c9ffe;
    outline-offset: 2px;
}

/* Scrollable body */
.instruction-body,
#instructionBody {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding-top: 0;
}

#instructionBody .scenario-title,
#instructionBody .scenario-goal {
    margin-top: 0;
    margin-bottom: 6px;
}


#instructionBody kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.85em;
    padding: 0.1em 0.35em;
    border: 1px solid #ccc;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #f9f9f9;
    color: #333;
    white-space: nowrap;
}

/* Responsive tweaks */
@media (max-width: 520px) {
    .instruction-header-row {
        gap: 6px;
    }

    .instruction-nav {
        inline-size: 1.8rem;
        block-size: 1.8rem;
    }

    .instruction-pager {
        font-size: 0.85rem;
    }
}


/* keyboard hints fills remaining height and scrolls */
.keyboard-hints {
    margin-top: 5px;
    border: 1px solid #e3e3e3;
    background: #fff;
    padding: 10px 12px;
    flex: 1 1 0; /* fill leftover height */
    min-height: 0; /* allow internal scroll */
    overflow-y: auto;
}

.kbd-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 6px 0;
    /* keep header visible while list scrolls */
    position: sticky;
    top: -10px;
    background: #fff;
    z-index: 1;
    border-bottom: 1px solid #eee;
}

.kbd-head h4 {
    margin: 0 0 6px 0;
}

.kbd-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 16px;
    margin: 0;
}

.kbd-list dt {
    font-weight: 600;
}

.kbd-list dt kbd {
    border: 1px solid #cfcfcf;
    padding: 1px 6px;
    border-radius: 3px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.88rem;
    background: #f7f7f7;
}

.kbd-list dd {
    margin-inline-start: 0;
}

pre code {
    white-space: pre;
}

/* Key Overlay (bottom-left) */
.key-overlay {
    position: fixed;
    left: 120px;
    bottom: 60px;
    z-index: 9999;
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 220ms ease, transform 220ms ease;
    pointer-events: none;
}

.key-overlay.is-visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.key-overlay__bubble {
    background: rgba(34, 37, 42, 0.92);
    color: #fdfdfd;
    padding: 12px 12px;
    border-radius: 20px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.35);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    max-width: 60vw;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.6;
}

.key-overlay__list {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    line-height: 1.4;
}

/* Visual key token */
.key-overlay__kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 1.25em;
    font-weight: 700;
    padding: 12px 20px;
    border-radius: 12px;
    background: linear-gradient(145deg, rgba(0, 123, 255, 0.35), rgba(0, 92, 200, 0.35));
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    white-space: nowrap;
    box-shadow:
            0 0 8px rgba(0, 140, 255, 0.35),
            inset 0 1px 2px rgba(255,255,255,0.15);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.key-overlay__kbd:hover {
    transform: scale(1.08);
    box-shadow:
            0 0 12px rgba(0, 160, 255, 0.5),
            inset 0 1px 3px rgba(255,255,255,0.2);
}


.key-overlay__plus {
    font-size: 1.5em;
    font-weight: 700;
    opacity: 0.85;
    user-select: none;
    color: #e0e0e0;
}


@media (prefers-reduced-motion: reduce) {
    .key-overlay {
        transition: none;
    }
}


@media (prefers-color-scheme: light) {
    .key-overlay__bubble {
        background: rgba(250, 251, 253, 0.96);
        color: #222;
        border: 1px solid rgba(0, 0, 0, 0.15);
    }

    .key-overlay__kbd {
        background: linear-gradient(145deg, rgba(0, 132, 255, 0.3), rgba(0, 102, 220, 0.3));
        color: #222;
        border: 1px solid rgba(0,0,0,0.2);
        box-shadow: 0 0 8px rgba(0, 150, 255, 0.35);
    }

    .key-overlay__plus {
        color: #333;
    }
}

/* Red + blinking for any highlighted connection path */
.blocklyHighlightedConnectionPath {
    stroke: #FF4D2E !important;
    animation: blockly-conn-blink 1.5s steps(1) infinite;
}

@keyframes blockly-conn-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}
