/* PHET PREMIUM PENDULUM CSS */

:root {
    --phet-primary: #3b9eff;
    --phet-secondary: #fdd835;
    --phet-panel-bg: #f8f9fa;
    --phet-box-border: #999;
    --phet-blue-header: #2c7ac4;
    --phet-red-header: #d32f2f;
    --ke-color: #fdd835;
    --pe-color: #4caf50;
    --th-color: #f44336;
    --total-color: #2196f3;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body.phet-theme {
    font-family: 'Outfit', sans-serif;
    user-select: none;
    background: #000;
    color: var(--phet-text);
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
    height: 100vh;
}

#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    background: #fff;
}

#sim-app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* TOP MINI TABS */
.sim-tabs {
    display: flex;
    justify-content: center;
    background: #000;
    gap: 2px;
    height: 40px;
}

.nav-tab {
    padding: 8px 30px;
    background: #2b2b2b;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    font-size: 14px;
    border-top: 3px solid transparent;
}

.nav-tab.active {
    background: #fff;
    color: #000;
    border-top-color: var(--phet-primary);
}

.nav-tab:hover:not(.active) {
    background: #555;
}

/* MAIN CONTAINER */
.sim-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: #fff;
}

/* CANVAS & PANELS */
.canvas-panel {
    background: radial-gradient(circle at 50% 50%, #fff 0%, #e8f4fd 100%);
    position: relative;
    border-bottom: 2px solid #ccc;
    flex: 1;
    overflow: hidden;
}

#pendulum-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* TOOL OVERLAYS (Draggable) */
#tool-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.tool-widget {
    position: absolute;
    pointer-events: auto;
    background: #444;
    color: #a8d5a8;
    border: 3px solid #666;
    border-radius: 10px;
    cursor: move;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

/* Realistic Meter Stick (Vertical) */
#ruler {
    width: 44px;
    height: 250px;
    /* 1 meter at SCALE=250px/m */
    background: #fbc02d;
    border: 2px solid #b7950b;
    border-radius: 4px;
    padding: 0;
    overflow: visible;
    box-shadow: 4px 4px 15px rgba(0, 0, 0, 0.4);
}

