[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }

:root {
    --glass: rgba(15, 12, 8, 0.62);
    --glass-border: rgba(255, 235, 200, 0.25);
    --accent: #c9a24b;
    --accent-hover: #e0bb63;
    --text: #f3ead8;
    --castle: #ff6b5b;
    --relic: #7cc4ff;
}

html, body { height: 100%; margin: 0; }

body {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.05em;
    color: var(--text);
    background: #1b1610;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Blurred copy of the current scene filling the whole window */
#backdrop {
    position: fixed;
    inset: -40px;
    z-index: -1;
    background: #1b1610 url('../main.webp') center / cover no-repeat;
    filter: blur(18px) brightness(0.55);
    transition: background-image 0.4s;
}
/* Menu: the full picture, sharp, stretched to the window like the original page */
body:not(.playing) #backdrop {
    inset: 0;
    filter: none;
    background-size: 100% 100%;
}
/* Tall phone screens: stretching a square picture that far looks wrong, so crop instead */
@media (max-aspect-ratio: 3/4) {
    body:not(.playing) #backdrop { background-size: cover; }
}
/* Menu title in the original dark style */
body:not(.playing) header { text-shadow: none; color: #333; }
/* Menu panel: darker and more blurred so it reads the same over the sharp background */
#menu.panel { background: rgba(15, 12, 8, 0.7); backdrop-filter: blur(10px) brightness(0.85); }
body:not(.playing) .tagline { font-family: Arial, sans-serif; font-size: 1.1em; color: #111; }

header {
    flex: 0 0 auto;
    text-align: center;
    padding: 6px 12px 4px;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

h1, h2 {
    font-family: 'IM Fell English SC', Georgia, serif;
    font-weight: normal;
    margin: 0;
}
h1 { font-size: clamp(1.8em, 6vw, 3em); line-height: 1.1; }

.tagline { margin: 4px 0; font-size: 1em; }
body.playing .tagline { display: none; }

/* HUD */
#hud {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 14px;
    margin-top: 4px;
    font-size: 0.95em;
}
.hud-item strong { font-variant-numeric: tabular-nums; color: var(--accent-hover); }

button {
    font: inherit;
    cursor: pointer;
}

.hud-button, .small-button {
    background: rgba(0, 0, 0, 0.5);
    color: var(--text);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.9em;
    transition: background-color 0.2s;
}
.hud-button:hover:not(:disabled), .small-button:hover { background: rgba(255, 255, 255, 0.15); }
.hud-button:disabled { opacity: 0.45; cursor: not-allowed; }

/* Menu panel */
.panel {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 15px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    padding: 24px;
    width: min(440px, calc(100% - 32px));
    margin: clamp(16px, 8vh, 120px) auto 16px;
    text-align: center;
    max-height: calc(100% - 32px);
    overflow-y: auto;
}

.panel > button, #join-form button {
    background: #1a1a1a;
    color: #fff;
    padding: 12px 24px;
    margin: 6px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    transition: background-color 0.2s, transform 0.15s;
}
.panel > button:hover, #join-form button:hover { background: #4a4030; transform: scale(1.04); }

.small { font-size: 0.85em; opacity: 0.85; }
.link-button { background: none; border: none; color: var(--accent-hover); text-decoration: underline; font-size: 1em; padding: 0 4px; }
.link-button:hover { color: #ff9b8a; }
.more-games { margin: 16px 0 0; }
.more-games a { color: var(--accent-hover); }
.build-info { margin: 14px 0 0; font-size: 0.7em; opacity: 0.5; }
.hud-code {
    background: none; border: none; padding: 0; color: var(--accent-hover);
    font-weight: bold; font-variant-numeric: tabular-nums; text-decoration: underline dotted; cursor: copy;
}
.level-intro-code { margin-top: 14px; font-size: 0.95em; opacity: 0; line-height: 1.5; }
.level-intro-code strong { color: var(--accent-hover); letter-spacing: 0.12em; font-size: 1.3em; }
#level-intro.play .level-intro-code { animation: introFade 0.8s 1.2s forwards; }

#join-form { margin-top: 14px; }
#join-code-input {
    font: bold 1.2em monospace;
    letter-spacing: 0.15em;
    width: 7.5em;
    padding: 8px;
    text-align: center;
    border-radius: 6px;
    border: 1px solid #ccc;
}
.error { color: #ff9b8a; min-height: 1.2em; margin: 6px 0 0; font-size: 0.9em; }

/* Saved games on the menu */
#saved-games { margin-top: 18px; border-top: 1px solid var(--glass-border); padding-top: 12px; }
#saved-games h2 { font-size: 1.5em; color: var(--accent-hover); margin-bottom: 8px; }
#saved-games-list, #other-games-list { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.other-games-toggle { display: block; margin: 10px auto 6px; font-size: 0.9em; }
.game-card {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 10px 12px;
}
.game-card.recent { border-color: var(--accent); }
.game-card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.game-card-code { font: bold 1.15em monospace; letter-spacing: 0.1em; color: var(--accent-hover); margin-right: 4px; }
.level-badge {
    font-size: 0.75em;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    opacity: 0.6;
    white-space: nowrap;
}
.level-badge.done { background: #2f6b2a; border-color: #67c25d; opacity: 1; }
.level-progress { display: flex; gap: 3px; margin-top: 8px; }
.level-progress .seg {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 0.6em;
    line-height: 1.6;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.45);
    overflow: hidden;
}
.level-progress .seg.done { background: #2f6b2a; color: #d9f5d4; }
.level-progress .seg.current { outline: 1px solid var(--accent); color: var(--accent-hover); }
.game-card-delete {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text);
    opacity: 0.5;
    padding: 2px 6px;
}
.game-card-delete:hover { opacity: 1; color: #ff9b8a; }
.game-card-status { margin: 6px 0 8px; font-size: 0.95em; }
.game-card-stats { margin: -4px 0 8px; font-size: 0.8em; opacity: 0.8; }
.journal-completed { text-align: center; margin: 4px 0; padding: 6px 10px; border-radius: 8px; background: rgba(47, 107, 42, 0.5); border: 1px solid #67c25d; font-size: 0.9em; }
.game-card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.game-card-actions .action-button { padding: 7px 14px; font-size: 0.95em; }

/* Stage: a square that fits the remaining space, so the bird is at the
   same place in the picture on every screen size. */
#stage-wrap {
    flex: 1 1 auto;
    min-height: 0;
    container-type: size;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px 8px;
}
body:not(.playing) #stage-wrap { display: none; }

#stage {
    position: relative;
    --ar: 1;   /* picture width / height, set per scene */
    width: min(100cqw, calc(100cqh * var(--ar)));
    aspect-ratio: var(--ar);
    background: #000 center / cover no-repeat;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    cursor: crosshair;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.stage-banner {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.9em;
    white-space: nowrap;
    max-width: 94%;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 3;
}
.stage-banner.fade { animation: bannerFade 6s forwards; }
@keyframes bannerFade {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; }
}

#hummingbird {
    position: absolute;
    width: 4.5%;
    min-width: 26px;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    z-index: 2;
    opacity: 0.92;
    animation: hover 2.4s ease-in-out infinite;
}
#hummingbird::after { /* larger invisible tap target for touch screens */
    content: '';
    position: absolute;
    inset: -8px;
}
#hummingbird img {
    width: 100%; height: 100%; display: block; pointer-events: none;
    transform: rotate(var(--tilt, 0deg));
}
#hummingbird.flipped img { transform: scaleX(-1) rotate(var(--tilt, 0deg)); }

