:root {
    --bg: #f5f5f7;
    --bg-elev: #ffffff;
    --bg-subtle: #fafafc;
    --ink: #1d1d1f;
    --ink-soft: #6e6e73;
    --ink-muted: #86868b;
    --line: rgba(0, 0, 0, 0.08);
    --line-strong: rgba(0, 0, 0, 0.12);
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --uranium: #5e5ce6;
    --product: #ff9f0a;
    --neutron: #30d158;
    --danger: #ff453a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.08), 0 8px 20px rgba(0, 0, 0, 0.04);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --radius-xl: 28px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(1200px 600px at 20% -10%, #eaf2ff 0%, transparent 60%),
                radial-gradient(900px 500px at 100% 10%, #f2e9ff 0%, transparent 55%),
                var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
    min-height: 100%;
}

.app {
    max-width: 1480px;
    margin: 0 auto;
    padding: clamp(12px, 2vw, 24px) clamp(16px, 3vw, 32px) 32px;
}

/* HERO */
.hero {
    text-align: center;
    padding: clamp(4px, 1vw, 10px) 0 clamp(16px, 2.5vw, 28px);
}

.eyebrow {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

.hero h1 {
    font-size: clamp(34px, 6vw, 64px);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.05;
    background: linear-gradient(180deg, #1d1d1f 0%, #3b3b40 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.subtitle {
    margin-top: 14px;
    font-size: clamp(15px, 2vw, 19px);
    color: var(--ink-soft);
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.5;
}

/* LAYOUT */
.layout {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr) 300px;
    gap: clamp(14px, 1.8vw, 22px);
    align-items: start;
}

@media (max-width: 1180px) {
    .layout {
        grid-template-columns: minmax(0, 1fr) 300px;
    }
    .panel-left {
        grid-column: 1 / -1;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .panel-left > .card {
        flex: 1 1 260px;
        min-width: 0;
    }
}

@media (max-width: 760px) {
    .layout {
        grid-template-columns: 1fr;
    }
    .panel-left,
    .panel-right {
        flex-direction: column;
    }
    .panel-left > .card {
        flex: none;
    }
}

/* CARDS */
.stage-card,
.card {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    backdrop-filter: saturate(140%) blur(20px);
}

.stage-card {
    padding: clamp(16px, 2vw, 22px);
    display: flex;
    flex-direction: column;
    /* Nu umple înălțimea rândului din grid — evită canvas-ul uriaș lângă panourile laterale */
    height: auto;
    min-height: 0;
    align-self: start;
    width: 100%;
}

.stage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 6px 16px;
    flex-wrap: wrap;
}

.stage-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stage-title h2 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--neutron);
    box-shadow: 0 0 0 4px rgba(48, 209, 88, 0.18);
    animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(48, 209, 88, 0.18); }
    50% { box-shadow: 0 0 0 8px rgba(48, 209, 88, 0.08); }
}

.stage-actions {
    display: flex;
    gap: 8px;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 980px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 113, 227, 0.3);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-ghost {
    background: rgba(0, 0, 0, 0.04);
    color: var(--ink);
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.07);
}

/* PRESETS */
.presets {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px 14px;
    flex-wrap: wrap;
}

.presets-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex-shrink: 0;
}

.preset-group {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 12px;
    flex-wrap: wrap;
}

.preset {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--ink-soft);
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.12s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: -0.01em;
}

.preset:hover {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.6);
}

.preset:active { transform: scale(0.97); }

.preset.active {
    background: #fff;
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.06);
}

.preset-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
    flex-shrink: 0;
}

@media (max-width: 520px) {
    .presets-label { display: none; }
    .preset-text { font-size: 12px; }
    .preset { padding: 6px 10px; }
}

