/*
 * Frutils Games shared theme, aligned with the Frutils site (Gmtl.Frutils.Web/wwwroot/input):
 *   - font: Nunito 600/700/800 (Google Fonts link in each game's index.html): rounded and easy to read;
 *     body text 600, headings/buttons/chips 800
 *   - colors: site variables from frutils-vars.css (--accent-color, --lead1..4, --text-color, ...)
 *   - buttons: .btn = site .btn (accent, rounded-xl, shadow-md gray, lift on hover), .btn--cta = site .btn-cta
 *   - top bar: site /oferta top bar (offer.css .offer-shell__topbar)
 *   - panels: site tile/panel components (white, 1px --border-color, rounded-lg)
 *   - chips/pills: site rounded-full chips on --leadN-bg
 * Game-only tokens below map onto site variables; Phaser reads them via lib/theme/tokens.js.
 * Dark mode follows the site: opt-in via a `.dark-mode` class, no automatic OS switch.
 */

:root {
    --color-primary: var(--accent-color);
    --color-accent: var(--lead2);
    --color-info: var(--lead3);
    --color-success: var(--lead4);
    --color-danger: var(--lead2);

    --bg: #fafafa;
    --surface: #ffffff;
    --surface-alt: var(--lead1-bg);
    --text: var(--text-color);
    --heading: var(--h-text-color);
    --text-muted: var(--secondary-muted-color);
    --text-on-primary: var(--primary-color);

    --tile-back: var(--lead1);
    --tile-back-pattern: rgba(255, 255, 255, 0.18);
    --tile-face: #ffffff;
    --tile-border: var(--border-color);

    /* Tailwind values used by the site */
    --radius-s: 6px;   /* rounded-md */
    --radius-m: 8px;   /* rounded-lg */
    --radius-btn: 12px; /* rounded-xl, site .btn */
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-btn: 0 4px 6px -1px #6b7280, 0 2px 4px -2px #6b7280; /* shadow-md shadow-gray-500 */

    --gap: 12px;
    --font: "Nunito", sans-serif;
    --header-height: 60px;
}

.dark-mode {
    --bg: var(--primary-color);
    --surface: var(--primary-muted-color);
    --surface-alt: #2c2c2c;
    --text: var(--secondary-color);
    --heading: var(--secondary-color);
    --tile-face: var(--primary-muted-color);
    --tile-border: #3a3a3a;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

/* ---------- Shell ---------- */

.game-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 1220px; /* site .fru-wrap */
    margin: 0 auto;
    position: relative;
}

/* Frutils top bar (lib/ui/frutilsBar.js), as the site's /oferta top bar (offer.css .offer-shell__topbar):
   translucent white, blurred, thin lead border and soft accent shadow. Logo + "Frutils" left, game controls right. */
.frutils-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--header-height);
    padding: 0 16px;
    background: color-mix(in srgb, var(--primary-color) 76%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid color-mix(in srgb, var(--accent-color) 22%, white);
    box-shadow: 0 8px 32px color-mix(in srgb, var(--accent-color-dark) 16%, transparent);
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.frutils-bar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--secondary-color);
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-decoration: none;
    flex-shrink: 0;
}

.frutils-bar__controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    min-width: 0;
}

.frutils-bar__logo {
    flex-shrink: 0;
}

/* 🎮 link to the games list, right after the brand */
.frutils-bar__games {
    flex-shrink: 0;
    text-decoration: none;
}

/* Phones: logo and name always stay; both shrink a little to leave room for the HUD chips */
@media (max-width: 420px) {
    .frutils-bar {
        gap: 4px;
        padding: 0 8px;
    }

    .frutils-bar__brand {
        gap: 6px;
        font-size: 1.15rem;
        letter-spacing: 0.02em;
    }

    .frutils-bar__logo {
        width: 24px;
        height: 24px;
    }

    .frutils-bar__controls {
        gap: 2px;
    }

    .frutils-bar .icon-btn {
        width: 36px;
    }
}

.game-hud {
    display: flex;
    gap: 6px;
}

/* site chip: rounded-full, bold, on a lead background */
.game-hud__item {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 56px;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--lead1-bg);
    color: var(--lead1);
    font-variant-numeric: tabular-nums;
    font-weight: 800;
    font-size: 15px;
}

/* Game-declared chips (shell.hud.setItems): tone = lead color, active = whose turn */
.game-hud__item--lead2 {
    background: var(--lead2-bg);
    color: var(--lead2);
}

