/* Mini Farm — базовые токены, типографика и общие компоненты */

:root {
    color-scheme: light;

    --bg: #F2E9D6;
    --bg-grad-1: #F7F0E0;
    --bg-grad-2: #EDE1C8;
    --panel: #FFFDF7;
    --panel-2: #FBF4E6;
    --panel-3: #F3E8D2;
    --line: #E6D8BC;
    --line-soft: #F0E5CF;

    --text: #3E342A;
    --text-2: #6D5C46;
    --muted: #97856B;

    --green: #5EAF3A;
    --green-2: #46912A;
    --green-soft: #E7F4DC;
    --blue: #3E9FE6;
    --blue-2: #2B84C6;
    --blue-soft: #E1F0FC;
    --amber: #F0A93B;
    --amber-2: #D68A1C;
    --amber-soft: #FDEFD9;
    --red: #DE5B44;
    --red-soft: #FBE6E1;
    --gold: #F2C33F;
    --gem: #4EC1F0;
    --xp: #8B6CE7;

    --radius-xl: 22px;
    --radius-lg: 18px;
    --radius: 14px;
    --radius-sm: 10px;

    --shadow-sm: 0 1px 2px rgba(80, 60, 30, .08);
    --shadow: 0 2px 4px rgba(80, 60, 30, .06), 0 8px 20px rgba(90, 70, 40, .08);
    --shadow-lg: 0 12px 34px rgba(70, 55, 30, .18);

    --header-h: 60px;
    --tabbar-h: 64px;
    --sidebar-w: 236px;

    --font: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #16130F;
    --bg-grad-1: #1C1813;
    --bg-grad-2: #12100C;
    --panel: #221E18;
    --panel-2: #2A251E;
    --panel-3: #332C23;
    --line: #3A3229;
    --line-soft: #2E2820;

    --text: #F3EADB;
    --text-2: #CDBEA6;
    --muted: #9C8B72;

    --green-soft: #24361C;
    --blue-soft: #16293A;
    --amber-soft: #3A2C15;
    --red-soft: #3A211B;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 8px 20px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 34px rgba(0, 0, 0, .5);
}

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

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
    background: var(--bg);
    background-image: linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2));
    background-attachment: fixed;
    overscroll-behavior-y: none;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: 0;
    background: none;
    padding: 0;
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: 800;
    letter-spacing: -.01em;
}

h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

p { margin: 0; }

.muted {
    color: var(--muted);
}

.hidden {
    display: none !important;
}

.spacer {
    flex: 1;
}

/* ------------------------------------------------------------- кнопки */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 11px 16px;
    border-radius: var(--radius);
    font-weight: 800;
    font-size: 14px;
    color: #fff;
    background: var(--green);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .16), var(--shadow-sm);
    transition: transform .12s ease, filter .12s ease, opacity .12s ease;
    white-space: nowrap;
    user-select: none;
}

.btn:active {
    transform: translateY(2px);
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .16);
}

.btn:disabled {
    opacity: .45;
    filter: grayscale(.5);
    cursor: not-allowed;
    transform: none;
}

.btn-blue { background: var(--blue); }
.btn-amber { background: var(--amber); }
.btn-red { background: var(--red); }

.btn-ghost {
    background: var(--panel-3);
    color: var(--text-2);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .06);
}

.btn-outline {
    background: transparent;
    color: var(--text-2);
    border: 2px solid var(--line);
    box-shadow: none;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.btn-block {
    width: 100%;
}

.icon-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    font-size: 17px;
    box-shadow: var(--shadow-sm);
}

.icon-btn:active {
    transform: scale(.94);
}

/* -------------------------------------------------------------- карточки */

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 14px;
    box-shadow: var(--shadow);
}

.card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.card-head h3 {
    font-size: 15px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    font-size: 19px;
    font-weight: 800;
}

/* ------------------------------------------------------------- прогресс */

.bar {
    height: 10px;
    border-radius: 999px;
    background: var(--panel-3);
    overflow: hidden;
    position: relative;
}

.bar > i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--green), #8CD05B);
    transition: width .4s ease;
}

.bar.bar-xp > i {
    background: linear-gradient(90deg, var(--xp), #B79BFF);
}

.bar.bar-amber > i {
    background: linear-gradient(90deg, var(--amber-2), var(--amber));
}

.bar-sm { height: 7px; }

/* ---------------------------------------------------------------- чипы */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--line-soft);
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-2);
}

