/* ========== RESET & BASE ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --gold: #D4AF37;
    --gold-light: #f0d060;
    --gold-dark: #b8941e;
    --brown-dark: #3E2723;
    --brown-mid: #5d3a2a;
    --ink: #1A1A1A;
    --parchment: #f5efe0;
    --parchment-dark: #e8dccc;
    --shadow: rgba(30, 20, 10, 0.35);
    --font-title: 'Cinzel', serif;
    --font-body: 'Lora', serif;
    --transition: 0.25s ease;
    --shelf-wood: #6d4c3a;
    --shelf-wood-light: #8b6b55;
    --shelf-wood-dark: #4a3124;
    --shelf-depth: #3d2a1e;
    --radius: 12px;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-body);
    background: var(--parchment);
    color: var(--ink);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* ========== SCREENS ========== */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1;
    overflow: hidden;
}
.screen.active {
    display: flex;
}

/* ========== MAIN MENU ========== */
#menuScreen {
    background: radial-gradient(ellipse at 50% 40%, #f5efe0 0%, #d4c8b8 100%);
    justify-content: flex-start;
    gap: 2px;
    padding: 8px 14px 10px;
    overflow-y: auto;
}

.menu-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    margin-bottom: 2px;
}
.menu-title {
    font-family: var(--font-title);
    font-size: clamp(1.5rem, 5.5vw, 2.8rem);
    font-weight: 900;
    color: var(--brown-dark);
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.12), 0 2px 0 var(--gold);
    letter-spacing: 0.04em;
    text-align: center;
    line-height: 1.1;
}
.menu-subtitle {
    font-size: clamp(0.78rem, 1.7vw, 1.08rem);
    color: var(--brown-mid);
    font-style: italic;
    letter-spacing: 0.04em;
    text-align: center;
    margin-top: 0;
}

.menu-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin: 2px 0 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: clamp(0.7rem, 1.4vw, 1rem);
    padding: 10px 20px;
    border: 2px solid var(--gold);
    border-radius: 40px;
    background: var(--brown-dark);
    color: var(--gold);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 0 var(--gold-dark), 0 6px 16px var(--shadow);
    text-align: center;
    letter-spacing: 0.06em;
    touch-action: manipulation;
    white-space: nowrap;
}
.btn:hover,
.btn:active {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--gold-dark), 0 10px 24px var(--shadow);
    background: #4d3227;
}
.btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--gold-dark);
}
.btn-secondary {
    background: transparent;
    color: var(--brown-dark);
    border-color: var(--brown-dark);
    box-shadow: 0 4px 0 var(--brown-dark), 0 4px 12px var(--shadow);
}
.btn-secondary:hover {
    background: var(--brown-dark);
    color: var(--gold);
}
.btn-gold {
    background: var(--gold);
    color: var(--brown-dark);
    border-color: var(--gold-dark);
    box-shadow: 0 4px 0 var(--gold-dark), 0 6px 16px var(--shadow);
}
.btn-gold:hover {
    background: var(--gold-light);
}
.btn-small {
    padding: 6px 14px;
    font-size: clamp(0.55rem, 1vw, 0.75rem);
}
.btn-pill {
    background: rgba(255, 255, 255, 0.35);
    color: var(--brown-mid);
    border: 1px solid var(--brown-mid);
    padding: 6px 16px;
    font-size: clamp(0.6rem, 1.1vw, 0.8rem);
    font-weight: 600;
    box-shadow: none;
}
.btn-pill:hover {
    background: var(--brown-dark);
    color: var(--gold);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--shadow);
}
.btn-pill:active {
    transform: translateY(1px);
    box-shadow: none;
}

/* ===== BOOKCASE ===== */
.bookcase-wrapper {
    flex: 0 0 auto;
    width: 100%;
    max-width: 1180px;
    display: flex;
    flex-direction: column;
    padding: 6px 0 4px;
    position: relative;
}
.bookcase {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 6px 8px 4px;
    min-height: 200px;
    background: linear-gradient(180deg, var(--shelf-wood-light), var(--shelf-wood));
    border-radius: 10px;
    border: 16px solid var(--shelf-wood-dark);
    border-bottom-width: 22px;
    box-shadow:
        inset 0 0 30px rgba(0, 0, 0, 0.15),
        inset 0 0 0 1px rgba(255, 255, 255, 0.05),
        0 0 0 1px rgba(0, 0, 0, 0.25),
        0 10px 34px rgba(0, 0, 0, 0.34);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.bookcase.is-ready {
    opacity: 1;
}
.bookcase::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(90deg,
            transparent 0px,
            rgba(0, 0, 0, 0.02) 2px,
            transparent 4px,
            rgba(255, 255, 255, 0.01) 6px,
            transparent 8px);
    pointer-events: none;
    z-index: 0;
}
.shelf-row {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}
.shelf-books {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    padding: 0 6px 1px;
}
.shelf-segment {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    flex-grow: var(--segment-weight, 1);
    flex-shrink: 1;
    flex-basis: 0;
}
.shelf-slot {
    display: flex;
    align-items: flex-end;
    min-width: 0;
    width: 100%;
    flex-grow: var(--thickness, 1);
    flex-shrink: 1;
    flex-basis: 0;
    position: relative;
}
.shelf-divider {
    flex: 0 0 26px;
    align-self: stretch;
    position: relative;
}
.shelf-divider::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 10%;
    bottom: 4%;
    width: 2px;
    transform: translateX(-50%);
    background: linear-gradient(180deg, transparent, var(--gold), transparent);
    opacity: 0.5;
}
.shelf-divider::after {
    content: '✦';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--gold);
    font-size: 0.75rem;
    line-height: 1;
    padding: 3px 2px;
    background: var(--shelf-wood);
    opacity: 0.85;
}
.shelf-edge {
    height: 4px;
    margin: 2px 4px 0;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--shelf-wood-dark), var(--shelf-depth));
    opacity: 0.55;
}
.shelf-label {
    display: block;
    text-align: center;
    font-family: var(--font-title);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    color: var(--parchment);
    opacity: 0.5;
    margin: 2px 0 0;
}

