/* ============================================================
   layer2.quest -- The Scaling Frontier
   Earth-tone RPG dashboard with dopamine micro-feedback.
   Fonts: Playfair Display (Google Fonts), Source Sans 3 (Google Fonts), Inconsolata.
   Internal panel padding: 20px. Border: 1px solid #b8963a.
   ============================================================ */

:root {
    --bg-deep: #2c2416;
    --panel-surface: #3a3020;
    --panel-surface-2: #443824;
    --border-gold: #b8963a;
    --border-gold-soft: rgba(184, 150, 58, 0.45);
    --text-primary: #e8dcc0;
    --text-secondary: #a09070;
    --gold-bright: #d4a843;
    --gold-deep: #8a6a2a;
    --badge-gray: #5a5040;
    --success-green: #5a8c4a;
    --shadow-quest: 0 12px 40px rgba(0, 0, 0, 0.55);
    --glow-gold: 0 0 18px rgba(184, 150, 58, 0.35);
    --tilt-x: 0deg;
    --tilt-y: 0deg;
    --tilt-lift: 0px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: "Source Sans 3", system-ui, sans-serif;
    overflow-x: hidden;
}

body {
    background:
        radial-gradient(circle at 18% 12%, rgba(184, 150, 58, 0.08), transparent 50%),
        radial-gradient(circle at 82% 88%, rgba(212, 168, 67, 0.06), transparent 55%),
        var(--bg-deep);
    background-attachment: fixed;
}

/* Subtle parchment grain via repeating gradient */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(0deg, rgba(184, 150, 58, 0.025) 0px, rgba(184, 150, 58, 0.025) 1px, transparent 1px, transparent 3px),
        repeating-linear-gradient(90deg, rgba(184, 150, 58, 0.02) 0px, rgba(184, 150, 58, 0.02) 1px, transparent 1px, transparent 4px);
    mix-blend-mode: overlay;
    opacity: 0.55;
    z-index: 1;
}

/* ============================================================
   DASHBOARD GRID
   ============================================================ */

#dashboard {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 8px;
    padding: 12px;
    width: 100vw;
    min-height: 100vh;
    perspective: 1400px;
}

/* ============================================================
   PANEL BASE STYLES
   ============================================================ */

.panel {
    position: relative;
    background: linear-gradient(165deg, var(--panel-surface) 0%, var(--panel-surface-2) 100%);
    border: 1px solid var(--border-gold);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 360ms ease-out, transform 360ms ease-out, box-shadow 220ms ease;
}

.panel.entered {
    opacity: 1;
    transform: translateY(0);
}

/* Animated gold corners drawn after panel enters */
.panel::before,
.panel::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    pointer-events: none;
    border-color: var(--gold-bright);
    border-style: solid;
    border-width: 0;
    opacity: 0;
    transition: opacity 360ms ease-out 200ms;
}
.panel::before { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.panel::after { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }
.panel.entered::before, .panel.entered::after { opacity: 1; }

.panel-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-gold-soft);
    font-family: "Playfair Display", "Source Sans 3", serif;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--gold-bright);
    background: linear-gradient(180deg, rgba(184, 150, 58, 0.08), transparent);
}

.panel-label::before {
    content: "// ";
    color: var(--text-secondary);
    font-family: "Inconsolata", monospace;
    letter-spacing: 0;
}

.panel-meta,
.panel-hint {
    font-family: "Inconsolata", monospace;
    font-size: 10px;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    text-transform: none;
}

.panel-content { padding: 18px 20px; }

/* ============================================================
   TOP BAR
   ============================================================ */

#top-bar {
    grid-row: 1;
}

#hero-title-area {
    padding: 24px 24px 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#hero-title {
    margin: 0;
    font-family: "Playfair Display", serif;
    font-weight: 900;
    font-size: clamp(28px, 4.5vw, 54px);
    letter-spacing: 0.02em;
    color: var(--text-primary);
    line-height: 1.05;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}

#hero-title .cursor {
    display: inline-block;
    width: 0.55ch;
    margin-left: 4px;
    color: var(--gold-bright);
    animation: cursor-blink 900ms steps(2) infinite;
}

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

#hero-subtitle {
    margin: 0;
    font-family: "Playfair Display", serif;
    font-style: italic;
    font-weight: 700;
    font-size: clamp(14px, 1.4vw, 18px);
    color: var(--gold-bright);
    letter-spacing: 0.04em;
}

