:root {
    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e6eaf0;
    --border-strong: #d7dde7;
    --text: #0f172a;
    --muted: #64748b;
    --faint: #94a3b8;

    --primary: #2563eb;
    --primary-700: #1d4ed8;
    --primary-soft: #eff6ff;

    --standard: #3b82f6;
    --reefer: #10b981;
    --danger: #f97316;
    --empty: #eef2f7;

    --success: #16a34a;
    --success-soft: #dcfce7;
    --error: #dc2626;
    --error-soft: #fee2e2;
    --warn: #b45309;
    --warn-soft: #fef3c7;

    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-pill: 999px;

    --sh-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
    --sh-md: 0 6px 18px rgba(15, 23, 42, .08);
    --sh-lg: 0 18px 44px rgba(15, 23, 42, .16);

    --gap: 22px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: var(--sh-sm);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), #4f7cf6);
    color: #fff;
    border-radius: 11px;
    font-size: 1.1rem;
    box-shadow: var(--sh-sm);
}
.brand-text h1 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
.subtitle { margin: 1px 0 0; font-size: 0.78rem; color: var(--faint); }

.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.yard-summary { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.yard-figure { font-size: 1.05rem; font-weight: 700; }
.yard-figure strong { color: var(--primary); }
.yard-sep { color: var(--faint); margin: 0 3px; font-weight: 500; }
.yard-label { font-size: 0.68rem; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }

.live-indicator {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 5px 11px;
    border-radius: var(--r-pill);
    font-size: 0.78rem; font-weight: 600;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live-indicator[data-state="live"] { color: var(--success); background: var(--success-soft); border-color: transparent; }
.live-indicator[data-state="live"] .live-dot { background: var(--success); box-shadow: 0 0 0 0 rgba(22,163,74,.5); animation: live-pulse 1.8s infinite; }
.live-indicator[data-state="connecting"] .live-dot { background: var(--warn); }
.live-indicator[data-state="reconnect"] { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.live-indicator[data-state="reconnect"] .live-dot { background: var(--warn); }
@keyframes live-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(22,163,74,.5); }
    70%  { box-shadow: 0 0 0 6px rgba(22,163,74,0); }
    100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); }
}

/* ---------- Buttons ---------- */

.btn {
    padding: 8px 15px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background .12s ease, box-shadow .12s ease, transform .05s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; }
.btn-primary {
    background: var(--primary); color: #fff; border-color: var(--primary);
    box-shadow: 0 2px 6px rgba(37, 99, 235, .25);
}
.btn-primary:hover { background: var(--primary-700); border-color: var(--primary-700); }
.btn-block { width: 100%; margin-top: 14px; padding: 11px; font-size: 0.92rem; }
.btn:disabled, .btn.loading { opacity: .65; cursor: progress; }

.icon-btn {
    border: none; background: transparent; cursor: pointer;
    color: var(--faint); font-size: 0.95rem; line-height: 1;
    width: 28px; height: 28px; border-radius: 7px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Layout & cards ---------- */

.layout {
    display: grid;
    grid-template-columns: 184px minmax(0, 1fr) 340px;
    gap: var(--gap);
    padding: var(--gap);
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 18px;
    box-shadow: var(--sh-sm);
}
.card-title {
    margin: 0 0 12px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--faint);
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head .card-title { margin-bottom: 0; }

/* ---------- Bay nav ---------- */

.bay-nav { position: sticky; top: 86px; }
.bay-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bay-item {
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface);
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.bay-item:hover { background: var(--surface-2); color: var(--text); }
.bay-item.active {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-700);
    box-shadow: inset 3px 0 0 var(--primary);
}

/* ---------- Bays column ---------- */

.bays-column { display: flex; flex-direction: column; min-width: 0; gap: var(--gap); }

