/*
 * Pixie's Potions - interface styling.
 *
 * The shelf itself is canvas; everything here is the calm frame around it.
 * Fonts are served from this origin so the game looks the same offline.
 */

@font-face {
    font-family: "Roboto";
    src: url(/webfonts/Roboto-VariableFont.ttf) format("truetype");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Bebas Neue";
    src: url(/webfonts/BebasNeue-Regular.ttf) format("truetype");
    font-display: swap;
}

:root {
    --dusk-1: #1b1430;
    --dusk-2: #2a1d3f;
    --dusk-3: #3b2647;
    --glow: #f0b429;
    --glow-soft: #ffe9a8;
    --ink: #f7f2ea;
    --ink-soft: rgba(247, 242, 234, 0.66);
    --ink-faint: rgba(247, 242, 234, 0.34);
    --surface: rgba(255, 255, 255, 0.08);
    --surface-strong: rgba(255, 255, 255, 0.14);
    --line: rgba(255, 255, 255, 0.16);
    --danger: #e06666;
    --radius: 18px;
    --gutter: 16px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Both of these carry the dusk colour, so that any strip iOS decides is outside
 * the page - under the home indicator, behind the status bar, or whatever it
 * makes of the viewport while its toolbars move - is dusk rather than white. */
html,
body {
    height: 100%;
    min-height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background-color: var(--dusk-1);
}

body {
    font-family: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

h1,
h2,
h3 {
    font-family: "Bebas Neue", "Roboto", sans-serif;
    font-weight: 400;
    letter-spacing: 0.04em;
    margin: 0;
}

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

/* The gradient lives here rather than on the body. A fixed background
 * attachment on the body is unreliable in iOS Safari, and this element is
 * already pinned to the viewport, so it paints exactly the area we can see.
 * dvh follows the viewport as iOS moves its toolbars; vh is the fallback. */
#app {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    background:
        radial-gradient(120% 80% at 50% 108%, rgba(240, 180, 41, 0.18), transparent 62%),
        radial-gradient(90% 60% at 12% -10%, rgba(130, 87, 230, 0.26), transparent 60%),
        linear-gradient(170deg, var(--dusk-1), var(--dusk-2) 55%, var(--dusk-3));
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen.is-active {
    display: flex;
}

/* ------------------------------------------------------------ home --- */

.home-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 26px;
    padding: 24px var(--gutter);
    max-width: 460px;
    margin: 0 auto;
    width: 100%;
    text-align: center;
}

.brand-mark {
    width: 128px;
    height: 128px;
    filter: drop-shadow(0 14px 30px rgba(130, 87, 230, 0.45));
    animation: hover 5s ease-in-out infinite;
}

@keyframes hover {
    0%, 100% { transform: translateY(0) rotate(-1.5deg); }
    50% { transform: translateY(-10px) rotate(1.5deg); }
}

.brand h1 {
    font-size: clamp(42px, 13vw, 62px);
    margin-top: 10px;
    background: linear-gradient(180deg, var(--ink) 30%, var(--glow-soft));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.tagline {
    margin: 6px 0 0;
    color: var(--ink-soft);
    font-size: 15px;
    line-height: 1.5;
    max-width: 30ch;
    margin-inline: auto;
}

.stat-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.stat {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 6px;
    backdrop-filter: blur(10px);
}

.stat-value {
    display: block;
    font-family: "Bebas Neue", sans-serif;
    font-size: 28px;
    line-height: 1;
    color: var(--glow-soft);
}

.stat-label {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.button-row {
    display: flex;
    gap: 10px;
}

.button-row .button {
    flex: 1;
}

.footnote {
    font-size: 12px;
    color: var(--ink-faint);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

#sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-faint);
    transition: background 0.3s ease;
}

#sync-dot[data-state="syncing"] { background: var(--glow); }
#sync-dot[data-state="synced"] { background: #58c99a; }
#sync-dot[data-state="offline"] { background: rgba(224, 102, 102, 0.8); }

/* --------------------------------------------------------- buttons --- */

.button {
    font-family: "Roboto", sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface-strong);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 18px;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s ease;
    backdrop-filter: blur(8px);
}

.button:active {
    transform: scale(0.97);
}

.button:disabled {
    opacity: 0.4;
    cursor: default;
}

.button.primary {
    background: linear-gradient(160deg, var(--glow), #e08c1f);
    border-color: rgba(255, 255, 255, 0.28);
    color: #2a1a05;
    font-size: 17px;
    padding: 16px 18px;
    box-shadow: 0 10px 26px rgba(240, 180, 41, 0.24);
}

.button.ghost {
    background: transparent;
    color: var(--ink-soft);
}

.button.danger {
    background: transparent;
    border-color: rgba(224, 102, 102, 0.5);
    color: var(--danger);
}

.icon-button {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    font-size: 22px;
    line-height: 1;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 13px;
    cursor: pointer;
}

.icon-button:active {
    transform: scale(0.94);
}

/* ------------------------------------------------------------ hud ---- */

.hud {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px var(--gutter);
}

.hud-block {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.hud-level {
    font-family: "Bebas Neue", sans-serif;
    font-size: 22px;
    letter-spacing: 0.04em;
}

.hud-moves {
    font-size: 12px;
    color: var(--ink-faint);
}

.hud-moves.over-par {
    color: rgba(255, 217, 138, 0.8);
}

.hud-spacer {
    flex: 1;
}

.hud-stars {
    font-family: "Bebas Neue", sans-serif;
    font-size: 20px;
    color: var(--glow-soft);
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
}

/* ---------------------------------------------------------- board ---- */

.board-wrap {
    flex: 1;
    min-height: 0;
    position: relative;
}

#board {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
}

/* -------------------------------------------------------- helpers ---- */

.helpers {
    display: flex;
    gap: 8px;
    padding: 10px var(--gutter) calc(14px + env(safe-area-inset-bottom));
    justify-content: center;
}

.helper {
    position: relative;
    flex: 1;
    max-width: 92px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 15px;
    color: var(--ink);
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.12s ease, opacity 0.2s ease;
}

.helper:active {
    transform: scale(0.95);
}

.helper:disabled {
    opacity: 0.35;
}

.helper-icon {
    font-size: 21px;
    line-height: 1;
}

.helper-name {
    font-size: 11px;
    color: var(--ink-soft);
}

.helper-count {
    position: absolute;
    top: -6px;
    right: -4px;
    min-width: 20px;
    padding: 1px 5px;
    font-size: 11px;
    font-weight: 700;
    color: #2a1a05;
    background: var(--glow);
    border-radius: 10px;
}

.helper-count.is-empty {
    background: rgba(255, 255, 255, 0.24);
    color: var(--ink-soft);
}

/* --------------------------------------------------------- panels ---- */

#overlay {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px var(--gutter);
    background: rgba(12, 8, 22, 0.66);
    backdrop-filter: blur(6px);
    z-index: 20;
}

#overlay.is-open {
    display: flex;
}

.panel {
    display: none;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 440px;
    max-height: 88vh;
    overflow-y: auto;
    padding: 22px;
    background: linear-gradient(170deg, rgba(58, 42, 82, 0.96), rgba(32, 23, 50, 0.97));
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    animation: rise 0.24s ease;
}

.panel.is-open {
    display: flex;
}

@keyframes rise {
    from { transform: translateY(18px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

.panel h2 {
    font-size: 30px;
}

.panel h3 {
    font-size: 20px;
    margin-top: 8px;
    color: var(--glow-soft);
}

.panel-note {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink-soft);
}

.result-row {
    display: flex;
    gap: 10px;
    margin: 6px 0;
}

.result-row div {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 6px;
    text-align: center;
}

.result-row span {
    display: block;
    font-family: "Bebas Neue", sans-serif;
    font-size: 26px;
    color: var(--glow-soft);
}

.result-row small {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-faint);
}

/* ----------------------------------------------------------- shop ---- */

.shop-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shop-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
}

.shop-icon {
    font-size: 26px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
}

.shop-copy {
    flex: 1;
    min-width: 0;
}

.shop-copy h3 {
    font-size: 19px;
    color: var(--ink);
    margin: 0;
}

.shop-copy p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--ink-soft);
    line-height: 1.4;
}

