/* ===== CSS Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Mars Theme Colors */
    --color-deep-space: #1a1a2e;
    --color-mars-red: #e94560;
    --color-mars-orange: #ff6b35;
    --color-tile-tray: #16213e;
    --color-mission-row: #0f3460;
    --color-text-light: #f0f0f0;
    --color-text-secondary: #b0b0b0;
    --color-success: #4caf50;
    --color-failure: #ff9800;
    --color-border: #2a2a3e;
    --color-accent-teal: #00d4aa;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;

    /* Sizes */
    --tile-size: 120px;
    --tile-size-small: 80px;
    --button-height: 48px;
    --border-radius: 3px;
}

body {
    font-family: 'Courier New', 'Consolas', monospace;
    background-color: var(--color-deep-space);
    background-image:
        radial-gradient(2px 2px at 20px 30px, rgba(255, 255, 255, 0.15), rgba(0,0,0,0)),
        radial-gradient(2px 2px at 60px 70px, rgba(255, 255, 255, 0.1), rgba(0,0,0,0)),
        radial-gradient(1px 1px at 50px 50px, rgba(255, 255, 255, 0.1), rgba(0,0,0,0)),
        radial-gradient(1px 1px at 130px 80px, rgba(255, 255, 255, 0.15), rgba(0,0,0,0)),
        radial-gradient(2px 2px at 90px 10px, rgba(255, 255, 255, 0.1), rgba(0,0,0,0)),
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 100, 150, 0.03) 2px, rgba(0, 100, 150, 0.03) 4px);
    background-size: 200px 200px, 200px 200px, 200px 200px, 200px 200px, 200px 200px, 100%;
    color: var(--color-text-light);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--spacing-sm);
    position: relative;
    overflow-x: hidden;
}

/* ===== Radar Grid Background ===== */
.radar-grid {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
    background-image:
        repeating-conic-gradient(
            from 0deg at 50% 50%,
            transparent 0deg,
            rgba(0, 212, 170, 0.3) 1deg,
            transparent 2deg,
            transparent 30deg
        ),
        repeating-radial-gradient(
            circle at 50% 50%,
            transparent 0,
            transparent 49px,
            rgba(0, 212, 170, 0.4) 50px,
            transparent 51px,
            transparent 99px
        );
    border-radius: 50%;
    animation: radar-sweep 8s linear infinite;
}

.radar-grid::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: conic-gradient(
        from 0deg at 50% 50%,
        transparent 0deg,
        rgba(0, 212, 170, 0.3) 90deg,
        transparent 180deg
    );
    border-radius: 50%;
    animation: radar-sweep 4s linear infinite;
}

@keyframes radar-sweep {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* ===== Status Panels ===== */
.status-panel {
    position: fixed;
    background: rgba(22, 33, 62, 0.9);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-sm);
    font-size: 0.75rem;
    min-width: 200px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 212, 170, 0.1);
    z-index: 10;
}

.status-panel-left {
    top: var(--spacing-lg);
    left: var(--spacing-sm);
}

.status-panel-right {
    top: var(--spacing-lg);
    right: var(--spacing-sm);
}

.panel-header {
    color: var(--color-mars-orange);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-xs);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.7rem;
}

.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: var(--spacing-xs) 0;
    padding: 4px 0;
}

.status-label {
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.status-value {
    color: var(--color-accent-teal);
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.status-online {
    color: var(--color-success);
}

.status-active {
    color: var(--color-accent-teal);
    animation: blink 2s infinite;
}

/* Signal Bars */
.signal-bars {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    height: 12px;
}

.signal-bars .bar {
    width: 3px;
    background: rgba(176, 176, 176, 0.3);
    border-radius: 1px;
}

.signal-bars .bar:nth-child(1) { height: 4px; }
.signal-bars .bar:nth-child(2) { height: 6px; }
.signal-bars .bar:nth-child(3) { height: 8px; }
.signal-bars .bar:nth-child(4) { height: 10px; }
.signal-bars .bar:nth-child(5) { height: 12px; }

.signal-bars .bar.active {
    background: var(--color-accent-teal);
}

/* Power Bar */
.power-bar-container {
    width: 60px;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--color-border);
    border-radius: 2px;
    overflow: hidden;
}

.power-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-success), var(--color-accent-teal));
    transition: width 0.3s ease;
}

