* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #1a0a2e;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: calc(100dvh * 800 / 600);
    max-height: calc(100vw * 600 / 800);
    border: none;
    border-radius: 0;
    box-shadow: none;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #2d5a1e;
    image-rendering: pixelated;
}

.hidden {
    display: none !important;
}

/* Title Screen */
#title-screen {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    isolation: isolate;
    overflow: hidden;
    background-color: #050b17;
    background-image: url("../assets/images/title-screen-background.png");
    background-position: center;
    background-size: cover;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(18px, 3.2vh, 34px);
    padding: clamp(24px, 5vh, 52px) clamp(20px, 5vw, 56px);
    z-index: 100;
}

#title-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -2;
    background:
        linear-gradient(180deg, rgba(2, 8, 21, 0.22) 0%, rgba(2, 7, 18, 0.04) 45%, rgba(2, 7, 16, 0.36) 100%),
        radial-gradient(ellipse at 50% 38%, rgba(6, 13, 31, 0.06) 0%, rgba(3, 9, 22, 0.58) 78%);
}

#title-screen::after {
    content: "";
    position: absolute;
    inset: 10px;
    z-index: 4;
    pointer-events: none;
    border: 1px solid rgba(229, 169, 53, 0.72);
    box-shadow:
        inset 0 0 0 3px rgba(7, 13, 25, 0.75),
        inset 0 0 0 5px rgba(177, 120, 28, 0.42),
        inset 0 0 38px rgba(0, 0, 0, 0.72);
}

.title-atmosphere {
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(circle at 17% 26%, rgba(54, 134, 255, 0.18) 0 2px, transparent 4px),
        radial-gradient(circle at 22% 29%, rgba(95, 244, 141, 0.16) 0 2px, transparent 5px),
        radial-gradient(circle at 17% 33%, rgba(255, 90, 70, 0.12) 0 2px, transparent 5px),
        linear-gradient(90deg, rgba(3, 8, 18, 0.34), transparent 28%, transparent 72%, rgba(3, 8, 18, 0.28));
}

.title-lockup {
    display: flex;
    flex-direction: column;
    align-items: center;
    filter: drop-shadow(0 8px 7px rgba(0, 0, 0, 0.85));
}

.title-crest {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 13px;
    height: 30px;
    margin-bottom: 2px;
    color: #e7af3f;
    text-shadow: 0 2px 0 #5a330c, 0 0 10px rgba(244, 179, 54, 0.5);
}

.crest-crown {
    font-size: clamp(22px, 3.4vw, 34px);
    line-height: 1;
    transform: translateY(-2px);
}

.crest-sword {
    font-size: clamp(15px, 2vw, 21px);
    color: #d1d6dc;
    text-shadow: 0 2px 0 #1b2028, 0 0 6px rgba(255, 255, 255, 0.35);
}

.crest-sword-left { transform: rotate(-14deg); }
.crest-sword-right { transform: scaleX(-1) rotate(-14deg); }

#title-screen h1 {
    margin: 0;
    color: #efbc55;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(46px, 8vw, 82px);
    font-weight: 800;
    line-height: 0.98;
    letter-spacing: clamp(1px, 0.4vw, 4px);
    text-align: center;
    white-space: nowrap;
    text-shadow:
        0 2px 0 #ffe292,
        0 5px 0 #8a500f,
        0 8px 0 #2d1b09,
        0 13px 18px rgba(0, 0, 0, 0.96),
        0 0 24px rgba(220, 151, 34, 0.2);
}

.subtitle-row {
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(94%, 620px);
    gap: 14px;
    margin-top: 17px;
}

.subtitle {
    flex: none;
    color: #b9ccff;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(15px, 2.65vw, 22px);
    font-weight: 600;
    font-style: italic;
    letter-spacing: 0.4px;
    text-shadow: 0 2px 4px #000, 0 0 15px rgba(102, 144, 255, 0.45);
}

.subtitle-rule {
    position: relative;
    flex: 1;
    min-width: 40px;
    height: 1px;
    background: linear-gradient(90deg, transparent, #bc791a);
    box-shadow: 0 1px 0 rgba(255, 210, 98, 0.28);
}

.subtitle-rule:last-child {
    background: linear-gradient(90deg, #bc791a, transparent);
}

.title-menu {
    position: relative;
    width: min(560px, 86%);
    padding: clamp(24px, 4vh, 34px) clamp(22px, 5vw, 52px) clamp(19px, 3vh, 27px);
    background:
        linear-gradient(180deg, rgba(12, 21, 40, 0.97), rgba(5, 11, 24, 0.98)),
        radial-gradient(circle at 50% 0, rgba(52, 83, 133, 0.18), transparent 55%);
    border: 2px solid #9b6922;
    clip-path: polygon(18px 0, calc(100% - 18px) 0, 100% 18px, 100% calc(100% - 18px), calc(100% - 18px) 100%, 18px 100%, 0 calc(100% - 18px), 0 18px);
    box-shadow:
        inset 0 0 0 2px #111a29,
        inset 0 0 0 4px rgba(225, 166, 60, 0.2),
        inset 0 18px 38px rgba(38, 59, 100, 0.15),
        0 13px 32px rgba(0, 0, 0, 0.72),
        0 0 28px rgba(0, 0, 0, 0.3);
}

.title-menu::before,
.title-menu::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    background: #e0a634;
    border: 2px solid #4f300c;
    transform: rotate(45deg);
    top: 12px;
}

.title-menu::before { left: 14px; }
.title-menu::after { right: 14px; }

.menu-ornament {
    position: absolute;
    top: -10px;
    left: 50%;
    display: flex;
    align-items: center;
    width: 58%;
    transform: translateX(-50%);
    color: #e5aa37;
}

.menu-ornament span {
    flex: 1;
    height: 2px;
    background: linear-gradient(90deg, transparent, #b97b1d);
}

.menu-ornament span:last-child {
    background: linear-gradient(90deg, #b97b1d, transparent);
}

.menu-ornament b {
    padding: 0 10px;
    font-size: 13px;
    text-shadow: 0 0 8px rgba(255, 191, 62, 0.6);
}

.menu-kicker {
    margin-bottom: 14px;
    color: #e7b854;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(15px, 2.2vw, 18px);
    font-weight: 700;
    letter-spacing: 3px;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 0 2px 3px #000;
}

.title-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 190px;
    margin: 7px;
    padding: 13px 30px;
    border: 1px solid #cb8b25;
    border-radius: 2px;
    background: linear-gradient(180deg, #543611 0%, #2b1b0b 100%);
    box-shadow:
        inset 0 0 0 2px #17110a,
        inset 0 0 0 3px rgba(238, 180, 67, 0.38),
        0 5px 0 #090705,
        0 7px 12px rgba(0, 0, 0, 0.6);
    color: #f5eddc;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1.2;
    text-shadow: 0 2px 2px #000;
    cursor: pointer;
    transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
}

.menu-btn-primary {
    background: linear-gradient(180deg, #a56a15 0%, #68400e 100%);
    border-color: #f0b641;
    color: #fff8e7;
}

.menu-btn:hover,
.menu-btn:focus-visible {
    filter: brightness(1.2);
    outline: none;
    box-shadow:
        inset 0 0 0 2px #17110a,
        inset 0 0 0 3px rgba(255, 215, 111, 0.6),
        0 5px 0 #090705,
        0 0 18px rgba(240, 175, 52, 0.42);
    transform: translateY(-2px);
}

.menu-btn:active {
    transform: translateY(2px);
    box-shadow:
        inset 0 0 0 2px #17110a,
        inset 0 0 0 3px rgba(255, 215, 111, 0.45),
        0 2px 0 #090705;
}

.menu-note {
    margin-top: 12px;
    color: #8493ad;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 12px;
    font-style: italic;
    letter-spacing: 0.5px;
    text-align: center;
}

.title-version {
    position: absolute;
    bottom: 23px;
    left: 50%;
    color: rgba(205, 215, 232, 0.7);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 10px;
    letter-spacing: 2px;
    text-shadow: 0 2px 3px #000;
    text-transform: uppercase;
    transform: translateX(-50%);
    white-space: nowrap;
}

/* Controls Screen */
#controls-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        linear-gradient(rgba(4, 9, 20, 0.89), rgba(4, 9, 20, 0.95)),
        url("../assets/images/title-screen-background.png") center / cover;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#controls-screen h2 {
    color: #efbc55;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 34px;
    margin-bottom: 20px;
    text-shadow: 0 3px 0 #5d360d, 0 7px 12px #000;
}

.controls-list {
    width: min(520px, 84%);
    margin-bottom: 16px;
    padding: 14px 22px;
    background: rgba(7, 14, 29, 0.94);
    border: 2px solid #9b6922;
    box-shadow: inset 0 0 0 3px rgba(223, 168, 65, 0.12), 0 10px 30px rgba(0, 0, 0, 0.6);
}

.control-item {
    color: #ddd;
    font-size: 16px;
    margin: 8px 0;
}

.key {
    display: inline-block;
    background: #333;
    color: #ffd700;
    padding: 3px 10px;
    border-radius: 3px;
    border: 1px solid #666;
    min-width: 100px;
    text-align: center;
    margin-right: 10px;
    font-family: monospace;
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#hud-top {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 8px 12px;
    background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
}

#health-bar {
    position: relative;
    width: 180px;
    height: 22px;
    background: #333;
    border: 2px solid #888;
    border-radius: 3px;
    overflow: hidden;
}

#health-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #4caf50 0%, #2e7d32 100%);
    transition: width 0.3s;
}

#health-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    text-shadow: 1px 1px 2px #000;
}

