:root {
    --lcd: #9aa88c;
    --ink: #2b3326;
    --matrix:
        repeating-linear-gradient(0deg, rgba(43, 51, 38, .13) 0 1px, transparent 1px 3px),
        repeating-linear-gradient(90deg, rgba(43, 51, 38, .13) 0 1px, transparent 1px 3px);
    --matrix-inverse:
        repeating-linear-gradient(0deg, rgba(154, 168, 140, .14) 0 1px, transparent 1px 3px),
        repeating-linear-gradient(90deg, rgba(154, 168, 140, .14) 0 1px, transparent 1px 3px);
    font-family: "Press Start 2P", ui-monospace, monospace;
    color: var(--ink);
    background: #14121c;
    font-synthesis: none;
}

* {
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
}

html,
body {
    width: 100%;
    height: 100%;
    min-width: 320px;
    min-height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    background: #14121c;
}

button,
output {
    font: inherit;
}

button {
    color: inherit;
}

.device {
    display: flex;
    width: min(100%, 390px);
    min-height: min(844px, 100vh);
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    padding: 28px 0;
    background-color: var(--lcd);
    background-image: var(--matrix);
    box-shadow: 0 28px 90px rgba(0, 0, 0, .35);
}

.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 18px;
    font-size: 10px;
    line-height: 1.5;
}

.status-bar b {
    font-size: inherit;
    font-weight: inherit;
}

.today-status {
    display: flex;
    align-items: center;
    gap: 7px;
    line-height: 1;
}

.today-empty {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.today-empty i {
    width: 7px;
    height: 10px;
    background: var(--ink);
    transform: translateY(-1px);
}

[hidden] {
    display: none !important;
}

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 0 20px;
}

.pet-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.pixel-pet {
    width: 128px;
    height: 104px;
    shape-rendering: crispEdges;
    animation: bob 2s steps(2) infinite;
}

.pixel-pet .ink {
    fill: var(--ink);
}

.pixel-pet .lcd {
    fill: var(--lcd);
}

.pixel-pet .spark {
    fill: none;
    stroke: var(--ink);
    stroke-width: 8;
}

.pixel-pet .lcd-cut {
    fill-rule: evenodd;
}

.pixel-pet .face {
    display: none;
}

.pixel-pet[data-mood="elend"] .face-elend,
.pixel-pet[data-mood="sad"] .face-sad,
.pixel-pet[data-mood="neutral"] .face-neutral,
.pixel-pet[data-mood="happy"] .face-happy,
.pixel-pet[data-mood="jubel"] .face-jubel {
    display: block;
}

.pet-wrap p {
    margin: 0;
    font-size: 10px;
    letter-spacing: 1px;
}

.pixel-rule {
    width: 100%;
    height: 5px;
    background: var(--ink);
    opacity: .55;
}

.balance {
    text-align: center;
}

.label,
.unit {
    margin: 0;
    font-size: 11px;
    letter-spacing: 2px;
}

.remaining {
    width: 350px;
    margin: 12px 0 7px;
    overflow: hidden;
    font-size: clamp(72px, 25vw, 100px);
    line-height: .92;
    letter-spacing: -.08em;
    white-space: nowrap;
}

.remaining.is-overtime {
    animation: blink 1s steps(1) infinite;
}

.unit {
    font-size: 10px;
    letter-spacing: 0;
}

