/**
 * Lift Logic game styles.
 *
 * Design tokens only (no hard-coded colors/spacing). Mobile-first; two-column
 * sim + editor on wide viewports, stacked on mobile. Dark-theme safe because
 * every color resolves through main.css custom properties.
 */

/* ===== Custom properties (app-local) ===== */
:root {
    --ll-container-max: 1080px;
    --ll-canvas-height: 480px;
    --ll-transition: var(--transition-fast);
    --ll-primary: var(--color-primary);
    --ll-primary-soft: color-mix(in srgb, var(--color-primary) 14%, var(--color-bg-card));
    --ll-accent-b: var(--color-primary-light);
    --ll-accent-b-soft: color-mix(in srgb, var(--color-primary-light) 16%, var(--color-bg-card));
    --ll-ok: var(--color-success);
    --ll-ok-soft: color-mix(in srgb, var(--color-success) 18%, var(--color-bg-card));
    --ll-warn: var(--color-warning);
    --ll-err: var(--color-error);
    --ll-err-soft: color-mix(in srgb, var(--color-error) 14%, var(--color-bg-card));
    --ll-border: var(--color-border);
    --ll-border-dark: var(--color-border-dark);
}

/* ===== Container ===== */
.ll-container {
    width: 100%;
    max-width: var(--ll-container-max);
    margin: 0 auto;
}

#lift-logic {
    background: var(--color-bg-card);
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-8);
}

/* ===== Level bar ===== */
.ll-levelbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-alt);
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
}
.ll-levelbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.ll-levelbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}
.ll-level-name {
    font-weight: 700;
    font-size: var(--font-size-md);
}
.ll-mode-tag {
    display: inline-block;
    padding: var(--space-1) var(--space-2);
    background: var(--ll-primary-soft);
    color: var(--ll-primary);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.ll-meta-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: var(--color-bg-card);
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

/* The inline-flex display above would override the UA [hidden] rule,
   so the hidden state must win explicitly (needed for Free Play,
   which hides the par time / par energy chips — SPEC §6.7) */
.ll-meta-chip[hidden] {
    display: none;
}
.ll-meta-chip-label {
    color: var(--color-text-muted);
    font-weight: 500;
}

/* ===== Buttons ===== */
.ll-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--ll-transition), border-color var(--ll-transition), box-shadow var(--ll-transition), transform var(--ll-transition);
}
.ll-btn:active {
    transform: translateY(1px);
}
.ll-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}
/* The inline-flex display above would override the UA [hidden] rule, so the
   hidden state must win explicitly. The result dialog toggles its action
   buttons (Restart / New Building / Next-Play Again) via the hidden attribute
   (SPEC §6.7), so without this override they stay visible in the wrong states. */
.ll-btn[hidden] {
    display: none;
}
.ll-btn-primary {
    background: var(--ll-primary);
    color: var(--color-text-inverse);
    border-color: var(--ll-primary);
}
.ll-btn-primary:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}
.ll-btn-secondary {
    background: var(--color-bg-card);
    color: var(--color-text);
    border-color: var(--ll-border-dark);
}
.ll-btn-secondary:hover {
    border-color: var(--ll-primary);
    background: var(--ll-primary-soft);
}
.ll-btn-sm {
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
}
.ll-icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-card);
    color: var(--color-text);
    cursor: pointer;
    transition: border-color var(--ll-transition), box-shadow var(--ll-transition);
}
.ll-icon-btn:hover,
.ll-icon-btn[aria-pressed="true"] {
    border-color: var(--ll-primary);
    background: var(--ll-primary-soft);
}
.ll-icon-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}
/* Non-color cue for the muted state (struck-through note + reduced opacity) */
.ll-icon-btn[aria-pressed="false"] .ll-sound-icon {
    opacity: 0.55;
    text-decoration: line-through;
}

/* ===== Game layout ===== */
.ll-game {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
}
@media (min-width: 900px) {
    .ll-game {
        grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
        align-items: start;
    }
}

/* ===== Simulation ===== */
.ll-sim {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
}
.ll-canvas {
    width: 100%;
    height: var(--ll-canvas-height);
    display: block;
    background: var(--color-bg-alt);
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-md);
}
/* Manual (tutorial) levels: floors on the building are tap targets.
   Cursor is a non-color affordance; keyboard remains the accessible path.
   `manipulation` keeps pan/pinch while removing double-tap zoom delay. */