#gem-counter, #gold-counter, #arrow-counter, #green-gem-counter, #potion-counter, #sky-counter,
#apple-counter, #companion-counter {
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    text-shadow: 1px 1px 3px #000;
}

.gem-icon, .gold-icon, .arrow-icon, .apple-icon, .companion-icon {
    font-size: 18px;
}

#sky-counter {
    color: #dcefff;
    text-shadow: 0 0 6px rgba(140, 200, 255, 0.8), 1px 1px 3px #000;
}

#quest-items {
    display: flex;
    gap: 4px;
    align-items: center;
}

.quest-item-icon {
    display: inline-flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #ffd700;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 14px;
    color: #ffd700;
    animation: quest-pulse 2s infinite;
}

@keyframes quest-pulse {
    0%, 100% { border-color: #ffd700; }
    50% { border-color: #ffaa00; box-shadow: 0 0 6px rgba(255, 215, 0, 0.4); }
}

.shop-sell-section {
    border-top: 1px solid #555;
    margin-top: 10px;
    padding-top: 8px;
}

.shop-sell-section h3 {
    color: #ff9944;
    text-align: center;
    margin-bottom: 6px;
    font-size: 14px;
}

.shop-item.sell-item {
    cursor: pointer;
}

.shop-item.sell-item:hover {
    border-color: #ff9944;
}

.shop-item.sell-item .shop-item-price {
    color: #ffcc44;
}

#hud-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 8px 12px;
    background: linear-gradient(0deg, rgba(0,0,0,0.7) 0%, transparent 100%);
}

#weapon-display {
    color: #fff;
    font-size: 16px;
    text-shadow: 1px 1px 3px #000;
}

#element-display {
    display: flex;
    gap: 6px;
}

.element-slot {
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #555;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    opacity: 0.3;
    transition: all 0.2s;
}

.element-slot.unlocked {
    opacity: 1;
    border-color: #ffd700;
}

.element-slot.active {
    opacity: 1;
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

/* Minimap */
#minimap-container {
    position: absolute;
    top: 42px;
    right: 8px;
    border: 2px solid #8b6914;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.5);
}

#minimap {
    display: block;
    border-radius: 2px;
}

/* Map Overlay */
#map-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 30, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

#map-overlay h2 {
    color: #ffd700;
    font-size: 28px;
    margin-bottom: 10px;
}

#worldmap {
    border: 2px solid #8b6914;
    border-radius: 4px;
}

.map-hint {
    color: #999;
    margin-top: 8px;
    font-size: 14px;
}

/* Lore Overlay (Merlin's Hut) */
#lore-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 8, 30, 0.96);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 55;
}

#lore-overlay h2 {
    color: #aa88ff;
    font-size: 26px;
    margin-bottom: 4px;
    text-shadow: 0 0 15px rgba(160, 100, 255, 0.5);
}

#lore-subtitle {
    color: #888;
    font-size: 12px;
    font-style: italic;
    margin-bottom: 12px;
}

#lore-content {
    background: rgba(30, 20, 50, 0.8);
    border: 2px solid #6a4aaa;
    border-radius: 8px;
    padding: 20px 24px;
    max-width: 560px;
    width: 85%;
    max-height: 320px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    margin-bottom: 12px;
}

.lore-entry-icon {
    font-size: 32px;
    display: block;
    text-align: center;
    margin-bottom: 6px;
}

.lore-entry-title {
    color: #ffd700;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

.lore-entry-text {
    color: #ddd;
    font-size: 14px;
    line-height: 1.6;
    text-align: justify;
}

#lore-nav {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

#lore-page-num {
    color: #aa88ff;
    font-size: 14px;
    min-width: 60px;
    text-align: center;
}

.lore-nav-btn {
    padding: 6px 16px;
    background: rgba(60, 30, 100, 0.8);
    border: 2px solid #6a4aaa;
    border-radius: 4px;
    color: #ddd;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    pointer-events: auto;
}

.lore-nav-btn:hover {
    background: rgba(80, 40, 140, 0.9);
    border-color: #aa88ff;
    color: #fff;
}

.lore-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Riddle Overlay */
#riddle-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 20, 40, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 55;
}

#riddle-overlay h2 {
    color: #88ccff;
    font-size: 26px;
    margin-bottom: 8px;
    text-shadow: 0 0 15px rgba(100, 180, 255, 0.5);
}

#riddle-question {
    color: #eee;
    font-size: 16px;
    max-width: 550px;
    text-align: center;
    margin-bottom: 20px;
    line-height: 1.5;
    font-style: italic;
}

#riddle-choices {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 400px;
}

.riddle-choice {
    padding: 10px 20px;
    background: rgba(30, 50, 80, 0.8);
    border: 2px solid #4488aa;
    border-radius: 6px;
    color: #ddd;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-family: inherit;
    pointer-events: auto;
}

.riddle-choice:hover {
    background: rgba(40, 70, 110, 0.9);
    border-color: #88ccff;
    color: #fff;
    box-shadow: 0 0 10px rgba(100, 180, 255, 0.3);
}

.riddle-choice.correct {
    border-color: #44cc44;
    background: rgba(30, 100, 30, 0.8);
    color: #88ff88;
}

.riddle-choice.wrong {
    border-color: #cc4444;
    background: rgba(100, 30, 30, 0.8);
    color: #ff8888;
}

#riddle-result {
    color: #88ccff;
    font-size: 16px;
    margin-top: 15px;
    min-height: 24px;
    text-align: center;
    max-width: 500px;
}

