/* Pseudocode styling */
/* Global Page Styling */
html,
body {
    height: 100%;
    margin: 0;
}

body {
    font-family: Arial, sans-serif;
    font-size: 14px;
    /* no global background here (only on index) */
}


body.with-bg {
    background-size: cover;
    background-position: center 1px;
}

/* Prevent page scroll on advanced page while letting panels scroll internally */
body.advanced {
    overflow: hidden;
}

/* Center full container */
#mainContainer {
    display: flex;
    justify-content: center;
}

.main-title {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    z-index: 1000;
    /* ensures it stays above panels */
}


#container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Remove duplicate background here (keeps body background only) */
    /*background: transparent;*/
    padding: 18px;
    padding-top: 70px;
    /* allow space for .main-title so panels don't overlap header */
    box-sizing: border-box;
    max-width: 1400px;
    margin: 0 auto;
    overflow: hidden;
}

/* Add .container shared by both pages (panels container) */
.container {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    max-width: 1200px;
}

/* ROW OF PANELS */
#panelRow {
    display: flex;
    justify-content: center;
    /* center panels horizontally */
    width: 100%;
    gap: 24px;
    /* slightly larger gap */
    align-items: stretch;
    /* equal height panels */
    max-width: 1400px;
}

/* Panel Styling - make all panels identical size and larger, but fit viewport */
.panel {
    background: white;
    padding: 18px;
    flex: 0 0 420px;
    /* fixed width to ensure same size */
    width: 420px;
    /* ensure fixed width */
    border-radius: 10px;
    box-shadow: 0px 8px 24px rgba(0, 0, 0, 0.25), 0px 4px 8px rgba(0, 0, 0, 0.2), 0px 2px 4px rgba(0, 0, 0, 0.15);
    height: 520px;
    /* fixed height so panels are identical across pages */
    max-height: calc(100vh - 120px);
    /* ensure panels fit inside viewport */
    margin: 0;
    /* remove top margin */
    box-sizing: border-box;
    overflow: auto;
    /* enable internal scrolling if content exceeds panel */
    position: relative;
    /* for absolute-positioned elements inside panel */
}

/* Ensure advanced page panels adopt the same default size as index */
body.advanced .panel,
#advancedSection .panel {
    width: 420px;
    flex: 0 0 420px;
    height: 520px;
    max-height: calc(100vh - 120px);
}

/* Make the internal container match the layout properties of #panelRow so panels sizes and alignment match */
#advancedSection .container {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    max-width: 1200px;
}

/* Back button positioned inside the panel at the top-right corner */
.go-back-btn {
    position: absolute;
    /* panel has position: relative; anchors this inside panel */
    top: 8px;
    /* inside the panel */
    right: 8px;
    /* inside the panel */
    padding: 6px 10px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    z-index: 10;
}

/* Keep responsiveness for small screens */
@media (max-width: 1000px) {
    .go-back-btn {
        top: 8px;
        right: 8px;
        font-size: 11px;
        padding: 5px 8px;
    }
}

/* Inputs */
.inputBox {
    width: 85%;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid #888;
}

/* Speed Slider Styling */
.speed-control-container {
    margin-top: 5px;
}

.range-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

.speed-label {
    font-size: 12px;
    color: #555;
    font-weight: bold;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: #d3d3d3;
    outline: none;
    opacity: 0.9;
    transition: opacity .2s;
}

.slider:hover {
    opacity: 1;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #0066ff;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #0066ff;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    border: none;
}

/* Buttons */
.button {
    padding: 6px 12px;
    margin-top: 8px;
    background: #0066ff;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s, opacity 0.15s;
}

/* Disabled appearance */
.button:disabled,
.button[disabled] {
    background: #c4c4c4;
    color: #666666;
    cursor: not-allowed;
    opacity: 0.95;
    box-shadow: none;
    pointer-events: none;
}

.resetBtn {
    background: #ff4d4d;
}

.button:hover {
    opacity: 0.95;
}

/* Coin Display */
.coin-box {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.coin {
    padding: 6px 6px;
    background: #ddd;
    border-radius: 6px;
    border: 1px solid #888;
    font-size: 14px;
}

.highlight {
    background: #4CAF50 !important;
    color: white;
}

/* Selected Coins */
#selectedCoins {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 10px;
    padding: 8px;
    border: 1px dashed #aaa;
    margin-top: 8px;
}

/* Remaining Amount */
#remainingAmount {
    font-size: 18px;
    text-align: center;
    margin-bottom: 12px;
}

/* Summary Table */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

table th,
table td {
    border: 1px solid #666;
    padding: 4px;
    font-size: 13px;
}

table th {
    background: #f2f2f2;
}

#pseudocodeBox {
    background: #ffffff;
    color: #000000;
    padding: 12px;
    border-radius: 10px;
    margin-top: 14px;

    border: 1px solid #000000;
    box-sizing: border-box;
    position: relative;
    /* required for absolutely positioned arrow */
    padding-left: 34px;
    /* make room for the arrow */
}