.ruler-body {
    width: 100%;
    height: 100%;
    position: relative;
    background: linear-gradient(to right, #fbc02d 0%, #f9a825 100%);
}

.ruler-marks-container {
    width: 100%;
    height: 100%;
    position: relative;
    /* Ticks on RIGHT edge */
    background-image:
        repeating-linear-gradient(0deg, #333 0, #333 1px, transparent 1px, transparent 2.5px),
        repeating-linear-gradient(0deg, #000 0, #000 2px, transparent 2px, transparent 25px);
    background-size: 14px 2.5px, 24px 25px;
    background-repeat: no-repeat;
    background-position: top right;
}

.rmark {
    position: absolute;
    right: 28px;
    font-size: 10px;
    font-weight: bold;
    color: #4e342e;
    transform: translateY(-50%);
}

.ruler-label {
    position: absolute;
    bottom: 5px;
    left: 4px;
    font-size: 10px;
    font-weight: bold;
    color: #4e342e;
    opacity: 0.8;
}

.ruler-edge.top {
    border-top: 1px solid rgba(255, 255, 255, 0.4);
    height: 2px;
}

.ruler-edge.bottom {
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
}

/* Stopwatch */
#stopwatch {
    width: 120px;
    padding: 5px;
    background: #666;
    border-radius: 12px;
    top: 100px;
    left: 500px;
    cursor: move;
}

.stopwatch-screen {
    background: #2e3b2e;
    color: #a8d5a8;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 18px;
    text-align: center;
    padding: 8px 0;
    border-radius: 6px;
    border: 2px solid #555;
    margin-bottom: 5px;
}

.stopwatch-btns {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.sw-btn {
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    cursor: pointer;
    color: white;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.sw-btn.start {
    background: #4caf50;
}

.sw-btn.reset {
    background: #fbc02d;
    color: #333;
}

/* PhET Energy Bar Chart Panel */
.phet-energy-panel {
    width: 200px;
    background: #e6e6e6;
    border: 2px solid #999;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.2);
    top: 50px;
    left: 20px;
}

.panel-header-mini {
    padding: 6px 10px;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #ccc;
    color: #333;
}

.collapse-icon {
    background: #ff7043;
    color: white;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    font-size: 12px;
}

.energy-chart-inner {
    flex: 1;
    background: #fff;
    margin: 10px;
    border: 1px solid #bbb;
    border-radius: 8px;
    position: relative;
    padding: 10px;
    display: flex;
}

.axis-y {
    width: 2px;
    height: 90%;
    background: #444;
    position: relative;
    margin-right: 5px;
}

.axis-y::after {
    content: '';
    position: absolute;
    top: -5px;
    left: -4px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 8px solid #444;
}

.bars-container {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 180px;
    padding-bottom: 40px;
}

.bar-col {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    position: relative;
}

.bar-fill {
    width: 100%;
    transition: height 0.05s linear;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.bar-fill.ke {
    background: #fdd835;
}

.bar-fill.pe {
    background: #4caf50;
}

.bar-fill.th {
    background: #f44336;
}

.bar-fill.total {
    background: #2196f3;
}

.bar-tag {
    position: absolute;
    bottom: -35px;
    transform: rotate(-90deg);
    transform-origin: center;
    font-size: 11px;
    font-weight: bold;
    white-space: nowrap;
    width: 60px;
    text-align: center;
}

.bar-tag sub {
    font-size: 8px;
    vertical-align: sub;
}

.th-reset-btn {
    position: absolute;
    bottom: -62px;
    background: #fff;
    border: 1px solid #999;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    padding: 0;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    z-index: 10;
}

.th-reset-btn:hover {
    background: #eee;
    color: #333;
}

.panel-footer-mini {
    height: 40px;
    padding: 6px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #e6e6e6;
    border-top: 1px solid #ccc;
    border-radius: 0 0 12px 12px;
}

/* Energy Legend Overlay */
#energy-legend {
    position: absolute;
    background: white;
    border: 3px solid #ccc;
    padding: 24px;
    border-radius: 24px;
    z-index: 1500;
    width: 300px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    font-family: 'Outfit', sans-serif;
}

.legend-header {
    font-size: 28px;
    text-align: center;
    margin-bottom: 24px;
    font-weight: 500;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 18px;
    font-size: 18px;
    gap: 20px;
}

.legend-symbol {
    font-weight: bold;
    width: 50px;
    text-align: right;
}

.legend-symbol.ke {
    color: #fdd835;
}

.legend-symbol.pe {
    color: #4caf50;
}

.legend-symbol.th {
    color: #f44336;
}

.legend-symbol.total {
    color: #2196f3;
}

.legend-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: #d32f2f;
    color: white;
    border: none;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
}

.footer-btn {
    border: 1px solid #aaa;
    background: #fff;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.zoom-btns {
    display: flex;
    gap: 4px;
}

/* Period Timer */
#period-timer {
    background: #004d40;
    padding: 8px 12px;
    min-width: 120px;
    border-radius: 4px;
    top: 200px;
    left: 450px;
    color: white;
    text-align: center;
    cursor: move;
}

#period-timer .pt-screen {
    background: #00332a;
    padding: 5px;
    border-radius: 4px;
    box-shadow: inset 0 0 5px #000;
    font-weight: bold;
    font-family: monospace;
    font-size: 16px;
    margin: 4px 0;
}

.pt-label {
    font-size: 10px;
    opacity: 0.8;
}

.pt-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 2px 6px;
    border-radius: 2px;
    cursor: pointer;
}

/* Sidebar Energy Chart (Intro/Lab) */
.energy-section {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 5px;
}

.energy-chart {
    height: 120px;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #fff;
    padding: 5px 10px 25px;
    position: relative;
    border-bottom: 2px solid #555;
    margin-top: 5px;
}

.energy-chart .bar-col {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
}

