/* === layer2.quest - RPG Quest Dashboard === */

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

:root {
    --bg-deep: #2c2416;
    --panel-surface: #3a3020;
    --border-gold: #b8963a;
    --text-primary: #e8dcc0;
    --text-secondary: #a09070;
    --gold-bright: #d4a843;
    --gold-dark: #8a6a2a;
    --badge-gray: #5a5040;
    --success-green: #5a8c4a;
    --font-serif: 'Playfair Display', Georgia, serif;
    --font-sans: 'Source Sans 3', 'Segoe UI', sans-serif;
    --font-mono: 'Inconsolata', 'Courier New', monospace;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: clamp(14px, 1.4vw, 17px);
    line-height: 1.65;
}

/* ---- Dashboard Layout ---- */
#dashboard {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
}

/* ---- Panel Base Styles ---- */
.panel {
    background: var(--panel-surface);
    border: 1px solid transparent;
    border-radius: 2px;
    position: relative;
    overflow: hidden;
    opacity: 0;
}

.panel.revealed {
    opacity: 1;
}

/* Border draw animation: using clip-path to trace the border */
.panel.border-drawing {
    border-color: var(--border-gold);
    animation: draw-border 0.3s ease-out forwards;
}

@keyframes draw-border {
    0% {
        clip-path: polygon(0 0, 0 0, 0 0, 0 0);
    }
    25% {
        clip-path: polygon(0 0, 100% 0, 100% 0, 0 0);
    }
    50% {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 100% 100%);
    }
    75% {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
    }
    100% {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
    }
}

.panel.revealed {
    border-color: var(--border-gold);
    clip-path: none;
}

/* Panel reveal with border trace */
.panel.revealing {
    animation: panel-reveal 0.35s ease-out forwards;
}

@keyframes panel-reveal {
    0% {
        opacity: 0;
        clip-path: inset(0 100% 100% 0);
    }
    40% {
        opacity: 1;
        clip-path: inset(0 0 100% 0);
    }
    70% {
        clip-path: inset(0 0 0 0);
    }
    100% {
        opacity: 1;
        clip-path: inset(0 0 0 0);
    }
}

.panel-title-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    border-bottom: 1px solid rgba(184, 150, 58, 0.3);
    background: rgba(44, 36, 22, 0.6);
}

.panel-label {
    font-family: var(--font-serif);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--border-gold);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.panel.revealed .panel-label {
    opacity: 1;
}

.panel-hint {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity 0.4s ease 0.2s;
}

.panel.revealed .panel-hint {
    opacity: 0.6;
}

.panel-content {
    padding: 20px;
    height: calc(100% - 34px);
    overflow-y: auto;
}

/* Scrollbar styling */
.panel-content::-webkit-scrollbar {
    width: 4px;
}

.panel-content::-webkit-scrollbar-track {
    background: var(--bg-deep);
}

.panel-content::-webkit-scrollbar-thumb {
    background: var(--border-gold);
    border-radius: 2px;
}

/* ---- Top Bar ---- */
#top-bar {
    flex-shrink: 0;
    min-height: 80px;
}

#hero-title-area {
    padding: 10px 20px 14px;
    text-align: left;
}

#hero-title {
    font-family: var(--font-serif);
    font-weight: 900;
    font-size: clamp(24px, 4vw, 48px);
    letter-spacing: 0.02em;
    color: var(--text-primary);
    line-height: 1.1;
    min-height: 1.2em;
}

#hero-title .cursor {
    display: inline-block;
    width: 3px;
    height: 0.9em;
    background: var(--border-gold);
    margin-left: 2px;
    vertical-align: baseline;
    animation: blink-cursor 0.7s step-end infinite;
}

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

#hero-subtitle {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: clamp(12px, 1.5vw, 18px);
    color: var(--text-secondary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#hero-subtitle.visible {
    opacity: 1;
}

/* ---- Panel Grid ---- */
#panel-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    min-height: 0;
}

/* ---- Active Quest Panel ---- */
#active-quest {
    cursor: pointer;
    transition: transform 0.15s ease-out, box-shadow 0.3s ease;
    transform-style: preserve-3d;
    will-change: transform;
}

#active-quest:hover {
    border-color: var(--gold-bright);
    box-shadow: 0 0 20px rgba(184, 150, 58, 0.1);
}

.quest-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.quest-badge-icon svg {
    display: block;
}

.quest-name {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: clamp(18px, 2.5vw, 30px);
    letter-spacing: 0.02em;
    color: var(--text-primary);
}

.quest-details {
    opacity: 1;
}

.quest-section {
    margin-bottom: 14px;
}

.quest-section h3 {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--border-gold);
    margin-bottom: 4px;
}

.quest-section p {
    font-family: var(--font-sans);
    font-size: clamp(13px, 1.2vw, 15px);
    color: var(--text-secondary);
    line-height: 1.6;
}

.reward-text {
    color: var(--text-primary);
}

.xp-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--success-green);
    font-size: 15px;
    letter-spacing: 0.04em;
}