.legend {
    display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
    font-size: 0.82rem; color: var(--muted); padding: 12px 18px;
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.swatch {
    display: inline-grid; place-items: center;
    width: 20px; height: 20px; border-radius: 6px;
    color: #fff; font-size: 0.7rem;
}
.swatch.empty { background: var(--empty); border: 1px solid var(--border-strong); }
.swatch.standard { background: var(--standard); }
.swatch.reefer { background: var(--reefer); }
.swatch.danger { background: var(--danger); }
.swatch.reefer-danger {
    background: repeating-linear-gradient(45deg, var(--reefer) 0, var(--reefer) 6px, var(--danger) 6px, var(--danger) 12px);
}

.bays-container { display: flex; flex-direction: column; gap: var(--gap); }

.bay-section { padding: 20px; }
.bay-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.bay-title { margin: 0; font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em; }
.bay-occ {
    font-size: 0.74rem; font-weight: 700; color: var(--muted);
    background: var(--surface-2); border: 1px solid var(--border);
    padding: 3px 9px; border-radius: var(--r-pill);
}

.bay-wrapper { display: flex; align-items: stretch; }
.tier-axis { display: flex; flex-direction: column-reverse; gap: 6px; margin-right: 8px; }
.tier-axis .label, .row-axis .label { color: var(--faint); font-size: 0.72rem; font-weight: 600; text-align: center; }
.tier-axis .label { width: 30px; height: 58px; display: flex; align-items: center; justify-content: center; }
.bay-grid { flex: 1; display: grid; gap: 7px; }
.row-axis { display: grid; gap: 7px; margin: 8px 0 0 38px; }

/* ---------- Slots ---------- */

.slot {
    height: 58px;
    border-radius: 9px;
    background: var(--empty);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 1px;
    font-size: 0.78rem;
    color: #fff; font-weight: 600;
    border: 1px solid transparent;
    box-shadow: var(--sh-sm);
    transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
    cursor: default;
    position: relative;
}
.slot.empty {
    background: var(--surface-2);
    color: var(--faint);
    font-weight: 500;
    border: 1px dashed var(--border-strong);
    box-shadow: none;
}
.slot.standard { background: linear-gradient(160deg, #4f8bf7, var(--standard)); }
.slot.reefer   { background: linear-gradient(160deg, #2dd4a7, var(--reefer)); }
.slot.danger   { background: linear-gradient(160deg, #fb923c, var(--danger)); }
.slot.reefer-danger {
    background: repeating-linear-gradient(45deg, var(--reefer) 0, var(--reefer) 10px, var(--danger) 10px, var(--danger) 20px);
}
.slot-icon { font-size: 1.05rem; line-height: 1; }
.slot-weight { font-size: 0.72rem; opacity: .95; }

.slot.power-outlet::after {
    content: "⚡"; position: absolute; top: 3px; right: 5px;
    font-size: 0.62rem; opacity: .8;
}

.slot.clickable { cursor: pointer; }
.slot.clickable:hover { transform: translateY(-2px); box-shadow: var(--sh-md); filter: brightness(1.05); }

.slot.selected {
    outline: 3px solid var(--primary);
    outline-offset: 1px;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .18), var(--sh-md);
}

@keyframes flash-placed {
    0%   { box-shadow: 0 0 0 0 rgba(22, 163, 74, .85); }
    25%  { box-shadow: 0 0 0 12px rgba(22, 163, 74, .45); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}
.slot.just-placed { animation: flash-placed 2.0s ease-out 1; outline: 2px solid var(--success); outline-offset: -2px; }

@keyframes flash-removed {
    0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, .8); }
    25%  { box-shadow: 0 0 0 12px rgba(37, 99, 235, .4); }
    100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}
.slot.just-removed { animation: flash-removed 1.8s ease-out 1; outline: 2px dashed var(--primary); outline-offset: -2px; }

@keyframes pulse-error {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .8); }
    50%      { box-shadow: 0 0 0 7px rgba(220, 38, 38, 0); }
}
.slot.violation { animation: pulse-error 1.4s ease-in-out infinite; border: 2px solid var(--error); }

/* ---------- Skeleton / empty ---------- */

.bay-section:not(.is-loading) .bay-skeleton { display: none; }
.bay-section.is-loading .bay-wrapper,
.bay-section.is-loading .row-axis { display: none; }
.bay-skeleton { display: flex; flex-direction: column; gap: 8px; }
.sk-row { height: 58px; border-radius: 9px; background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%); background-size: 400% 100%; animation: shimmer 1.3s ease-in-out infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- Side panel ---------- */

.side-panel { display: flex; flex-direction: column; gap: var(--gap); position: sticky; top: 86px; }

.placeholder { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.5; }

.detail-hero { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.detail-icon {
    width: 46px; height: 46px; display: grid; place-items: center;
    border-radius: 12px; font-size: 1.3rem; color: #fff; background: var(--standard); flex-shrink: 0;
}
.detail-hero.reefer .detail-icon { background: var(--reefer); }
.detail-hero.danger .detail-icon { background: var(--danger); }
.detail-hero.reefer-danger .detail-icon { background: repeating-linear-gradient(45deg, var(--reefer) 0, var(--reefer) 6px, var(--danger) 6px, var(--danger) 12px); }
.detail-hero.empty .detail-icon { background: var(--faint); }
.detail-title { font-weight: 700; font-size: 1.0rem; }
.detail-sub { color: var(--muted); font-size: 0.85rem; margin-top: 1px; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.badge {
    font-size: 0.72rem; font-weight: 600; padding: 3px 9px; border-radius: var(--r-pill);
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge-reefer { background: var(--success-soft); color: #047857; border-color: transparent; }
.badge-danger { background: #ffedd5; color: #c2410c; border-color: transparent; }
.badge-power { background: var(--primary-soft); color: var(--primary-700); border-color: transparent; }

.detail-list { margin: 0; display: flex; flex-direction: column; gap: 0; }
.detail-list > div {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 8px 0; border-bottom: 1px solid var(--border);
    font-size: 0.86rem;
}
.detail-list > div:last-child { border-bottom: none; }
.detail-list dt { color: var(--muted); margin: 0; }
.detail-list dd { margin: 0; text-align: right; font-weight: 600; }
.detail-list dd.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-weight: 500; color: var(--muted); }

.rehandle {
    margin-top: 14px; padding: 10px 12px; border-radius: var(--r-sm);
    font-size: 0.84rem; font-weight: 600;
}
.rehandle.ok { background: var(--success-soft); color: #047857; }
.rehandle.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- KPI ---------- */

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--r-md); padding: 14px 12px; text-align: center;
}
.kpi-value { display: block; font-size: 1.6rem; font-weight: 800; color: var(--primary); line-height: 1; }
.kpi-label { display: block; margin-top: 5px; font-size: 0.72rem; color: var(--muted); }

/* ---------- Validation list ---------- */

.error-list { list-style: none; padding: 0; margin: 0; max-height: 42vh; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; }
.error-list li {
    padding: 9px 11px; border-left: 3px solid var(--error);
    background: var(--error-soft); border-radius: var(--r-sm);
    font-size: 0.82rem; line-height: 1.4;
}
.error-list li strong { color: #991b1b; }
.error-list li.muted { border-left-color: var(--border-strong); background: var(--surface-2); color: var(--muted); }

/* ---------- Tooltip ---------- */

.tooltip {
    position: fixed; pointer-events: none; z-index: 50;
    background: rgba(15, 23, 42, .96); color: #fff;
    padding: 8px 11px; border-radius: 8px; font-size: 0.8rem; line-height: 1.35;
    box-shadow: var(--sh-md); max-width: 260px;
}
.tooltip strong { color: #fff; }
.tip-sub { color: #cbd5e1; font-size: 0.72rem; margin-top: 2px; }
.tooltip.hidden { display: none; }

/* ---------- Toasts ---------- */

.toast-container {
    position: fixed; top: 76px; right: 22px; z-index: 60;
    display: flex; flex-direction: column; gap: 10px; max-width: 340px;
}
.toast {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-left: 4px solid var(--faint);
    border-radius: var(--r-md); padding: 11px 14px;
    box-shadow: var(--sh-lg); font-size: 0.86rem; font-weight: 500;
    opacity: 0; transform: translateX(16px); transition: opacity .22s ease, transform .22s ease;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-icon {
    width: 20px; height: 20px; flex-shrink: 0; border-radius: 50%;
    display: grid; place-items: center; color: #fff; font-size: 0.72rem; font-weight: 700;
    background: var(--faint);
}
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { background: var(--success); }
.toast-error { border-left-color: var(--error); }
.toast-error .toast-icon { background: var(--error); }
.toast-info .toast-icon { background: var(--primary); }

/* ---------- Hafen-Tycoon Dashboard ---------- */

.tycoon-bar {
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 14px 24px;
    margin: 16px 24px 0;
    border-radius: var(--r-lg);
    background: linear-gradient(135deg, #0f172a, #1e293b);
    color: #e2e8f0;
    box-shadow: var(--sh-md);
    flex-wrap: wrap;
}
.tycoon-bar[data-status="running"] { background: linear-gradient(135deg, #0b3b2e, #0f766e); }
.tycoon-bar[data-status="over"]    { background: linear-gradient(135deg, #3b0d0d, #7f1d1d); }

.tycoon-title { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.tycoon-emoji { font-size: 1.7rem; }
.tycoon-title h2 { margin: 0; font-size: 1.1rem; letter-spacing: -0.01em; }
.tycoon-hint { margin: 2px 0 0; font-size: 0.78rem; color: #94a3b8; }
.tycoon-bar[data-status="running"] .tycoon-hint,
.tycoon-bar[data-status="over"] .tycoon-hint { color: rgba(255,255,255,.7); }

.tycoon-clock {
    font-size: 2.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    min-width: 110px;
    text-align: center;
    color: #fff;
}
/* Ruhige Uhr — nur in den letzten 10 Sekunden pulsiert sie (Endspurt). */
.tycoon-clock.urgent { color: #fca5a5; animation: clock-pulse 1s ease-in-out infinite; }
@keyframes clock-pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.tycoon-kpis { display: flex; gap: 18px; }
.tycoon-kpi { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.tk-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: #94a3b8; }
.tycoon-bar[data-status="running"] .tk-label,
.tycoon-bar[data-status="over"] .tk-label { color: rgba(255,255,255,.65); }
.tk-value { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tycoon-kpi.balance .tk-value { color: #fff; }
.tycoon-kpi.income .tk-value { color: #34d399; }
.tycoon-kpi.loss .tk-value { color: #f87171; }

.tycoon-start { white-space: nowrap; }

/* ---------- Truck card + placeable slots ---------- */

.truck-card { border: 1px solid var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.truck-waiting {
    font-size: 0.72rem; font-weight: 700; color: var(--primary-700);
    background: var(--primary-soft); padding: 3px 9px; border-radius: var(--r-pill);
}
.truck-instruction { margin: 14px 0 0; font-size: 0.84rem; color: var(--muted); line-height: 1.45; }
.truck-instruction strong { color: var(--warn); }

.slot.placeable {
    cursor: pointer;
    border: 1px dashed var(--primary);
    background: var(--primary-soft);
    color: var(--primary-700);
}
.slot.placeable:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .25), var(--sh-md);
    background: #dbeafe;
}

/* ---------- Game-over modal ---------- */

.modal-overlay {
    position: fixed; inset: 0; z-index: 80;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(2px);
    display: grid; place-items: center;
    padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    padding: 28px;
    width: 100%; max-width: 380px;
    text-align: center;
    animation: modal-in .22s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal h2 { margin: 0 0 4px; font-size: 1.4rem; }
.modal-sub { margin: 0 0 18px; color: var(--muted); font-size: 0.88rem; }
.balance-sheet { margin: 0 0 6px; display: flex; flex-direction: column; }
.balance-sheet > div {
    display: flex; justify-content: space-between;
    padding: 9px 0; border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.balance-sheet dt { color: var(--muted); margin: 0; }
.balance-sheet dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.balance-sheet .pos { color: var(--success); }
.balance-sheet .neg { color: var(--error); }
.balance-sheet .total { border-bottom: none; margin-top: 4px; }
.balance-sheet .total dt { color: var(--text); font-weight: 700; }
.balance-sheet .total dd { font-size: 1.25rem; font-weight: 800; }
.modal-close-link {
    margin-top: 10px; background: none; border: none; cursor: pointer;
    color: var(--muted); font-size: 0.82rem; text-decoration: underline;
}

/* ---------- Tycoon Juice (Popups, Combo, Rush, Countdown, Confetti) ---------- */

.tycoon-bar { position: relative; }
.tycoon-clock-wrap { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 110px; }

.tycoon-combo {
    font-size: 0.7rem; font-weight: 800; letter-spacing: 0.04em; color: #fff;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    padding: 2px 10px; border-radius: var(--r-pill);
    animation: combo-pop .3s ease-out;
}
@keyframes combo-pop { 0% { transform: scale(.5); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

.tk-rate { color: #34d399; font-weight: 700; font-size: 0.62rem; }

.tk-value.flash-up   { animation: kpi-up .65s ease-out; }
.tk-value.flash-down { animation: kpi-down .65s ease-out; }
@keyframes kpi-up   { 0% { transform: scale(1.2); text-shadow: 0 0 12px rgba(52,211,153,.9); } 100% { transform: scale(1); } }
@keyframes kpi-down { 0% { transform: scale(1.2); text-shadow: 0 0 12px rgba(248,113,113,.9); } 100% { transform: scale(1); } }

.rush-banner {
    position: absolute; top: -11px; left: 50%; transform: translateX(-50%);
    background: linear-gradient(135deg, #ef4444, #f59e0b);
    color: #fff; font-weight: 800; font-size: 0.78rem; letter-spacing: 0.08em;
    padding: 4px 16px; border-radius: var(--r-pill); box-shadow: var(--sh-md);
    animation: rush-flash 1s ease-in-out infinite;
}
@keyframes rush-flash { 0%,100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.07); } }

.popup-layer { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
.popup {
    position: fixed; transform: translate(-50%, -50%);
    font-weight: 800; font-size: 1.0rem; white-space: nowrap;
    text-shadow: 0 1px 4px rgba(0,0,0,.35);
    animation: popup-float 1.1s ease-out forwards;
}
.popup-gain    { color: #16a34a; }
.popup-penalty { color: #dc2626; font-size: 1.15rem; }
.popup-crane   { color: #ea580c; }
@keyframes popup-float {
    0%   { opacity: 0; transform: translate(-50%, -40%) scale(.8); }
    15%  { opacity: 1; transform: translate(-50%, -65%) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

.countdown-overlay {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(15, 23, 42, .72); backdrop-filter: blur(3px);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.countdown-overlay.hidden { display: none; }
.countdown-num { font-size: 8rem; font-weight: 900; color: #fff; line-height: 1; text-shadow: 0 12px 44px rgba(37, 99, 235, .5); }
.countdown-num.pop { animation: count-pop .68s ease-out; }
@keyframes count-pop { 0% { transform: scale(.3); opacity: 0; } 40% { transform: scale(1.18); opacity: 1; } 100% { transform: scale(1); opacity: .92; } }
.countdown-goal { color: #cbd5e1; font-size: 0.95rem; max-width: 440px; text-align: center; line-height: 1.5; }

.modal { position: relative; overflow: hidden; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece {
    position: absolute; top: -14px; width: 9px; height: 14px; border-radius: 2px;
    animation: confetti-fall 2.6s ease-in forwards;
}
@keyframes confetti-fall {
    0%   { transform: translateY(-20px) rotate(0); opacity: 1; }
    100% { transform: translateY(440px) rotate(560deg); opacity: 0; }
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
    .layout { grid-template-columns: 1fr; }
    .bay-nav, .side-panel { position: static; }
    .bay-list { flex-direction: row; flex-wrap: wrap; }
    .bay-item { flex: 1 1 auto; text-align: center; box-shadow: none; }
    .bay-item.active { box-shadow: none; }
}
@media (max-width: 560px) {
    .topbar { flex-wrap: wrap; }
    .yard-label { display: none; }
}

/* ============================================================
   HAFEN-PUZZLE  (body.puzzle) — gemütlicher Dusk-Hafen.
   Eigene, abgekapselte Welt; berührt das Leitstand-UI nicht.
   ============================================================ */

body.puzzle {
    --pz-ink: #2a1f3d;
    --pz-cream: #fff3e0;
    --pz-mint: #6ef0b8;
    --pz-gold: #ffcf6b;
    --pz-socket: rgba(20, 14, 34, .26);

    font-family: "Nunito", system-ui, sans-serif;
    color: var(--pz-cream);
    /* Dämmerungs-Himmel: Indigo oben → warmer Horizont → Wasserband unten. */
    background:
        radial-gradient(120% 70% at 78% 8%, rgba(255, 203, 128, .30), transparent 55%),
        linear-gradient(180deg, #241a4d 0%, #3b2c6b 34%, #6b3f7e 56%,
                                 #c05f76 76%, #ef9a6b 90%, #1d6f74 90%, #18606b 100%);
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
}

.pz-app {
    position: relative;
    z-index: 1;
    width: min(100vw, 460px);
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: max(14px, env(safe-area-inset-top)) 18px max(16px, env(safe-area-inset-bottom));
}

/* ---- Himmel-Deko ---- */
.pz-sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.pz-sun {
    position: absolute; top: 7%; right: 14%; width: 92px; height: 92px; border-radius: 50%;
    background: radial-gradient(circle at 50% 50%, #fff1cf, #ffcf6b 60%, rgba(255, 180, 90, 0) 72%);
    box-shadow: 0 0 70px 30px rgba(255, 193, 110, .35);
    animation: pz-bob 9s ease-in-out infinite;
}
.pz-cloud { position: absolute; height: 26px; border-radius: var(--r-pill); background: rgba(255, 240, 225, .16); filter: blur(6px); }
.pz-cloud-1 { width: 150px; top: 20%; left: -60px; animation: pz-drift 38s linear infinite; }
.pz-cloud-2 { width: 110px; top: 31%; left: -80px; animation: pz-drift 52s linear infinite 6s; }
.pz-gull { position: absolute; color: rgba(255, 243, 224, .55); font-size: 13px; }
.pz-gull-1 { top: 14%; left: 22%; animation: pz-bob 7s ease-in-out infinite; }
.pz-gull-2 { top: 17%; left: 30%; animation: pz-bob 6s ease-in-out infinite .6s; }
@keyframes pz-drift { to { transform: translateX(620px); } }
@keyframes pz-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

/* ---- HUD ---- */
.pz-hud { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.pz-score { display: flex; flex-direction: column; line-height: .95; }
.pz-score-num {
    font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 44px; color: #fff;
    text-shadow: 0 2px 0 rgba(0, 0, 0, .18), 0 0 24px rgba(255, 207, 107, .35);
}
.pz-score-num.pz-pop-num { animation: pz-num .42s ease; }
@keyframes pz-num { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }
.pz-score-label {
    font-size: 11px; letter-spacing: .18em; text-transform: uppercase;
    color: rgba(255, 243, 224, .6); font-weight: 800; margin-top: 2px; padding-left: 3px;
}
.pz-combo {
    margin-left: 6px; font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 15px;
    background: linear-gradient(180deg, #ffd97a, #ff9e57); color: #5a2a12;
    padding: 7px 13px; border-radius: var(--r-pill);
    box-shadow: 0 6px 16px rgba(255, 140, 70, .4), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.pz-combo.pz-bump { animation: pz-bump .4s ease; }
@keyframes pz-bump { 0% { transform: scale(1) rotate(0); } 40% { transform: scale(1.22) rotate(-3deg); } 100% { transform: scale(1); } }
.pz-icon-btn {
    margin-left: auto; width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
    background: rgba(255, 243, 224, .14); color: #fff3e0; font-size: 22px; line-height: 1;
    backdrop-filter: blur(6px); transition: transform .2s, background .15s;
}
.pz-icon-btn:hover { background: rgba(255, 243, 224, .24); }
.pz-icon-btn:active { transform: rotate(-180deg) scale(.92); }

/* ---- Board ---- */
.pz-stage { flex: 1; display: flex; align-items: center; justify-content: center; }
.pz-board-frame {
    position: relative; width: 100%; padding: 16px 16px 22px; border-radius: 26px;
    background: linear-gradient(180deg, rgba(35, 24, 64, .5), rgba(20, 14, 38, .62));
    box-shadow: 0 24px 60px rgba(10, 6, 26, .5), inset 0 1px 0 rgba(255, 255, 255, .08);
    backdrop-filter: blur(3px); border: 1px solid rgba(255, 255, 255, .07);
}
.pz-dock {
    position: absolute; left: 10px; right: 10px; bottom: 8px; height: 7px; border-radius: var(--r-pill);
    background: repeating-linear-gradient(90deg, rgba(255, 207, 107, .5) 0 14px, rgba(255, 207, 107, .12) 14px 22px);
    opacity: .5;
}
.pz-board { display: grid; grid-template-columns: repeat(var(--pz-cols, 6), 1fr); gap: 7px; }

.pz-cell {
    aspect-ratio: 1 / 1; border-radius: 13px; position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; user-select: none;
}
.pz-cell.pz-locked {
    background: var(--pz-socket);
    box-shadow: inset 0 3px 7px rgba(0, 0, 0, .32), inset 0 -1px 0 rgba(255, 255, 255, .05);
}
.pz-cell.pz-legal {
    cursor: pointer; background: rgba(110, 240, 184, .14);
    border: 2px dashed rgba(110, 240, 184, .7); animation: pz-glow 1.8s ease-in-out infinite;
}
.pz-cell.pz-legal::after { content: "+"; font-family: "Fredoka", sans-serif; font-weight: 600; color: rgba(110, 240, 184, .9); font-size: 22px; }
.pz-cell.pz-legal:active { transform: scale(.93); }
@keyframes pz-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(110, 240, 184, 0); border-color: rgba(110, 240, 184, .45); }
    50%      { box-shadow: 0 0 16px 2px rgba(110, 240, 184, .45); border-color: rgba(110, 240, 184, .95); }
}

.pz-cell.pz-filled {
    color: #3a230f; border-radius: 12px;
    box-shadow: 0 5px 0 rgba(0, 0, 0, .22), inset 0 2px 0 rgba(255, 255, 255, .55), inset 0 -6px 10px rgba(0, 0, 0, .16);
}
.pz-cell.pz-filled .pz-w { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: clamp(15px, 5vw, 22px); line-height: 1; }
.pz-cell.pz-filled .pz-w small { font-size: .55em; font-weight: 600; opacity: .8; }
.pz-cell.pz-filled .pz-type { font-size: 9px; font-weight: 800; letter-spacing: .06em; opacity: .62; margin-top: 2px; }
.w-light {background: linear-gradient(180deg, #76e0cf, #34b3a0); color: #0c3b34; }
.w-mid   { background: linear-gradient(180deg, #ffe09c, #f4bf69);  }
.w-heavy { background: linear-gradient(180deg, #ff9f7a, #ec5a4d); color: #fff; }
.w-heavy .pz-type { opacity: .8; }

.pz-cell.pz-just { animation: pz-drop .42s cubic-bezier(.3, 1.5, .5, 1); z-index: 2; }
@keyframes pz-drop {
    0%   { transform: translateY(-260%) scaleY(1.12); }
    70%  { transform: translateY(0) scaleY(.86); }
    100% { transform: translateY(0) scaleY(1); }
}
.pz-board.pz-intro .pz-cell { animation: pz-in .5s both; animation-delay: calc(var(--i) * 22ms); }
@keyframes pz-in { from { opacity: 0; transform: translateY(10px) scale(.8); } to { opacity: 1; transform: none; } }

/* ---- Tor / Truck ---- */
.pz-gate { margin-top: 8px; }
.pz-gate-rail { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; padding: 0 4px; }
.pz-gate-tag { font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: rgba(255, 243, 224, .55); }
.pz-hint {
    font-size: 13px; font-weight: 700; color: #0c3b34; background: var(--pz-mint);
    padding: 4px 11px; border-radius: var(--r-pill); box-shadow: 0 4px 12px rgba(110, 240, 184, .4);
    animation: pz-bob 2.4s ease-in-out infinite;
}
.pz-hint.pz-hide { display: none; }
.pz-truck {
    position: relative; display: flex; align-items: center; justify-content: center; padding: 14px 18px 20px;
    border-radius: 18px 18px 10px 10px; border: 1px solid rgba(255, 255, 255, .06);
    background: linear-gradient(180deg, rgba(20, 14, 38, .55), rgba(20, 14, 38, .78));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07);
}
.pz-pending {
    min-width: 116px; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 14px 22px; border-radius: 12px; color: #3a230f;
    box-shadow: 0 6px 0 rgba(0, 0, 0, .22), inset 0 2px 0 rgba(255, 255, 255, .55), inset 0 -7px 12px rgba(0, 0, 0, .16);
}
.pz-pending .pz-w { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 30px; line-height: 1; }
.pz-pending .pz-w small { font-size: .5em; font-weight: 600; opacity: .8; }
.pz-pending .pz-type { font-size: 11px; font-weight: 800; letter-spacing: .04em; opacity: .66; }
.pz-pending.pz-arrive { animation: pz-arrive .42s cubic-bezier(.3, 1.3, .5, 1); }
@keyframes pz-arrive { from { transform: translateX(40px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.pz-wheel { position: absolute; bottom: -7px; width: 18px; height: 18px; border-radius: 50%; background: #1a1326; border: 3px solid #3a2f50; }
.pz-truck .pz-wheel:first-of-type { left: 28%; }
.pz-truck .pz-wheel:last-of-type { right: 28%; }

/* ---- Punkte-Popups ---- */
.pz-popups { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.pz-pop {
    position: fixed; transform: translate(-50%, -50%); white-space: nowrap;
    font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 26px; color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, .4);
    display: flex; flex-direction: column; align-items: center; line-height: 1;
    animation: pz-pop 1s ease-out forwards;
}
.pz-pop small { font-size: .5em; font-weight: 800; color: var(--pz-gold); letter-spacing: .04em; margin-top: 3px; }
@keyframes pz-pop {
    0%   { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
    25%  { opacity: 1; transform: translate(-50%, -60%) scale(1.05); }
    100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}
.pz-pop-bad { color: #ff8a78; }
.pz-pop-bad small { color: #ffd1c7; }

/* ---- Game over ---- */
.pz-over {
    position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 26px;
    background: radial-gradient(120% 90% at 50% 20%, rgba(40, 24, 70, .55), rgba(12, 8, 26, .82));
    backdrop-filter: blur(8px); animation: pz-fade .3s ease;
}
.pz-over[hidden] { display: none; }
@keyframes pz-fade { from { opacity: 0; } to { opacity: 1; } }
.pz-over-card {
    width: min(100%, 340px); text-align: center; color: var(--pz-ink);
    background: linear-gradient(180deg, #fff6e8, #ffe9cf); border-radius: 26px; padding: 30px 26px 26px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, .5), inset 0 2px 0 rgba(255, 255, 255, .7);
    animation: pz-rise .42s cubic-bezier(.3, 1.3, .5, 1);
}
@keyframes pz-rise { from { opacity: 0; transform: translateY(26px) scale(.94); } to { opacity: 1; transform: none; } }
.pz-over-badge { font-size: 46px; }
.pz-over-title { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 30px; margin: 4px 0; color: #3a2150; }
.pz-over-sub { font-size: 14px; color: #6a567e; margin: 0 0 18px; font-weight: 600; }
.pz-over-stats { display: flex; gap: 14px; margin-bottom: 20px; }
.pz-stat { flex: 1; background: rgba(58, 33, 80, .07); border-radius: 16px; padding: 12px 8px; }
.pz-stat b { display: block; font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 28px; color: #c0476a; }
.pz-stat span { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: #8a7799; }
.pz-btn {
    width: 100%; border: none; cursor: pointer; color: #fff;
    font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 19px; padding: 15px; border-radius: 16px;
    background: linear-gradient(180deg, #ff9e57, #f56a4a);
    box-shadow: 0 8px 0 #c84a30, 0 12px 22px rgba(245, 106, 74, .5); transition: transform .1s, box-shadow .1s;
}
.pz-btn:active { transform: translateY(5px); box-shadow: 0 3px 0 #c84a30, 0 6px 14px rgba(245, 106, 74, .5); }

/* ---- Reefer & Stromplätze (Phase 2) ---- */
.pz-cell.pz-power::before {
    content: "⚡"; position: absolute; top: 3px; right: 5px; font-size: 11px; line-height: 1;
    opacity: .55; color: #bfe0ff; pointer-events: none;
}
.pz-cell.pz-locked.pz-power { background: rgba(110, 170, 255, .16); }
.pz-cell.pz-legal.pz-power { border-color: rgba(150, 220, 255, .9); }

.pz-cell.pz-is-reefer {
    box-shadow: 0 5px 0 rgba(0, 0, 0, .22), inset 0 0 0 3px rgba(125, 222, 255, .85),
                inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -6px 10px rgba(0, 0, 0, .16);
}
.pz-snow { position: absolute; top: 2px; left: 5px; font-size: 11px; line-height: 1; color: #eafaff; text-shadow: 0 1px 2px rgba(0, 80, 120, .5); }

.pz-pending .pz-sub { font-size: 11px; font-weight: 800; letter-spacing: .04em; color: rgba(58, 35, 15, .6); min-height: 14px; }
.pz-pending.pz-is-reefer {
    box-shadow: 0 6px 0 rgba(0, 0, 0, .22), inset 0 0 0 3px rgba(125, 222, 255, .9),
                inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -7px 12px rgba(0, 0, 0, .16);
}
.pz-chip-reefer {
    display: inline-block; background: linear-gradient(180deg, #d3f4ff, #8fd9f5); color: #06506e;
    padding: 2px 9px; border-radius: var(--r-pill); font-weight: 800; font-size: 11px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6);
}
.pz-cell.pz-is-danger {
    box-shadow: 0 5px 0 rgba(0, 0, 0, .22), inset 0 0 0 3px rgba(245, 179, 1, .9),
                inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -6px 10px rgba(0, 0, 0, .16);
}
.pz-haz { position: absolute; top: 2px; left: 5px; font-size: 11px; line-height: 1; color: #ffe08a; text-shadow: 0 1px 2px rgba(90, 50, 0, .6); }
.pz-pending.pz-is-danger {
    box-shadow: 0 6px 0 rgba(0, 0, 0, .22), inset 0 0 0 3px rgba(245, 179, 1, .95),
                inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -7px 12px rgba(0, 0, 0, .16);
}
.pz-chip-danger {
    display: inline-block; background: linear-gradient(180deg, #ffd96b, #f5a623); color: #5a3000;
    padding: 2px 9px; border-radius: var(--r-pill); font-weight: 800; font-size: 11px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
}
.pz-hint.pz-rule {
    background: linear-gradient(180deg, #d3f4ff, #8fd9f5); color: #06506e;
    animation: pz-rulepop .4s cubic-bezier(.3, 1.4, .5, 1);
}
.pz-hint.pz-rule-danger { background: linear-gradient(180deg, #ffd96b, #f5a623); color: #5a3000; }
@keyframes pz-rulepop { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
    body.puzzle * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