#hero-meta {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 11px;
    background: rgba(184, 150, 58, 0.06);
    border: 1px solid var(--border-gold-soft);
    font-family: "Inconsolata", monospace;
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}
.chip-key { color: var(--gold-bright); text-transform: uppercase; }
.chip-val { color: var(--text-primary); }

/* ============================================================
   PANEL GRID (2x2)
   ============================================================ */

#panel-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    grid-template-rows: minmax(280px, 1fr) minmax(260px, 1fr);
    gap: 8px;
    grid-template-areas:
        "active stats"
        "inventory map";
}

#active-quest    { grid-area: active; }
#stats-panel     { grid-area: stats; }
#inventory-panel { grid-area: inventory; }
#map-panel       { grid-area: map; }

/* ============================================================
   ACTIVE QUEST PANEL
   ============================================================ */

#active-quest {
    cursor: pointer;
    overflow: hidden;
}

#active-quest .panel-content {
    transform-style: preserve-3d;
    transform: rotateX(var(--tilt-y)) rotateY(var(--tilt-x)) translateZ(var(--tilt-lift));
    transition: transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
}

#active-quest:hover {
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35), 0 6px 24px rgba(0, 0, 0, 0.55), var(--glow-gold);
}

.quest-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px dashed var(--border-gold-soft);
    transform: translateZ(20px);
}

.quest-badge-icon {
    flex-shrink: 0;
    display: inline-flex;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(184, 150, 58, 0.18), transparent 70%);
    box-shadow: 0 0 24px rgba(184, 150, 58, 0.28);
    animation: badge-breathe 3.6s ease-in-out infinite;
}

@keyframes badge-breathe {
    0%, 100% { box-shadow: 0 0 18px rgba(184, 150, 58, 0.28); }
    50%      { box-shadow: 0 0 32px rgba(212, 168, 67, 0.55); }
}

.quest-title-block { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.quest-name {
    margin: 0;
    font-family: "Playfair Display", serif;
    font-weight: 700;
    font-size: clamp(20px, 2.4vw, 30px);
    letter-spacing: 0.01em;
    color: var(--text-primary);
}

.quest-tagline {
    margin: 0;
    font-family: "Playfair Display", serif;
    font-style: italic;
    font-size: 13px;
    color: var(--text-secondary);
}

.quest-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
    transform: translateZ(15px);
}

.meta-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border-gold-soft);
    background: rgba(0, 0, 0, 0.18);
    font-family: "Inconsolata", monospace;
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--text-primary);
}

.meta-key { color: var(--text-secondary); text-transform: uppercase; font-size: 10px; }
.meta-val { color: var(--gold-bright); }

.dot {
    width: 7px; height: 7px; border-radius: 50%;
    display: inline-block;
    background: var(--text-secondary);
}
.dot-active {
    background: var(--gold-bright);
    box-shadow: 0 0 8px var(--gold-bright);
    animation: pulse-dot 1.6s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.4); opacity: 0.65; }
}

.quest-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
    transform: translateZ(10px);
}

.quest-section h3 {
    margin: 0 0 4px 0;
    font-family: "Playfair Display", serif;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--gold-bright);
}

.quest-section p {
    margin: 0;
    font-size: clamp(13px, 1.05vw, 15px);
    line-height: 1.65;
    color: var(--text-primary);
}

.reward-text { font-style: italic; }

.xp-value {
    display: inline-block;
    font-family: "Inconsolata", monospace;
    font-weight: 600;
    color: var(--gold-bright);
    background: rgba(184, 150, 58, 0.12);
    padding: 1px 8px;
    border: 1px solid var(--border-gold-soft);
    letter-spacing: 0.06em;
}

.quest-objectives-list ul {
    margin: 4px 0 0 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.quest-objectives-list li {
    font-family: "Inconsolata", monospace;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    transition: color 180ms ease, transform 180ms ease;
}

.quest-objectives-list li.done { color: var(--success-green); text-decoration: line-through; text-decoration-color: rgba(90, 140, 74, 0.6); }
.quest-objectives-list li.active { color: var(--gold-bright); }

.quest-objectives-list .check {
    width: 16px;
    text-align: center;
    color: inherit;
    font-size: 12px;
}

.quest-action-row {
    display: flex;
    gap: 10px;
    margin-top: 6px;
    transform: translateZ(8px);
}

.quest-btn {
    font-family: "Inconsolata", monospace;
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    padding: 8px 14px;
    background: transparent;
    color: var(--gold-bright);
    border: 1px solid var(--border-gold-soft);
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease, transform 120ms ease, box-shadow 180ms ease;
}

.quest-btn:hover {
    background: rgba(184, 150, 58, 0.14);
    box-shadow: var(--glow-gold);
}

.quest-btn:active { transform: translateY(1px); }

.quest-btn.primary {
    background: linear-gradient(180deg, var(--border-gold), var(--gold-deep));
    color: var(--bg-deep);
    border-color: var(--gold-bright);
    font-weight: 600;
}

.quest-btn.primary:hover {
    background: linear-gradient(180deg, var(--gold-bright), var(--border-gold));
    box-shadow: 0 0 22px rgba(212, 168, 67, 0.6);
}

/* ============================================================
   STATS PANEL
   ============================================================ */

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 16px;
}

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

