:root {
    --bg-color: #050505;
    --card-bg: #141414;
    --text-color: #e0e0e0;
    --accent-color: #00e5ff;
    --accent-glow: rgba(0, 229, 255, 0.3);
    --success-color: #00ff9d;
    --error-color: #ff2a6d;
    --hub-bg: #0a0a0a;
    --font-main: 'Inter', sans-serif;
    --font-mono: 'Space Mono', monospace;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    background-image:
        radial-gradient(circle at 50% 0%, #1a1a2e 0%, transparent 70%),
        linear-gradient(0deg, rgba(0, 229, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 229, 255, 0.05) 1px, transparent 1px);
    background-size: 100% 100%, 40px 40px, 40px 40px;
}

.app-container {
    width: 100%;
    max-width: 500px;
    background-color: rgba(10, 10, 10, 0.95);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
    border-left: 1px solid #222;
    border-right: 1px solid #222;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

/* Header */
header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    background-color: rgba(20, 20, 20, 0.8);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 1.5rem;
    animation: pulse 3s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.7;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }

    100% {
        opacity: 0.7;
        transform: scale(1);
    }
}

header h1 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: linear-gradient(to right, #fff, var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.date-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 229, 255, 0.1);
    padding: 4px;
    border-radius: 6px;
    border: 1px solid var(--accent-color);
}

.nav-arrow {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 5px;
    transition: opacity 0.2s;
}

.nav-arrow:disabled {
    opacity: 0.3;
    cursor: default;
}

.date-display {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-color);
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 4px;
}

.date-display:hover {
    background: rgba(0, 229, 255, 0.2);
}

#today-btn {
    background: var(--accent-color);
    color: #000;
    border: none;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

#today-btn.hidden {
    display: none;
}

#stats-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s;
}

#stats-btn:hover {
    transform: scale(1.1);
}

/* Views */
.view {
    flex: 1;
    display: none;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
}

.view.active {
    display: flex;
}

/* HUB STYLES */
.hub-header {
    margin-bottom: 25px;
}

