/* Shelf Sort: cozy tactile supermarket sorting puzzle with Allo typography & glossy Bentomino pills. */
:root {
    --ink: #3c2410;
    --cream: #fff9ef;
    --gold-top: #ffe05a;
    --gold-bot: #f09e18;
    --gold-lip: #b56c08;
    --green-top: #67eb58;
    --green-bot: #1db035;
    --green-lip: #107822;
    --blue-top: #5cc4ff;
    --blue-bot: #2480e8;
    --blue-lip: #1454a8;
    --coral-top: #ff7e66;
    --coral-bot: #e64638;
    --coral-lip: #a8241a;
    --round: "ROND" 100;
    --font: "Allo", system-ui, sans-serif;
    --top: max(10px, env(safe-area-inset-top));
    --bottom: max(12px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #3d5475;
    color: var(--ink);
    font-family: var(--font);
    font-variation-settings: var(--round);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

body { touch-action: none; overscroll-behavior: none; }

button {
    font: inherit;
    color: inherit;
    border: 0;
    padding: 0;
    background: none;
    cursor: pointer;
    touch-action: manipulation;
}

svg { display: block; }

/* ---------------------------------------------------------------- loader */

#loader {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 22px;
    background: radial-gradient(ellipse at 50% 40%, #58749e, #314460);
    transition: opacity 0.22s;
}

#loader img { width: min(72vw, 330px); animation: breathe-logo 1.5s ease-in-out infinite alternate; }
#loader i {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.28);
    border-top-color: #ffe258;
    animation: spin 0.85s linear infinite;
}
#loader.gone { opacity: 0; pointer-events: none; }

@keyframes breathe-logo { to { transform: scale(1.04); } }
@keyframes spin { to { transform: rotate(1turn); } }

/* ---------------------------------------------------------------- cozy drifting backdrop */

#bg {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: #3d5475;
}

body[data-world="market"] { --back: url(media/back-market.jpg); --wash: rgba(46, 70, 104, 0.52); --vig: rgba(24, 38, 60, 0.56); }
body[data-world="produce"] { --back: url(media/back-produce.jpg); --wash: rgba(42, 78, 56, 0.42); --vig: rgba(18, 40, 26, 0.52); }
body[data-world="bakery"] { --back: url(media/back-bakery.jpg); --wash: rgba(102, 66, 36, 0.34); --vig: rgba(54, 32, 14, 0.52); }
body[data-world="night"] { --back: url(media/back-night.jpg); --wash: rgba(24, 30, 58, 0.42); --vig: rgba(12, 14, 34, 0.62); }

#bg i {
    position: absolute;
    inset: -12%;
    background: var(--back, url(media/back-market.jpg)) center / cover;
    animation: drift 48s ease-in-out infinite alternate;
    will-change: transform;
    transition: background-image 0.8s ease;
}

#bg i + i {
    transform: scaleX(-1);
    animation: drift2 40s ease-in-out infinite alternate, breathe 24s ease-in-out infinite alternate;
    opacity: 0.42;
}

#bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(180deg, var(--wash, rgba(46, 70, 104, 0.52)), var(--wash, rgba(46, 70, 104, 0.52))),
        radial-gradient(ellipse at 50% 46%, rgba(255, 250, 240, 0.08) 18%, var(--vig, rgba(24, 38, 60, 0.56)) 100%);
}

@keyframes drift {
    from { transform: scale(1.06) translate(-2.2%, -1.8%) rotate(-1.2deg); }
    to { transform: scale(1.15) translate(2.2%, 2.2%) rotate(1.6deg); }
}

@keyframes drift2 {
    from { transform: scaleX(-1) scale(1.16) translate(2.6%, 1.8%) rotate(2.4deg); }
    to { transform: scaleX(-1) scale(1.07) translate(-2.2%, -2.6%) rotate(-1.8deg); }
}

@keyframes breathe { from { opacity: 0.16; } to { opacity: 0.56; } }

/* ---------------------------------------------------------------- screens */

#home, #game { position: fixed; inset: 0; display: none; }
body[data-screen="home"] #home, body[data-screen="game"] #game { display: block; }