.game-hud__item--lead3 {
    background: var(--lead3-bg);
    color: color-mix(in srgb, var(--lead3) 60%, black);
}

.game-hud__item--lead4 {
    background: var(--lead4-bg);
    color: color-mix(in srgb, var(--lead4) 55%, black);
}

.game-hud__item--active {
    box-shadow: 0 0 0 2px currentColor;
}

@media (max-width: 420px) {
    .game-hud__item {
        min-width: 46px;
        padding: 4px 8px;
    }
}

/* Board + optional footer with game controls; side by side on a short landscape screen */
.game-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.game-board {
    flex: 1;
    min-width: 0;
    min-height: 0;
    position: relative;
    padding: var(--gap);
}

.game-footer {
    flex-shrink: 0;
    display: grid;
    gap: 8px;
    justify-items: center;
    padding: 0 var(--gap) max(var(--gap), env(safe-area-inset-bottom));
}

@media (orientation: landscape) and (max-height: 520px) {
    .game-body {
        flex-direction: row;
    }

    .game-footer {
        width: 236px;
        align-content: center;
        padding: var(--gap) var(--gap) var(--gap) 0;
    }
}

.game-board__canvas {
    position: absolute;
    inset: var(--gap);
    overflow: hidden;
}

.game-board canvas {
    touch-action: none;
    display: block;
}

/* ---------- Buttons (site .btn) ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 100px;
    min-height: 44px;
    padding: 8px 12px;
    border: 0;
    border-radius: var(--radius-btn);
    background: var(--accent-color);
    color: var(--primary-color);
    box-shadow: var(--shadow-btn);
    font: inherit;
    font-weight: 800;
    font-size: 16px;
    line-height: 24px;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.btn:hover,
.btn:active {
    background: var(--accent-color-dark);
    transform: translateY(-2px);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
}

.btn:focus-visible {
    outline: 3px solid var(--lead3);
    outline-offset: 2px;
}

/* site .btn-cta: main call to action */
.btn--cta {
    background: #3bb273;
}

.btn--cta:hover,
.btn--cta:active {
    background: #329960;
}

/* Lower-priority actions next to a main one (site .live-button-component look) */
.btn--secondary {
    background: var(--primary-color);
    color: var(--accent-color);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--accent-color-light);
}

.btn--secondary:hover,
.btn--secondary:active {
    background: var(--hover-color);
}

.btn--block {
    width: 100%;
}

/* Round header icon button (site home icon buttons: transparent, lead1-bg on hover) */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--secondary-muted-color);
    font: inherit;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.icon-btn:hover,
.icon-btn:active {
    background: var(--lead1-bg);
    color: var(--lead1);
}

.icon-btn:focus-visible {
    outline: 3px solid var(--lead3);
}

/* ---------- Footer controls: toolbar (undo, hint, ...) and digit keypad ---------- */

.toolbar {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 500px;
}

.tool-btn {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 48px;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-m);
    background: var(--surface);
    color: var(--heading);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.tool-btn:hover {
    background: var(--hover-color);
}

.tool-btn__icon {
    font-size: 20px;
    line-height: 1;
}

.tool-btn[aria-pressed="true"] {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: var(--primary-color);
}

.tool-btn:disabled,
.keypad__key:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}

.tool-btn:focus-visible,
.keypad__key:focus-visible {
    outline: 3px solid var(--lead3);
    outline-offset: 2px;
}

.keypad {
    display: grid;
    grid-template-columns: repeat(var(--keypad-columns, 9), 1fr);
    gap: 4px;
    width: 100%;
    max-width: 500px;
}