/* Expanded state */
#active-quest.expanded {
    position: fixed;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 100;
    border-color: var(--gold-bright);
    overflow-y: auto;
    box-shadow: 0 0 60px rgba(184, 150, 58, 0.15), 0 0 120px rgba(44, 36, 22, 0.8);
    animation: expand-panel 0.4s ease-out forwards;
}

@keyframes expand-panel {
    0% {
        opacity: 0.8;
    }
    100% {
        opacity: 1;
    }
}

#active-quest.expanded .panel-content {
    overflow-y: auto;
}

#active-quest.expanded .panel-hint {
    opacity: 0;
}

#active-quest.expanded .quest-details {
    animation: slide-reveal 0.3s ease-out 0.1s both;
}

@keyframes slide-reveal {
    0% {
        opacity: 0;
        transform: translateY(40px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dim other panels when quest is expanded */
.panels-dimmed .panel:not(.expanded) {
    opacity: 0.2 !important;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* ---- Stats Panel ---- */
.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stat-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-info {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.stat-name {
    font-family: var(--font-serif);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text-primary);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--border-gold);
}

.progress-bar-track {
    width: 100%;
    height: 10px;
    background: var(--bg-deep);
    border-radius: 5px;
    overflow: visible;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 5px;
    background: linear-gradient(to right, var(--border-gold), var(--gold-dark));
    transition: width 1.2s ease-out;
    position: relative;
}

.sparkle {
    position: absolute;
    top: 50%;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(212, 168, 67, 0.95), rgba(184, 150, 58, 0) 70%);
    transform: translateY(-50%) scale(0);
    opacity: 0;
    pointer-events: none;
}

.sparkle.flash {
    animation: sparkle-flash 0.4s ease-out forwards;
}

@keyframes sparkle-flash {
    0% { transform: translateY(-50%) scale(0); opacity: 1; }
    30% { transform: translateY(-50%) scale(3); opacity: 0.9; }
    60% { transform: translateY(-50%) scale(1.5); opacity: 0.5; }
    100% { transform: translateY(-50%) scale(0); opacity: 0; }
}

.total-xp {
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px solid rgba(184, 150, 58, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.xp-label {
    font-family: var(--font-serif);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
}

.xp-number {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--success-green);
}

/* ---- Inventory Panel ---- */
.badge-grid {
    display: grid;
    grid-template-columns: repeat(4, 40px);
    gap: 10px;
    justify-content: center;
}

.badge {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
}

.badge.visible {
    opacity: 1;
}

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

.badge.earned {
    box-shadow: 0 0 10px rgba(184, 150, 58, 0.2);
}

.badge.earned:hover {
    transform: scale(1.15);
    box-shadow: 0 0 20px rgba(184, 150, 58, 0.45);
}

.badge.locked {
    border-color: var(--badge-gray);
    filter: blur(1px) grayscale(1);
    opacity: 0;
}

.badge.locked.visible {
    opacity: 0.5;
}

/* Badge tooltip */
.tooltip {
    position: fixed;
    padding: 5px 10px;
    background: var(--panel-surface);
    border: 1px solid var(--border-gold);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    border-radius: 2px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 200;
    white-space: nowrap;
}

.tooltip.active {
    opacity: 1;
    transform: translateY(0);
}

/* ---- Map Panel ---- */
#network-map {
    width: 100%;
    height: 100%;
    display: block;
}

.map-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 0.8s ease-out;
}

.map-line.drawn {
    stroke-dashoffset: 0;
}

.map-node {
    opacity: 0;
    transition: opacity 0.4s ease;
}

.map-node.visible {
    opacity: 1;
}

.map-node circle {
    transition: stroke 0.3s ease, stroke-width 0.3s ease, filter 0.3s ease;
}

.map-node:hover circle {
    stroke: var(--gold-bright);
    stroke-width: 2;
    filter: drop-shadow(0 0 8px rgba(212, 168, 67, 0.5));
}

.active-node circle {
    animation: pulse-node 3s ease-in-out infinite;
}

@keyframes pulse-node {
    0%, 100% {
        stroke-width: 2;
        filter: drop-shadow(0 0 4px rgba(212, 168, 67, 0.3));
    }
    50% {
        stroke-width: 3;
        filter: drop-shadow(0 0 12px rgba(212, 168, 67, 0.7));
    }
}

/* ---- Confetti Canvas ---- */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 300;
}

/* ---- Background subtle texture ---- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(184, 150, 58, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 30%, rgba(138, 106, 42, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

#dashboard {
    position: relative;
    z-index: 1;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    #panel-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    #dashboard {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    html, body {
        overflow: auto;
    }

    .panel-content {
        max-height: 300px;
    }

    #active-quest.expanded {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
    }

    .badge-grid {
        grid-template-columns: repeat(4, 40px);
    }
}

@media (max-width: 480px) {
    #hero-title {
        font-size: 24px;
    }

    .badge-grid {
        grid-template-columns: repeat(3, 40px);
    }
}
