/* ============================================
   gamelicen.se - Pixel Art Game Licensing Terminal
   ============================================ */

/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    image-rendering: pixelated;
    -ms-interpolation-mode: nearest-neighbor;
    overflow: hidden;
    height: 100%;
}

body {
    font-family: 'VT323', monospace;
    background: #0D1B2A;
    color: #C8E6C9;
    height: 100%;
    overflow: hidden;
    font-smooth: never;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: unset;
    text-rendering: optimizeSpeed;
}

/* CRT Scanline Overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(120, 144, 156, 0.08) 1px,
        rgba(120, 144, 156, 0.08) 2px
    );
}

/* CRT Vignette */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

/* ============================================
   Progress Bar
   ============================================ */
#progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 9000;
    padding: 8px 32px;
    background: rgba(13, 27, 42, 0.9);
    border-bottom: 2px solid #42A5F5;
}

#progress-track {
    position: relative;
    width: 100%;
    height: 8px;
    background: #1B2838;
    border: 1px solid #42A5F5;
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: #2E7D32;
    transition: width 0.4s ease;
}

#progress-sprite {
    position: absolute;
    top: -6px;
    left: 0%;
    transition: left 0.4s ease;
    z-index: 2;
}

/* Walking sprite 2-frame animation */
.sprite-frame {
    image-rendering: pixelated;
}

#progress-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
}

.progress-label {
    font-family: 'Silkscreen', monospace;
    font-size: 10px;
    color: #78909C;
    letter-spacing: 0.05em;
    transition: color 0.3s;
}

.progress-label.active {
    color: #FFD54F;
}

/* ============================================
   Stage Container
   ============================================ */
#stage-container {
    display: flex;
    flex-direction: row;
    width: 500vw;
    height: 100vh;
    overflow-x: scroll;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

#stage-container::-webkit-scrollbar {
    display: none;
}

.stage {
    width: 100vw;
    height: 100vh;
    flex-shrink: 0;
    scroll-snap-align: start;
    position: relative;
    overflow: hidden;
}

.stage-content {
    width: 100%;
    height: 100%;
    padding: 56px 32px 32px 32px;
    position: relative;
}

.stage-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Stage backgrounds */
[data-bg="boot"] {
    background-color: #0D1B2A;
}

[data-bg="cartridge"] {
    background-color: #1B2838;
}

/* ============================================
   Typography
   ============================================ */
.stage-heading {
    font-family: 'Press Start 2P', monospace;
    font-size: 20px;
    color: #C8E6C9;
    letter-spacing: 0.05em;
    line-height: 1.8;
    margin-bottom: 16px;
    font-smooth: never;
    -webkit-font-smoothing: none;
    text-rendering: optimizeSpeed;
}

.stage-heading-center {
    text-align: center;
}

/* ============================================
   Dialog Boxes (JRPG double-border)
   ============================================ */
.dialog-box {
    background: rgba(13, 27, 42, 0.92);
    border: 2px solid #42A5F5;
    box-shadow: inset 0 0 0 2px #0D1B2A, inset 0 0 0 4px #42A5F5;
    padding: 16px;
    position: relative;
}

/* ============================================
   Stage 1: Title Screen
   ============================================ */
#title-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
}

#title-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 32px;
    color: #C8E6C9;
    letter-spacing: 0.05em;
    line-height: 1.8;
    white-space: nowrap;
    font-smooth: never;
    -webkit-font-smoothing: none;
    text-rendering: optimizeSpeed;
}

#title-mask {
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: #0D1B2A;
    animation: typewriter-reveal 1s steps(12) 0.4s forwards;
}

@keyframes typewriter-reveal {
    from { width: 100%; }
    to { width: 0%; }
}

#press-start {
    font-family: 'Silkscreen', monospace;
    font-weight: 700;
    font-size: 14px;
    color: #FFD54F;
    letter-spacing: 0.05em;
    margin-top: 32px;
    opacity: 0;
    animation: press-start-appear 0.01s 1.6s forwards, blink-hard 1.2s 1.6s step-start infinite;
}

@keyframes press-start-appear {
    to { opacity: 1; }
}

@keyframes blink-hard {
    0%, 49% { visibility: visible; }
    50%, 100% { visibility: hidden; }
}

/* CRT Flicker - irregular timing */
#stage-1 {
    animation: crt-flicker 4s infinite;
}