.mission-time {
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}

/* ===== Header ===== */
header {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    border: 1px solid var(--color-border);
    background: var(--color-tile-tray);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
    border-top: 2px solid var(--color-accent-teal);
}

h1 {
    font-size: clamp(1.75rem, 5vw, 3rem);
    color: var(--color-mars-red);
    text-shadow: 0 0 20px rgba(233, 69, 96, 0.5);
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 4px;
}

.status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    font-size: 0.875rem;
    color: var(--color-accent-teal);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--color-border);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--color-accent-teal);
    border-radius: 50%;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.reminders {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    max-width: 800px;
    margin: 0 auto;
}

.reminders p {
    font-size: clamp(0.875rem, 2vw, 1rem);
    color: var(--color-text-secondary);
    margin: var(--spacing-xs) 0;
}

h2 {
    font-size: clamp(1rem, 3vw, 1.25rem);
    color: var(--color-mars-orange);
    margin-bottom: var(--spacing-md);
    text-transform: uppercase;
    letter-spacing: 3px;
}

/* ===== Tile Tray ===== */
.tile-tray {
    background: var(--color-tile-tray);
    border: 1px solid var(--color-border);
    border-top: 2px solid var(--color-mars-orange);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    box-shadow: inset 0 0 20px rgba(233, 69, 96, 0.1), inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.tray-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    justify-content: center;
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: var(--tile-size);
    height: var(--tile-size);
    background: linear-gradient(135deg, var(--color-mars-red), var(--color-mars-orange));
    border: 3px solid var(--color-border);
    border-radius: var(--border-radius);
    cursor: grab;
    user-select: none;
    touch-action: none;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    position: relative;
}

.tile:hover,
.tile:focus {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(233, 69, 96, 0.4);
    outline: none;
}

.tile:focus-visible {
    outline: 3px solid var(--color-mars-orange);
    outline-offset: 2px;
}

.tile:active {
    cursor: grabbing;
}

.tile svg {
    width: 48px;
    height: 48px;
    fill: white;
    margin-bottom: var(--spacing-xs);
}

.tile span {
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    color: white;
}

.tile.dragging {
    opacity: 0.5;
}

/* ===== Mission Section ===== */
.mission-section {
    background: var(--color-mission-row);
    border: 1px solid var(--color-border);
    border-top: 2px solid var(--color-mars-orange);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    min-height: 200px;
    box-shadow: inset 0 0 20px rgba(15, 52, 96, 0.5), inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.mission-row {
    display: flex;
    gap: var(--spacing-lg);
    overflow-x: auto;
    padding: var(--spacing-lg);
    min-height: 140px;
    align-items: center;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 255, 170, 0.03) 2px,
            rgba(0, 255, 170, 0.03) 4px
        ),
        rgba(0, 0, 0, 0.3);
    border-radius: var(--border-radius);
    position: relative;
}

.mission-row::-webkit-scrollbar {
    height: 8px;
}

.mission-row::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.mission-row::-webkit-scrollbar-thumb {
    background: var(--color-mars-red);
    border-radius: 4px;
}

.empty-state {
    width: 100%;
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 1.125rem;
    font-style: italic;
}

.mission-tile-wrapper {
    position: relative;
    flex-shrink: 0;
    transition: transform 0.2s ease-out;
}

.mission-tile-wrapper.placeholder {
    transition: none;
}

.mission-tile {
    width: var(--tile-size-small);
    height: var(--tile-size-small);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-mars-red), var(--color-mars-orange));
    border: 3px solid var(--color-border);
    border-radius: var(--border-radius);
    cursor: grab;
    touch-action: none;
    transition: transform 0.2s, box-shadow 0.2s;
}

.placeholder-tile {
    opacity: 0.5;
    border-style: dashed;
    border-color: var(--color-accent-teal);
    background: linear-gradient(135deg, rgba(0, 212, 170, 0.2), rgba(0, 212, 170, 0.3));
    cursor: default;
    animation: pulse-placeholder 1s ease-in-out infinite;
}