.energy-chart .bar-fill {
    width: 100%;
    transition: height 0.05s linear;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.energy-chart .bar-label {
    position: absolute;
    bottom: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    font-weight: 700;
    white-space: nowrap;
    color: #444;
}

.control-panel {
    width: 270px;
    background: #e6e6e6;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    box-shadow: inset 1px 0 3px rgba(0, 0, 0, 0.1);
    border-left: 1px solid #ddd;
    overflow-y: auto;
}

/* Phet Style Boxes */
.panel-section.phet-box {
    background: #fdfdfd;
    border: 1px solid var(--phet-box-border);
    border-radius: 6px;
    padding: 8px;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}

.section-header {
    font-weight: 700;
    font-size: 13px;
    padding: 2px 2px 6px;
    margin-bottom: 8px;
    border-bottom: 1px solid #ddd;
    text-align: center;
}

.section-header.phet-blue {
    color: var(--phet-blue-header);
}

.section-header.phet-red {
    color: var(--phet-red-header);
}

.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
}

/* Sliders with buttons */
.slider-with-btns {
    display: flex;
    align-items: center;
    gap: 6px;
}

.slider-with-btns input[type="range"] {
    flex: 1;
    cursor: pointer;
    accent-color: var(--phet-primary);
}

.adj-btn {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid #999;
    background: #fff;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.adj-btn:active {
    background: #eee;
    transform: translateY(1px);
}

.val-display {
    text-align: center;
    font-weight: 700;
    padding: 2px 0;
    color: #444;
}

.phet-select {
    width: 100%;
    padding: 3px;
    border-radius: 4px;
    border: 1px solid #999;
    font-family: inherit;
}

/* Energy section */
.energy-section {
    background: #fff !important;
}

.energy-chart {
    display: flex;
    height: 110px;
    gap: 6px;
    padding: 10px 4px;
    align-items: flex-end;
}

.bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
}

.bar-fill {
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 3px 3px 0 0;
    min-height: 0;
    transition: height 0.1s;
}

.bar-fill.ke {
    background: var(--ke-color);
}

.bar-fill.pe {
    background: var(--pe-color);
}

.bar-fill.th {
    background: var(--th-color);
}

.bar-fill.total {
    background: var(--total-color);
    opacity: 0.8;
    height: 100%;
}

.bar-label {
    font-size: 9px;
    font-weight: bold;
    margin-top: 4px;
}

/* Options box */
.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
}

.divider {
    height: 1px;
    background: #ddd;
    margin: 8px 0;
}

/* Buttons */
.compare-btn {
    background: #ffa726;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 2px solid #fb8c00;
    font-size: 16px;
    padding: 12px;
    font-weight: 700;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

.compare-btn:hover {
    background: #fb8c00;
}

/* BOTTOM PANEL */
.playback-bar {
    height: 90px;
    background: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid #bbb;
}

.playback-btns {
    display: flex;
    align-items: center;
    gap: 30px;
}

.playback-main {
    display: flex;
    align-items: center;
    gap: 15px;
}

.control-btn {
    background: #fff;
    border: none;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    color: #444;
    transition: transform 0.1s, box-shadow 0.1s;
}

.control-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
}

.control-btn.play {
    width: 68px;
    height: 68px;
    color: var(--phet-primary);
    border: 4px solid var(--phet-primary);
    font-size: 24px;
}

.control-btn.reset {
    color: #f44336;
    font-size: 22px;
}

.speed-toggle {
    color: #fff;
    font-size: 13px;
    font-weight: 500;
}

/* PHET BUTTONS */
.phet-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

.phet-btn.secondary {
    background: #fde4a5;
    color: #856404;
    border: 1px solid #ffeeba;
}

.phet-btn.secondary:hover {
    background: #f9d85d;
}

/* FLOATING Graph Panel */
.floating-panel {
    position: absolute;
    bottom: 90px;
    left: 20px;
    width: 300px;
    height: 200px;
    background: #fff;
    border: 1px solid #aaa;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

.panel-header {
    background: #eee;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 8px 8px 0 0;
}

#graph-canvas {
    flex: 1;
    background: #fff;
    border-radius: 0 0 8px 8px;
}

.close-panel {
    background: none;
    border: none;
    cursor: pointer;
    color: #888;
}