/* Arrow indicator that moves beside the active pseudocode line */
.pseudo-arrow {
    position: absolute;
    left: 10px;
    font-size: 16px;
    color: #0bc520;
    line-height: 1;
    /* faster transition so arrow keeps up with highlighting and coin selection */
    transition: top 80ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 80ms linear, transform 80ms cubic-bezier(0.2, 0.8, 0.2, 1);
    opacity: 0;
    transform: translateX(-6px);
    pointer-events: none;
    will-change: top, transform, opacity;
    /* hint for smoother animations */
    backface-visibility: hidden;
}

.pseudo-arrow.visible {
    opacity: 1;
    transform: translateX(0);
}

.code-line {
    display: block;
}

.line-text {
    display: inline-block;
    /* width follows the content (text length) */
    white-space: pre;
    /* preserve indentation */
    color: #111; /* default text color */
    font-weight: normal;
    border-radius: 4px;
    padding: 2px 4px;
    transition: color 180ms ease, font-weight 150ms;
}

/* Permanent highlight for lines that run once (1-4) */
.line-text.done {
    color: #ff3300; /* bright red-orange for strong contrast */
    font-weight: 800;
}

/* Active loop-line highlight (toggles between lines 5-8) */
.line-text.loop-active {
    color: #ff3300; /* bright red-orange to catch attention */
    font-weight: 800;
}

/* Dark mode: use violet highlight so it stands out on dark backgrounds */
@media (prefers-color-scheme: dark) {
    .line-text.done {
        color: #ff5533; /* bright orange-red for dark mode */
    }
    .line-text.loop-active {
        color: #ff5533; /* bright orange-red for dark mode */
    }
}

#pseudocode {
    font-size: 13.5px;
    line-height: 20px;
    white-space: pre-wrap;
    text-align: left;
}

/* legacy .highlight-line removed - using .code-line now */

/* New styles for advanced.html integration */

/* Headings */
h2 {
    text-align: center;
    margin: 0 0 12px 0;
    font-size: 20px;
}

/* Coin container (used on advanced page) */
.coin-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

/* Summary box reuse for both pages */
.summary-box {
    padding: 8px;
    background: #f1faff;
    border: 1px solid #77a;
    border-radius: 8px;
    margin-top: 8px;
}

/* Execution logs box */
.exec-logs-box {
    background: #0f1720;
    color: #e6eef8;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    padding: 8px;
    border-radius: 8px;
    height: 160px;
    overflow: auto;
    border: 1px solid rgba(255,255,255,0.06);
}
.exec-log-entry {
    padding: 6px 8px;
    margin-bottom: 6px;
    background: rgba(255,255,255,0.02);
    border-radius: 6px;
}
.exec-log-entry .log-time {
    color: #93c5fd;
    margin-right: 8px;
    font-weight: 600;
}

/* Visual classes for greedy/optimal coins */
.greedy-coin {
    background: #ffeeba;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #888;
    font-weight: bold;
    font-size: 14px;
}

.optimal-coin {
    background: #c8f7c5;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #888;
    font-weight: bold;
    font-size: 14px;
}

/* Reduce min-height for short viewports (keeps page from overflowing) */
@media (max-height: 900px) {
    .main-title {
        font-size: 22px;
    }

    #container {
        padding: 12px;
    }

    /* panels become flexible on short screens to avoid overflow */
    .panel {
        height: auto;
        max-height: calc(100vh - 80px);
    }

    .coin {
        padding: 5px 8px;
        font-size: 13px;
    }

    #remainingAmount {
        font-size: 16px;
    }
}

@media (max-width: 1000px) {
    #panelRow {
        flex-direction: column;
        gap: 16px;
        align-items: center;
    }

    .panel {
        flex: 0 0 90%;
        width: 90%;
        height: auto;
        margin-top: 0;
    }

    .inputBox {
        width: 100%;
    }
}

@media (min-width: 1400px) {
    #container {
        max-width: 1400px;
    }
}

.start-guide {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);

    background: #1f2933;
    color: #ffffff;

    padding: 14px 20px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;

    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    z-index: 9999;

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.start-guide.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(-8px);
}

/* Top navigation (Procedure / Posttest) centered within page width */
.top-nav {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 48px);
    max-width: 1400px;
    z-index: 1300;
    pointer-events: none; /* allow children to control interaction */
}
.top-nav-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto; /* enable clicks inside */
}
.nav-btn {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 700;
    box-shadow: 0 3px 8px rgba(0,0,0,0.10);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    min-width: 84px;
    text-align: center;
}
.nav-left { background: #0066ff; }
.nav-right { background: #10b981; }

/* Prevent overlap on narrow viewports: collapse to smaller buttons and keep inside padding */
@media (max-width: 760px) {
    .top-nav { width: calc(100% - 24px); top: 6px; }
    .nav-btn { padding: 5px 8px; font-size: 12px; min-width: 72px; }
}

@media (max-width: 420px) {
    .top-nav-inner { gap: 8px; }
    .nav-left, .nav-right { padding: 4px 6px; font-size: 11px; min-width: 64px; }
}