/* Level 2: smaller (size set from JS), fainter, still, and blended in */
#hummingbird.expert {
    min-width: 15px;
    opacity: 0.72;
    animation: none;
}
#hummingbird.expert img { filter: saturate(0.55) brightness(0.8) contrast(0.9); }
#hummingbird.expert::after { inset: -10px; }
/* Relic round in the same picture: smaller bird (size set from JS), very slightly fainter */
#hummingbird.small-round { min-width: 21px; opacity: 0.93; }
#hummingbird.small-round::after { inset: -10px; }
.hud-round { font-size: 0.8em; padding: 2px 10px; border-radius: 10px; border: 1px solid var(--glass-border); }
.hud-round.small { background: rgba(201, 162, 75, 0.35); border-color: var(--accent); }
#hummingbird.found { animation: foundPop 0.6s ease-out forwards; }

@keyframes hover {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(1px, -3px); }
}
@keyframes foundPop {
    0% { transform: scale(1); opacity: 1; }
    40% { transform: scale(2.2); opacity: 1; filter: drop-shadow(0 0 10px gold); }
    100% { transform: scale(0.2) translateY(-60px); opacity: 0; }
}

#hint-ring {
    position: absolute;
    aspect-ratio: 1 / 1;
    transform: translate(-50%, -50%);
    border: 3px dashed rgba(255, 220, 120, 0.9);
    border-radius: 50%;
    box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.25), inset 0 0 20px rgba(255, 220, 120, 0.4);
    pointer-events: none;
    z-index: 1;
}
#hint-ring.pulse { animation: ringPulse 1.4s ease-out 2; }
@keyframes ringPulse {
    0% { transform: translate(-50%, -50%) scale(1.4); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.miss {
    position: absolute;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    pointer-events: none;
    animation: miss 0.6s ease-out forwards;
}
@keyframes miss {
    from { transform: scale(0.3); opacity: 1; }
    to { transform: scale(1.6); opacity: 0; }
}

.sparkle {
    position: absolute;
    width: 8px;
    height: 8px;
    margin: -4px 0 0 -4px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, gold 60%, transparent 70%);
    pointer-events: none;
    z-index: 3;
    animation: sparkle 0.9s ease-out forwards;
}
@keyframes sparkle {
    to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}

/* Covers the picture while the bird moves or a new picture loads */
#curtain {
    position: absolute;
    inset: 0;
    z-index: 4;
    background: #0d0a07;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.38s ease;
}
#curtain.closed { opacity: 1; pointer-events: auto; }
#curtain.instant { transition: none; }