.totals {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.totals > div {
    padding: 8px 12px 12px;
    box-shadow: inset 0 0 0 4px var(--ink);
}

.totals > div:last-child {
    text-align: right;
}

.totals span {
    font-size: 10px;
    opacity: 1;
}

.totals strong {
    display: block;
    margin-top: 8px;
    font-size: 20px;
    font-weight: 400;
}

.totals strong span {
    font-size: inherit;
    opacity: 1;
}

.thick-minus {
    display: inline-block;
    width: 18px;
    height: 3px;
    margin-right: 3px;
    background: var(--ink);
    vertical-align: .46em;
}

.controls {
    display: flex;
    margin-top: 34px;
    flex-direction: column;
    gap: 12px;
    padding: 18px 20px 0;
}

.pending {
    display: flex;
    min-height: 48px;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    color: var(--lcd);
    background: var(--ink);
}

.pending > span {
    font-size: 10px;
}

.pending-amount {
    display: flex;
    align-items: center;
    gap: 1em;
    font-size: 20px;
    line-height: 1;
}

.pending-amount output {
    font-size: inherit;
    line-height: inherit;
}

.pending-amount > span {
    font-size: inherit;
    line-height: inherit;
}

.pending-amount::after {
    width: 12px;
    height: 18px;
    background: var(--lcd);
    content: "";
    animation: blink 2s steps(1) infinite;
    transform: translateY(-1px);
}

.pending-amount output.is-negative::before {
    display: inline-block;
    width: 14px;
    height: 3px;
    margin-right: 7px;
    background: var(--lcd);
    vertical-align: .46em;
    content: "";
}

.step-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.step,
.apply {
    height: 66px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--lcd);
    cursor: pointer;
}

.step {
    display: grid;
    place-items: center;
    color: var(--ink);
    background-color: var(--lcd);
    background-image: var(--matrix);
    box-shadow: inset 0 0 0 5px var(--ink);
}

.step:active:not(:disabled) {
    color: var(--lcd);
    background-color: var(--ink);
    background-image: var(--matrix-inverse);
}

.step:disabled {
    opacity: .48;
    cursor: default;
}

.pixel-minus,
.pixel-plus {
    position: relative;
    display: block;
    width: 34px;
    height: 8px;
    background: currentColor;
}

.pixel-plus::after {
    position: absolute;
    top: -13px;
    left: 13px;
    width: 8px;
    height: 34px;
    background: currentColor;
    content: "";
}

.apply {
    display: grid;
    color: var(--lcd);
    background: var(--ink);
    font-size: 13px;
    letter-spacing: 1px;
    place-items: center;
}

.apply:disabled {
    opacity: .48;
    cursor: default;
}

.apply .apply-label,
.apply .pixel-loader {
    grid-area: 1 / 1;
}

.pixel-loader {
    display: none;
    align-items: end;
    gap: 6px;
    height: 20px;
}

.pixel-loader i {
    width: 10px;
    height: 10px;
    background: currentColor;
    animation: pixel-load 1.2s steps(1) infinite;
}

.pixel-loader i:nth-child(2) {
    animation-delay: .2s;
}

.pixel-loader i:nth-child(3) {
    animation-delay: .4s;
}

.is-loader-visible .apply {
    opacity: 1;
}

.is-loader-visible .apply-label {
    visibility: hidden;
}

.is-loader-visible .pixel-loader {
    display: flex;
}

.apply:active:not(:disabled) {
    color: var(--ink);
    background: var(--lcd);
    box-shadow: inset 0 0 0 5px var(--ink);
}

button:focus-visible {
    outline: 4px solid var(--ink);
    outline-offset: 3px;
}

@keyframes blink {
    0%,
    49% {
        opacity: 1;
    }

    50%,
    100% {
        opacity: .18;
    }
}

@keyframes bob {
    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

@keyframes pixel-load {
    0%,
    24%,
    100% {
        transform: translateY(0);
    }

    25%,
    49% {
        transform: translateY(-8px);
    }
}

@media (max-width: 430px) {
    body {
        display: block;
    }

    .device {
        width: 100%;
        min-height: 100dvh;
        box-shadow: none;
    }
}

@media (max-height: 740px) {
    .device {
        padding: max(18px, env(safe-area-inset-top)) 0 max(18px, env(safe-area-inset-bottom));
    }

    .screen {
        gap: 12px;
    }

    .pixel-pet {
        width: 104px;
        height: 84px;
    }

    .remaining {
        margin-top: 8px;
        font-size: 72px;
    }

    .controls {
        padding-top: 12px;
    }

    .step,
    .apply {
        height: 56px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pixel-pet,
    .pending-amount::after,
    .pixel-loader i,
    .remaining.is-overtime {
        animation: none;
    }

    .pixel-loader i:nth-child(2) {
        transform: translateY(-4px);
    }

    .pixel-loader i:nth-child(3) {
        transform: translateY(-8px);
    }
}