.progress-container {
    background: linear-gradient(145deg, #1a1a1a, #111);
    border: 1px solid #333;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#progress-text {
    display: block;
    margin-bottom: 12px;
    font-weight: bold;
    font-size: 0.8rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.progress-bar {
    height: 6px;
    background-color: #222;
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-color);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.cartridge-stack {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cartridge {
    background: linear-gradient(90deg, #1a1a1a, #151515);
    color: #fff;
    padding: 15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid #333;
    position: relative;
    overflow: hidden;
}

.cartridge::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: #444;
    transition: background-color 0.3s;
}

.cartridge:hover {
    transform: translateX(5px);
    border-color: #555;
    background: #222;
}

.cartridge:active {
    transform: scale(0.98) translateX(5px);
}

.cartridge.completed {
    border-color: var(--success-color);
    background: rgba(0, 255, 157, 0.05);
}

.cartridge.completed::before {
    background-color: var(--success-color);
    box-shadow: 0 0 10px var(--success-color);
}

.cart-icon-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    margin-right: 15px;
    filter: grayscale(100%);
    transition: filter 0.3s;
}

.cartridge:hover .cart-icon-img,
.cartridge.completed .cart-icon-img {
    filter: grayscale(0%);
}

.cart-info {
    flex: 1;
}

.cart-category {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: bold;
    color: #666;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.cart-theme {
    font-size: 1rem;
    font-weight: 700;
    color: #eee;
}

.cart-status {
    font-size: 1rem;
    min-width: 60px;
    text-align: right;
}

/* GAME VIEW STYLES */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.icon-btn {
    background: none;
    border: 1px solid #333;
    color: #aaa;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 20px;
    transition: all 0.2s;
    font-family: var(--font-mono);
}

.icon-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.lives-container {
    letter-spacing: 2px;
    font-size: 0.9rem;
}

.theme-image-container {
    width: 100%;
    height: 150px;
    background-color: #111;
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid #333;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-image-container::after {
    content: 'NO IMAGE DATA';
    color: #333;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    position: absolute;
    z-index: 0;
}

#theme-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: relative;
    z-index: 1;
    display: block;
}

.theme-title {
    text-align: center;
    font-size: 1.4rem;
    font-weight: 900;
    margin-bottom: 25px;
    color: #fff;
    text-shadow: 0 0 20px rgba(0, 229, 255, 0.2);
}

.timeline-board {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.timeline-board::before {
    content: '';
    position: absolute;
    left: 20px;
    top: 10px;
    bottom: 10px;
    width: 2px;
    background: linear-gradient(to bottom, transparent, #333 10%, #333 90%, transparent);
    z-index: 0;
}

.timeline-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.timeline-item {
    background-color: var(--card-bg);
    padding: 15px 15px 15px 40px;
    /* Space for timeline line */
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #333;
    cursor: grab;
    /* Whole item is draggable */
    position: relative;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    touch-action: none;
    /* CRITICAL FOR MOBILE DRAG */
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #333;
    border: 2px solid #111;
    transition: background-color 0.3s;
}

.timeline-item:hover {
    border-color: #555;
    transform: translateX(2px);
}

.timeline-item:active {
    cursor: grabbing;
    background-color: #222;
    z-index: 10;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
}

.sortable-ghost {
    opacity: 0.4;
    background-color: var(--accent-color);
}

.item-content {
    flex: 1;
    pointer-events: none;
    /* Prevent text selection on content */
}

.item-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: #ddd;
}

.item-year {
    font-family: var(--font-mono);
    color: var(--accent-color);
    font-weight: bold;
    font-size: 0.9rem;
    display: none;
    margin-top: 4px;
}

.item-year.revealed {
    display: block;
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.drag-handle {
    color: #555;
    margin-left: 15px;
    font-size: 1.5rem;
    padding: 10px;
    opacity: 0.5;
    /* Visual cue only now */
}

/* Feedback states */
.timeline-item.correct {
    border-color: var(--success-color);
    background: rgba(0, 255, 157, 0.1);
}

.timeline-item.correct::before {
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

.timeline-item.wrong {
    border-color: var(--error-color);
    background: rgba(255, 42, 109, 0.1);
}

.timeline-item.wrong::before {
    background-color: var(--error-color);
    box-shadow: 0 0 8px var(--error-color);
}

.game-footer {
    padding-top: 20px;
}

.action-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent-color);
    color: #000;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 900;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s;
    box-shadow: 0 0 15px var(--accent-glow);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px var(--accent-glow);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    background: #444;
}

/* OVERLAY */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.result-card {
    background-color: #1a1a1a;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    width: 85%;
    border: 1px solid #444;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.stars {
    font-size: 2.5rem;
    margin: 20px 0;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

#result-title {
    margin-top: 0;
    font-size: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* STATS MODAL */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-box {
    background: #222;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--accent-color);
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #888;
    margin-top: 5px;
}

.stats-chart {
    margin-top: 20px;
    text-align: left;
}

.chart-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.8rem;
}

.chart-label {
    width: 20px;
    text-align: right;
    margin-right: 10px;
}

.chart-bar-container {
    flex: 1;
    background: #222;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
}

.chart-bar {
    height: 100%;
    background: var(--accent-color);
}

/* Calendar Styles */
.calendar-card {
    width: 90%;
    max-width: 400px;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.cal-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid #333;
    background: #222;
    color: #666;
}

.cal-day.has-data {
    color: #fff;
    border-color: #555;
}

.cal-day.has-data:hover {
    border-color: var(--accent-color);
    background: #333;
}

.cal-day.selected {
    background: var(--accent-color);
    color: #000;
    font-weight: bold;
    box-shadow: 0 0 10px var(--accent-glow);
}

.cal-day.today {
    border: 1px solid var(--accent-color);
}

.cal-day.empty {
    background: transparent;
    border: none;
    cursor: default;
}