html, body { 
  height: 100%; 
  margin: 0; 
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 
  background:#ffffff; 
  color:#46220a; 
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Background decoration */
.bg-decoration {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}
.bg-mascot {
  position: absolute;
  background-image: url('images/mascot.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.06;
}

body {
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.wrap { 
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px; 
}
.card {
  background: #fff5dc;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(70, 34, 10, 0.1);
    width: min(90vw, 500px);
    max-width: 100%;
  margin: 2rem auto;
  text-align: center;
  transition: opacity 0.4s, transform 0.4s;
    box-sizing: border-box;
}
@media (max-width: 600px) {
    .card {
        width: min(90vw, 500px); /* clamp to viewport on small screens */
        margin: 1.25rem auto; /* slightly tighter vertical spacing on very small screens */
        padding: 1.6rem 1.4rem; /* reduce padding for better fit */
    }
}

.card[hidden] {
  display: none;
}
.card.slide-out-left {
    animation: slideOutLeft 0.4s ease-out forwards;
}
.card.slide-in-right {
    animation: slideInRight 0.4s ease-out forwards;
}
@keyframes slideOutLeft {
    0% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(-100vw); opacity: 0; }
}
@keyframes slideInRight {
    0% { transform: translateX(100vw); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}
h1 { color: #46220a; }
h2 { color: #46220a; margin: 0 0 8px; font-size: 24px; font-weight: 700; }
.h3, h3 { 
    text-align: center; 
    color: #46220a; 
    margin: 16px 0; 
}
.card { color: #46220a; }
h1 { margin: 0 0 12px; font-size: 22px; font-weight: 700; letter-spacing: 0.5px; color: #f8fafc; }
.img-frame { position: relative; background:#46220a; border:1px solid #1f2937; border-radius: 10px; padding: 12px; }
img { 
    display:block; 
    max-width:100%; 
    height:auto; 
    border-radius: 8px; 
}
.hint { 
    margin-top:10px; 
    color:#94a3b8; 
    font-size: 13px; 
}
a { 
    color:#93c5fd; 
}

/* Top bar */
.top-bar {
    background: #fff5dc;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-bottom: 1px solid #f1e9cf;
}
.top-bar .logo {
        display: block;
        height: auto;           /* allow natural aspect ratio */
        max-height: 56px;       /* cap height on normal screens */
        width: auto;            /* preserve aspect */
        max-width: 90vw;        /* prevent overflow on very small screens */
        object-fit: contain;    /* safety for odd cases */
}
@media (max-width: 600px) {
    .top-bar .logo {
        max-height: 48px;       /* slightly smaller cap on very small screens */
    }
}
.top-bar .brand {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.top-bar .slogan {
    margin-top: 4px;
    color: #46220a;
    opacity: 0.85;
    font-weight: 600;
    font-size: clamp(12px, 2vw, 16px);
    text-align: center;
}
.album-link {
    position: relative; /* for badge positioning */
    display: inline-flex;
}
.album-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 16px;
    height: 16px;
    background: #fa901d;
    color: #46220a;
    font-weight: 700;
    font-size: 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(70,34,10,0.18);
    border: 2px solid #fff5dc;
    pointer-events: none;
    z-index: 101;
    transition: transform 0.1s ease;
}
.album-badge.badge-update {
    animation: badgeZoomStar 0.6s ease-out;
}
@keyframes badgeZoomStar {
    0% { 
        transform: scale(1); 
        filter: brightness(1);
    }
    30% { 
        transform: scale(1.5); 
        filter: brightness(1.6);
        box-shadow: 0 0 12px rgba(250, 144, 29, 0.8);
    }
    50% {
        transform: scale(1.3);
        filter: brightness(1.5);
    }
    100% { 
        transform: scale(1); 
        filter: brightness(1);
    }
}


.album-icon {
    display: block;
    height: 75px;
    width: auto;
    transition: transform 0.2s ease;
}
.toys-icon {
    display: block;
    height: 75px;
    width: auto;
}
.toys-wrapper { position: relative; display: inline-flex; }
.toys-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 16px;
    height: 16px;
    background: #fa901d;
    color: #46220a;
    font-weight: 700;
    font-size: 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(70,34,10,0.18);
    border: 2px solid #fff5dc;
    pointer-events: none;
    z-index: 101;
    transition: transform 0.1s ease;
}
.album-toolbar {
    position: fixed; /* default: not small screens */
    top: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 500;
}
.album-icon:hover {
    transform: scale(1.1);
}

/* Album overlay and card */
.album-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: flex-end; /* push album card to right */
    align-items: flex-start; /* top alignment */
    padding: 90px 16px 16px; /* smaller right/side margin to appear flush */
    z-index: 1000;
    pointer-events: auto; /* capture clicks for outside-close */
}
.album-overlay[hidden] {
    display: none;
}
.album-card {
    background: #fff5dc;
    border-radius: 16px;
    padding: 24px 24px 32px;
    width: 360px; /* expanded width */
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: 0 8px 28px rgba(70, 34, 10, 0.25);
    color: #46220a;
    pointer-events: auto; /* re-enable interaction inside card */
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0; /* override .card centering */
}
.clear-album-btn {
    margin-top: 4px;
    align-self: stretch;
    padding: 8px 14px; /* reduced height */
    border: 2px solid #46220a;
    background: #fff5dc;
    color: #46220a;
    border-radius: 10px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
}
.clear-album-btn:hover:not(:disabled) {
    background: #46220a;
    color: #ffffff;
    transform: translateY(-2px);
}
.clear-album-btn:active:not(:disabled) {
    transform: translateY(0);
}
.clear-album-btn:disabled {
    opacity: 0.55;
    cursor: default;
}
@media (max-width: 600px) {
    .album-link {
        position: relative;
        right: auto;
        top: auto;
        z-index: auto;
        display: inline-flex;
        justify-content: center;
        margin: 10px auto 8px;
    }
    .album-badge {
        position: absolute;
        top: -8px;
        right: -8px;
        min-width: 16px;
        height: 16px;
        font-size: 12px;
    }
    .album-toolbar {
        position: static;
        display: flex;
        justify-content: center;
        margin: 10px auto 8px;
    }
}

/* Toast notification */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1600;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}
.toast {
    background: #ffffff;
    border: 2px solid #46220a;
    color: #46220a;
    padding: 12px 18px;
    border-radius: 12px;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(70,34,10,0.25);
    display: flex;
    gap: 16px;
    align-items: center;
    animation: toast-in 250ms ease;
}
@keyframes toast-in {
    0% { transform: translateY(12px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}
.toast button {
    padding: 8px 14px;
    background: #46220a;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}
.toast button:hover {
    background: #5c2d12;
}
.album-banner {
    height: 100px;
    width: auto;
    align-self: center;
    margin-bottom: 8px;
    display: block;
}
.album-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.album-header h2 {
    margin: 0;
    color: #46220a;
    font-size: clamp(20px, 4vw, 28px);
}
.album-close {
    background: none;
    border: none;
    font-size: 36px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.album-close:hover {
    color: #46220a;
}
.album-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* three columns */
    gap: 14px 12px;
}
.album-cat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.album-cat img {
    width: 100%;          /* fill grid cell width */
    height: auto;         /* preserve aspect ratio */
    object-fit: contain;  /* never stretch/crop, just contain */
    border-radius: 8px;
}
.album-cat-name {
    font-size: 14px;
    color: #46220a;
    text-align: center;
    font-weight: 600;
}
.album-cat.locked img {
    filter: grayscale(100%) brightness(0.5);
    opacity: 0.3;
}

/* Toys grid (inside toys card overlay) */
.toys-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 14px;
    margin-top: 8px;
}
.toy-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.toy-item img {
    width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
    background: #ffffff;
    padding: 10px;
    box-shadow: 0 4px 16px rgba(70,34,10,0.15);
}
.toy-name {
    font-size: 14px;
    font-weight: 600;
    color: #46220a;
    text-align: center;
}
@media (max-width: 600px) {
    .toys-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px 10px;
    }
    .toy-item img {
        padding: 8px;
    }
    .toy-name { font-size: 13px; }
}

/* Status removed */

/* Grid overlay covering the image area inside the padded frame */
.img-inner { position: relative; display: inline-block; overflow: hidden; border-radius: 8px; }
.grid-overlay {
    position: absolute;
    inset: 0; /* exactly cover the image */
    display: grid;
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    grid-template-rows: repeat(var(--rows, 4), 1fr);
    gap: 6px; /* spacing between cells */
    z-index: 2; /* above image */
    border-radius: 8px;
}

.cell {
    background: #ffffff;
    color: #46220a;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: clamp(14px, 2.2vw, 20px);
    cursor: pointer;
        -webkit-user-select: none;
    user-select: none;
    transition: transform 0.08s ease, background-color 0.15s ease, opacity 0.2s ease;
}
.cell:hover { transform: translateY(-1px); }
.cell:active { transform: translateY(0); }
.cell.selected { background: #fde68a; /* amber-200 */ }
.cell.hidden { opacity: 0; pointer-events: none; }

/* Celebration overlay and image zoom */
.confetti-canvas { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.img-frame.zoom-celebrate { animation: zoomPulse 0.9s ease-in-out infinite; transform-origin: center center; }
@keyframes zoomPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.06); }
    100% { transform: scale(1); }
}

/* Celebration logo overlay */
.celebration-logo {
    position: absolute;
    bottom: 8px;
    right: 8px;
    height: 70px;
    width: auto;
    z-index: 5;
    pointer-events: none;
}

/* Timer */
.timer { 
        margin-bottom: 10px; 
        margin-top: 10px;
        font-weight: 700; 
        letter-spacing: 0.5px; 
}

.restart-btn {
    margin: 20px auto;
    padding: 16px 40px;
    border-radius: 12px;
    border: 2px solid #46220a;
    background: #46220a;
    color: #ffffff;
    font-weight: 700;
    font-size: 18px;
    cursor: pointer;
    display: block;
    transition: all 0.2s ease;
}
.restart-btn[hidden] {
    display: none;
}
.restart-btn:hover { 
    filter: brightness(1.1);
    transform: scale(1.05);
}
.restart-btn:active { 
    transform: scale(0.98);
}

/* Message overlay */
.message-overlay {
        position: absolute;
        inset: 0;
        display: flex;
        align-items: flex-start;
        justify-content: center;
        padding-top: 20px;
        z-index: 5;
        pointer-events: none;
}
.message-overlay .text {
        color: #ffffff;
        font-weight: 800;
        text-align: center;
        font-size: clamp(24px, 4.2vw, 40px);
        text-shadow: 0 2px 6px rgba(0,0,0,0.45);
        animation: popIn 300ms ease-out both;
}
@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Game Mode Selection */
.game-mode-card {
    padding: 30px;
    gap: 16px;
}
.game-mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}
.game-mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 20px 24px;
    border: 2px solid #46220a;
    background: #ffffff;
    color: #46220a;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}
.game-mode-btn:hover {
    background: #46220a;
    color: #ffffff;
    transform: translateY(-2px);
}
.game-mode-btn:active {
    transform: translateY(0);
}
.mode-label {
    font-size: 20px;
}

/* Difficulty Selection */
.difficulty-card {
    padding: 30px;
    gap: 16px;
}
.difficulty-desc {
    margin: 0 0 20px;
    font-size: 14px;
    opacity: 0.8;
}
.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}
.difficulty-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 16px 24px;
    border: 2px solid #46220a;
    background: #ffffff;
    color: #46220a;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}
.difficulty-btn:hover {
    background: #46220a;
    color: #ffffff;
    transform: translateY(-2px);
}
.difficulty-btn:active {
    transform: translateY(0);
}
.diff-label {
    font-size: 18px;
}
.diff-grid {
    font-size: 14px;
    opacity: 0.7;
}
.difficulty-btn:hover .diff-grid {
    opacity: 0.9;
}

/* Cat Selection */
.cat-card {
    padding: 30px;
    gap: 16px;
}
.cat-desc {
    margin: 0 0 20px;
    font-size: 14px;
    opacity: 0.8;
}
.cat-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}
.level-navigation {
    display: flex;
    gap: 8px;
    justify-content: center;
    padding-top: 12px;
    border-top: 4px solid #ffffff;
}
.level-nav-btn {
    padding: 10px 20px;
    border: 2px solid #46220a;
    background: #ffffff;
    color: #46220a;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}
.level-nav-btn:hover:not(:disabled) {
    background: #fff5dc;
    transform: translateY(-1px);
}
.level-nav-btn.active {
    background: #46220a;
    color: #ffffff;
}
.level-nav-btn.locked {
    background: #f5f5f5;
    color: #999;
    border-color: #ddd;
    cursor: not-allowed;
}
.level-nav-btn .small-lock-icon {
    width: 14px;
    height: 14px;
    opacity: 0.5;
}
.cats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}
.cat-btn {
    padding: 14px 20px;
    border: 2px solid #46220a;
    background: #ffffff;
    color: #46220a;
    border-radius: 10px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.cat-btn:hover {
    background: #46220a;
    color: #ffffff;
    transform: translateY(-2px);
}
.cat-btn:active {
    transform: translateY(0);
}
.cat-btn.locked-level {
    background: #f0f0f0;
    color: #999;
    border-color: #ddd;
    cursor: not-allowed;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.cat-btn.locked-level:hover {
    background: #f0f0f0;
    color: #999;
    transform: none;
}
.cat-btn .lock-icon {
    width: 20px;
    height: 20px;
    opacity: 0.6;
}

/* Milestone overlays (Level Up, Toy Claim) */
.milestone-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.milestone-overlay[hidden] {
    display: none;
}
.milestone-card {
    background: #fff5dc;
    border-radius: 16px;
    padding: 48px 40px;
    box-shadow: 0 8px 28px rgba(70, 34, 10, 0.35);
    text-align: center;
    min-width: 320px;
}
.milestone-card h2 {
    margin: 0 0 32px;
    font-size: 32px;
    color: #46220a;
}
.toy-claim-image {
    width: 150px;
    height: auto;
    margin: 0 auto 16px;
    display: block;
}
.toy-claim-name {
    font-size: 20px;
    font-weight: 600;
    color: #46220a;
    margin-bottom: 32px;
}
.milestone-btn {
    padding: 14px 40px;
    background: #46220a;
    color: #ffffff;
    border: 2px solid #46220a;
    border-radius: 10px;
    font-weight: 700;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.milestone-btn:hover {
    filter: brightness(1.1);
    transform: scale(1.05);
}
.milestone-btn:active {
    transform: scale(0.98);
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px;
    margin-top: auto;
    color: #46220a;
    font-size: 14px;
    /* background: #ffffff; */
}
.footer .heart {
    color: #e74c3c;
    display: inline-block;
    animation: heartbeat 1.5s ease-in-out infinite;
}
@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.1); }
}