/* Level title card */
#level-intro {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.85) 75%);
    cursor: pointer;
}
.level-intro-card { text-align: center; padding: 20px; }
.level-intro-ornament { color: var(--accent); letter-spacing: 0.6em; opacity: 0; }
.level-intro-number {
    font-family: 'IM Fell English SC', Georgia, serif;
    font-size: clamp(3em, 14cqmin, 7em);
    line-height: 1.1;
    background: linear-gradient(180deg, #fff6d5 0%, #e0bb63 55%, #8a6a24 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.9));
    opacity: 0;
}
.level-intro-text { font-size: 1.15em; max-width: 26em; margin: 4px auto 0; opacity: 0; }
.level-intro-tap { margin-top: 18px; font-size: 0.85em; opacity: 0; }
#level-intro.play .level-intro-ornament { animation: introFade 0.8s 0.1s forwards; }
#level-intro.play .level-intro-number { animation: introZoom 1s 0.2s cubic-bezier(.2, 1.4, .4, 1) forwards; }
#level-intro.play .level-intro-text { animation: introFade 0.8s 0.9s forwards; }
#level-intro.play .level-intro-tap { animation: introBlink 1.6s 1.6s infinite; }
@keyframes introZoom {
    from { transform: scale(2.5); opacity: 0; letter-spacing: 0.4em; }
    to { transform: scale(1); opacity: 1; letter-spacing: 0.05em; }
}
@keyframes introFade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes introBlink { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.9; } }