.shop-owned {
    font-size: 11px;
    color: var(--ink-faint);
}

.button.buy {
    font-family: "Bebas Neue", sans-serif;
    font-size: 17px;
    letter-spacing: 0.04em;
    padding: 10px 14px;
    white-space: nowrap;
}

/* --------------------------------------------------------- levels ---- */

.levels-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    gap: 8px;
    max-height: 46vh;
    overflow-y: auto;
    padding: 2px;
}

.level-chip {
    position: relative;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    font-family: "Bebas Neue", sans-serif;
    font-size: 19px;
    color: var(--ink-soft);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 13px;
    cursor: pointer;
}

.level-chip.is-done {
    color: var(--ink);
    background: rgba(240, 180, 41, 0.16);
    border-color: rgba(240, 180, 41, 0.4);
}

.level-chip.is-current {
    border-color: var(--glow);
    box-shadow: 0 0 0 2px rgba(240, 180, 41, 0.28);
}

.level-chip i {
    position: absolute;
    top: 2px;
    right: 5px;
    font-size: 10px;
    font-style: normal;
    color: var(--glow);
}

/* ----------------------------------------------------------- help ---- */

.help-body p {
    margin: 0 0 12px;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--ink-soft);
}

.swatches {
    display: flex;
    gap: 8px;
    margin: 4px 0 14px;
}