.stat-info {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: "Inconsolata", monospace;
    font-size: 12px;
    letter-spacing: 0.05em;
}

.stat-name { color: var(--text-primary); }
.stat-value {
    color: var(--gold-bright);
    font-family: "Playfair Display", serif;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.02em;
}

.progress-bar-track {
    position: relative;
    height: 12px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.4);
    overflow: visible;
    border: 1px solid var(--border-gold-soft);
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.6);
}

.progress-bar-fill {
    position: relative;
    height: 100%;
    width: 0%;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--gold-deep) 0%, var(--border-gold) 50%, var(--gold-bright) 100%);
    box-shadow: 0 0 10px rgba(184, 150, 58, 0.45);
    transition: width 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.progress-bar-fill::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 6px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
    background-size: 200% 100%;
    animation: shine-sweep 3s linear infinite;
}

@keyframes shine-sweep {
    0% { background-position: -120% 0; }
    100% { background-position: 220% 0; }
}

.sparkle {
    position: absolute;
    top: 50%;
    right: -2px;
    width: 22px;
    height: 22px;
    transform: translate(50%, -50%) scale(0);
    background: radial-gradient(circle, rgba(255, 230, 160, 0.95), rgba(212, 168, 67, 0.45) 35%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
}

.sparkle.firing { animation: sparkle-fire 360ms ease-out forwards; }

@keyframes sparkle-fire {
    0%   { transform: translate(50%, -50%) scale(0); opacity: 1; }
    50%  { transform: translate(50%, -50%) scale(1.8); opacity: 1; }
    100% { transform: translate(50%, -50%) scale(0.4); opacity: 0; }
}

.total-xp {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border-gold-soft);
}

.xp-pair {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: flex-start;
}

.xp-label {
    font-family: "Inconsolata", monospace;
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.xp-number {
    font-family: "Playfair Display", serif;
    font-weight: 900;
    font-size: 22px;
    color: var(--gold-bright);
    letter-spacing: 0.02em;
    text-shadow: 0 0 12px rgba(212, 168, 67, 0.4);
}

/* ============================================================
   INVENTORY PANEL
   ============================================================ */

.badge-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 16px;
}

.badge {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 56px;
    margin: 0 auto;
    border-radius: 50%;
    border: 1px solid var(--border-gold);
    background: radial-gradient(circle at 30% 30%, rgba(184, 150, 58, 0.18), transparent 70%), var(--panel-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.6);
    transition: transform 200ms ease, box-shadow 200ms ease, opacity 240ms ease;
}

.badge.appeared { opacity: 1; transform: scale(1); }

.badge svg { width: 70%; height: 70%; }

.badge.earned {
    box-shadow: 0 0 0 1px var(--border-gold), 0 0 18px rgba(184, 150, 58, 0.32);
}

.badge.earned:hover {
    transform: scale(1.12);
    box-shadow: 0 0 0 1px var(--gold-bright), 0 0 28px rgba(212, 168, 67, 0.6);
}

.badge.locked {
    border-color: var(--badge-gray);
    background: var(--panel-surface);
    filter: grayscale(1) blur(0.6px);
    opacity: 0.7;
}
.badge.locked.appeared { opacity: 0.55; }

.badge.locked:hover {
    filter: grayscale(0.7) blur(0.4px);
    opacity: 0.9;
}

.inventory-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-gold-soft);
    font-family: "Inconsolata", monospace;
    font-size: 11px;
    letter-spacing: 0.06em;
}

.foot-key { color: var(--text-secondary); text-transform: uppercase; }
.foot-val { color: var(--gold-bright); }

/* ============================================================
   MAP PANEL
   ============================================================ */

#map-panel .panel-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