/* ===== SPINES (both menu and game) ===== */
.shelf-book {
    width: 100%;
    height: var(--spine-height, 110px);
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 3px;
    position: relative;
    font: inherit;
    appearance: none;
    -webkit-appearance: none;
    border-radius: 2px 5px 5px 2px;
    border: 1px solid rgba(0, 0, 0, 0.28);
    box-shadow:
        inset -4px 0 10px rgba(0, 0, 0, 0.28),
        inset 2px 0 0 rgba(255, 255, 255, 0.07),
        3px 0 6px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.2s ease;
}
.shelf-book {
    filter: saturate(1.08);
}
.shelf-book:hover {
    transform: translateY(-7px);
    filter: brightness(1.35) saturate(1.15);
    z-index: 10;
}
.shelf-book:focus-visible {
    outline: 3px solid var(--gold-light);
    outline-offset: 2px;
    z-index: 11;
}
.shelf-book.is-speaking {
    transform: translateY(-12px);
    filter: brightness(1.3);
    box-shadow:
        inset -4px 0 10px rgba(0, 0, 0, 0.28),
        0 0 22px rgba(212, 175, 55, 0.65),
        3px 0 6px rgba(0, 0, 0, 0.22);
    z-index: 12;
}
.shelf-book::before,
.shelf-book::after {
    content: '❦';
    position: absolute;
    left: 4px;
    right: 4px;
    text-align: center;
    font-size: 9px;
    line-height: 1;
    font-family: Georgia, 'Times New Roman', serif;
    color: var(--gold-light);
    padding: 3px 0;
    border-top: 1px solid var(--gold);
    border-bottom: 1px solid var(--gold);
    opacity: 0.8;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}
.shelf-book::before {
    top: 4px;
}
.shelf-book::after {
    bottom: 4px;
}

/* ===== SPINE BINDING VARIETY (5 styles cycling across the 66 books) ===== */
/* Each style keeps top and bottom identical (a proper old book always
   matches), varying only the ornament glyph and the corner shape */

/* spine-style-1: classic hedera ornament (default above) */

/* spine-style-2: four-point star, slightly squarer corners */
.shelf-book.spine-style-2 {
    border-radius: 1px 3px 3px 1px;
}
.shelf-book.spine-style-2::before,
.shelf-book.spine-style-2::after {
    content: '✦';
    font-size: 8px;
}

/* spine-style-3: rotated floral bullet, rounder corners */
.shelf-book.spine-style-3 {
    border-radius: 3px 7px 7px 3px;
}
.shelf-book.spine-style-3::before,
.shelf-book.spine-style-3::after {
    content: '❧';
}

/* spine-style-4: fleur-de-lis, sharp corners */
.shelf-book.spine-style-4 {
    border-radius: 0 4px 4px 0;
}
.shelf-book.spine-style-4::before,
.shelf-book.spine-style-4::after {
    content: '⚜';
    font-size: 10px;
}

/* spine-style-5: open star, bolder rule lines */
.shelf-book.spine-style-5::before,
.shelf-book.spine-style-5::after {
    content: '✧';
    border-top-width: 2px;
    border-bottom-width: 2px;
}

.shelf-book .book-label {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: center;
    gap: 0.04em;
    max-width: 100%;
    max-height: 100%;
    font-family: var(--font-title);
    font-weight: 800;
    line-height: 1.08;
    letter-spacing: 0.02em;
    color: #fdf6e3;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.45);
    font-size: var(--book-font-size, 16px);
}
.shelf-book .book-line {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
}