.chip-gold { color: #A97A12; background: #FDF3D6; border-color: #F3E2AE; }
.chip-gem { color: #1D7FA8; background: #E2F5FD; border-color: #BFE7F7; }
.chip-green { color: #3C7C25; background: var(--green-soft); border-color: #CFE8BE; }

:root[data-theme="dark"] .chip-gold { background: #3A2E12; border-color: #4A3A18; color: #F2C33F; }
:root[data-theme="dark"] .chip-gem { background: #13303C; border-color: #1B4354; color: #7FD6F5; }

.price {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 800;
    color: #A97A12;
}

.price.gem { color: #1D7FA8; }

.price.dim { color: var(--muted); }

/* --------------------------------------------------------------- тосты */

.toast-host {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 90;
    pointer-events: none;
    width: max-content;
    max-width: min(92vw, 420px);
}

.toast {
    padding: 11px 16px;
    border-radius: 14px;
    background: rgba(38, 30, 22, .94);
    color: #FFF6E6;
    font-weight: 700;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: toast-in .22s ease, toast-out .3s ease 2.4s forwards;
    text-align: center;
}

.toast.ok { background: rgba(58, 122, 32, .95); }
.toast.err { background: rgba(186, 62, 42, .95); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(14px) scale(.96); }
    to { opacity: 1; transform: none; }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateY(-8px); }
}

/* ---------------------------------------------------------- шторка/модал */

.sheet-host {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(28, 22, 14, .5);
    backdrop-filter: blur(2px);
    animation: fade-in .18s ease;
}

.sheet {
    position: relative;
    width: min(520px, 100%);
    max-height: 86vh;
    overflow-y: auto;
    background: var(--panel);
    border-radius: 24px 24px 0 0;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
    animation: sheet-up .26s cubic-bezier(.2, .9, .3, 1);
}

.sheet-grip {
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    margin: 6px auto 12px;
}

.sheet-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 17px;
    font-weight: 800;
    margin-bottom: 12px;
}

@keyframes sheet-up {
    from { transform: translateY(100%); }
    to { transform: none; }
}

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

@media (min-width: 760px) {
    .sheet-host { align-items: center; }

    .sheet {
        border-radius: 24px;
        padding-bottom: 20px;
        animation: pop-in .22s cubic-bezier(.2, .9, .3, 1);
    }

    .sheet-grip { display: none; }
}

@keyframes pop-in {
    from { opacity: 0; transform: scale(.94); }
    to { opacity: 1; transform: none; }
}

/* -------------------------------------------------- летящие монеты и т.п. */

.fly {
    position: fixed;
    z-index: 120;
    pointer-events: none;
    font-weight: 900;
    font-size: 18px;
    color: #B98910;
    text-shadow: 0 2px 0 #fff;
    animation: fly-up 1s ease-out forwards;
}

.fly.gem { color: #1D7FA8; }
.fly.xp { color: var(--xp); }
.fly.neg { color: #C6553E; }

@keyframes fly-up {
    0% { opacity: 0; transform: translate(-50%, 0) scale(.8); }
    18% { opacity: 1; transform: translate(-50%, -12px) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}

.levelup {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.levelup-card {
    background: linear-gradient(160deg, #FFF6DF, #FFE9B8);
    border: 2px solid #F0CE7B;
    border-radius: 24px;
    padding: 22px 30px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: pop-in .3s cubic-bezier(.2, .9, .3, 1),
               fade-out .4s ease 2s forwards;
    color: #6B4E12;
}

.levelup-card b {
    display: block;
    font-size: 32px;
    line-height: 1.1;
}

@keyframes fade-out {
    to { opacity: 0; transform: scale(.96); }
}

.skeleton {
    background: linear-gradient(90deg, var(--panel-2), var(--panel-3), var(--panel-2));
    background-size: 200% 100%;
    animation: shimmer 1.2s linear infinite;
    border-radius: var(--radius);
}

@keyframes shimmer {
    to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

/* ------------------------------------------------------------ загрузка */

.loader {
    position: fixed;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 12px;
    background: var(--bg);
    background-image: linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2));
    z-index: 200;
}

.loader-emoji {
    font-size: 52px;
    animation: grow-pulse 1.4s ease-in-out infinite;
}

.loader-text {
    font-weight: 800;
    color: var(--muted);
}

@keyframes grow-pulse {
    0%, 100% { transform: scale(1) rotate(-3deg); }
    50% { transform: scale(1.14) rotate(3deg); }
}