@keyframes crt-flicker {
    0%, 100% { filter: brightness(1.0); }
    3% { filter: brightness(0.97); }
    4% { filter: brightness(1.0); }
    27% { filter: brightness(1.0); }
    28% { filter: brightness(0.97); }
    29% { filter: brightness(1.0); }
    47% { filter: brightness(1.0); }
    48% { filter: brightness(0.97); }
    49% { filter: brightness(1.0); }
    72% { filter: brightness(1.0); }
    73% { filter: brightness(0.97); }
    74% { filter: brightness(1.0); }
    91% { filter: brightness(1.0); }
    92% { filter: brightness(0.97); }
    93% { filter: brightness(1.0); }
}

/* ============================================
   Stage 2: Select Your License
   ============================================ */
#stage2-upper {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-bottom: 24px;
    padding-left: 32px;
}

#cartridge-sprite {
    animation: rotate-cartridge 20s linear infinite;
    flex-shrink: 0;
}

@keyframes rotate-cartridge {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#license-menu-box {
    margin-left: 32px;
    max-width: 500px;
}

#license-menu {
    list-style: none;
}

.menu-item {
    font-family: 'VT323', monospace;
    font-size: 20px;
    color: #C8E6C9;
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    line-height: 1.6;
    letter-spacing: 0.02em;
    transition: color 0.15s;
}

.menu-item:hover,
.menu-item.active {
    color: #FFD54F;
}

.menu-cursor {
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 8px solid #FFD54F;
    opacity: 0;
    flex-shrink: 0;
}

.menu-item.active .menu-cursor {
    opacity: 1;
    animation: cursor-blink 0.8s step-start infinite;
}

.menu-item:hover .menu-cursor {
    opacity: 1;
}

@keyframes cursor-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

#license-desc-box {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%) translateX(20px);
    max-width: 320px;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
}

#license-desc-box.visible {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

#license-desc-text {
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: #78909C;
    line-height: 1.6;
    letter-spacing: 0.02em;
}

/* ============================================
   Stage 3: The Archive / Timeline
   ============================================ */
#stage-3 .stage-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 64px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #42A5F5 #0D1B2A;
}

#timeline {
    position: relative;
    width: 600px;
    max-width: 90vw;
    padding: 24px 0 48px 0;
}

.timeline-spine {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #42A5F5;
    transform: translateX(-50%);
}

.timeline-node {
    position: relative;
    display: flex;
    align-items: flex-start;
    margin-bottom: 32px;
    opacity: 0;
    transform: scale(0);
}

.timeline-node.animate-in {
    opacity: 1;
    transform: scale(1);
    animation: bounce-enter 0.3s ease-out forwards;
}

@keyframes bounce-enter {
    0% { transform: scale(0); }
    70% { transform: scale(1.1); }
    100% { transform: scale(1.0); }
}

.timeline-node.left {
    flex-direction: row-reverse;
    padding-right: calc(50% + 24px);
}

.timeline-node.right {
    padding-left: calc(50% + 24px);
}

.timeline-node.left .node-sprite {
    margin-left: 16px;
}

.timeline-node.right .node-sprite {
    margin-right: 16px;
}

.node-sprite {
    flex-shrink: 0;
}

.node-sprite svg {
    image-rendering: pixelated;
}

.node-content {
    max-width: 220px;
}

.node-date {
    font-family: 'Silkscreen', monospace;
    font-size: 12px;
    color: #FFD54F;
    display: block;
    margin-bottom: 8px;
}

.node-text {
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: #C8E6C9;
    line-height: 1.6;
    letter-spacing: 0.02em;
}

/* ============================================
   Stage 4: The Forge
   ============================================ */
#forge-layout {
    display: flex;
    gap: 32px;
    height: calc(100% - 80px);
}

#forge-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-left: 32px;
}

#forge-right {
    flex: 1;
    display: flex;
    align-items: flex-start;
}

#license-portrait {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px;
}

#shield-sprite {
    animation: shield-glow 2s ease-in-out infinite;
}

@keyframes shield-glow {
    0%, 100% { filter: drop-shadow(0 0 12px rgba(255, 213, 79, 0.2)); }
    50% { filter: drop-shadow(0 0 24px rgba(255, 213, 79, 0.4)); }
}

.portrait-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    color: #FFD54F;
    letter-spacing: 0.05em;
}

/* Stat Bars */
#stat-bars {
    padding: 16px;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.stat-row:last-child {
    margin-bottom: 0;
}

.stat-label {
    font-family: 'Silkscreen', monospace;
    font-size: 12px;
    color: #C8E6C9;
    width: 120px;
    flex-shrink: 0;
    letter-spacing: 0.05em;
}

.stat-bar {
    flex: 1;
    height: 16px;
    background: #78909C;
    border: 2px solid #42A5F5;
    position: relative;
}

.stat-fill {
    height: 100%;
    background: #2E7D32;
    position: relative;
}

.stat-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 2px;
    height: 100%;
    background: #FFD54F;
}