/* ---------------------------------------------------------------- glossy tactile buttons */

.key, .big, .tool {
    position: relative;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--ink);
    background: linear-gradient(#ffffff, #f2e5d0);
    box-shadow: 0 5px 0 #baa180, 0 8px 0 rgba(22, 16, 10, 0.30);
    transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s, filter 0.15s;
}

.key:active, .big:active, .tool:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #baa180, 0 3px 0 rgba(22, 16, 10, 0.30);
}

.key.round { width: 46px; height: 46px; }
.key.round svg { width: 22px; height: 22px; }

.key .dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ef3048;
    box-shadow: 0 0 0 2.5px #fff;
    display: none;
}
.key.has-dot .dot { display: block; }

.tool {
    width: 60px;
    height: 60px;
    border: 2.5px solid rgba(255, 255, 255, 0.65);
}
.tool svg { width: 27px; height: 27px; }
.tool:disabled { opacity: 0.45; cursor: default; filter: grayscale(0.35); }
.tool:disabled:active { transform: none; }

.tool.gold {
    color: #fff;
    background: linear-gradient(var(--gold-top), var(--gold-bot));
    box-shadow: 0 5px 0 var(--gold-lip), 0 8px 0 rgba(22, 16, 10, 0.32);
}
.tool.gold:active { box-shadow: 0 1px 0 var(--gold-lip), 0 3px 0 rgba(22, 16, 10, 0.32); }

.tool.blue {
    color: #fff;
    background: linear-gradient(var(--blue-top), var(--blue-bot));
    box-shadow: 0 5px 0 var(--blue-lip), 0 8px 0 rgba(22, 16, 10, 0.32);
}
.tool.blue:active { box-shadow: 0 1px 0 var(--blue-lip), 0 3px 0 rgba(22, 16, 10, 0.32); }

.tool.coral {
    color: #fff;
    background: linear-gradient(var(--coral-top), var(--coral-bot));
    box-shadow: 0 5px 0 var(--coral-lip), 0 8px 0 rgba(22, 16, 10, 0.32);
}
.tool.coral:active { box-shadow: 0 1px 0 var(--coral-lip), 0 3px 0 rgba(22, 16, 10, 0.32); }