.keypad__key {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 2px 0;
    border: 0;
    border-radius: var(--radius-m);
    background: var(--lead1-bg);
    color: var(--lead1);
    font: inherit;
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.keypad__key:hover {
    background: var(--accent-color-light);
}

.keypad__count {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
}

@media (orientation: landscape) and (max-height: 520px) {
    .keypad {
        grid-template-columns: repeat(3, 1fr);
    }

    .keypad__key {
        min-height: 40px;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .tool-btn {
        flex-basis: 40%;
        min-height: 40px;
    }
}

/* ---------- Overlay / panels (site modal + tile/panel components) ---------- */

.game-overlay {
    position: absolute;
    inset: var(--header-height) 0 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
    background: var(--bg);
    z-index: 10;
}

.game-overlay:focus {
    outline: none;
}

.game-overlay--dim {
    background: rgba(0, 0, 0, 0.6); /* site .modal-overlay */
    align-items: center;
}

.panel {
    width: 100%;
    max-width: 500px; /* site .modal-container */
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-m);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: panel-in 0.2s ease-out; /* site fru-popup-fade-in */
}

.panel__title {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    color: var(--heading);
    text-align: center;
}

.panel__subtitle {
    margin: -8px 0 0;
    color: var(--text-muted);
    text-align: center;
}

.panel__section-label {
    margin: 0;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

@keyframes panel-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
}

/* ---------- Menu ---------- */

/* Featured entry, site home card idiom: --leadN-bg fill + lead-tinted border */
.feature-card {
    --card-lead: var(--lead2);
    --card-bg: var(--lead2-bg);
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    border: 1px solid color-mix(in srgb, var(--card-lead) 45%, white);
    border-radius: var(--radius-m);
    background: var(--card-bg);
    color: var(--heading);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.feature-card:hover,
.feature-card:active {
    transform: translateY(-2px);
}

.feature-card--success {
    --card-lead: var(--lead4);
    --card-bg: var(--lead4-bg);
}

.feature-card__icon {
    font-size: 30px;
}

.feature-card__body {
    flex: 1;
}

.feature-card__title {
    font-weight: 800;
    font-size: 18px;
    color: var(--card-lead);
}

.feature-card__meta {
    font-size: 14px;
    color: var(--text);
}

.feature-card__arrow {
    font-size: 22px;
    color: var(--card-lead);
}

/* Mode switch, site pagination/live-button idiom: white pill track, accent selected pill */
.segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
    padding: 6px;
    border-radius: 999px;
    background: var(--surface);
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

.segmented__option {
    min-height: 40px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--secondary-color);
    font: inherit;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.segmented__option:hover {
    background: var(--hover-color);
}

.segmented__option[aria-pressed="true"] {
    background: var(--accent-color);
    color: var(--primary-color);
}

.hint-text {
    margin: 0;
    font-size: 14px;
    color: var(--text-muted);
    text-align: center;
}

.howto-list {
    display: grid;
    gap: 6px;
    margin: 0;
    padding-left: 20px;
    font-size: 15px;
    color: var(--text);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

/* site .tile-component + live-button hover */
.level-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 14px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-m);
    background: var(--surface);
    color: var(--heading);
    font: inherit;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.level-btn:hover,
.level-btn:active {
    background: var(--hover-color);
    transform: scale(1.03);
}

.level-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
    background: var(--surface);
}

/* Packs of many numbered levels: four small buttons per row */
.level-grid--compact {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.level-grid--compact .level-btn {
    padding: 10px 4px;
}

.level-btn__name {
    font-weight: 800;
}

.level-btn__meta {
    font-size: 13px;
    color: var(--text-muted);
}

.level-btn__stars {
    font-size: 22px;
    line-height: 1.1;
    letter-spacing: 3px;
    color: var(--lead2);
}

.level-grid--compact .level-btn__stars {
    font-size: 16px;
    letter-spacing: 1px;
}

/* ---------- Result ---------- */

.result-stars {
    display: flex;
    justify-content: center;
    gap: 8px;
    font-size: 40px;
    line-height: 1;
}

.result-stars__star {
    color: var(--border-color);
    animation: star-pop 0.35s ease-out backwards;
}

.result-stars__star--on {
    color: var(--lead2);
}

@keyframes star-pop {
    from {
        transform: scale(0.2);
        opacity: 0;
    }
}

.result-badge {
    align-self: center;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--lead4-bg);
    color: color-mix(in srgb, var(--lead4) 55%, black);
    font-weight: 800;
    font-size: 14px;
}

.stat-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 8px;
}

.stat {
    padding: 10px;
    border-radius: var(--radius-m);
    background: var(--lead1-bg);
    text-align: center;
}

.stat__value {
    font-size: 22px;
    font-weight: 800;
    color: var(--lead1);
    font-variant-numeric: tabular-nums;
}

.stat__label {
    font-size: 12px;
    color: var(--text-muted);
}

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

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    /* left: 50% alone would cap the width at half the screen and wrap short messages */
    width: max-content;
    max-width: min(460px, calc(100vw - 32px));
    padding: 10px 18px;
    border-radius: 24px;
    text-align: center;
    background: var(--secondary-color);
    color: var(--primary-color);
    font-weight: 800;
    box-shadow: var(--shadow-md);
    z-index: 100;
    animation: panel-in 0.2s ease-out;
}

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