/* Shop Overlay */
#shop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 10, 5, 0.94);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 0;
    z-index: 50;
    overflow-y: auto;
}

#shop-overlay h2 {
    color: #ffd700;
    font-size: 28px;
    margin-bottom: 15px;
}

#shop-gold-display {
    color: #ffd700;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 12px;
    text-shadow: 1px 1px 3px #000;
}

#shop-items {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 600px;
    margin-bottom: 15px;
}

.shop-item {
    background: rgba(60, 40, 20, 0.9);
    border: 2px solid #8b6914;
    border-radius: 6px;
    padding: 12px;
    width: 170px;
    text-align: center;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.2s;
}

.shop-item:hover {
    border-color: #ffd700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.shop-item.owned {
    opacity: 0.5;
    border-color: #555;
}

.shop-item.too-expensive {
    opacity: 0.5;
    border-color: #555;
    cursor: not-allowed;
}

.shop-item.too-expensive .shop-item-price {
    color: #cc4444;
}

.shop-item-icon {
    font-size: 32px;
    display: block;
    margin-bottom: 5px;
}

.shop-item-name {
    color: #ffd700;
    font-size: 14px;
    font-weight: bold;
}

.shop-item-desc {
    color: #ccc;
    font-size: 11px;
    margin: 4px 0;
}

.shop-item-stats {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 6px 0 4px;
    font-size: 10px;
    color: #aaa;
}

.shop-item-stats span {
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 6px;
    border-radius: 3px;
    color: #ddc89a;
}

.shop-item-price {
    color: #4caf50;
    font-size: 14px;
    font-weight: bold;
}

/* Enchant Overlay */
#enchant-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 10, 40, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    overflow-y: auto;
}

#enchant-overlay h2 {
    color: #aa66ff;
    font-size: 26px;
    margin-bottom: 8px;
    text-shadow: 0 0 15px rgba(160, 100, 255, 0.5);
}

#enchant-desc, #enchant-element-desc {
    color: #ddd;
    font-size: 14px;
    margin-bottom: 12px;
    text-align: center;
}

#enchant-items, #enchant-elements {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 600px;
    margin-bottom: 15px;
}

/* Inventory Overlay */
#inventory-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 30, 0.94);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 0;
    z-index: 50;
    overflow-y: auto;
}

#inventory-overlay h2 {
    color: #ffd700;
    font-size: 28px;
    margin-bottom: 15px;
}

#inventory-weapons, #inventory-bows, #inventory-armor, #inventory-gems {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 500px;
    margin-bottom: 15px;
}

.inv-item {
    background: rgba(40, 30, 60, 0.9);
    border: 2px solid #555;
    border-radius: 6px;
    padding: 10px;
    width: 110px;
    text-align: center;
    cursor: pointer;
    pointer-events: auto;
}

.inv-item.equipped {
    border-color: #ffd700;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

.inv-item:hover {
    border-color: #aaa;
}

.inv-item-icon {
    font-size: 28px;
    display: block;
}

.inv-item-name {
    color: #ddd;
    font-size: 12px;
    margin-top: 4px;
}

/* ============================================
   Storybook Armory — Inventory & Shop
   ============================================ */

#shop-overlay,
#inventory-overlay {
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 8px;
    overflow: hidden;
    align-items: stretch;
    justify-content: stretch;
    color: #e8e1d2;
    font-family: Georgia, 'Times New Roman', serif;
    background:
        linear-gradient(rgba(4, 17, 10, .91), rgba(3, 12, 8, .96)),
        repeating-linear-gradient(0deg, transparent 0 31px, rgba(53, 109, 67, .12) 32px 33px),
        repeating-linear-gradient(90deg, transparent 0 31px, rgba(53, 109, 67, .12) 32px 33px);
    z-index: 55;
}

.armory-window,
.inventory-window {
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at 48% 12%, rgba(54, 70, 99, .17), transparent 34%),
        linear-gradient(145deg, #111827 0%, #090f1d 66%, #070c16 100%);
    border: 3px solid #282d38;
    box-shadow:
        inset 0 0 0 2px #070a10,
        inset 0 0 0 4px #75613a,
        inset 0 0 0 6px #1f2024,
        inset 0 0 38px rgba(0, 0, 0, .82),
        0 8px 22px rgba(0, 0, 0, .8);
}

.armory-window::before,
.inventory-window::before {
    content: "";
    position: absolute;
    inset: 14px;
    z-index: 4;
    pointer-events: none;
    border: 1px solid rgba(225, 169, 67, .74);
    clip-path: polygon(0 10px, 10px 10px, 10px 0, calc(100% - 10px) 0, calc(100% - 10px) 10px, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 10px calc(100% - 10px), 0 calc(100% - 10px));
}

.armory-header {
    position: relative;
    z-index: 5;
    min-height: 66px;
    padding: 10px 18px 9px 23px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    border-bottom: 2px solid #826528;
    background: linear-gradient(180deg, rgba(18, 27, 47, .98), rgba(8, 14, 27, .98));
    box-shadow: 0 4px 0 #05080f, 0 7px 16px rgba(0, 0, 0, .45);
}

.armory-heading,
.armory-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.armory-crest {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    color: #f3c65f;
    font-size: 25px;
    border: 2px solid #8d6b2b;
    border-radius: 4px 4px 13px 13px;
    background: linear-gradient(135deg, #202e45, #0b1120);
    box-shadow: inset 0 0 0 2px #080c14, 0 2px 0 #020407;
    text-shadow: 0 2px 0 #5d330b, 0 0 8px rgba(255, 206, 95, .35);
}

.armory-eyebrow {
    display: block;
    margin-bottom: 1px;
    color: #857d70;
    font-family: 'Segoe UI', sans-serif;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: 2.3px;
    text-transform: uppercase;
}

#shop-overlay h2,
#inventory-overlay h2 {
    margin: 0;
    color: #efc361;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 27px;
    line-height: 1;
    letter-spacing: .4px;
    text-shadow: 0 2px 0 #5a330e, 0 4px 8px #000;
}

.gold-purse {
    margin: 0;
    min-width: 112px;
    padding: 8px 12px;
    color: #e7d39e;
    font-size: 13px;
    text-align: center;
    background: #090e18;
    border: 1px solid #66512b;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .025);
}

.coin-icon,
.tiny-coin {
    color: #f5c242;
    font-style: normal;
    text-shadow: -1px 0 #a66a11, 0 1px #a66a11, 1px 0 #ffe58d;
}

.overlay-close {
    position: relative;
    z-index: 6;
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    padding: 0 0 4px;
    color: #edbd57;
    font-family: Georgia, serif;
    font-size: 38px;
    line-height: 1;
    cursor: pointer;
    border: 2px solid #8e6b2b;
    border-radius: 4px;
    background: linear-gradient(#182236, #0a101c);
    box-shadow: inset 0 0 0 2px #05080e, 0 2px 0 #05070b;
    text-shadow: 0 2px #593209;
}

.overlay-close:hover,
.overlay-close:focus-visible,
.back-arrow-btn:hover,
.back-arrow-btn:focus-visible {
    color: #ffe39a;
    border-color: #e5b84f;
    filter: brightness(1.15);
    outline: none;
}

.shop-main {
    min-height: 0;
    padding: 13px 17px 9px;
    display: grid;
    grid-template-columns: 164px minmax(0, 1fr);
    gap: 12px;
    flex: 1 1 auto;
}

.merchant-card,
.paper-doll-panel,
.shop-catalog,
.inventory-browser {
    min-width: 0;
    min-height: 0;
    border: 1px solid #4f4532;
    background: rgba(7, 11, 20, .72);
    box-shadow: inset 0 0 0 2px #03060b, inset 0 0 20px rgba(0, 0, 0, .48);
}

.merchant-card {
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 11px;
    background:
        linear-gradient(180deg, rgba(78, 59, 25, .18), transparent 48%),
        rgba(7, 11, 20, .76);
}

#merchant-portrait {
    width: 112px;
    height: 112px;
    image-rendering: pixelated;
    background: #090d17;
    box-shadow: 0 0 0 2px #05070b, 0 0 0 4px #84642a, 0 6px 14px #000;
}