/* Book color variants - rich leather tones */
.shelf-book.book-color-1 {
    background: linear-gradient(135deg, #915353, #bf6a6a, #915353);
}
.shelf-book.book-color-2 {
    background: linear-gradient(135deg, #684d36, #96684d, #684d36);
}
.shelf-book.book-color-3 {
    background: linear-gradient(135deg, #36684d, #519668, #36684d);
}
.shelf-book.book-color-4 {
    background: linear-gradient(135deg, #4d3668, #7b5196, #4d3668);
}
.shelf-book.book-color-5 {
    background: linear-gradient(135deg, #91644d, #bf7f5b, #91644d);
}
.shelf-book.book-color-6 {
    background: linear-gradient(135deg, #364d7b, #517bac, #364d7b);
}
.shelf-book.book-color-7 {
    background: linear-gradient(135deg, #684d4d, #966868, #684d4d);
}
.shelf-book.book-color-8 {
    background: linear-gradient(135deg, #4d684d, #689668, #4d684d);
}
.shelf-book.book-color-9 {
    background: linear-gradient(135deg, #7b4d36, #ac684d, #7b4d36);
}
.shelf-book.book-color-10 {
    background: linear-gradient(135deg, #4d4d7b, #6868ac, #4d4d7b);
}
.shelf-book.book-color-11 {
    background: linear-gradient(135deg, #7b364d, #ac5168, #7b364d);
}
.shelf-book.book-color-12 {
    background: linear-gradient(135deg, #366464, #519191, #366464);
}
.shelf-book.book-color-13 {
    background: linear-gradient(135deg, #917b4d, #bf9664, #917b4d);
}
.shelf-book.book-color-14 {
    background: linear-gradient(135deg, #644d7b, #9168ac, #644d7b);
}
.shelf-book.book-color-15 {
    background: linear-gradient(135deg, #4d7b64, #68ac91, #4d7b64);
}
.shelf-book.book-color-16 {
    background: linear-gradient(135deg, #7b3636, #ac5151, #7b3636);
}

/* ===== GAME SCREEN ===== */
#gameScreen {
    background: var(--parchment);
    padding: 0;
    justify-content: flex-start;
}

/* --- 1. PARCHMENT HEADER (Matches Menu) --- */
.game-header {
    width: 100%;
    max-width: 900px;
    flex-shrink: 0;
    padding: 12px 16px 4px 16px;
    background: radial-gradient(ellipse at 50% 40%, #f5efe0 0%, #d4c8b8 100%);
    border-bottom: 3px solid var(--shelf-wood-dark);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-title {
    font-family: var(--font-title);
    font-size: clamp(1.2rem, 3.5vw, 2rem);
    font-weight: 900;
    color: var(--brown-dark);
    text-shadow: 0 2px 0 var(--gold);
    letter-spacing: 0.04em;
    margin: 0 0 2px 0;
    line-height: 1.1;
}

.game-subtitle {
    font-size: clamp(0.7rem, 1.2vw, 0.95rem);
    color: var(--brown-mid);
    font-style: italic;
    letter-spacing: 0.04em;
    margin: 0 0 6px 0;
}

/* --- 2. UPDATED HUD (Sits inside the parchment) --- */
#gameScreen .game-hud {
    width: 100%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding: 4px 8px 4px 8px;
    background: rgba(62, 39, 35, 0.04);
    border-radius: 40px;
    border: 1px solid rgba(212, 175, 55, 0.15);
}
#gameScreen .hud-left,
#gameScreen .hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(0.65rem, 1.2vw, 0.9rem);
}
#gameScreen .hud-back {
    background: none;
    border: none;
    font-size: clamp(1.2rem, 2.4vw, 1.8rem);
    cursor: pointer;
    padding: 0 6px;
    color: var(--brown-dark);
    transition: var(--transition);
}
#gameScreen .hud-back:hover {
    color: var(--gold-dark);
    transform: scale(1.1);
}
#gameScreen .hud-streak {
    font-weight: 700;
    color: var(--gold-dark);
    display: flex;
    align-items: center;
    gap: 4px;
}
#gameScreen .hud-streak .streak-num {
    font-size: clamp(0.9rem, 1.8vw, 1.3rem);
    min-width: 20px;
    text-align: center;
}
#gameScreen .hud-quills {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    color: var(--brown-dark);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 30px;
    transition: var(--transition);
    background: rgba(212, 175, 55, 0.1);
    border: 1px solid transparent;
    font-size: clamp(0.7rem, 1.2vw, 0.9rem);
}
#gameScreen .hud-quills:hover {
    background: rgba(212, 175, 55, 0.2);
    border-color: var(--gold);
}

.bridge-area {
    flex: 1;
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    padding: 6px 10px 2px;
    overflow: hidden;
    min-height: 0;
}
.bridge-scroll-progress {
    width: 100%;
    height: 8px;
    background: #c8b8a0;
    border-radius: 12px;
    margin-bottom: 6px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}
.bridge-scroll-progress .fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold-light), var(--gold));
    border-radius: 12px;
    transition: width 0.8s ease;
}

/* ===== GAME SCREEN SLOTS (Real Bookshelf Look) ===== */
.slots-container {
    flex: 0 1 auto;
    max-height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin-bottom: 0px;
    border-radius: 8px 8px 0 0;
    background: linear-gradient(180deg, var(--shelf-wood-light), var(--shelf-wood));
    padding: 8px 10px 2px 10px;
    border: 6px solid var(--shelf-wood-dark);
    border-bottom-width: 0px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.15);
}
.slots-container .shelf-books {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    padding: 0;
}

/* The empty drop zone - styled like a wooden shelf gap */
.slots-container .empty-slot {
    background: rgba(0, 0, 0, 0.08);
    border-radius: 2px 4px 4px 2px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 0 10px rgba(212, 175, 55, 0.15);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: all 0.2s ease;
    height: var(--spine-height, 90px);
    padding-bottom: 8px;
    margin-bottom: 1px;
    animation: emptySlotGlow 2.4s ease-in-out infinite;
}
.slots-container .empty-slot .slot-placeholder {
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    opacity: 0.15;
    color: var(--brown-dark);
}

/* When a book is being dragged OVER this slot */
.slots-container .empty-slot.drag-over {
    background: rgba(212, 175, 55, 0.18);
    border-color: #fff2b0;
    border-width: 3px;
    box-shadow: 0 0 40px rgba(212, 175, 55, 0.5), 0 0 12px rgba(255, 242, 176, 0.8), inset 0 0 20px rgba(212, 175, 55, 0.15);
    transform: scale(1.04);
    animation: none;
}
.slots-container .empty-slot.drag-over .slot-placeholder {
    opacity: 0.9;
    color: var(--gold);
}

/* When a book is successfully placed */
.slots-container .empty-slot.filled {
    border: none;
    background: transparent;
    box-shadow: none;
    padding-bottom: 0;
    margin-bottom: 0;
    animation: none;
}

/* Helper hints */
.slots-container .empty-slot.hint-glow {
    border-color: #4CAF50;
    box-shadow: 0 0 30px rgba(76, 175, 80, 0.5);
    animation: hintPulse 0.6s ease 3;
}
.slots-container .empty-slot.helper-flash {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.15);
    box-shadow: 0 0 40px rgba(76, 175, 80, 0.4);
}

/* A book in a level you have not reached yet: reserve its real width and
   height so the shelf's shape never shifts, but stay anonymous and inert */
.slots-container .shelf-slot.is-future {
    display: flex;
    align-items: flex-end;
}
.slots-container .shelf-slot.is-future::after {
    content: '';
    display: block;
    width: 100%;
    height: var(--spine-height, 90px);
    border-radius: 2px 5px 5px 2px;
    background: rgba(62, 39, 35, 0.05);
    border: 1px dashed rgba(62, 39, 35, 0.12);
}

/* ===== GAME SCREEN BOOKS (Draggable Spines) ===== */
.books-container {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    padding: 4px 6px 2px;
    border-radius: 6px;
    background: transparent;
}
.books-container .shelf-slot {
    flex: 0 0 auto;
    width: calc(var(--thickness, 1) * 55px);
}
.books-container .shelf-books {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
}

/* The draggable spine - MUST match the menu exactly */
.book-draggable {
    cursor: grab;
    touch-action: none;
    height: var(--spine-height, 110px) !important;
    width: 100%;
    min-width: 0;
    flex-grow: var(--thickness, 1);
    flex-shrink: 1;
    flex-basis: 0;
    
    border-radius: 2px 5px 5px 2px;
    border: 1px solid rgba(0, 0, 0, 0.28);
    box-shadow: inset -4px 0 10px rgba(0, 0, 0, 0.28), inset 2px 0 0 rgba(255, 255, 255, 0.07), 3px 0 6px rgba(0, 0, 0, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 3px;
    position: relative;
    filter: saturate(1.08);
    transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.2s ease;
}
.book-draggable:hover {
    transform: translateY(-7px);
    filter: brightness(1.35) saturate(1.15);
    z-index: 10;
}
.book-draggable.dragging {
    cursor: grabbing;
}
.book-draggable.wrong-shake {
    animation: wrongShake 0.45s ease;
}

/* ===== WOODEN SHELF EDGE (Bottom of the slots) ===== */
.slots-shelf-edge {
    width: 100%;
    max-width: 900px;
    height: 6px;
    background: linear-gradient(180deg, var(--shelf-wood-dark), var(--shelf-depth));
    border-radius: 0 0 6px 6px;
    flex-shrink: 0;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 2;
    margin-bottom: 8px;
}
.slots-shelf-edge::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
}


/* ===== OTHER SCREENS ===== */
#bossScreen {
    background: radial-gradient(ellipse at center, #2a1f18 0%, #0d0a07 100%);
    justify-content: center;
    gap: 12px;
}
#bossScreen .boss-title {
    font-family: var(--font-title);
    font-size: clamp(1.4rem, 4vw, 2.6rem);
    color: var(--gold);
    text-shadow: 0 0 40px rgba(212, 175, 55, 0.3);
    text-align: center;
}
#bossScreen .boss-sub {
    font-size: clamp(0.9rem, 2vw, 1.4rem);
    color: #c0b090;
    text-align: center;
}
#bossScreen .boss-emoji {
    font-size: clamp(3.5rem, 12vw, 7rem);
    animation: bossFloat 2s ease-in-out infinite;
}
@keyframes bossFloat {
    0%, 100% { transform: translateY(0) rotate(-4deg); }
    50% { transform: translateY(-16px) rotate(4deg); }
}
#bossScreen .btn {
    margin-top: 10px;
    min-width: 180px;
}

