/* Cake Slice Sort: sunlit luxury patisserie puzzle with Allo typography & glossy tactile pills. */
:root {
    --ink: #462312;
    --cream: #fffaf2;
    --gold-top: #ffe468;
    --gold-bot: #f09e18;
    --gold-lip: #b56a08;
    --berry-top: #ff7ba2;
    --berry-bot: #e63664;
    --berry-lip: #a31840;
    --green-top: #67eb58;
    --green-bot: #1db035;
    --green-lip: #107822;
    --blue-top: #62c8ff;
    --blue-bot: #2882e8;
    --blue-lip: #1654a8;
    --coral-top: #ff8668;
    --coral-bot: #e84836;
    --coral-lip: #a82418;
    --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: #6e4432;
    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%, #9a644a, #523020);
    transition: opacity 0.24s;
}

#loader img { width: min(74vw, 340px); 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: #ffe468;
    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); } }

/* ---------------------------------------------------------------- sunlit patisserie backdrop */

#bg {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: #6e4432;
}

body[data-world="paris"]  { --back: url(media/back-paris.jpg);  --wash: rgba(114, 64, 52, 0.34); --vig: rgba(56, 28, 22, 0.52); }
body[data-world="garden"] { --back: url(media/back-garden.jpg); --wash: rgba(46, 86, 58, 0.34);  --vig: rgba(24, 48, 30, 0.52); }
body[data-world="vienna"] { --back: url(media/back-vienna.jpg); --wash: rgba(88, 48, 26, 0.36);  --vig: rgba(42, 20, 10, 0.56); }
body[data-world="kyoto"]  { --back: url(media/back-kyoto.jpg);  --wash: rgba(74, 88, 56, 0.34);  --vig: rgba(38, 44, 28, 0.52); }

#bg i {
    position: absolute;
    inset: -12%;
    background: var(--back, url(media/back-paris.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.40;
}

#bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(180deg, var(--wash, rgba(114, 64, 52, 0.34)), var(--wash, rgba(114, 64, 52, 0.34))),
        radial-gradient(ellipse at 50% 46%, rgba(255, 248, 236, 0.14) 16%, var(--vig, rgba(56, 28, 22, 0.52)) 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.54; } }

/* ---------------------------------------------------------------- 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, #f6e7d4);
    box-shadow: 0 5px 0 #c2a07e, 0 8px 0 rgba(28, 14, 6, 0.28);
    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 #c2a07e, 0 3px 0 rgba(28, 14, 6, 0.28);
}

.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: #ef2c52;
    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.72);
}
.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(28, 14, 6, 0.30);
}
.tool.gold:active { box-shadow: 0 1px 0 var(--gold-lip), 0 3px 0 rgba(28, 14, 6, 0.30); }

.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(28, 14, 6, 0.30);
}
.tool.blue:active { box-shadow: 0 1px 0 var(--blue-lip), 0 3px 0 rgba(28, 14, 6, 0.30); }

.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(28, 14, 6, 0.30);
}
.tool.coral:active { box-shadow: 0 1px 0 var(--coral-lip), 0 3px 0 rgba(28, 14, 6, 0.30); }
.tool.armed {
    transform: translateY(-4px) scale(1.08);
    box-shadow: 0 0 0 4px #ffe468, 0 8px 0 var(--coral-lip), 0 12px 0 rgba(28, 14, 6, 0.34);
}

.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: #ef2c52;
    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, #f6e7d4); box-shadow: 0 5px 0 #c2a07e, 0 8px 0 rgba(28, 14, 6, 0.24); }
.big.berry { color: #fff; background: linear-gradient(var(--berry-top), var(--berry-bot)); box-shadow: 0 5px 0 var(--berry-lip), 0 8px 0 rgba(28, 14, 6, 0.28); }
.big.berry:active { box-shadow: 0 1px 0 var(--berry-lip), 0 3px 0 rgba(28, 14, 6, 0.28); }
.big.coral { color: #fff; background: linear-gradient(var(--coral-top), var(--coral-bot)); box-shadow: 0 5px 0 var(--coral-lip), 0 8px 0 rgba(28, 14, 6, 0.28); }
.big.coral:active { box-shadow: 0 1px 0 var(--coral-lip), 0 3px 0 rgba(28, 14, 6, 0.28); }
.big[hidden] { display: none; }

/* ---------------------------------------------------------------- home / patisserie 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, 256px);
    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.62);
    text-shadow: 0 2px 0 rgba(96, 12, 34, 0.50);
    font-feature-settings: "tnum";
    transition: transform 0.08s, box-shadow 0.08s;
}
.play svg { width: 24px; height: 24px; }
.play.berry {
    background: linear-gradient(var(--berry-top), var(--berry-bot));
    box-shadow: 0 6px 0 var(--berry-lip), 0 11px 0 rgba(28, 12, 16, 0.34);
}
.play.berry:active {
    transform: translateY(5px);
    box-shadow: 0 1px 0 var(--berry-lip), 0 4px 0 rgba(28, 12, 16, 0.34);
}

/* ---------------------------------------------------------------- gameplay HUD & 3D stage */