.merchant-copy {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 7px;
    text-align: center;
}

.merchant-copy strong {
    color: #e8bd61;
    font-size: 14px;
}

.merchant-copy span {
    color: #9c998e;
    font-family: 'Segoe UI', sans-serif;
    font-size: 10px;
    font-style: italic;
    line-height: 1.45;
}

.shop-catalog,
.inventory-browser {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.category-tabs {
    display: flex;
    flex: 0 0 auto;
    border-bottom: 1px solid #595039;
    background: #090f1a;
}

.category-tab {
    position: relative;
    min-width: 0;
    min-height: 48px;
    padding: 5px 9px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    flex: 1 1 0;
    color: #8c8c8d;
    cursor: pointer;
    border: 0;
    border-right: 1px solid #313440;
    border-radius: 0;
    background: linear-gradient(#171e2b, #0c111c);
    box-shadow: inset 0 -3px 0 #05070c;
}

.category-tab:last-child { border-right: 0; }

.category-tab span {
    height: 20px;
    color: #aaa69d;
    font-size: 18px;
    line-height: 18px;
}

.category-tab b {
    font-family: 'Segoe UI', sans-serif;
    font-size: 9px;
    letter-spacing: .15px;
}

.category-tab i {
    position: absolute;
    top: 3px;
    right: 5px;
    color: #80755f;
    font-family: 'Segoe UI', sans-serif;
    font-size: 7px;
    font-style: normal;
}

.category-tab:hover,
.category-tab:focus-visible {
    color: #d8c99f;
    background: #182132;
    outline: none;
}

.category-tab.active {
    color: #f3ce77;
    background: linear-gradient(#51401e, #2b2316);
    box-shadow: inset 0 -3px 0 #d6a741, inset 0 0 15px rgba(230, 178, 70, .12);
}

.category-tab.active span { color: #f3c45d; }

.catalog-list,
.inventory-grid {
    min-height: 0;
    padding: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-color: #8f6c2e #080d16;
    scrollbar-width: thin;
}

#shop-items.catalog-list {
    width: auto;
    max-width: none;
    margin: 0;
    display: block;
    flex: 1 1 auto;
    justify-content: initial;
}

.catalog-row {
    min-height: 78px;
    margin-bottom: 7px;
    padding: 7px 8px;
    display: grid;
    grid-template-columns: 52px minmax(120px, 1fr) minmax(122px, 155px) 72px;
    align-items: center;
    gap: 9px;
    border: 1px solid #414651;
    background: linear-gradient(90deg, rgba(18, 25, 40, .96), rgba(8, 13, 23, .96));
    box-shadow: inset 0 0 0 2px #060912, 0 2px 3px rgba(0, 0, 0, .55);
}

.catalog-row:hover { border-color: #8b6e38; }
.catalog-row.equipped { border-left: 3px solid #edbc52; }
.catalog-row.too-expensive { border-style: dashed; }

.catalog-icon {
    width: 48px;
    height: 58px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 30px;
    border: 1px solid #6a542e;
    background: radial-gradient(circle, #273144, #0b101a 68%);
    box-shadow: inset 0 0 0 2px #05080e;
    filter: saturate(.85);
}

.catalog-copy { min-width: 0; }

.catalog-name {
    display: flex;
    align-items: baseline;
    gap: 7px;
}

.catalog-name strong {
    overflow: hidden;
    color: #e9d8ae;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.catalog-name span {
    color: #84775e;
    font-family: 'Segoe UI', sans-serif;
    font-size: 7px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.catalog-copy p {
    margin-top: 4px;
    color: #8f9297;
    font-family: 'Segoe UI', sans-serif;
    font-size: 9px;
    line-height: 1.3;
}

.stat-comparison {
    padding-left: 9px;
    border-left: 1px solid #30343f;
    font-family: 'Segoe UI', sans-serif;
}

.stat-comparison > div {
    display: grid;
    grid-template-columns: 28px 20px 16px 22px 13px;
    align-items: center;
    color: #a7a9ad;
    font-size: 11px;
}

.stat-comparison span { color: #7f8490; font-size: 8px; font-weight: 800; }
.stat-comparison i { color: #797e86; font-style: normal; }
.stat-comparison em { font-style: normal; font-weight: 900; }
.stat-comparison .upgrade { color: #66dc58; }
.stat-comparison .downgrade { color: #f05c51; }
.stat-comparison .same { color: #aaa; }
.stat-comparison small { color: #766f63; font-size: 8px; white-space: nowrap; }

.catalog-action {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
}

.row-price {
    color: #e9ce81;
    font-family: 'Segoe UI', sans-serif;
    font-size: 11px;
    font-weight: 800;
    text-align: center;
}

.row-price i { margin-right: 4px; }

.trade-button,
.supply-card button {
    min-height: 44px;
    padding: 5px 8px;
    color: #fff3cf;
    font-family: Georgia, serif;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    border: 1px solid #d1a84d;
    border-radius: 2px;
    background: linear-gradient(#b88832, #704713);
    box-shadow: inset 0 1px rgba(255, 233, 161, .38), 0 2px 0 #281605;
}

.trade-button:hover:not(:disabled),
.trade-button:focus-visible:not(:disabled),
.supply-card button:hover {
    filter: brightness(1.22);
    outline: none;
}

.trade-button:disabled,
.owned-button {
    color: #7d7e80;
    cursor: default;
    border-color: #3f4147;
    background: #22252b;
    box-shadow: inset 0 0 0 1px #14161a;
}

.sell-button {
    color: #ffe3b1;
    border-color: #c37d3c;
    background: linear-gradient(#9a5827, #5e2d14);
}

.catalog-empty {
    min-height: 100%;
    padding: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #787e87;
    text-align: center;
}

.catalog-empty > span { color: #a78342; font-size: 35px; }
.catalog-empty strong { margin: 8px 0 5px; color: #cdbb91; font-size: 14px; }
.catalog-empty p { max-width: 330px; font-family: 'Segoe UI', sans-serif; font-size: 10px; line-height: 1.5; }

.armory-footer {
    position: relative;
    z-index: 5;
    min-height: 50px;
    padding: 7px 18px 8px 23px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    border-top: 1px solid #56462a;
    background: #090e18;
}

.armory-footer > span {
    color: #777b80;
    font-family: 'Segoe UI', sans-serif;
    font-size: 9px;
}

.back-arrow-btn {
    min-width: 100px;
    min-height: 44px;
    padding: 6px 13px;
    color: #e7b951;
    font-family: Georgia, serif;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    border: 2px solid #8e6c30;
    border-radius: 3px;
    background: linear-gradient(#1c273a, #0b111d);
    box-shadow: inset 0 0 0 2px #05080e, 0 2px 0 #020305;
}

.back-arrow-btn span { margin-right: 5px; font-size: 19px; vertical-align: -1px; }

/* Inventory-specific layout */
.inventory-main {
    min-height: 0;
    padding: 11px 17px 7px;
    display: grid;
    grid-template-columns: minmax(300px, 42%) minmax(0, 1fr);
    gap: 11px;
    flex: 1 1 auto;
}

.paper-doll-panel {
    position: relative;
    padding: 31px 8px 8px;
    overflow: hidden;
}

.section-ribbon {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 29px;
    display: grid;
    place-items: center;
    color: #ddba6e;
    border-bottom: 1px solid #55482e;
    background: rgba(12, 18, 30, .95);
    text-shadow: 0 2px #000;
}

.section-ribbon span { font-size: 14px; font-weight: 800; }

.paper-doll-stage {
    position: relative;
    height: calc(100% - 65px);
    min-height: 190px;
    overflow: hidden;
    background:
        linear-gradient(90deg, transparent 49.5%, rgba(189, 142, 55, .12) 50%, transparent 50.5%),
        radial-gradient(circle at center, rgba(69, 82, 111, .18), transparent 56%);
}

#inventory-hero {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 180px;
    height: 190px;
    transform: translate(-50%, -50%);
    image-rendering: pixelated;
}

.equipment-slot {
    position: absolute;
    z-index: 2;
    width: 91px;
    min-height: 55px;
    padding: 4px 5px 4px 34px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #d6d1c6;
    border: 1px solid #5d5036;
    background: linear-gradient(135deg, rgba(26, 34, 50, .97), rgba(7, 11, 19, .97));
    box-shadow: inset 0 0 0 2px #05070c, 0 2px 5px rgba(0, 0, 0, .55);
}

.equipment-slot > span {
    position: absolute;
    left: 5px;
    top: 50%;
    width: 25px;
    transform: translateY(-50%);
    font-size: 22px;
    text-align: center;
}

.equipment-slot small,
.equipment-slot i {
    overflow: hidden;
    font-family: 'Segoe UI', sans-serif;
    font-size: 7px;
    font-style: normal;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.equipment-slot small { color: #8a806d; text-transform: uppercase; letter-spacing: .6px; }
.equipment-slot strong { overflow: hidden; color: #d8caac; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.equipment-slot i { color: #e3b653; }
.equipment-slot-weapon { left: 0; top: 13%; border-color: #a77e2f; }
.equipment-slot-bow { right: 0; top: 13%; }
.equipment-slot-armor { left: 0; bottom: 8%; }
.equipment-slot-consumable { right: 0; bottom: 8%; }

.equipped-summary {
    height: 58px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
}

.equipped-summary > div {
    padding: 5px 3px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    border: 1px solid #3d414a;
    background: #090e17;
}

.equipped-summary span { color: #817969; font-family: 'Segoe UI', sans-serif; font-size: 7px; text-transform: uppercase; }
.equipped-summary b { grid-row: 1 / 3; grid-column: 2; color: #e4c06c; font-size: 18px; }
.equipped-summary small { color: #6d727c; font-family: 'Segoe UI', sans-serif; font-size: 7px; }

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 6px;
}

.inventory-group-title {
    grid-column: 1 / -1;
    margin: 3px 0 0;
    padding: 2px 3px 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #d6b86d;
    font-size: 11px;
    border-bottom: 1px solid #3e392e;
}

.inventory-group-title i {
    color: #6f747d;
    font-family: 'Segoe UI', sans-serif;
    font-size: 7px;
    font-style: normal;
    font-weight: 500;
}

.inventory-card,
.supply-card,
.pet-card,
.relic-card,
.empty-pet-slot,
.pet-intro {
    min-width: 0;
    min-height: 56px;
    border: 1px solid #3d424d;
    background: linear-gradient(100deg, rgba(20, 27, 42, .96), rgba(8, 13, 23, .96));
    box-shadow: inset 0 0 0 1px #05080d;
}

.inventory-card {
    padding: 5px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    gap: 0 5px;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.inventory-card:hover,
.inventory-card:focus-visible { border-color: #b48a38; outline: none; }
.inventory-card.equipped { border-color: #ddb04b; background: linear-gradient(100deg, rgba(76, 58, 25, .75), rgba(17, 20, 27, .98)); }

.inventory-card-icon {
    grid-row: 1 / 3;
    align-self: center;
    font-size: 25px;
    text-align: center;
}

.inventory-card-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.inventory-card-copy strong {
    overflow: hidden;
    color: #dfd7c7;
    font-family: Georgia, serif;
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inventory-card-copy small,
.supply-card small,
.pet-card small,
.relic-card small {
    color: #7e838c;
    font-family: 'Segoe UI', sans-serif;
    font-size: 7px;
    line-height: 1.25;
}

.inventory-card-state {
    color: #a27e37;
    font-family: 'Segoe UI', sans-serif;
    font-size: 7px;
    font-weight: 800;
}

.inventory-card.equipped .inventory-card-state { color: #f0c65f; }

.supply-card {
    grid-column: 1 / -1;
    padding: 6px 7px;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 35px auto;
    align-items: center;
    gap: 7px;
}

.supply-card .inventory-card-icon { grid-row: auto; }
.supply-card > div { display: flex; flex-direction: column; }
.supply-card strong { color: #dcd3c1; font-size: 10px; }
.supply-card > b { color: #d8b966; font-family: 'Segoe UI', sans-serif; font-size: 10px; text-align: right; }
.supply-card.empty { border-style: dashed; filter: saturate(.4); }
.supply-card button { min-width: 48px; }

.pet-intro {
    grid-column: 1 / -1;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-color: #4a6945;
    background: linear-gradient(100deg, rgba(30, 65, 40, .42), rgba(8, 15, 22, .96));
}

.pet-intro > span { color: #87c479; font-size: 27px; }
.pet-intro strong { color: #b9d8a8; font-size: 11px; }
.pet-intro p { margin-top: 2px; color: #74816f; font-family: 'Segoe UI', sans-serif; font-size: 8px; }

.pet-card {
    grid-column: 1 / -1;
    padding: 7px;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 62px;
    align-items: center;
    gap: 8px;
    border-color: #436240;
}

.pet-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    font-size: 27px;
    border: 1px solid #55764e;
    border-radius: 50%;
    background: #13201a;
}

.pet-card > div { min-width: 0; display: flex; flex-direction: column; }
.pet-card strong { color: #c8dfbc; font-size: 10px; }
.pet-card > b { color: #8eae82; font-family: 'Segoe UI', sans-serif; font-size: 8px; line-height: 1.55; text-align: right; }
.pet-health { height: 4px; margin-top: 5px; overflow: hidden; background: #1b2520; border: 1px solid #344138; }
.pet-health i { height: 100%; display: block; background: #63ae55; }

.empty-pet-slot {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: #626a66;
    border-style: dashed;
}

.empty-pet-slot span { font-size: 17px; }
.empty-pet-slot small { font-family: 'Segoe UI', sans-serif; font-size: 8px; }

.inventory-empty-hint {
    grid-column: 1 / -1;
    padding: 8px;
    color: #7b8088;
    font-family: 'Segoe UI', sans-serif;
    font-size: 9px;
    line-height: 1.45;
    text-align: center;
}

.relic-card {
    grid-column: 1 / -1;
    padding: 6px 8px;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    color: inherit;
    text-align: left;
}

button.relic-card { cursor: pointer; }
button.relic-card:hover { filter: brightness(1.18); }
.relic-card > span { font-size: 27px; text-align: center; }
.relic-card > div { display: flex; flex-direction: column; }
.relic-card strong { color: #ddd3bd; font-size: 10px; }
.relic-card > b { color: #c19bea; font-family: 'Segoe UI', sans-serif; font-size: 9px; }
.relic-card.blue { border-color: #345c8a; }
.relic-card.green { border-color: #47753e; }
.relic-card.violet { border-color: #6d4582; }
.relic-card.gold { border-color: #8b6a2a; }
.relic-card.red { border-color: #7b3c38; }
.relic-card.rainbow { border-color: #a87ac8; box-shadow: inset 3px 0 #e45b5b, inset -3px 0 #5bcde4; }

.relic-shelf {
    position: relative;
    z-index: 3;
    margin: 0 17px 7px;
    padding: 21px 7px 6px;
    flex: 0 0 91px;
    border: 1px solid #51472f;
    background: rgba(5, 9, 16, .9);
    box-shadow: inset 0 0 0 2px #020408;
}

.relic-shelf-title {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 20px;
    display: grid;
    place-items: center;
    color: #b99a58;
    font-size: 10px;
    border-bottom: 1px solid #3e382a;
    background: #0d131f;
}

.relic-row {
    height: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(82px, 1.15fr);
    gap: 5px;
}

.element-relic,
.special-relic-summary {
    min-width: 0;
    padding: 3px;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    grid-template-rows: 1fr 1fr;
    align-items: center;
    color: #6e7278;
    border: 1px solid #343843;
    background: linear-gradient(#141b29, #090e17);
}

.element-relic > span,
.special-relic-summary > span {
    grid-row: 1 / 3;
    color: #5d626b;
    font-size: 21px;
    text-align: center;
}

.element-relic small,
.special-relic-summary small { color: #aaa397; font-family: Georgia, serif; font-size: 8px; text-align: left; }
.element-relic i,
.special-relic-summary i { color: #5f646d; font-family: 'Segoe UI', sans-serif; font-size: 7px; font-style: normal; text-align: left; }
.element-relic.unlocked,
.special-relic-summary { cursor: pointer; border-color: color-mix(in srgb, var(--element-color, #c89c48) 55%, #343843); }
.element-relic.unlocked > span { color: var(--element-color); filter: drop-shadow(0 0 5px color-mix(in srgb, var(--element-color) 60%, transparent)); }
.element-relic.active { border-color: var(--element-color); box-shadow: inset 0 0 12px color-mix(in srgb, var(--element-color) 22%, transparent); }
.element-relic.active i { color: var(--element-color); }
.element-relic:disabled { cursor: default; }
.special-relic-summary { --element-color: #d6a94b; }
.special-relic-summary > span { color: #d6a94b; }
.special-relic-summary.active { border-color: #e1b852; box-shadow: inset 0 0 10px rgba(219, 174, 74, .2); }

.legacy-inventory-sections { display: none !important; }

/* Dialog Box */
#dialog-box {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    background: rgba(10, 10, 30, 0.92);
    border: 2px solid #8b6914;
    border-radius: 6px;
    padding: 15px 20px;
    z-index: 40;
}

#dialog-text {
    color: #eee;
    font-size: 16px;
    line-height: 1.4;
}

.dialog-hint {
    color: #888;
    font-size: 12px;
    float: right;
    margin-top: 5px;
}

/* Game Over */
#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#game-over-screen h1 {
    font-size: 48px;
    color: #ff4444;
    text-shadow: 0 0 20px rgba(255, 0, 0, 0.5);
    margin-bottom: 15px;
}

#game-over-screen.victory h1 {
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

#game-over-text {
    color: #ccc;
    font-size: 18px;
    margin-bottom: 25px;
    text-align: center;
    max-width: 500px;
}

/* Boss health bar */
#boss-health-container {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 400px;
    text-align: center;
    z-index: 11;
    pointer-events: none;
}

#boss-name {
    color: #ff4444;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 1px 1px 3px #000;
    margin-bottom: 4px;
}

#boss-health-bar {
    width: 100%;
    height: 18px;
    background: #333;
    border: 2px solid #888;
    border-radius: 3px;
    overflow: hidden;
}

#boss-health-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #ff4444 0%, #aa0000 100%);
    transition: width 0.3s;
}

/* Damage numbers */
.damage-number {
    position: absolute;
    color: #ff4444;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
    z-index: 15;
    animation: floatUp 0.8s ease-out forwards;
}

.damage-number.heal {
    color: #4caf50;
}

.damage-number.crit {
    color: #ffd700;
    font-size: 24px;
}

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

/* Notification */
.notification {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid #ffd700;
    border-radius: 6px;
    padding: 10px 25px;
    color: #ffd700;
    font-size: 16px;
    font-weight: bold;
    z-index: 45;
    pointer-events: none;
    animation: notifyIn 0.3s ease-out, notifyOut 0.5s ease-in 2s forwards;
    text-align: center;
    max-width: 90%;
}

@keyframes notifyIn {
    from { opacity: 0; transform: translate(-50%, -20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes notifyOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============================================
   Portrait Mode - Rotate Device Overlay
   ============================================ */

#rotate-device {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(180deg, #0a0a2e 0%, #1a0a3e 50%, #2a1a4e 100%);
    z-index: 99999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.rotate-content {
    text-align: center;
    padding: 30px;
}

.rotate-icon {
    font-size: 64px;
    margin-bottom: 20px;
    animation: rotateHint 2s ease-in-out infinite;
}

@keyframes rotateHint {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-20deg); }
    75% { transform: rotate(20deg); }
}

#rotate-device h2 {
    color: #ffd700;
    font-size: 28px;
    margin-bottom: 12px;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    letter-spacing: 1px;
}

#rotate-device p {
    color: #c0c0c0;
    font-size: 16px;
    line-height: 1.6;
}

/* Show rotate overlay on mobile portrait orientation */
@media (orientation: portrait) and (max-width: 900px) {
    #rotate-device {
        display: flex;
    }

    #game-container {
        visibility: hidden;
        pointer-events: none;
    }
}

@media (orientation: portrait) and (pointer: coarse) {
    #rotate-device {
        display: flex;
    }

    #game-container {
        visibility: hidden;
        pointer-events: none;
    }
}

/* ============================================
   Touch Controls & Mobile Responsive
   ============================================ */

#touch-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
}

#touch-joystick-zone {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 40%;
    height: 55%;
    pointer-events: auto;
}

#touch-joystick-base {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: 3px solid rgba(255, 255, 255, 0.25);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.5;
    transition: opacity 0.15s;
}

#touch-joystick-knob {
    position: absolute;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.7) 0%, rgba(255, 215, 0, 0.3) 100%);
    border: 3px solid rgba(255, 215, 0, 0.8);
    top: 50%;
    left: 50%;
    margin-left: -26px;
    margin-top: -26px;
    transition: transform 0.05s;
}

#touch-buttons-right-wrapper {
    position: absolute;
    bottom: 16px;
    right: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

#touch-buttons-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    pointer-events: auto;
}

.touch-btn {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    border: 3px solid rgba(255, 215, 0, 0.6);
    font-size: 15px;
    font-weight: bold;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 1px 1px 3px #000;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.touch-btn:active {
    transform: scale(0.9);
    filter: brightness(1.3);
}

.touch-btn-attack {
    background: radial-gradient(circle, rgba(200, 50, 50, 0.75) 0%, rgba(150, 30, 30, 0.55) 100%);
    border-color: rgba(255, 80, 80, 0.7);
}

.touch-btn-shoot {
    background: radial-gradient(circle, rgba(180, 140, 50, 0.75) 0%, rgba(120, 90, 30, 0.55) 100%);
    border-color: rgba(220, 180, 60, 0.7);
}

.touch-btn-element {
    background: radial-gradient(circle, rgba(80, 80, 200, 0.75) 0%, rgba(40, 40, 150, 0.55) 100%);
    border-color: rgba(100, 100, 255, 0.7);
}

.touch-btn-interact {
    background: radial-gradient(circle, rgba(50, 180, 50, 0.75) 0%, rgba(30, 120, 30, 0.55) 100%);
    border-color: rgba(80, 220, 80, 0.7);
}

.touch-btn-potion {
    background: radial-gradient(circle, rgba(180, 50, 180, 0.75) 0%, rgba(120, 30, 120, 0.55) 100%);
    border-color: rgba(220, 80, 220, 0.7);
}

#touch-buttons-top {
    position: absolute;
    top: 42px;
    left: 10px;
    display: flex;
    gap: 10px;
    pointer-events: auto;
}

.touch-btn-small {
    width: 52px;
    height: 38px;
    border-radius: 8px;
    background: rgba(40, 40, 60, 0.85);
    border: 2px solid rgba(255, 215, 0, 0.5);
    color: #ffd700;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.touch-btn-small:active {
    background: rgba(80, 80, 100, 0.9);
    filter: brightness(1.3);
}

/* ============================================
   Mobile Fullscreen & Responsive
   ============================================ */

@media (max-width: 900px), (pointer: coarse) {
    html, body {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        touch-action: none;
        overscroll-behavior: none;
    }

    body {
        align-items: flex-start;
        justify-content: center;
        min-height: 0;
    }

    /* Scale HUD elements */
    #hud-top {
        padding: 4px 8px;
        gap: 8px;
        flex-wrap: wrap;
    }

    #health-bar {
        width: 100px;
        height: 16px;
    }

    #health-text {
        font-size: 9px;
    }

    #gem-counter, #gold-counter, #arrow-counter, #green-gem-counter, #potion-counter, #sky-counter,
    #apple-counter, #companion-counter {
        font-size: 12px;
    }

    .gem-icon, .gold-icon, .arrow-icon, .apple-icon, .companion-icon {
        font-size: 13px;
    }

    #hud-bottom {
        padding: 6px 8px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }

    #weapon-display {
        font-size: 12px;
    }

    #element-display {
        /* Center element powerups at bottom-center, between joystick and action buttons */
        position: absolute;
        bottom: 16px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 25;
    }

    .element-slot {
        width: 32px;
        height: 32px;
        font-size: 14px;
        pointer-events: auto;
        z-index: 25;
        position: relative;
    }

    #minimap-container {
        top: 36px;
        right: 4px;
        transform: scale(0.65);
        transform-origin: top right;
    }

    /* Overlay scaling for small screens */
    #title-screen {
        gap: 14px;
        padding: 22px 34px;
    }

    #title-screen h1 {
        font-size: clamp(38px, 8vw, 60px);
        letter-spacing: 1px;
    }

    .title-crest {
        height: 24px;
        margin-bottom: 0;
    }

    .crest-crown {
        font-size: 23px;
    }

    .crest-sword {
        font-size: 15px;
    }

    .subtitle-row {
        margin-top: 11px;
    }

    .subtitle {
        font-size: 13px;
    }

    .title-menu {
        width: min(520px, 88%);
        padding: 20px 28px 17px;
    }

    .menu-kicker {
        margin-bottom: 8px;
        font-size: 13px;
        letter-spacing: 2px;
    }

    .title-actions {
        gap: 8px;
    }

    .menu-btn {
        min-width: 156px;
        padding: 10px 24px;
        font-size: 14px;
    }

    .menu-note {
        margin-top: 8px;
        font-size: 10px;
    }

    .title-version {
        bottom: 18px;
        font-size: 8px;
    }

    /* Controls screen */
    #controls-screen h2 {
        font-size: 22px;
    }

    .control-item {
        font-size: 12px;
    }

    .key {
        min-width: 60px;
        font-size: 10px;
        padding: 2px 5px;
    }

    /* Shop overlay - compact row layout for mobile */
    #shop-overlay {
        overflow-y: auto;
        padding: 10px 5px;
    }

    #shop-overlay h2 {
        font-size: 18px;
        margin-bottom: 6px;
    }

    #shop-gold-display {
        font-size: 13px;
        margin-bottom: 6px;
    }

    #shop-items {
        max-width: 95%;
        gap: 4px;
        overflow-y: auto;
        max-height: 65%;
        flex-direction: column;
    }

    .shop-item {
        width: 100%;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 6px 10px;
        text-align: left;
    }

    .shop-item-icon {
        font-size: 20px;
        display: inline;
        margin-bottom: 0;
        flex-shrink: 0;
        width: 24px;
        text-align: center;
    }

    .shop-item-name {
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .shop-item-desc {
        display: none;
    }

    .shop-item-stats {
        gap: 2px;
        font-size: 9px;
        flex-shrink: 0;
        margin: 0;
    }

    .shop-item-stats span {
        padding: 1px 3px;
    }

    .shop-item-price {
        font-size: 11px;
        flex-shrink: 0;
        margin-left: auto;
    }

    /* Inventory overlay - compact row layout for mobile */
    #inventory-overlay {
        overflow-y: auto;
        padding: 10px 5px;
    }

    #inventory-overlay h2 {
        font-size: 18px;
        margin-bottom: 4px;
    }

    #inventory-weapons, #inventory-bows, #inventory-armor, #inventory-gems {
        max-width: 95%;
        gap: 3px;
        flex-direction: column;
        overflow-y: visible;
        max-height: none;
        margin-bottom: 6px;
    }

    .inv-item {
        width: 100%;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        padding: 5px 10px;
        text-align: left;
    }

    .inv-item-icon {
        font-size: 18px;
        display: inline;
        flex-shrink: 0;
        width: 22px;
        text-align: center;
    }

    .inv-item-name {
        font-size: 11px;
        display: inline;
        margin-top: 0;
        white-space: nowrap;
    }

    /* Enchant overlay mobile */
    #enchant-overlay {
        padding: 10px 5px;
    }

    #enchant-overlay h2 {
        font-size: 18px;
    }

    #enchant-desc, #enchant-element-desc {
        font-size: 12px;
    }

    #enchant-items, #enchant-elements {
        max-width: 95%;
        gap: 4px;
        flex-direction: column;
    }

    #enchant-items .shop-item,
    #enchant-elements .shop-item {
        width: 100%;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 6px 10px;
        text-align: left;
    }

    #enchant-items .shop-item-desc,
    #enchant-elements .shop-item-desc {
        display: inline;
        flex: 1;
        font-size: 10px;
        color: #aaa;
    }

    /* Dialog box - raised above touch buttons */
    #dialog-box {
        width: 60%;
        bottom: auto;
        top: 50%;
        transform: translate(-50%, -50%);
        padding: 10px 14px;
    }

    #dialog-text {
        font-size: 13px;
    }

    .dialog-hint {
        font-size: 9px;
    }

    /* Map overlay */
    #map-overlay h2 {
        font-size: 20px;
        margin-bottom: 5px;
    }

    #worldmap {
        max-width: 90vw;
        max-height: 70vh;
        max-height: 70dvh;
    }

    /* Lore overlay */
    #lore-overlay {
        overflow-y: auto;
        padding: 10px 5px;
    }

    #lore-overlay h2 {
        font-size: 18px;
    }

    #lore-subtitle {
        font-size: 10px;
        margin-bottom: 6px;
    }

    #lore-content {
        max-width: 95%;
        max-height: 55%;
        padding: 12px 14px;
    }

    .lore-entry-icon {
        font-size: 24px;
    }

    .lore-entry-title {
        font-size: 14px;
    }

    .lore-entry-text {
        font-size: 12px;
        line-height: 1.5;
    }

    .lore-nav-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* Riddle overlay */
    #riddle-overlay {
        overflow-y: auto;
        padding: 15px 10px;
    }

    #riddle-overlay h2 {
        font-size: 18px;
    }

    #riddle-question {
        font-size: 13px;
        max-width: 90%;
    }

    #riddle-choices {
        width: 90%;
        max-width: 340px;
    }

    .riddle-choice {
        padding: 10px 14px;
        font-size: 13px;
    }

    /* Game over */
    #game-over-screen h1 {
        font-size: 30px;
    }

    #game-over-text {
        font-size: 14px;
        max-width: 85%;
    }

    /* Boss health */
    #boss-health-container {
        width: 55%;
    }

    #boss-name {
        font-size: 13px;
    }

    #boss-health-bar {
        height: 12px;
    }

    /* Notification */
    .notification {
        top: 55px;
        font-size: 13px;
        padding: 7px 16px;
    }
}