/* CANVAS — înălțime limitată; nu mai „împinge” pagina în jos */
.canvas-wrap {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background:
        radial-gradient(ellipse at top, #ffffff, #f0f0f5 70%),
        #f2f2f7;
    border: 1px solid var(--line);
    flex: 0 0 auto;
    width: 100%;
    height: clamp(260px, 48vh, 480px);
}

@media (max-width: 760px) {
    .canvas-wrap {
        height: auto;
        max-height: min(70vh, 520px);
        aspect-ratio: 4 / 5;
        min-height: 240px;
    }
}

@media (max-width: 520px) {
    .canvas-wrap {
        max-height: min(65vh, 440px);
    }
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

.legend {
    position: absolute;
    left: 14px;
    bottom: 14px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    pointer-events: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--line);
    border-radius: 980px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.swatch.uranium { background: var(--uranium); }
.swatch.product { background: var(--product); }
.swatch.neutron { background: var(--neutron); }

/* PANEL */
.panel {
    display: flex;
    flex-direction: column;
    gap: clamp(14px, 2vw, 20px);
    position: sticky;
    top: 24px;
}

@media (max-width: 1180px) {
    .panel { position: static; }
}

.card {
    padding: 22px;
}

.card h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 14px;
}

/* CONTROLS */
.control {
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.control:first-of-type {
    border-top: none;
    padding-top: 4px;
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.control label {
    font-size: 15px;
    color: var(--ink);
    font-weight: 500;
}

.value {
    font-size: 13px;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
    background: rgba(0, 0, 0, 0.04);
    padding: 3px 8px;
    border-radius: 8px;
}

/* SLIDER */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent) var(--val, 50%), rgba(0,0,0,0.09) var(--val, 50%));
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    cursor: grab;
    transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.1); cursor: grabbing; }

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    cursor: grab;
}

/* TOGGLE */
.control.toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--line);
}

.switch {
    appearance: none;
    -webkit-appearance: none;
    width: 46px;
    height: 28px;
    background: rgba(120,120,128,0.2);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s ease;
    outline: none;
    flex-shrink: 0;
}

.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.switch:checked {
    background: #30d158;
}

.switch:checked::after {
    transform: translateX(18px);
}

/* STATS */
.stats .stat {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}

.stats .stat:first-of-type {
    border-top: none;
}

.stat-label {
    font-size: 14px;
    color: var(--ink-soft);
}