#fameScreen {
    background: var(--parchment);
    padding: 20px;
    gap: 8px;
    overflow-y: auto;
}
#fameScreen h2 {
    font-family: var(--font-title);
    font-size: clamp(1.4rem, 4vw, 2.2rem);
    color: var(--brown-dark);
}
.fame-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    max-width: 720px;
    margin: 6px 0 12px;
}
.fame-medal {
    width: 150px;
    padding: 16px 10px 14px;
    background: linear-gradient(160deg, #fff6dc 0%, #f0dba0 45%, #e0be6a 100%);
    border-radius: var(--radius);
    border: 3px solid var(--gold);
    box-shadow: 0 3px 0 rgba(150, 110, 20, 0.4), 0 6px 14px rgba(150, 110, 20, 0.25);
    text-align: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease, filter 0.25s ease, border-color 0.25s ease;
    cursor: default;
}
.fame-medal:hover {
    transform: translateY(-8px) scale(1.1);
    border-color: #fff2b0;
    filter: brightness(1.12) saturate(1.2);
    box-shadow: 0 8px 0 rgba(150, 110, 20, 0.4), 0 16px 28px rgba(212, 175, 55, 0.5), 0 0 24px rgba(255, 221, 100, 0.5);
}
.fame-medal:hover .medal-icon {
    transform: scale(1.2) rotate(-6deg);
}
.fame-medal.perfect {
    border-color: #fff2b0;
    box-shadow: 0 3px 0 rgba(150, 110, 20, 0.4), 0 0 22px rgba(255, 221, 100, 0.6);
}
.fame-medal .medal-icon {
    font-size: clamp(2.4rem, 5vw, 3.2rem);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
    display: inline-block;
    transition: transform 0.25s ease;
}
.fame-medal .medal-name {
    font-family: var(--font-title);
    font-size: clamp(0.78rem, 1.4vw, 0.92rem);
    font-weight: 700;
    color: var(--brown-dark);
    margin-top: 6px;
    line-height: 1.2;
}
.fame-medal .medal-stars {
    font-size: clamp(0.75rem, 1.3vw, 1rem);
    margin-top: 3px;
}
.fame-medal .medal-virtue {
    margin-top: 7px;
    padding-top: 7px;
    border-top: 1px dashed rgba(93, 58, 42, 0.35);
    font-size: clamp(0.68rem, 1.1vw, 0.8rem);
    font-weight: 700;
    color: var(--brown-mid);
}
.fame-medal.locked {
    background: linear-gradient(160deg, #e8e2d4 0%, #d8d0bd 100%);
    border-color: rgba(93, 58, 42, 0.2);
    box-shadow: none;
}
.fame-medal.locked:hover {
    transform: none;
    filter: none;
    box-shadow: none;
    border-color: rgba(93, 58, 42, 0.2);
}
.fame-medal.locked .medal-icon {
    opacity: 0.4;
    filter: grayscale(1);
}
.fame-medal.locked .medal-name {
    opacity: 0.55;
}
.fame-medal.locked .medal-stars {
    opacity: 0.4;
}
@keyframes medalPopIn {
    0% { opacity: 0; transform: scale(0.6) translateY(10px); }
    70% { opacity: 1; transform: scale(1.05) translateY(-2px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ===== VIRTUE MEDALLIONS (collection, replaces old hat/pet vault) ===== */
.virtue-medallion {
    position: relative;
    width: 176px;
    flex-shrink: 0;
    padding: 18px 14px 16px;
    background: linear-gradient(160deg, #fdf6e3 0%, #f0e2bd 100%);
    border-radius: 16px;
    border: 5px solid var(--gold);
    text-align: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
}
.virtue-medallion .virtue-icon-badge {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.55);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}
.virtue-medallion .virtue-icon {
    font-size: clamp(2.1rem, 4.5vw, 2.7rem);
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
}
.virtue-medallion .virtue-name {
    font-family: var(--font-title);
    font-weight: 800;
    font-size: clamp(1.05rem, 2vw, 1.25rem);
    color: var(--brown-dark);
    margin-top: 9px;
}
.virtue-medallion .virtue-verse {
    font-size: clamp(0.8rem, 1.4vw, 0.92rem);
    color: var(--brown-mid);
    font-style: italic;
    margin-top: 4px;
}
.virtue-medallion .virtue-spark {
    position: absolute;
    top: -10px;
    right: -8px;
    font-size: 1.3rem;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}
.virtue-medallion.locked {
    background: linear-gradient(160deg, #e8e2d4 0%, #d8d0bd 100%);
    border-color: rgba(93, 58, 42, 0.2);
    box-shadow: none;
}
.virtue-medallion.locked .virtue-icon-badge {
    background: rgba(255, 255, 255, 0.25);
    box-shadow: none;
}
.virtue-medallion.locked .virtue-icon {
    opacity: 0.45;
}
.virtue-medallion.locked .virtue-name {
    opacity: 0.55;
    letter-spacing: 0.1em;
}

/* Each of the 12 virtues gets its own bold, deliberately clashing accent
   color and a cycling shape, so the collection reads as 12 distinct
   treasures, not one template repeated with different text */
.virtue-medallion.earned:nth-child(1)  { border-color: #ffb300; box-shadow: 0 0 14px rgba(255, 179, 0, 0.45), 0 3px 10px rgba(0,0,0,0.15); }
.virtue-medallion.earned:nth-child(2)  { border-color: #1565c0; box-shadow: 0 0 14px rgba(21, 101, 192, 0.4), 0 3px 10px rgba(0,0,0,0.15); border-radius: 6px; }
.virtue-medallion.earned:nth-child(3)  { border-color: #6a1b9a; box-shadow: 0 0 14px rgba(106, 27, 154, 0.4), 0 3px 10px rgba(0,0,0,0.15); }
.virtue-medallion.earned:nth-child(4)  { border-color: #e65100; box-shadow: 0 0 14px rgba(230, 81, 0, 0.4), 0 3px 10px rgba(0,0,0,0.15); border-radius: 6px; }
.virtue-medallion.earned:nth-child(5)  { border-color: #ff4081; box-shadow: 0 0 14px rgba(255, 64, 129, 0.4), 0 3px 10px rgba(0,0,0,0.15); }
.virtue-medallion.earned:nth-child(6)  { border-color: #d32f2f; box-shadow: 0 0 14px rgba(211, 47, 47, 0.4), 0 3px 10px rgba(0,0,0,0.15); border-radius: 6px; }
.virtue-medallion.earned:nth-child(7)  { border-color: #00897b; box-shadow: 0 0 14px rgba(0, 137, 123, 0.4), 0 3px 10px rgba(0,0,0,0.15); }
.virtue-medallion.earned:nth-child(8)  { border-color: #c2185b; box-shadow: 0 0 14px rgba(194, 24, 91, 0.4), 0 3px 10px rgba(0,0,0,0.15); border-radius: 6px; }
.virtue-medallion.earned:nth-child(9)  { border-color: #ab47bc; box-shadow: 0 0 14px rgba(171, 71, 188, 0.4), 0 3px 10px rgba(0,0,0,0.15); }
.virtue-medallion.earned:nth-child(10) { border-color: #283593; box-shadow: 0 0 14px rgba(40, 53, 147, 0.4), 0 3px 10px rgba(0,0,0,0.15); border-radius: 6px; }
.virtue-medallion.earned:nth-child(11) { border-color: #2e7d32; box-shadow: 0 0 14px rgba(46, 125, 50, 0.4), 0 3px 10px rgba(0,0,0,0.15); }
.virtue-medallion.earned:nth-child(12) {
    border-color: var(--gold);
    background: linear-gradient(160deg, #fff8dc 0%, #f0d060 55%, #e0be6a 100%);
    box-shadow: 0 0 22px rgba(212, 175, 55, 0.6), 0 3px 10px rgba(0, 0, 0, 0.15);
}

@keyframes virtuePopIn {
    0% { opacity: 0; transform: scale(0.5) rotate(-8deg); }
    60% { opacity: 1; transform: scale(1.08) rotate(4deg); }
    80% { transform: scale(0.97) rotate(-2deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
@keyframes virtueWiggle {
    0%, 100% { transform: rotate(0deg) scale(1); }
    20% { transform: rotate(-6deg) scale(1.05); }
    40% { transform: rotate(5deg) scale(1.05); }
    60% { transform: rotate(-4deg) scale(1.03); }
    80% { transform: rotate(2deg) scale(1.01); }
}
.virtue-medallion.earned {
    opacity: 1;
    cursor: pointer;
}
.virtue-medallion.earned:hover,
.virtue-medallion.earned:active {
    animation: virtueWiggle 0.5s ease;
}


/* ===== MINI BOOKSHELF (menu collection strip and finale screen) ===== */
.mini-shelf {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    max-width: 700px;
    margin: 6px auto 14px;
}
.mini-book {
    width: 34px;
    height: 90px;
    border-radius: 2px 4px 4px 2px;
    box-shadow: inset -3px 0 6px rgba(0, 0, 0, 0.25), 2px 2px 5px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 6px 2px;
    flex-shrink: 0;
}
.mini-icon {
    font-size: 0.85rem;
    margin-bottom: 4px;
    opacity: 0.85;
}
.mini-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    color: #fdf6e3;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.52rem;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
    max-height: 76px;
    overflow: hidden;
}
.shelf-empty-msg {
    color: var(--brown-mid);
    opacity: 0.6;
    font-style: italic;
    font-size: 0.85rem;
}

/* Vault grid holds virtue-medallion cards, used in both the popup and the finale screen */
.vault-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, 176px);
    justify-content: center;
    gap: 10px;
    margin: 10px 0 14px;
}

/* ===== FINALE SCREEN ===== */
.finale-screen {
    overflow-y: auto;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
}
.finale-hero {
    position: relative;
    width: 100%;
    min-height: 380px; /* This is the only actual fix: space for fireworks */
    padding: 40px 16px 24px;
    background: radial-gradient(ellipse at 50% 20%, #3a2418 0%, #1a1008 75%);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.finale-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.finale-hero-content {
    position: relative;
    z-index: 1;
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
}
.finale-title {
    font-family: var(--font-title);
    font-size: clamp(1.8rem, 5vw, 3rem);
    font-weight: 900;
    color: var(--gold-light);
    text-shadow: 0 2px 12px rgba(212, 175, 55, 0.6), 0 0 40px rgba(212, 175, 55, 0.3);
    margin-bottom: 6px;
    animation: finaleTitlePulse 2.4s ease-in-out infinite;
}
.finale-sub {
    color: var(--parchment);
    opacity: 0.85;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    margin-bottom: 20px;
}
.finale-stats {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}
.finale-stat {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 10px;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
}
.finale-stat-value {
    font-family: var(--font-title);
    font-size: clamp(1.2rem, 3vw, 1.7rem);
    font-weight: 800;
    color: var(--gold-light);
}
.finale-stat-label {
    font-size: 0.75rem;
    color: var(--parchment);
    opacity: 0.7;
    margin-top: 2px;
}
.finale-body {
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.finale-section-title {
    font-family: var(--font-title);
    color: var(--brown-dark);
    font-size: clamp(1rem, 2.4vw, 1.3rem);
    margin: 18px 0 10px;
}
.finale-shelf,
.finale-vault-grid {
    background: rgba(62, 39, 35, 0.04);
    border-radius: 10px;
    padding: 10px;
    width: 100%;
}
.finale-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 26px;
}
@keyframes finaleTitlePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* ===== TOAST & HELPERS ===== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--brown-dark);
    color: var(--gold-light);
    padding: 10px 24px;
    border-radius: 60px;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: clamp(0.7rem, 1.4vw, 1rem);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    border: 2px solid var(--gold);
    z-index: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    text-align: center;
    max-width: 90vw;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.helper-badge {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: rgba(76, 175, 80, 0.92);
    color: #fff;
    padding: 14px 28px;
    border-radius: 60px;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: clamp(0.9rem, 2vw, 1.4rem);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    z-index: 700;
    pointer-events: none;
    border: 2px solid #fff;
    transition: none;
}
.helper-badge.show {
    animation: helperBadgeAnim 1.2s ease forwards;
}
@keyframes helperBadgeAnim {
    0% { transform: translate(-50%, -50%) scale(0) rotate(-10deg); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.2) rotate(2deg); opacity: 1; }
    60% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.8) rotate(0deg); opacity: 0; }
}

/* ===== ANIMATIONS ===== */
@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-12px) rotate(-3deg); }
    40% { transform: translateX(12px) rotate(3deg); }
    60% { transform: translateX(-8px); }
    80% { transform: translateX(8px); }
}
@keyframes hintPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(76, 175, 80, 0.2); }
    50% { box-shadow: 0 0 50px rgba(76, 175, 80, 0.6); }
}
@keyframes emptySlotGlow {
    0%, 100% { box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 0 10px rgba(212, 175, 55, 0.15); }
    50% { box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 0 22px rgba(212, 175, 55, 0.45); }
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 20px;
}
.modal-overlay.active {
    display: flex;
}
.modal {
    background: var(--parchment);
    border-radius: 28px;
    padding: 28px 24px 24px;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 2px solid var(--gold);
    text-align: center;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 {
    font-family: var(--font-title);
    font-size: clamp(1.2rem, 3.5vw, 1.8rem);
    color: var(--brown-dark);
    margin-bottom: 2px;
}
.modal .sub {
    font-size: clamp(0.8rem, 1.4vw, 1rem);
    color: var(--brown-mid);
    margin-bottom: 10px;
}
.modal .stars-display {
    font-size: clamp(2rem, 5vw, 3.2rem);
    letter-spacing: 6px;
    margin: 4px 0 8px;
}
.modal .stat-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: clamp(0.75rem, 1.2vw, 0.9rem);
    color: var(--brown-mid);
    margin: 4px 0 10px;
}
.modal .stat-row span {
    font-weight: 700;
    color: var(--brown-dark);
}
.modal .btn {
    margin-top: 4px;
    width: 100%;
}
.chest-area {
    background: rgba(212, 175, 55, 0.1);
    border: 2px dashed rgba(212, 175, 55, 0.5);
    border-radius: var(--radius);
    padding: 10px 12px 12px;
    margin: 10px 0;
}
.chest-prompt {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: clamp(0.85rem, 2vw, 1rem);
    color: var(--brown-dark);
    margin-bottom: 2px;
}
.chest-prompt:empty {
    display: none;
}
.modal .chest-btn {
    font-size: clamp(2.4rem, 6vw, 3.6rem);
    background: radial-gradient(circle, rgba(255, 244, 200, 0.9) 0%, rgba(212, 175, 55, 0.25) 70%, transparent 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    padding: 10px;
    touch-action: manipulation;
    animation: chestBounce 1.4s ease-in-out infinite;
}
.modal .chest-btn:disabled:not(.opened) {
    opacity: 0.4;
    cursor: default;
    transform: none !important;
    animation: none;
}
.modal .chest-btn.opened {
    display: none;
}
.modal .chest-btn:hover:not(:disabled) {
    transform: scale(1.15);
}
.modal .chest-btn:active:not(:disabled) {
    transform: scale(0.9);
}
@keyframes chestBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-6px) scale(1.05); }
}
.modal .reward-reveal {
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    margin: 6px 0 2px;
    min-height: 1rem;
}

.menu-share-btn {
    font-family: var(--font-body);
    font-size: clamp(0.7rem, 1.4vw, 0.85rem);
    font-weight: 700;
    color: var(--brown-dark);
    background: var(--parchment);
    border: 2px solid var(--gold);
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
    box-shadow: 0 3px 0 var(--gold-dark), 0 4px 10px var(--shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.menu-share-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 0 var(--gold-dark), 0 6px 14px var(--shadow);
}
.menu-share-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 var(--gold-dark);
}
.share-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 14px 0 4px;
}
.share-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    border-radius: 10px;
    color: #ffffff;
    font-family: var(--font-body);
    font-weight: 700;
    text-decoration: none;
    transition: opacity 0.2s ease;
}
.share-link:hover {
    opacity: 0.9;
}
.share-link.copy {
    background: var(--brown-dark);
    color: var(--gold);
    border: 2px solid var(--gold);
}
.share-link.copy.success {
    background: #2f7a4d;
    color: #ffffff;
    border-color: #2f7a4d;
}
.share-link.sms {
    background: #34b7f1;
    display: none;
}
@media (hover: none) and (pointer: coarse) {
    .share-link.sms {
        display: flex;
    }
}
.share-link.email {
    background: #4a6fa5;
}
.share-link.whatsapp {
    background: #25D366;
}
.share-link.facebook {
    background: #1877F2;
}
.share-link.pinterest {
    background: #E60023;
}
.share-link.twitter {
    background: #000000;
}


.reward-reveal.revealed {
    background: linear-gradient(160deg, #fdf6e3 0%, #f0e2bd 100%);
    border: 3px solid var(--gold);
    border-radius: var(--radius);
    padding: 12px;
}
.reward-icon-badge {
    font-size: 2.2rem;
}
.reward-name {
    font-family: var(--font-title);
    font-weight: 800;
    font-size: clamp(1.1rem, 2.5vw, 1.4rem);
    color: var(--brown-dark);
    margin-top: 2px;
}
.reward-verse-text {
    font-size: clamp(0.8rem, 1.6vw, 0.95rem);
    color: var(--brown-mid);
    font-style: italic;
    margin-top: 6px;
}
.reward-verse-ref {
    font-size: clamp(0.75rem, 1.4vw, 0.85rem);
    color: var(--brown-mid);
    font-weight: 700;
    margin-top: 3px;
}

.vault-popup .modal {
    max-width: 430px;
}

/* ===== SHELF PROGRESS COUNTER ===== */
.shelf-progress {
    flex-shrink: 0;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: clamp(0.7rem, 1.3vw, 0.95rem);
    color: var(--brown-dark);
    letter-spacing: 0.08em;
    text-align: center;
    margin: 2px 0 4px;
}
.shelf-progress .count {
    color: var(--gold-dark);
}

/* ===== MASTERED VS LOCKED SPINES ===== */
.shelf-book.is-locked {
    filter: grayscale(0.5) brightness(0.86);
}
.shelf-book.is-locked .book-label {
    color: #f4ece0;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
.shelf-book.is-locked:hover {
    filter: grayscale(0) brightness(1.35) saturate(1.15);
}
.shelf-book.is-mastered {
    border-color: rgba(212, 175, 55, 0.55);
    box-shadow:
        inset -4px 0 10px rgba(0, 0, 0, 0.28),
        inset 2px 0 0 rgba(255, 255, 255, 0.07),
        0 0 12px rgba(212, 175, 55, 0.35),
        3px 0 6px rgba(0, 0, 0, 0.22);
}
.shelf-book.is-mastered::before,
.shelf-book.is-mastered::after {
    opacity: 0.85;
}

/* ===== MENU FOOTER ===== */
.menu-footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 8px 6px;
    text-align: center;
}
.menu-intro {
    max-width: 720px;
    font-family: var(--font-body);
    font-size: clamp(0.62rem, 1.1vw, 0.8rem);
    line-height: 1.5;
    color: var(--brown-mid);
}
.menu-footer-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
.menu-intro a {
    color: var(--brown-dark);
    text-decoration: underline;
}
.reset-link {
    background: none;
    border: none;
    padding: 2px 6px;
    font-family: var(--font-body);
    font-size: clamp(0.58rem, 1vw, 0.72rem);
    color: var(--brown-mid);
    opacity: 0.7;
    text-decoration: underline;
    cursor: pointer;
    touch-action: manipulation;
}
.reset-link:hover {
    opacity: 1;
    color: #8a2b2b;
}
.reset-link:focus-visible {
    outline: 2px solid var(--gold-dark);
    outline-offset: 2px;
}

/* ===== CONFIRM DIALOG ===== */
.confirm-modal .modal {
    max-width: 460px;
    text-align: center;
}
.confirm-modal h2 {
    font-family: var(--font-title);
    color: var(--brown-dark);
    margin-bottom: 6px;
}
.confirm-body {
    font-family: var(--font-body);
    font-size: clamp(0.82rem, 1.5vw, 0.98rem);
    line-height: 1.55;
    color: var(--brown-mid);
    margin-bottom: 16px;
}
.confirm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}
.btn-danger {
    background: linear-gradient(180deg, #a8402f, #7e2c20);
    color: #fdf6e3;
    border: 2px solid #6a2418;
}
.btn-danger:hover {
    background: linear-gradient(180deg, #c04b37, #8f3325);
}

/* ===== RESPONSIVE (Mobile & Tablet) ===== */
@media (max-width: 900px) {
    /* Menu bookcase: per-row horizontal scroll */
    .bookcase {
        overflow: hidden;
        min-height: auto;
        border-width: 6px !important;
        border-bottom-width: 8px !important;
        padding: 4px 4px 2px !important;
        border-radius: 6px !important;
        width: 100%;
    }
    .shelf-books {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        padding: 0 2px 1px;
        scrollbar-width: thin;
        display: flex;
    }
    .shelf-books::-webkit-scrollbar {
        height: 4px;
    }
    .shelf-books::-webkit-scrollbar-thumb {
        background: var(--gold-dark);
        border-radius: 6px;
    }
    .shelf-books::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.05);
        border-radius: 6px;
    }
    .shelf-segment {
        flex: 0 0 auto;
        display: flex;
        gap: 2px;
        align-items: flex-end;
    }
    .shelf-slot {
        min-width: 34px;
        flex-basis: 34px;
        flex-shrink: 0;
    }
    .shelf-divider {
        flex: 0 0 10px;
        flex-shrink: 0;
    }
    .shelf-label {
        display: none;
    }
    .shelf-book::before,
    .shelf-book::after {
        left: 2px;
        right: 2px;
        font-size: 7px;
        padding: 2px 0;
    }
    .shelf-edge {
        height: 3px !important;
    }
    
    /* Game screen: same per-row scroll */
    .slots-container .shelf-books,
    .books-container .shelf-books {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        padding: 0 2px 1px;
        scrollbar-width: thin;
        display: flex;
    }
    .slots-container .shelf-segment,
    .books-container .shelf-segment {
        flex: 0 0 auto;
        display: flex;
        gap: 2px;
        align-items: flex-end;
    }
    .slots-container .empty-slot {
        min-width: 34px;
        flex-basis: 34px;
        flex-shrink: 0;
    }
    .slots-container .shelf-slot {
        min-width: 34px;
        flex-basis: 34px;
        flex-shrink: 0;
    }

    /* --- SHRINK THE TOP SHELF & BOOKS ON MOBILE --- */
    .slots-container {
        min-height: 50px !important;       /* Floor, not a forced height */
        padding: 4px 6px 2px 6px !important;
        border-width: 4px !important;
    }
    .slots-container .empty-slot {
        height: min(var(--spine-height, 90px), 140px) !important;
        padding-bottom: 4px !important;
    }
    .slots-container .empty-slot .slot-placeholder {
        font-size: clamp(1rem, 2vw, 1.5rem) !important;
    }
    
    .book-draggable,
    .slots-container .shelf-book {
        height: min(var(--spine-height, 110px), 140px) !important;
        padding: 8px 2px !important;
    }
    .book-draggable .book-line,
    .slots-container .shelf-book .book-line {
        font-size: 13px !important;
    }
    .slots-container .shelf-slot.is-future::after {
        height: min(var(--spine-height, 90px), 140px) !important;
    }
}

/* ===== UTILITIES ===== */
.book-draggable,
.empty-slot,
.btn,
.chest-btn,
.hud-back,
.hud-quills {
    touch-action: manipulation;
}