/* Landscape-specific: tighter vertical spacing */
@media (max-height: 500px) {
    #title-screen {
        gap: 10px;
        padding: 16px 28px;
    }

    .title-crest {
        display: none;
    }

    #title-screen h1 {
        font-size: clamp(34px, 7.5vw, 50px);
    }

    .subtitle-row {
        margin-top: 9px;
    }

    .title-menu {
        padding: 16px 24px 13px;
    }

    .menu-kicker {
        margin-bottom: 4px;
    }

    .menu-note {
        display: none;
    }

    .title-version {
        display: none;
    }

    #touch-joystick-zone {
        height: 65%;
    }

    #touch-buttons-right-wrapper {
        bottom: 8px;
        right: 8px;
        gap: 6px;
    }

    #touch-buttons-right {
        gap: 8px;
    }

    .touch-btn {
        width: 62px;
        height: 62px;
        font-size: 12px;
    }

    #touch-buttons-top {
        top: 36px;
    }

    #dialog-box {
        width: 50%;
    }

    #hud-top {
        padding: 2px 6px;
        gap: 6px;
    }

    #health-bar {
        width: 80px;
        height: 14px;
    }

    .element-slot {
        width: 26px;
        height: 26px;
        font-size: 12px;
        pointer-events: auto;
        z-index: 25;
        position: relative;
    }

    #element-display {
        bottom: 10px;
    }

    #minimap-container {
        transform: scale(0.5);
    }
}