.ll-canvas-manual {
    cursor: pointer;
    touch-action: manipulation;
}
@media (max-width: 560px) {
    .ll-canvas {
        height: var(--ll-canvas-height-mobile, 360px);
    }
}

.ll-hud {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}
.ll-hud-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: var(--color-bg-alt);
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 600;
}
.ll-hud-label {
    color: var(--color-text-muted);
    font-weight: 500;
}

.ll-panel-title {
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin: 0 0 var(--space-2);
}


.ll-status {
    margin: 0;
    min-height: 1.4em;
    font-size: var(--font-size-sm);
    /* Full text color (not muted): muted slate on the soft-primary background
       fails WCAG AA contrast in light mode (3.84:1 < 4.5:1). */
    color: var(--color-text);
    padding: var(--space-2) var(--space-3);
    background: var(--ll-primary-soft);
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-md);
}

.ll-manual {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}
.ll-manual[hidden] {
    display: none;
}

/* ===== Result overlay ===== */
.ll-result {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: color-mix(in srgb, var(--color-bg) 72%, transparent);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    border-radius: var(--radius-md);
    z-index: 5;
}
.ll-result[hidden] {
    display: none;
}
.ll-result-stars[hidden],
.ll-result-stats > div[hidden] {
    display: none;
}
.ll-result-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-bg-card);
    border: 1px solid var(--ll-border-dark);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-xl);
    text-align: center;
}
.ll-result-title {
    margin: 0 0 var(--space-3);
    font-size: var(--font-size-xl);
}
.ll-result-stars {
    margin: 0 0 var(--space-4);
    font-size: var(--font-size-3xl);
    letter-spacing: 0.1em;
    color: var(--ll-warn);
}
.ll-result-stats {
    margin: 0 0 var(--space-4);
    display: grid;
    gap: var(--space-2);
}
.ll-result-stats > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    background: var(--color-bg-alt);
    border-radius: var(--radius-sm);
}
.ll-result-stats dt {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}
.ll-result-stats dd {
    margin: 0;
    font-weight: 700;
}
.ll-result-actions {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* ===== Level map modal ===== */
.ll-levelmap {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 50;
}
.ll-levelmap[hidden] {
    display: none;
}
.ll-levelmap-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--color-bg) 70%, transparent);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.ll-levelmap-content {
    position: relative;
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--color-bg-card);
    border: 1px solid var(--ll-border-dark);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5);
}
.ll-levelmap-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}
.ll-levelmap-head h2 {
    margin: 0;
    font-size: var(--font-size-lg);
}
.ll-levelmap-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-2);
}
.ll-level-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3);
    text-align: left;
    border: 1px solid var(--ll-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-alt);
    color: var(--color-text);
    cursor: pointer;
    transition: border-color var(--ll-transition), box-shadow var(--ll-transition), transform var(--ll-transition);
}
.ll-level-card:hover:not(.is-locked),
.ll-level-card:focus-visible:not(.is-locked) {
    border-color: var(--ll-primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}
.ll-level-card.is-current {
    border-color: var(--ll-primary);
    box-shadow: var(--focus-ring);
}
.ll-level-card.is-locked {
    opacity: 0.55;
    cursor: not-allowed;
}
.ll-level-card-num {
    font-size: var(--font-size-lg);
    font-weight: 800;
}
.ll-level-card-mode {
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    color: var(--ll-primary);
}
.ll-level-card-floors {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}
.ll-level-card-stars {
    font-size: var(--font-size-xs);
    color: var(--ll-warn);
}
.ll-level-card-state {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-muted);
}
/* Free Play entry (SPEC §6.7): visually distinct from the campaign grid,
   always available, never locked, no star state. */
.ll-freeplay-card {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: var(--space-3);
    border-style: dashed;
    border-color: var(--ll-primary);
    background: var(--ll-primary-soft);
}
.ll-freeplay-card:hover,
.ll-freeplay-card:focus-visible {
    border-color: var(--ll-primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}
.ll-levelmap-foot {
    display: flex;
    justify-content: flex-end;
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    .ll-btn,
    .ll-level-card {
        transition: none;
    }
    .ll-level-card:hover:not(.is-locked),
    .ll-freeplay-card:hover {
        transform: none;
    }
}