.swatch {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.22);
}

/* ------------------------------------------------------- settings ---- */

.switch {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    font-size: 14.5px;
    cursor: pointer;
}

.switch input {
    width: 20px;
    height: 20px;
    accent-color: var(--glow);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.field input {
    font-family: inherit;
    font-size: 14px;
    letter-spacing: normal;
    text-transform: none;
    color: var(--ink);
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    user-select: text;
}

.signin-slot {
    display: flex;
    justify-content: center;
    min-height: 44px;
    margin: 2px 0 4px;
}

.signin-slot:empty::after {
    content: "Sign in is unavailable while you are offline.";
    font-size: 13px;
    color: var(--ink-faint);
    align-self: center;
}

.panel-note.small {
    font-size: 12.5px;
    color: var(--ink-faint);
}

/* --------------------------------------------------------- toasts ---- */

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(96px + env(safe-area-inset-bottom));
    transform: translate(-50%, 16px);
    max-width: min(420px, calc(100vw - 32px));
    padding: 12px 18px;
    font-size: 14px;
    text-align: center;
    background: rgba(20, 14, 32, 0.94);
    border: 1px solid var(--line);
    border-radius: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 30;
}

#toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

#star-pop {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    font-family: "Bebas Neue", sans-serif;
    font-size: 40px;
    color: var(--glow-soft);
    text-shadow: 0 6px 24px rgba(240, 180, 41, 0.45);
    opacity: 0;
    pointer-events: none;
    z-index: 15;
}

#star-pop.is-visible {
    animation: star-pop 1s ease forwards;
}

@keyframes star-pop {
    0% { opacity: 0; transform: translate(-50%, 10px) scale(0.8); }
    25% { opacity: 1; transform: translate(-50%, -6px) scale(1.05); }
    100% { opacity: 0; transform: translate(-50%, -48px) scale(1); }
}

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

@media (min-width: 720px) {
    .helpers {
        gap: 12px;
    }

    .helper {
        max-width: 108px;
        padding: 12px 8px;
    }

    .hud {
        padding: 16px 24px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .panel,
    .brand-mark,
    #star-pop.is-visible {
        animation: none;
    }
}