/* Touch mode specific - body class added by TouchControls */
body.touch-mode {
    touch-action: none;
    overscroll-behavior: none;
}

body.touch-mode #dialog-box .dialog-hint {
    display: none;
}

body.touch-mode #controls-screen .controls-list {
    display: none;
}

body.touch-mode #controls-screen::after {
    content: "Use the virtual joystick to move. ATK = Attack, BOW = Shoot, PWR = Elemental Power, ACT = Interact. MAP and INV buttons at the top. Tap element icons to select powers.";
    color: #ddd;
    font-size: 14px;
    text-align: center;
    max-width: 80%;
    line-height: 1.6;
}

/* Prevent text selection and callout on long press */
body.touch-mode * {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Final compact overrides for the fixed armory layouts. */
@media (max-width: 700px), (max-height: 520px) {
    #shop-overlay,
    #inventory-overlay {
        padding: 4px;
    }

    .armory-header {
        min-height: 50px;
        padding: 5px 10px 5px 15px;
    }

    .armory-crest {
        width: 34px;
        height: 34px;
        font-size: 19px;
    }

    .armory-eyebrow { display: none; }

    #shop-overlay h2,
    #inventory-overlay h2 {
        font-size: 19px;
    }

    .overlay-close {
        width: 44px;
        height: 44px;
        font-size: 31px;
    }

    .gold-purse {
        min-width: 90px;
        padding: 6px 8px;
        font-size: 10px;
    }

    .shop-main {
        padding: 8px 10px 5px;
        grid-template-columns: 120px minmax(0, 1fr);
        gap: 7px;
    }

    .merchant-card { padding: 8px; gap: 7px; }

    #merchant-portrait {
        width: 82px;
        height: 82px;
    }

    .merchant-copy strong { font-size: 11px; }
    .merchant-copy span { font-size: 7px; line-height: 1.25; }

    .category-tab {
        min-height: 44px;
        padding: 3px 5px;
    }

    .category-tab span { height: 16px; font-size: 14px; line-height: 14px; }
    .category-tab b { font-size: 7px; }

    .catalog-list,
    .inventory-grid { padding: 5px; gap: 4px; }

    .catalog-row {
        min-height: 61px;
        margin-bottom: 4px;
        padding: 4px 5px;
        grid-template-columns: 39px minmax(90px, 1fr) minmax(100px, 124px) 62px;
        gap: 5px;
    }

    .catalog-icon {
        width: 36px;
        height: 47px;
        font-size: 21px;
    }

    .catalog-name strong { font-size: 10px; }
    .catalog-name span { display: none; }
    .catalog-copy p { font-size: 7px; }
    .stat-comparison { padding-left: 5px; }
    .stat-comparison > div { grid-template-columns: 24px 17px 12px 19px 10px; font-size: 9px; }
    .stat-comparison small { font-size: 6px; }
    .row-price { font-size: 8px; }
    .trade-button { min-height: 44px; padding: 3px 4px; font-size: 9px; }

    .armory-footer {
        min-height: 40px;
        padding: 4px 10px 5px 15px;
    }

    .armory-footer > span { font-size: 7px; }

    .back-arrow-btn {
        min-width: 82px;
        min-height: 44px;
        padding: 3px 9px;
        font-size: 10px;
    }

    .back-arrow-btn span { font-size: 15px; }

    .inventory-main {
        padding: 7px 10px 4px;
        grid-template-columns: minmax(255px, 40%) minmax(0, 1fr);
        gap: 7px;
    }

    .paper-doll-panel { padding: 25px 5px 5px; }
    .section-ribbon { height: 24px; }
    .section-ribbon span { font-size: 11px; }

    .paper-doll-stage {
        height: calc(100% - 48px);
        min-height: 150px;
    }

    #inventory-hero {
        width: 145px;
        height: 153px;
    }

    .equipment-slot {
        width: 76px;
        min-height: 45px;
        padding: 3px 3px 3px 27px;
    }

    .equipment-slot > span { left: 3px; width: 22px; font-size: 18px; }
    .equipment-slot small,
    .equipment-slot i { font-size: 6px; }
    .equipment-slot strong { font-size: 7px; }
    .equipped-summary { height: 43px; }
    .equipped-summary > div { padding: 2px; }
    .equipped-summary b { font-size: 14px; }
    .equipped-summary span,
    .equipped-summary small { font-size: 6px; }

    .inventory-card,
    .supply-card,
    .pet-card,
    .relic-card { min-height: 45px; }

    .inventory-card { grid-template-columns: 27px minmax(0, 1fr); padding: 3px; }
    .inventory-card-icon { font-size: 20px; }
    .inventory-card-copy strong { font-size: 8px; }
    .inventory-card-copy small,
    .inventory-card-state,
    .supply-card small,
    .pet-card small,
    .relic-card small { font-size: 6px; }

    .relic-shelf {
        margin: 0 10px 4px;
        padding: 17px 5px 4px;
        flex-basis: 70px;
    }

    .relic-shelf-title { height: 16px; font-size: 8px; }
    .relic-row { gap: 3px; }
    .element-relic,
    .special-relic-summary { grid-template-columns: 21px minmax(0, 1fr); padding: 2px; }
    .element-relic > span,
    .special-relic-summary > span { font-size: 16px; }
    .element-relic small,
    .special-relic-summary small { font-size: 6px; }
    .element-relic i,
    .special-relic-summary i { font-size: 5px; }
}