.stat-value {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.stat-value small {
    font-size: 12px;
    color: var(--ink-muted);
    font-weight: 500;
    margin-left: 4px;
}

/* INFO BUTTON (floating on canvas) */
.info-btn {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: var(--ink-soft);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
    z-index: 3;
}

.info-btn:hover {
    background: #fff;
    color: var(--accent);
}

.info-btn:active {
    transform: scale(0.94);
}

.info-btn[aria-expanded="true"] {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

/* INFO POPOVER */
.info-popover {
    position: absolute;
    top: 58px;
    left: 14px;
    width: min(340px, calc(100% - 28px));
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(160%) blur(24px);
    -webkit-backdrop-filter: saturate(160%) blur(24px);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 16px 18px 18px;
    z-index: 4;
    transform-origin: 20px -10px;
    animation: pop-in 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.info-popover[hidden] { display: none; }

@keyframes pop-in {
    from { opacity: 0; transform: scale(0.92) translateY(-6px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.info-popover::before {
    content: "";
    position: absolute;
    top: -6px;
    left: 16px;
    width: 12px;
    height: 12px;
    background: inherit;
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
    transform: rotate(45deg);
}

.info-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.info-popover-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    text-transform: none;
    letter-spacing: -0.01em;
    margin: 0;
}

.info-close {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    color: var(--ink-soft);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.info-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--ink);
}

.info-popover-body p {
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ink-soft);
}

.info-popover-body p + p {
    margin-top: 8px;
}

.info-popover-body .tip {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    color: var(--ink);
    font-weight: 500;
    font-size: 13px;
}

/* ACTIONS CARD */
.actions-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-block {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-block:active { transform: scale(0.98); }

.btn-inject {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 113, 227, 0.3);
}

.btn-inject:hover { background: var(--accent-hover); }

.btn-scram {
    background: linear-gradient(180deg, #ff5a4f, #ff3b30);
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.02em;
    box-shadow: 0 1px 2px rgba(255, 59, 48, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.btn-scram:hover {
    background: linear-gradient(180deg, #ff6a60, #ff453a);
}

/* TEMPERATURE BAR */
.temp-bar {
    height: 6px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.06);
    overflow: hidden;
    margin: 2px 0 4px;
}

.temp-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #30d158 0%, #ffd60a 55%, #ff9f0a 78%, #ff453a 100%);
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* K BLOCK */
.k-block {
    position: relative;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.k-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.k-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.k-info {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.06);
    color: var(--ink-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s ease, color 0.2s ease;
}

.k-info:hover {
    background: rgba(0, 0, 0, 0.12);
    color: var(--ink);
}

.k-value {
    font-size: 22px;
    font-variant-numeric: tabular-nums;
}

.k-gauge {
    position: relative;
    height: 10px;
    margin-bottom: 6px;
}

.k-segments {
    display: flex;
    height: 100%;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.06);
}

.k-seg {
    flex: 1;
    opacity: 0.75;
}

.k-sub   { background: linear-gradient(90deg, #64a9ff, #4a90e2); }
.k-crit  { background: linear-gradient(90deg, #30d158, #2fc44e); flex: 0.4; }
.k-super { background: linear-gradient(90deg, #ff9f0a, #ff453a); }

.k-marker {
    position: absolute;
    top: -3px;
    left: 0;
    width: 3px;
    height: 16px;
    border-radius: 2px;
    background: var(--ink);
    box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: left 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.k-legend {
    display: flex;
    justify-content: space-between;
    font-size: 10.5px;
    color: var(--ink-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-weight: 500;
    margin-top: 2px;
}

.k-status {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    background: rgba(0, 0, 0, 0.04);
    color: var(--ink-soft);
    transition: background 0.3s ease, color 0.3s ease;
}

.k-status.sub {
    background: rgba(74, 144, 226, 0.12);
    color: #1a6fd8;
}

.k-status.crit {
    background: rgba(48, 209, 88, 0.14);
    color: #1f8f3c;
}

.k-status.super {
    background: rgba(255, 69, 58, 0.12);
    color: #c0352a;
    animation: pulseSuper 1.2s ease-in-out infinite;
}

@keyframes pulseSuper {
    0%, 100% { background: rgba(255, 69, 58, 0.12); }
    50% { background: rgba(255, 69, 58, 0.22); }
}

/* K TOOLTIP */
.k-tooltip {
    position: absolute;
    top: 42px;
    left: 0;
    right: 0;
    padding: 14px 16px;
    background: rgba(30, 30, 34, 0.94);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #f5f5f7;
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 5;
    font-size: 12.5px;
    line-height: 1.5;
    animation: pop-in 0.18s cubic-bezier(0.32, 0.72, 0, 1);
}

.k-tooltip[hidden] { display: none; }

.k-tooltip::before {
    content: "";
    position: absolute;
    top: -5px;
    left: 66px;
    width: 10px;
    height: 10px;
    background: inherit;
    transform: rotate(45deg);
}

.k-tooltip p {
    margin: 0 0 6px;
    color: #f5f5f7;
}

.k-tooltip .formula {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 13px;
    margin: 8px 0 10px;
    color: #fff;
}

.k-tooltip .frac {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.2;
    margin-left: 4px;
}

.k-tooltip .frac .num {
    border-bottom: 1px solid rgba(255, 255, 255, 0.5);
    padding: 0 8px 2px;
    font-size: 11px;
}

.k-tooltip .frac .den {
    padding-top: 2px;
    font-size: 11px;
}

.k-tooltip ul {
    margin: 0;
    padding-left: 16px;
    color: rgba(245, 245, 247, 0.85);
}

.k-tooltip ul li {
    margin-bottom: 3px;
    font-size: 12px;
}

@media (max-width: 520px) {
    .stage-actions .btn span { display: none; }
    .btn { padding: 8px 12px; }
    .canvas-wrap { aspect-ratio: 4 / 5; }
}

@media (prefers-reduced-motion: reduce) {
    .dot { animation: none; }
    * { transition: none !important; }
}