.tool.pulse { animation: pulse-hint 1.2s ease-in-out infinite; }
@keyframes pulse-hint {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.tool .count, .big .count {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    border-radius: 12px;
    font-style: normal;
    font-size: 13px;
    font-weight: 900;
    line-height: 24px;
    text-align: center;
    color: #fff;
    background: #ef2e48;
    box-shadow: 0 0 0 2.5px #fff;
    font-feature-settings: "tnum";
}

.big { width: 68px; height: 68px; }
.big svg { width: 30px; height: 30px; }
.big.plain { color: var(--ink); background: linear-gradient(#ffffff, #f2e5d0); box-shadow: 0 5px 0 #baa180, 0 8px 0 rgba(22, 16, 10, 0.24); }
.big.green { color: #fff; background: linear-gradient(var(--green-top), var(--green-bot)); box-shadow: 0 5px 0 var(--green-lip), 0 8px 0 rgba(22, 16, 10, 0.28); }
.big.green:active { box-shadow: 0 1px 0 var(--green-lip), 0 3px 0 rgba(22, 16, 10, 0.28); }
.big.blue { color: #fff; background: linear-gradient(var(--blue-top), var(--blue-bot)); box-shadow: 0 5px 0 var(--blue-lip), 0 8px 0 rgba(22, 16, 10, 0.28); }
.big.blue:active { box-shadow: 0 1px 0 var(--blue-lip), 0 3px 0 rgba(22, 16, 10, 0.28); }
.big[hidden] { display: none; }

/* ---------------------------------------------------------------- home / world map */

#mapview { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#scroller {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    overscroll-behavior: contain;
    scrollbar-width: none;
}
#scroller::-webkit-scrollbar { display: none; }
@media (pointer: fine) { #scroller { cursor: grab; } #scroller.dragging { cursor: grabbing; } }

.bar-top {
    position: absolute;
    top: var(--top);
    left: 14px;
    right: 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    pointer-events: none;
    z-index: 5;
}
.bar-top > * { pointer-events: auto; }

#logo {
    width: min(56vw, 250px);
    margin-top: -6px;
    pointer-events: none;
}

.bar-foot {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(var(--bottom) + 8px);
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
}

.play {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 64px;
    padding: 0 34px;
    border-radius: 32px;
    color: #fff;
    font-size: clamp(20px, 5vw, 25px);
    font-weight: 900;
    letter-spacing: 0.02em;
    border: 2.5px solid rgba(255, 255, 255, 0.56);
    text-shadow: 0 2px 0 rgba(16, 72, 22, 0.52);
    font-feature-settings: "tnum";
    transition: transform 0.08s, box-shadow 0.08s;
}
.play svg { width: 24px; height: 24px; }
.play.green {
    background: linear-gradient(var(--green-top), var(--green-bot));
    box-shadow: 0 6px 0 var(--green-lip), 0 11px 0 rgba(16, 20, 28, 0.34);
}
.play.green:active {
    transform: translateY(5px);
    box-shadow: 0 1px 0 var(--green-lip), 0 4px 0 rgba(16, 20, 28, 0.34);
}

/* ---------------------------------------------------------------- gameplay HUD & stage */

#view, #fxview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}
#view { cursor: grab; }
#view.dragging { cursor: grabbing; }
#fxview { pointer-events: none; z-index: 3; }

#top {
    position: absolute;
    top: var(--top);
    left: 14px;
    right: 14px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    pointer-events: none;
    z-index: 6;
}
#top > * { pointer-events: auto; }
.top-left { display: flex; gap: 8px; align-items: center; }
.top-right { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
#center-hud { display: flex; justify-content: center; pointer-events: none; }

#level-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 16px;
    border-radius: 22px;
    background: rgba(255, 249, 238, 0.94);
    border: 2.5px solid #d49652;
    box-shadow: 0 4px 0 #9d6328, 0 7px 0 rgba(18, 16, 14, 0.25);
    color: var(--ink);
    font-feature-settings: "tnum";
}

#level-label {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.prog-track {
    width: clamp(68px, 18vw, 136px);
    height: 11px;
    border-radius: 6px;
    background: #e8d3b3;
    overflow: hidden;
    box-shadow: inset 0 2px 2px rgba(78, 42, 12, 0.2);
}

#prog-fill {
    width: 0%;
    height: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, #ffbd2e, #5ce04c);
    transition: width 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

#sets-val {
    font-size: 15px;
    font-weight: 850;
    color: #7c4a18;
    min-width: 34px;
    text-align: right;
}

#bar {
    position: absolute;
    left: 50%;
    bottom: calc(var(--bottom) + 6px);
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    align-items: center;
    z-index: 6;
}

/* On very wide, short windows move the tool tray cleanly to the right side so shelves never get crowded! */
@media (min-aspect-ratio: 16/9) and (max-height: 600px) {
    #bar {
        left: auto;
        right: 16px;
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
        flex-direction: column;
        gap: 12px;
    }
    .tool { width: 52px; height: 52px; }
    .tool svg { width: 23px; height: 23px; }
}

/* ---------------------------------------------------------------- modal sheets & cards */

.sheet {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(20, 26, 40, 0.56);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    animation: fade-in 0.2s ease-out;
}
.sheet[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } }

.card {
    position: relative;
    width: min(92vw, 370px);
    padding: 28px 24px 26px;
    border-radius: 30px;
    background: linear-gradient(#fffdf8, #f7ead4);
    border: 3px solid #e0ad6e;
    box-shadow: 0 10px 0 #a36a2c, 0 22px 42px rgba(12, 16, 28, 0.45);
    text-align: center;
    animation: pop-card 0.26s cubic-bezier(0.2, 1.35, 0.4, 1);
}

@keyframes pop-card {
    from { transform: scale(0.86) translateY(16px); opacity: 0; }
}

.card h2 {
    margin: 6px 0 14px;
    font-size: 30px;
    font-weight: 900;
    color: var(--ink);
    letter-spacing: 0.02em;
}

.card .close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #7c5634;
    background: rgba(140, 92, 42, 0.14);
}
.card .close svg { width: 17px; height: 17px; }