#view, #uiview, #fxview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}
#view { cursor: grab; z-index: 1; }
#view.dragging { cursor: grabbing; }
#view.hammer { cursor: crosshair; }
#uiview { pointer-events: none; z-index: 2; }
#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: 46px;
    padding: 0 5px 0 15px;
    border-radius: 24px;
    background: rgba(255, 250, 242, 0.96);
    border: 2.5px solid #e09c5a;
    box-shadow: 0 4px 0 #a36228, 0 7px 0 rgba(28, 14, 6, 0.24);
    color: var(--ink);
    font-feature-settings: "tnum";
}
#level-pill[data-diff="hard"] {
    border-color: #f08434;
    background: linear-gradient(180deg, #fffaf0, #ffecd2);
    box-shadow: 0 4px 0 #b85614, 0 7px 0 rgba(28, 14, 6, 0.26);
}
#level-pill[data-diff="peak"] {
    border-color: #ef4270;
    background: linear-gradient(180deg, #fff7fa, #ffe0ea);
    box-shadow: 0 4px 0 #a61e44, 0 7px 0 rgba(28, 14, 6, 0.28);
}

#level-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

#peak-crown {
    width: 17px;
    height: 17px;
    color: #ef4270;
    flex-shrink: 0;
}
#peak-crown[hidden] { display: none; }

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

.prog-track {
    width: clamp(54px, 14vw, 132px);
    height: 11px;
    border-radius: 6px;
    background: #eed8bd;
    overflow: hidden;
    box-shadow: inset 0 2px 2px rgba(78, 38, 12, 0.22);
}

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

#cake-goal {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 36px;
    padding: 0 12px 0 6px;
    border-radius: 19px;
    background: linear-gradient(180deg, #ff7098, #e63668);
    border: 2px solid rgba(255, 255, 255, 0.72);
    box-shadow: 0 3px 0 #a61a44;
    transform-origin: center;
}
#cake-goal.final {
    background: linear-gradient(180deg, #ffcf48, #f29616);
    box-shadow: 0 3px 0 #b06208;
    animation: pulse-final 1.1s ease-in-out infinite;
}
#cake-goal.bump {
    animation: bump-goal 0.34s cubic-bezier(0.2, 1.5, 0.4, 1);
}
@keyframes bump-goal {
    0% { transform: scale(1); }
    40% { transform: scale(1.26); }
    75% { transform: scale(0.95); }
    100% { transform: scale(1); }
}
@keyframes pulse-final {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.07); }
}

#cake-goal-img {
    width: 34px;
    height: 34px;
    margin: -5px 0 -3px -2px;
    object-fit: contain;
    pointer-events: none;
}

#cakes-val {
    font-size: 20px;
    font-weight: 900;
    line-height: 1;
    color: #fff;
    text-shadow: 0 2px 0 rgba(96, 12, 34, 0.52);
    min-width: 18px;
    text-align: center;
}

#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 to the right side so the 3D cake tray stays huge! */
@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(34, 18, 12, 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(#fffdf9, #fae9d6);
    border: 3px solid #e3a76a;
    box-shadow: 0 10px 0 #a3642a, 0 22px 42px rgba(20, 10, 6, 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: #845232;
    background: rgba(140, 86, 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: #fff4df;
    border: 2px solid #e6b06a;
}
.unlock-box[hidden] { display: none; }
#win-unlock-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2.5px solid #fff;
    box-shadow: 0 2px 5px rgba(56, 24, 8, 0.25);
    display: block;
}
.unlock-box span { font-size: 16px; font-weight: 850; color: #7e3f14; }

.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: #7c5234; }
.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: #9c5828; }
.line span { flex: 1; }

.switch {
    appearance: none;
    width: 52px;
    height: 30px;
    border-radius: 15px;
    background: #dcc5ad;
    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: #e63968; }
.switch:checked::after { transform: translateX(22px); }

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

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

@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; }
    #cakes-val { font-size: 14px; }
    #bar { gap: 12px; }
    .tool { width: 56px; height: 56px; }
}