/* Inventory */
#inventory-box {
    width: 100%;
}

.inventory-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    color: #C8E6C9;
    margin-bottom: 16px;
    letter-spacing: 0.05em;
}

#inventory-grid {
    display: grid;
    grid-template-columns: repeat(3, 72px);
    grid-template-rows: repeat(3, 72px);
    gap: 8px;
}

.inv-slot {
    width: 72px;
    height: 72px;
    background: rgba(13, 27, 42, 0.8);
    border: 2px solid #42A5F5;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.inv-slot:hover {
    transform: perspective(300px) rotateY(3deg) rotateX(-3deg);
    box-shadow: 0 0 16px rgba(66, 165, 245, 0.3);
}

.inv-slot svg {
    image-rendering: pixelated;
    width: 48px;
    height: 48px;
}

#inv-tooltip {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 400px;
    z-index: 100;
    text-align: center;
}

#tooltip-name {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    color: #FFD54F;
    display: block;
    margin-bottom: 8px;
}

#tooltip-desc {
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: #C8E6C9;
    line-height: 1.6;
}

/* ============================================
   Stage 5: The Seal
   ============================================ */
#seal-container {
    position: relative;
    width: 60vmin;
    height: 60vmin;
    max-width: 400px;
    max-height: 400px;
}

#seal-svg {
    width: 100%;
    height: 100%;
    transform: scale(0);
    animation: seal-enter 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    animation-play-state: paused;
}

#seal-svg.animate {
    animation-play-state: running;
}

@keyframes seal-enter {
    0% { transform: scale(0); }
    70% { transform: scale(1.05); }
    100% { transform: scale(1.0); }
}

#seal-border-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#seal-trace {
    transition: stroke-dashoffset 2s linear;
}

#seal-trace.animate {
    stroke-dashoffset: 0;
}

#seal-text {
    font-family: 'VT323', monospace;
    font-size: 20px;
    color: #C8E6C9;
    letter-spacing: 0.02em;
    line-height: 1.6;
    margin-top: 32px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.5s;
}

#seal-text.visible {
    opacity: 1;
}

/* ============================================
   Navigation Arrows
   ============================================ */
.nav-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9000;
    cursor: pointer;
    padding: 8px;
}

.nav-arrow-left {
    left: 16px;
    animation: arrow-pulse-left 0.8s ease-in-out infinite;
}

.nav-arrow-right {
    right: 16px;
    animation: arrow-pulse-right 0.8s ease-in-out infinite;
}

@keyframes arrow-pulse-right {
    0%, 100% { transform: translateY(-50%) translateX(0); }
    50% { transform: translateY(-50%) translateX(2px); }
}

@keyframes arrow-pulse-left {
    0%, 100% { transform: translateY(-50%) translateX(0); }
    50% { transform: translateY(-50%) translateX(-2px); }
}

.nav-arrow svg {
    image-rendering: pixelated;
}

/* Hide left arrow on first stage, right arrow on last */
.nav-arrow-left.hidden,
.nav-arrow-right.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Damage Red state for error/warning indicators */
.damage-flash {
    color: #E53935;
}

.inv-slot.error-state {
    border-color: #E53935;
}

/* ============================================
   Pixel Art Decorative Border
   ============================================ */
.pixel-divider {
    width: 100%;
    height: 16px;
    background-image:
        repeating-linear-gradient(
            90deg,
            #FFD54F 0px, #FFD54F 4px,
            transparent 4px, transparent 8px,
            #42A5F5 8px, #42A5F5 12px,
            transparent 12px, transparent 16px
        );
    background-size: 16px 4px;
    background-repeat: repeat-x;
    background-position: center;
    margin: 16px 0;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
    #title-text {
        font-size: 18px;
    }

    .stage-heading {
        font-size: 14px;
    }

    #forge-layout {
        flex-direction: column;
    }

    #forge-left {
        margin-left: 0;
    }

    #inventory-grid {
        grid-template-columns: repeat(3, 56px);
        grid-template-rows: repeat(3, 56px);
    }

    .inv-slot {
        width: 56px;
        height: 56px;
    }

    .menu-item {
        font-size: 16px;
    }

    #license-desc-box {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        margin-top: 16px;
        margin-left: 32px;
    }

    #license-desc-box.visible {
        transform: none;
    }

    #stage2-upper {
        flex-direction: column;
        align-items: flex-start;
    }

    #cartridge-sprite {
        width: 80px;
        height: 80px;
    }

    .timeline-node.left {
        padding-right: calc(50% + 16px);
    }

    .timeline-node.right {
        padding-left: calc(50% + 16px);
    }

    .node-content {
        max-width: 160px;
    }
}
