/* The Endless Anvil - forge-at-dusk theme */
:root {
    --bg-0: #0b0a12;
    --bg-1: #17162a;
    --bg-2: #232140;
    --panel: rgba(28, 26, 48, 0.88);
    --ink: #f3ebd9;
    --muted: #a39dbd;
    --ember: #ff8a3d;
    --ember-dark: #b94a14;
    --brass: #e3b34f;
    --brass-dark: #8d6a22;
    --teal: #3fb6a8;
    --danger: #e0614f;
    --font-main: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-title: Georgia, 'Palatino Linotype', 'Book Antiqua', serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background-color: var(--bg-0);
    font-family: var(--font-main);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    color: var(--ink);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* --- Main Game Container --- */
.game-container {
    width: 100%;
    height: 100%;
    max-width: 800px;
    max-height: 480px;
    background:
        linear-gradient(rgba(16, 15, 30, 0.80), rgba(16, 15, 30, 0.86)),
        url('assets/bg-forge.jpg') center / cover no-repeat,
        linear-gradient(160deg, #1d1b34, #100f1d);
    position: relative;
    border: 1px solid #2f2c4d;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(255, 138, 61, 0.10), 0 0 0 1px #000;
    user-select: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Title Bar --- */
.game-title-bar {
    color: var(--brass);
    font-family: var(--font-title);
    letter-spacing: 3px;
    text-transform: uppercase;
    text-align: center;
    font-size: 10px;
    padding: 3px 0;
    background: rgba(0, 0, 0, 0.35);
    border-bottom: 1px solid #2f2c4d;
}

/* --- Top Bar --- */
.top-bar {
    height: 50px;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
    background: linear-gradient(to bottom, rgba(45, 41, 78, 0.9), rgba(26, 24, 46, 0.9));
    border-bottom: 2px solid var(--brass-dark);
}

.top-buttons { display: flex; gap: 6px; }

.currency-ribbon {
    background: rgba(0, 0, 0, 0.45);
    padding: 5px 22px;
    border: 1px solid var(--brass);
    border-radius: 999px;
    box-shadow: inset 0 0 8px rgba(227, 179, 79, 0.25);
    font-family: var(--font-title);
    font-weight: bold;
    font-size: 18px;
    color: var(--brass);
    min-width: 200px;
    text-align: center;
}

/* --- Main Content Area --- */
.game-body { display: flex; flex-grow: 1; overflow: hidden; }

/* --- Buttons --- */
.btn-forge {
    width: 60px;
    height: 60px;
    background: linear-gradient(to bottom, #3a3664, #26234a);
    border: 1px solid var(--brass-dark);
    border-radius: 10px;
    color: var(--ink);
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 2px 4px rgba(0, 0, 0, 0.5);
    font-weight: bold;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    position: relative;
    z-index: 2;
}
.btn-forge:hover { border-color: var(--brass); }
.btn-forge:active {
    background: linear-gradient(to bottom, #26234a, #3a3664);
    transform: translateY(1px);
}
.btn-small { width: 40px; height: 34px; font-size: 16px; flex-direction: row; }
.btn-wide { width: 100%; height: 32px; margin-bottom: 5px; font-size: 13px; }
.btn-buy { border-color: var(--teal); color: #aef0e6; }

/* --- Middle Column --- */
.mid-col {
    flex-grow: 1;
    padding: 10px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.panel-header {
    background: linear-gradient(to bottom, #3a3664, #26234a);
    color: var(--brass);
    font-family: var(--font-title);
    padding: 6px 10px;
    border: 1px solid var(--brass-dark);
    border-radius: 8px;
    font-weight: bold;
    text-align: center;
}

/* --- Progress Bar --- */
.progress-container {
    height: 28px;
    background: #0d0c18;
    border: 2px solid #3a3664;
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(to bottom, #ffb35c, var(--ember) 50%, var(--ember-dark));
    box-shadow: 0 0 10px rgba(255, 138, 61, 0.6);
    border-radius: 14px;
    transition: width 0.1s linear;
}
.progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
}

/* --- Views / Station Rows --- */
.view-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    gap: 6px;
}

.station-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 5px 8px;
    background: var(--panel);
    border: 1px solid #2f2c4d;
    border-radius: 12px;
}

.station-icon {
    flex-shrink: 0;
    width: 58px;
    height: 58px;
    padding: 0;
    overflow: hidden;
}
.station-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 9px;
    pointer-events: none;
    font-size: 26px;
    line-height: 58px;
    text-align: center;
}

.station-controls {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.selector-row {
    display: flex;
    align-items: center;
    height: 24px;
    background: #0d0c18;
    border: 1px solid var(--brass-dark);
    border-radius: 12px;
    overflow: hidden;
}

.arrow-btn {
    background: transparent;
    color: var(--brass);
    border: none;
    width: 30px;
    height: 100%;
    cursor: pointer;
    font-size: 11px;
}
.arrow-btn:hover { background: rgba(227, 179, 79, 0.15); }
.arrow-btn:active { background: rgba(227, 179, 79, 0.3); }
.arrow-btn.new-unlock {
    background: var(--ember);
    color: #1a0a00;
    box-shadow: 0 0 8px var(--ember);
}

.selector-display {
    flex-grow: 1;
    text-align: center;
    font-size: 12px;
    font-weight: bold;
    color: var(--ink);
}

/* --- Upgrades View --- */
.upgrade-list {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    padding: 6px 2px;
    overflow-y: auto;
    align-content: start;
}

.btn-upgrade {
    width: 100%;
    height: 52px;
    padding: 4px;
    font-size: 10px;
    font-weight: bold;
    font-family: var(--font-main);
    background: linear-gradient(to bottom, #34305c, #221f40);
    border: 1px solid var(--brass-dark);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--ink);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
}
.btn-upgrade:hover { border-color: var(--brass); }
.btn-upgrade:active { transform: translateY(1px); }

.btn-upgrade:disabled, .btn-upgrade.btn-disabled {
    background: #16152a;
    border-color: #2a2848;
    color: #6f6a8c;
    cursor: default;
    pointer-events: none;
    box-shadow: none;
}
.btn-upgrade:disabled .cost-text, .btn-upgrade.btn-disabled .cost-text { color: #8a5a54; }

.upgrade-col-header {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 34px;
    font-size: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}
.hdr-icon { height: 28px; width: 28px; object-fit: cover; border-radius: 6px; }

/* --- Right Column: Inventory --- */
.right-col {
    width: 270px;
    background: var(--panel);
    border-left: 2px solid var(--brass-dark);
    display: flex;
    flex-direction: column;
    color: var(--ink);
}

.inv-header {
    padding: 7px;
    text-align: center;
    font-family: var(--font-title);
    font-weight: bold;
    letter-spacing: 1px;
    color: var(--brass);
    background: rgba(0, 0, 0, 0.35);
    border-bottom: 1px solid var(--brass-dark);
}

.inv-list { flex-grow: 1; overflow-y: auto; padding: 6px; font-size: 11px; }

.inv-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 2px;
    border-bottom: 1px solid #2a2848;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #100f1d; }
::-webkit-scrollbar-thumb { background: #3a3664; border-radius: 3px; }

/* Helpers */
.hidden { display: none !important; }
.text-yellow { color: var(--brass); font-weight: bold; }
.cost-text { font-weight: bold; color: #ffb35c; }

/* Pulse (reserved) */
@keyframes pulse {
    0% { box-shadow: 0 0 5px var(--ember); }
    50% { box-shadow: 0 0 15px var(--ember); }
    100% { box-shadow: 0 0 5px var(--ember); }
}
.active-task-pulse { animation: pulse 1s infinite; }

/* --- Offline Popup --- */
#offline-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 480px;
    background: linear-gradient(to bottom, #2b2850, #1a1830);
    border: 2px solid var(--brass-dark);
    border-radius: 14px;
    color: var(--ink);
    padding: 20px;
    z-index: 200;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
#offline-text {
    font-size: 14px;
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border: 1px solid #2f2c4d;
    border-radius: 8px;
    line-height: 1.6;
}
#offline-popup .btn-forge { width: 120px; height: 40px; align-self: center; font-size: 14px; }

/* --- Toast --- */
#toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.85);
    color: var(--ink);
    border: 1px solid var(--brass-dark);
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 300;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    html:not(.app-fit) .game-container { max-width: 100%; max-height: 100%; border: none; border-radius: 0; }
    html:not(.app-fit) .top-bar { height: auto; flex-wrap: wrap; padding: 5px; justify-content: center; }
    html:not(.app-fit) .currency-ribbon { width: 100%; margin-bottom: 5px; order: -1; }
    html:not(.app-fit) .game-body { flex-direction: column; }
    html:not(.app-fit) .right-col { width: 100%; height: 40%; border-left: none; border-top: 2px solid var(--brass-dark); }
    html:not(.app-fit) .station-icon { width: 46px; height: 46px; }
    html:not(.app-fit) .station-img { line-height: 46px; }
    html:not(.app-fit) .upgrade-list { grid-template-columns: repeat(5, 1fr); }
}


/* ---- Reforge screen ---- */
.reforge-body { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; padding-bottom: 6px; }
.rf-card { background: rgba(255,255,255,0.04); border: 1px solid var(--brass-dark); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.rf-dim { color: var(--muted); font-size: 11px; }
.rf-note { color: var(--muted); font-size: 11px; padding: 0 2px; }
.rf-perk { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: rgba(255,255,255,0.04); border: 1px solid #3a3860; border-radius: 10px; padding: 6px 10px; }
.rf-perk-name { font-weight: bold; font-size: 13px; color: var(--brass); }
.rf-perk-desc { font-size: 11px; color: var(--ink); }
.rf-buy { min-width: 84px; height: 30px; font-size: 12px; }
.btn-forge:disabled { opacity: 0.5; cursor: default; }
.btn-forge.ready { border-color: var(--ember); box-shadow: 0 0 10px var(--ember); }


/* ---- Android app: the 800x480 game is scaled to fit below the top banner (see ads.js) ---- */
.app-fit body { display: block; height: 100vh; overflow: hidden; }
.app-fit .game-container {
    position: absolute;
    width: 800px; height: 480px;
    max-width: none; max-height: none;
    transform-origin: 0 0;
    border: none; border-radius: 0; box-shadow: none;
}