/* Level complete stamp */
.stamp {
    display: inline-block;
    font-family: 'Permanent Marker', 'IM Fell English SC', cursive;
    font-size: 1.6em;
    color: #f9c80e;
    border: 3px solid #f9c80e;
    border-radius: 8px;
    padding: 2px 14px;
    transform: rotate(-4deg);
    text-shadow: 0 0 10px rgba(249, 200, 14, 0.6);
    animation: stampIn 0.5s cubic-bezier(.2, 1.6, .4, 1);
    margin-bottom: 4px;
}
@keyframes stampIn { from { transform: rotate(-4deg) scale(3); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }

/* Final celebration: graffiti wall */
#celebration {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: hidden;
    background:
        linear-gradient(rgba(10, 8, 20, 0.82), rgba(10, 8, 20, 0.9)),
        repeating-linear-gradient(0deg, transparent 0 38px, rgba(255, 255, 255, 0.04) 38px 40px),
        repeating-linear-gradient(90deg, transparent 0 78px, rgba(255, 255, 255, 0.04) 78px 80px);
    animation: introFade 0.4s;
}
#graffiti-tags { position: absolute; inset: 0; pointer-events: none; }
.graffiti-tag {
    position: absolute;
    font-family: 'Permanent Marker', cursive;
    white-space: nowrap;
    transform: rotate(var(--rot)) scale(0);
    text-shadow: 0 0 8px currentColor, 2px 2px 0 rgba(0, 0, 0, 0.6);
    opacity: 0;
    animation: sprayIn 0.5s forwards;
}
@keyframes sprayIn {
    0% { transform: rotate(var(--rot)) scale(1.8); opacity: 0; filter: blur(6px); }
    100% { transform: rotate(var(--rot)) scale(1); opacity: 0.85; filter: blur(0); }
}
.celebration-card {
    position: relative;
    text-align: center;
    max-width: 560px;
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
    background: rgba(20, 16, 30, 0.75);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 20px 22px;
    box-shadow: 0 0 60px rgba(185, 103, 255, 0.35);
}
.graffiti-main {
    font-family: 'Permanent Marker', cursive;
    font-size: clamp(2.6em, 11vw, 4.6em);
    line-height: 1.05;
    background: linear-gradient(90deg, #ff3d7f, #f9c80e, #7cff4f, #2de2e6, #b967ff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(3px 3px 0 #000) drop-shadow(0 0 14px rgba(255, 61, 127, 0.6));
    transform: rotate(-5deg);
    animation: graffitiIn 0.9s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes graffitiIn {
    from { transform: rotate(-5deg) scale(0.2); opacity: 0; filter: blur(10px); }
    to { transform: rotate(-5deg) scale(1); opacity: 1; }
}
.celebration-card h2 { font-size: 2em; color: var(--accent-hover); margin-top: 6px; }
.celebration-card ul { list-style: none; padding: 0; margin: 10px 0; }
.celebration-card li { margin: 4px 0; }

#fx-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

/* Message box */
#message {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 32px);
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid var(--glass-border);
    padding: 14px 22px;
    border-radius: 10px;
    font-size: 1.1em;
    text-align: center;
    z-index: 10;
    animation: slideUp 0.35s ease-out;
}
#message p { margin: 6px 0; }
@keyframes slideUp {
    from { transform: translate(-50%, 30px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

.congrats { font-family: 'IM Fell English SC', Georgia, serif; font-size: 1.3em; color: var(--accent-hover); }

.key-location {
    font-family: 'IM Fell English SC', Georgia, serif;
    font-size: 1.2em;
    color: #fff;
}
.castle-key-location { color: var(--castle); font-weight: bold; }
.relic-key-location { color: var(--relic); font-weight: bold; }

.button-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
}
.button-container:empty { display: none; }

.action-button {
    padding: 10px 20px;
    font-size: 16px;
    border: none;
    border-radius: 6px;
    background: #4a4a4a;
    color: #fff;
    transition: background-color 0.2s;
}
.action-button:hover { background: #666; }
.action-button.primary { background: #8a6a24; }
.action-button.primary:hover { background: #a8822f; }

/* Journal modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 20;
}
.modal-card {
    background: #241d14;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 20px;
    width: min(560px, 100%);
    max-height: 100%;
    overflow-y: auto;
}
.modal-card h2 { text-align: center; font-size: 1.8em; color: var(--accent-hover); }
.modal-card .small { text-align: center; }
.modal-card table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.95em; }
.modal-card th, .modal-card td { padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); text-align: left; }
.modal-card th { color: var(--accent); font-weight: normal; }
.tabs { display: flex; justify-content: center; gap: 8px; margin: 10px 0 4px; }
.tab {
    background: transparent; color: var(--text);
    border: 1px solid var(--glass-border); border-radius: 16px; padding: 4px 14px;
}
.tab.active { background: var(--accent); color: #1b1610; border-color: var(--accent); }
.modal-card tr.current { background: rgba(201, 162, 75, 0.15); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
