:root {
    --primary-hue: 210;
    --primary-color: hsl(var(--primary-hue), 80%, 60%);
    --bg-color: hsl(var(--primary-hue), 20%, 95%);
    --surface-color: hsla(0, 0%, 100%, 0.7);
    --glass-border: 1px solid hsla(0, 0%, 100%, 0.5);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    --text-color: hsl(var(--primary-hue), 20%, 20%);
    --text-muted: hsl(var(--primary-hue), 10%, 50%);
    --accent-color: hsl(160, 60%, 50%);
    --danger-color: hsl(340, 70%, 60%);
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;

    /* Energy Colors */
    --c-eth: #ff6b6b;
    /* Thermal - Red */
    --c-eph: #da77f2;
    /* Phase - Purple */
    --c-ket: #51cf66;
    /* KE trans - Green */
    --c-ker: #339af0;
    /* KE rot - Blue */
    --c-peg: #ff922b;
    /* PE grav - Orange */
    --c-pes: #ffd43b;
    /* PE elas - Yellow */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Energy Type Styles */
/* Sidebar Button Styling */
.energy-symbol.type-eth {
    background: var(--c-eth);
}

.energy-symbol.type-eph {
    background: var(--c-eph);
}

.energy-symbol.type-ket {
    background: var(--c-ket);
}

.energy-symbol.type-ker {
    background: var(--c-ker);
}

.energy-symbol.type-peg {
    background: var(--c-peg);
}

.energy-symbol.type-pes {
    background: var(--c-pes);
    color: #444;
}

/* Dark text for yellow */

/* Bubble Styling */
.energy-bubble.type-eth {
    background-color: #fff5f5;
    border-color: var(--c-eth);
}

.energy-bubble.type-eth .bubble-header {
    background: rgba(255, 107, 107, 0.1);
    border-bottom-color: var(--c-eth);
}

.energy-bubble.type-eph {
    background-color: #f8f0fc;
    border-color: var(--c-eph);
}

.energy-bubble.type-eph .bubble-header {
    background: rgba(218, 119, 242, 0.1);
    border-bottom-color: var(--c-eph);
}

.energy-bubble.type-ket {
    background-color: #ebfbee;
    border-color: var(--c-ket);
}

.energy-bubble.type-ket .bubble-header {
    background: rgba(81, 207, 102, 0.1);
    border-bottom-color: var(--c-ket);
}

.energy-bubble.type-ker {
    background-color: #e7f5ff;
    border-color: var(--c-ker);
}

.energy-bubble.type-ker .bubble-header {
    background: rgba(51, 154, 240, 0.1);
    border-bottom-color: var(--c-ker);
}

.energy-bubble.type-peg {
    background-color: #fff4e6;
    border-color: var(--c-peg);
}

.energy-bubble.type-peg .bubble-header {
    background: rgba(255, 146, 43, 0.1);
    border-bottom-color: var(--c-peg);
}

.energy-bubble.type-pes {
    background-color: #fff9db;
    border-color: var(--c-pes);
}

.energy-bubble.type-pes .bubble-header {
    background: rgba(255, 212, 59, 0.1);
    border-bottom-color: var(--c-pes);
}

body {
    font-family: 'Outfit', sans-serif;
    background: radial-gradient(circle at top left, #eef2f3, #8e9eab);
    background-attachment: fixed;
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: var(--surface-color);
    backdrop-filter: blur(10px);
    border-right: var(--glass-border);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 100;
    overflow-y: auto;
}

.energy-palette {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.energy-item {
    background: transparent;
    padding: 2px;
    border-radius: 50%;
    cursor: grab;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s;
}

.energy-item:hover {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.05);
}

.energy-symbol {
    background: var(--primary-color);
    color: white;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.65rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Toolkit */
.toolkit-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.25rem;
}

.var-btn,
.tool-btn {
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-sm);
    padding: 2px;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    font-size: 0.85rem;
    transition: all 0.2s;
    line-height: 1.2;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.var-btn:hover,
.tool-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.var-btn sub {
    vertical-align: bottom;
    position: relative;
    bottom: -0.2em;
    font-size: 0.7em;
}

/* Main Workspace */
.main-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1rem;
    overflow-y: auto;
}

/* Timeline */
.timeline-area {
    background: var(--surface-color);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
    box-shadow: var(--glass-shadow);
    flex-shrink: 0;
    width: 100%;
}

.timeline-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.header-text-row {
    display: flex;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    justify-content: space-between;
    align-items: center;
    padding: 0 5px;
    width: 100%;
}

.process-input-container {
    display: flex;
    justify-content: center;
    width: 150px;
    flex: none;
}

/* ContentEditable Styles */
.glass-textarea.single-line,
.process-input,
.indicator-input {
    height: 24px;
    min-height: 24px;
    padding: 2px 5px;
    font-size: 0.8rem;
    overflow: hidden;
    white-space: nowrap;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 4px;
    line-height: 18px;
    display: inline-block;
    cursor: text;
    vertical-align: middle;
}

.glass-textarea.single-line {
    width: 150px;
    text-align: left;
}

.process-input {
    width: 150px;
    text-align: center;
}

.indicator-input {
    width: 150px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

[contenteditable]:empty::before {
    content: attr(placeholder);
    color: var(--text-muted);
    opacity: 0.7;
    pointer-events: none;
    display: block;
}

.glass-textarea.single-line:hover,
.glass-textarea.single-line:focus,
.process-input:hover,
.process-input:focus,
.indicator-input:hover,
.indicator-input:focus {
    border-color: var(--primary-color);
    background: white;
    outline: none;
}

.header-arrow-row {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 20px;
    gap: 0.5rem;
}

.long-arrow {
    flex: 1;
    display: flex;
    align-items: center;
    height: 10px;
}

.arrow-shaft {
    flex: 1;
    height: 3px;
    background: var(--text-color);
    border-radius: 2px;
}

.arrow-point {
    width: 0;
    height: 0;
    border-left: 10px solid var(--text-color);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

.arrow-label {
    font-size: 1rem;
    font-weight: bold;
    font-style: italic;
    color: var(--text-color);
}

.indicators-container {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.indicator-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.indicator-controls {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.icon-btn.small {
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn.small.danger {
    color: var(--danger-color);
    border-color: #ffcdd2;
}

.icon-btn.small.danger:hover {
    background: var(--danger-color);
    color: white;
}

.icon-btn.small.primary {
    color: var(--primary-color);
    border-color: #bbdefb;
}

.icon-btn.small.primary:hover {
    background: var(--primary-color);
    color: white;
}

/* Canvas */
.canvas-area {
    flex: 1;
    background: var(--surface-color);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-lg);
    position: relative;
    box-shadow: var(--glass-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* System Boundary */
.system-boundary {
    width: 600px;
    height: 350px;
    border: 3px solid var(--text-color);
    border-radius: 50%;
    position: relative;
    padding: 2rem;
    transition: border-style 0.3s;
}

.system-boundary.closed {
    border-style: solid;
}

.system-boundary.open {
    border-style: dashed;
}

.system-label {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid transparent;
    border-radius: 4px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 600;
    min-width: 150px;
    max-width: 300px;
    padding: 2px 5px;
    cursor: text;
    z-index: 10;
}

.system-label:hover,
.system-label:focus {
    background: white;
    border-color: var(--primary-color);
    outline: none;
}

.boundary-content {
    height: 100%;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    align-content: center;
}

/* Equation Area */
.equation-area {
    background: var(--surface-color);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--glass-shadow);
}

.equation-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.equation-input {
    flex: 1;
    font-family: 'Times New Roman', serif;
    font-style: italic;
    font-size: 1.2rem;
    border: 1px solid transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    padding: 2px 5px;
    cursor: text;
    min-height: 28px;
}

.equation-input:focus {
    background: white;
    outline: none;
    border-bottom: 2px solid var(--primary-color);
}

/* Bubbles */
.energy-bubble {
    background: white;
    border: 1px solid var(--text-color);
    border-radius: 2rem;
    padding: 0.4rem 0.2rem;
    width: 130px;
    min-width: 130px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    position: relative;
    font-size: 0.7rem;
    align-items: center;
}

.bubble-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    border-bottom: 1px solid #eee;
    width: 95%;
}

.bubble-info {
    width: 20px;
    font-size: 0.6rem;
    text-align: center;
    border: 1px solid #ccc;
    height: 14px;
}

.bubble-body {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    width: 100%;
    align-items: center;
}

.variable-row {
    display: flex;
    align-items: center;
    gap: 1px;
    width: 100%;
    justify-content: center;
}

.var-name {
    width: 30px;
    font-weight: 600;
    font-size: 0.7rem;
    text-align: right;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: text;
    padding: 0 2px;
    white-space: nowrap;
    overflow: hidden;
}

.var-name:hover,
.var-name:focus {
    background: white;
    border-color: var(--primary-color);
    outline: none;
}

.var-value {
    width: 45px;
    height: 18px;
    font-size: 0.75rem;
    text-align: center;
    border: 1px solid #ccc;
}

.var-unit {
    width: 25px;
    height: 16px;
    font-size: 0.65rem;
    background: transparent;
    border: none;
}

.var-operator {
    min-width: 15px;
    text-align: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    padding: 0 2px;
    border-radius: 3px;
}

.var-operator:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* --- SYSTEM ARROW OVERHAUL --- */
.system-arrow {
    position: absolute;
    right: 70px;
    bottom: 25px;
    width: 40px;
    /* Q box size */
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.system-arrow.hidden {
    display: none;
}

.arrow-type-toggle {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    font-weight: 800;
    font-size: 1.4rem;
    color: var(--text-color);
    z-index: 10;
    position: relative;
    user-select: none;
    /* Shift label left and down to sit near arrow tail */
    /* Updated transform based on user request: Left 10px more from (-30px, 10px) */
    transform: translate(-40px, 10px);
}

#arrowShape {
    position: absolute;
    top: -20px;
    left: -100px;

    width: 80px;
    height: 20px;
    display: flex;
    align-items: center;

    transform: rotate(-135deg);
    transform-origin: center center;

    cursor: pointer;
    z-index: 5;
    transition: transform 0.3s cubic-bezier(0.4, 2.0, 0.4, 1.0);
}

#arrowShape.out {
    /* Flip 180deg to point Down-Right */
    transform: rotate(45deg);
}

.arrow-shaft {
    flex: 1;
    height: 3px;
    background: var(--text-color);
    border-radius: 2px;
}

.arrow-point {
    width: 0;
    min-width: 0;
    height: 0;
    border-left: 12px solid var(--text-color);
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
}

@media print {

    .sidebar,
    .add-indicator-btn,
    .icon-btn {
        display: none !important;
    }
}