.card .row {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

/* Win card stars & glints */
.stars {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 6px;
    height: 82px;
    margin-top: -6px;
}
.stars img {
    width: 66px;
    height: 66px;
    object-fit: contain;
    opacity: 0.22;
    transform: scale(0.75);
    transition: transform 0.34s cubic-bezier(0.2, 1.55, 0.4, 1), opacity 0.25s;
}
.stars img:nth-child(2) { width: 82px; height: 82px; transform: scale(0.75) translateY(-8px); }
.stars img.lit { opacity: 1; transform: scale(1); }
.stars img:nth-child(2).lit { transform: scale(1) translateY(-8px); }

.stars .glint {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--s);
    height: var(--s);
    background: radial-gradient(circle, #fff 0%, #ffe870 35%, transparent 70%);
    clip-path: polygon(50% 0%, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0% 50%, 38% 38%);
    opacity: 0;
    pointer-events: none;
}
.stars.sparkle .glint { animation: twinkle var(--d) ease-in-out infinite alternate; }
@keyframes twinkle {
    from { opacity: 0.12; transform: scale(0.5) rotate(0deg); }
    to { opacity: 0.95; transform: scale(1.12) rotate(24deg); }
}

.unlock-box {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 4px auto 8px;
    padding: 8px 16px 8px 12px;
    border-radius: 18px;
    background: #fff4db;
    border: 2px solid #e6b46c;
}
.unlock-box[hidden] { display: none; }
.unlock-box img { width: 42px; height: 42px; object-fit: contain; }
.unlock-box span { font-size: 16px; font-weight: 850; color: #7a4514; }

.chip {
    display: inline-block;
    margin: 4px auto 0;
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.03em;
}
.chip.gold { background: #ffe478; color: #784208; border: 2px solid #eab028; }
.chip[hidden] { display: none; }

/* Daily card */
.sub { margin: 4px 0 8px; font-size: 16px; font-weight: 700; color: #7c5634; }
.sub.done { display: inline-flex; align-items: center; gap: 6px; color: #1d9a34; font-weight: 900; }
.sub.done svg { width: 18px; height: 18px; }
.sub[hidden] { display: none; }
.streak { margin: 8px 0 18px; font-size: 18px; font-weight: 800; color: var(--ink); }
.streak b {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 12px;
    border-radius: 12px;
    background: #ffe066;
    color: #784208;
    font-feature-settings: "tnum";
}
#daily-go { margin: 0 auto; }

/* Settings form */
.card.form { text-align: left; }
.card.form h2 { text-align: center; margin-bottom: 18px; }

.line {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0 6px;
    font-size: 18px;
    font-weight: 800;
    color: var(--ink);
}
.line svg { width: 22px; height: 22px; color: #9c6228; }
.line span { flex: 1; }

.switch {
    appearance: none;
    width: 52px;
    height: 30px;
    border-radius: 15px;
    background: #d9c6ab;
    position: relative;
    cursor: pointer;
    transition: background 0.18s;
}
.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.22);
    transition: transform 0.18s;
}
.switch:checked { background: #34c749; }
.switch:checked::after { transform: translateX(22px); }

input[type="range"] {
    width: 100%;
    accent-color: #d98228;
    margin: 2px 0 8px;
    cursor: pointer;
}

.credit {
    margin: 18px 0 0;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: #9c7d5c;
}

@media (max-width: 440px) {
    #top { left: 10px; right: 10px; gap: 6px; }
    .key.round { width: 42px; height: 42px; }
    .key.round svg { width: 20px; height: 20px; }
    #level-pill { height: 42px; padding: 0 12px; gap: 8px; }
    #level-label { font-size: 14px; }
    #sets-val { font-size: 14px; }
    #bar { gap: 12px; }
    .tool { width: 56px; height: 56px; }
}