#network-map {
    width: 100%;
    max-width: 360px;
    height: auto;
}

.map-line {
    stroke: var(--badge-gray);
    stroke-width: 1;
    stroke-dasharray: 2 4;
    opacity: 0.7;
    transition: stroke 220ms ease, stroke-width 220ms ease;
}

.map-node {
    cursor: pointer;
    transition: transform 200ms ease;
    transform-origin: center;
    transform-box: fill-box;
}

.map-node circle {
    transition: fill 200ms ease, stroke 200ms ease;
}

.map-node:hover circle {
    fill: var(--panel-surface-2);
    stroke: var(--gold-bright);
}

.map-node.highlighted circle {
    stroke: var(--gold-bright) !important;
    stroke-width: 1.5 !important;
}

.map-node.active-node circle {
    fill: rgba(212, 168, 67, 0.16);
    stroke: var(--gold-bright);
    animation: node-pulse 3s ease-in-out infinite;
    transform-origin: center;
}

.map-node.active-node {
    animation: node-tilt 4s ease-in-out infinite;
}

@keyframes node-pulse {
    0%, 100% {
        filter: drop-shadow(0 0 4px rgba(212, 168, 67, 0.5));
    }
    50% {
        filter: drop-shadow(0 0 14px rgba(212, 168, 67, 0.95));
    }
}

@keyframes node-tilt {
    0%, 100% { transform: rotate(-1.5deg) scale(1); }
    50%      { transform: rotate(1.5deg) scale(1.06); }
}

.map-legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
    font-family: "Inconsolata", monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot {
    width: 8px; height: 8px; border-radius: 50%;
    border: 1px solid var(--border-gold-soft);
}
.legend-active { background: var(--gold-bright); box-shadow: 0 0 6px var(--gold-bright); }
.legend-known  { background: var(--border-gold); }
.legend-unknown { background: var(--badge-gray); }

/* ============================================================
   STATUS BAR (FOOTER)
   ============================================================ */

#status-bar {
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 10px 16px;
    gap: 14px;
    font-family: "Inconsolata", monospace;
    font-size: 11px;
    letter-spacing: 0.08em;
}

.status-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 2px solid var(--border-gold-soft);
    padding-left: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.status-cell:first-child { border-left: none; padding-left: 0; }

.status-key {
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 10px;
}
.status-val { color: var(--gold-bright); }

/* ============================================================
   TOOLTIP
   ============================================================ */

.tooltip {
    position: fixed;
    pointer-events: none;
    padding: 6px 12px;
    background: var(--panel-surface-2);
    color: var(--gold-bright);
    border: 1px solid var(--border-gold);
    font-family: "Inconsolata", monospace;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
    opacity: 0;
    transform: translate(-50%, -120%) translateY(4px);
    transition: opacity 160ms ease, transform 160ms ease;
    z-index: 100;
}

.tooltip.visible {
    opacity: 1;
    transform: translate(-50%, -120%);
}

/* ============================================================
   CONFETTI CANVAS
   ============================================================ */

#confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
}

/* ============================================================
   EXPANDED STATE (modal-like)
   ============================================================ */

#dashboard.has-expanded .panel:not(.expanded) {
    opacity: 0.18;
    pointer-events: none;
    transition: opacity 280ms ease-out;
}

.panel.expanded {
    position: fixed !important;
    inset: 24px;
    z-index: 50;
    overflow: auto;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.75), 0 0 0 1px var(--gold-bright), 0 0 60px rgba(212, 168, 67, 0.3);
    transition: inset 400ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 400ms ease-out, opacity 280ms;
    transform: translateY(0);
}

.panel.expanded .quest-details {
    animation: slide-reveal 320ms ease-out 80ms backwards;
}

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

.panel.expanded .panel-hint::before {
    content: "Press ";
}
.panel.expanded .panel-hint {
    color: var(--gold-bright);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 900px) {
    #panel-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        grid-template-areas:
            "active"
            "stats"
            "inventory"
            "map";
    }
    #status-bar { grid-template-columns: 1fr 1fr; }
    .badge-grid { grid-template-columns: repeat(6, 1fr); }
    #hero-meta { gap: 6px; }
    .meta-chip { font-size: 10px; }
}

@media (max-width: 540px) {
    #dashboard { padding: 8px; }
    .badge-grid { grid-template-columns: repeat(4, 1fr); }
    #status-bar { grid-template-columns: 1fr; }
    .total-xp { grid-template-columns: 1fr 1fr 1fr; }
}