@keyframes pulse-placeholder {
    0%, 100% {
        opacity: 0.5;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.02);
    }
}

.mission-tile:active {
    cursor: grabbing;
}

.mission-tile svg {
    width: 32px;
    height: 32px;
    fill: white;
    margin-bottom: 4px;
}

.mission-tile span {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    text-align: center;
}

.mission-tile.highlight {
    animation: pulse 0.8s ease-in-out infinite;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.8);
    transform: scale(1.1);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 30px rgba(255, 255, 255, 0.8);
    }
    50% {
        box-shadow: 0 0 50px rgba(255, 255, 255, 1);
    }
}

.tile-number {
    position: absolute;
    top: -12px;
    left: -12px;
    width: 28px;
    height: 28px;
    background: var(--color-mars-orange);
    border: 2px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.875rem;
    color: white;
    z-index: 1;
}

.remove-tile-btn {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 28px;
    height: 28px;
    background: var(--color-failure);
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    transition: transform 0.2s;
}

.remove-tile-btn:hover {
    transform: scale(1.1);
}

.remove-tile-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.drag-over {
    background: rgba(255, 107, 53, 0.3);
    border: 2px dashed var(--color-mars-orange);
}

/* ===== Controls ===== */
.controls-section {
    text-align: center;
    margin-bottom: var(--spacing-md);
}

.controls-label {
    font-size: 1rem;
    color: var(--color-accent-teal);
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: var(--spacing-sm);
}

.controls {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    min-height: var(--button-height);
    padding: 0 var(--spacing-lg);
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Courier New', 'Consolas', monospace;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    touch-action: manipulation;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: 3px solid var(--color-mars-orange);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-mars-red), var(--color-mars-orange));
    color: white;
}

.btn-secondary {
    background: #555;
    color: white;
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-failure {
    background: var(--color-failure);
    color: white;
}

/* ===== Running State ===== */
body.running .tile,
body.running .mission-tile,
body.running .btn {
    pointer-events: none;
}

body.running .controls .btn {
    opacity: 0.5;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--spacing-md);
}

.modal[hidden] {
    display: none;
}

.modal-content {
    background: var(--color-tile-tray);
    border: 3px solid var(--color-mars-red);
    border-radius: var(--border-radius);
    padding: var(--spacing-xl);
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(233, 69, 96, 0.5);
}

.modal-content h2 {
    color: var(--color-mars-red);
    margin-bottom: var(--spacing-md);
}

.modal-question {
    font-size: 1.25rem;
    margin-bottom: var(--spacing-lg);
    color: var(--color-text-light);
}

.modal-buttons {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
    flex-wrap: wrap;
}

.celebration {
    margin-top: var(--spacing-lg);
}

.celebration[hidden] {
    display: none;
}

.celebration-text {
    font-size: 2rem;
    font-weight: bold;
    color: var(--color-success);
    animation: celebrate 1s ease-in-out;
}

@keyframes celebrate {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

/* ===== Drag Clone ===== */
.tile-clone {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.9;
    transform: rotate(-5deg);
}

/* ===== Responsive Design ===== */
@media (max-width: 1024px) {
    .status-panel {
        position: static;
        margin: var(--spacing-sm) auto;
        max-width: 400px;
    }

    .status-panel-left,
    .status-panel-right {
        top: auto;
        left: auto;
        right: auto;
    }

    .radar-grid {
        width: 400px;
        height: 400px;
    }
}

@media (max-width: 768px) {
    :root {
        --tile-size: 100px;
        --tile-size-small: 70px;
    }

    .tile svg {
        width: 36px;
        height: 36px;
    }

    .tile span {
        font-size: 0.75rem;
    }

    .mission-tile svg {
        width: 28px;
        height: 28px;
    }

    .btn {
        font-size: 1rem;
        padding: 0 var(--spacing-md);
    }
}

@media (max-width: 480px) {
    :root {
        --tile-size: 90px;
        --tile-size-small: 65px;
    }

    .controls {
        flex-direction: column;
        width: 100%;
    }

    .btn {
        width: 100%;
    }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tile,
    .mission-tile {
        border-width: 4px;
    }

    .btn {
        border: 2px solid white;
    }
}
