@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,1,0&family=Roboto+Slab');

:root {
    --red: #f44;
    --green: #2d6;
    --blue: #27f;
    --yellow: #fc4;
    --cyan: #5fd;
    --magenta: #a5d;
    --fail-color: #c33;
    --shadow: #111;
    --bg: #222;
    --mid: color-mix(in srgb, var(--fg) 50%, var(--bg) 50%);
    --fg: #fff;
    --letters: 5;
    --key-gap: 3rem;
    --key-width: 5rem;
    --key-height: 5rem;
    --status-height: 5.5rem;
    --grid-width: 2px;
    --grid-color: #444;
    --column-size: calc(var(--key-width) + var(--key-gap));
    /* an extra pixel is needed to make the grid end invisible on odd widths */
    --field-width: calc((var(--column-size) * var(--letters)) - var(--grid-width) - 1px);
    --font: "Roboto Slab", sans-serif;
    --icon-font: "Material Symbols Rounded";
}

body {
    background: radial-gradient(circle, var(--bg) 0%, var(--shadow) 130%);
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font);
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    line-height: 1;

    /* grid has to be defined here because colors are changed on the body */
    --field-grid: repeating-linear-gradient(to right,
            transparent 0%,
            transparent calc(var(--column-size) - var(--grid-width)),
            var(--grid-color) calc(var(--column-size) - var(--grid-width)),
            var(--grid-color) var(--column-size));
}

/* hack to get fail to work with a gradient */
body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle, var(--fail-color) 0%, #911 100%);
    z-index: -1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

/* light mode colors */
body.light {
    --bg: #fff;
    --fg: #222;
    --grid-color: #ddd;
    --shadow: #ddd;
}

body.nightmare {
    --bg: #500;
    --shadow: #200;
    --grid-color: #ddd;
    --blue: #33a;
}

/* shows when you lose or make a mistake */
body.fail::before {
    opacity: 1;
}

/* field of numbers */
#field {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    margin: auto;
    font-size: 2rem;
    text-align: center;
    overflow-y: hidden;
    overflow-x: hidden;
    flex-grow: 1;
    width: var(--field-width);
    background: var(--field-grid);
}

.beat {
    height: var(--key-height);
    min-height: var(--key-height);
    margin: calc(var(--key-height) / 20);
    width: var(--field-width);
    position: relative;
}

.beat.chord {
    background: linear-gradient(to bottom,
            transparent calc(50% - var(--grid-width)),
            var(--fg) calc(50% - var(--grid-width)),
            var(--fg) calc(50% + var(--grid-width)),
            transparent calc(50% + var(--grid-width)));
}

.beat.full {
    background: linear-gradient(to bottom,
            transparent calc(50% - var(--grid-width) * 2),
            var(--fg) calc(50% - var(--grid-width) * 2),
            var(--fg) calc(50% + var(--grid-width) * 2),
            transparent calc(50% + var(--grid-width) * 2));
}

/* container for the keys */
#dfjk-container {
    display: flex;
    justify-content: center;
    gap: var(--key-gap);
    margin: auto;
    padding: 1rem 0;
    border-top: var(--grid-width) solid var(--grid-color);
    width: var(--field-width);
    background: var(--field-grid);

    .key {
        cursor: pointer;
    }
}

/* all keys */
.key {
    --color: #fff;
    background-color: var(--color);
    width: var(--key-width);
    height: var(--key-width);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    font-size: 2rem;
    user-select: none;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* keys on field */
#field .key {
    position: absolute;
    height: var(--key-height);
    min-height: var(--key-height);
    left: calc(var(--key-width) / -2 + var(--field-width) / 2);
    translate: calc((var(--key-width) + var(--key-gap)) * var(--x-offset) + (var(--key-width) + var(--key-gap)) / 2);
    border-radius: 0.5rem;
    transition: opacity 0.25s ease;
}

#field .key.pressed {
    opacity: 0.5;
    animation: quiver 0.25s linear;
    animation-iteration-count: infinite;
}

#field .chord .key {
    background: radial-gradient(circle, var(--fg) 50%, var(--color) 52%);
    color: var(--bg);
}

#field .full .key {
    display: none;
}

/* specific key colors */
.d {
    --color: var(--red);
}

.f {
    --color: var(--yellow);
}

.j {
    --color: var(--green);
}

.k {
    --color: var(--blue);
}

.l {
    --color: var(--magenta);
}

.s {
    --color: #000;
    color: #fff;
}

#status-bar {
    font-size: clamp(1rem, 2vw + 1rem, 3rem);
    background-color: var(--fg);
    color: var(--bg);
    text-align: center;
    line-height: var(--status-height);
    font-weight: bold;
    user-select: none;
    cursor: pointer;
    transition: background-color 0.5s ease;
}

.nightmare #back-button {
    animation: quiver 0.25s infinite;
}

/* doesn't actually hide the status bar, but does make it not affect the layout */
.hidden #status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
}

.play #status-bar {
    background: var(--blue);
}

.fail #status-bar {
    background: var(--bg);
    color: var(--fail-color);
}

.win #status-bar {
    background: var(--green);
}

.perfect #status-bar {
    background: var(--yellow);
}

.fail {
    animation: shake 0.25s ease;
}

/* played for every keypress */
@keyframes fall {
    from {
        transform: translateY(-100%);
    }

    to {
        transform: translateY(0);
    }
}

/* played on win */
@keyframes bounceAway {
    20% {
        transform: translate3d(0, -10px, 0) scaleY(0.9);
    }

    40%,
    45% {
        opacity: 1;
        transform: translate3d(0, 20px, 0) scaleY(0.9);
    }

    to {
        opacity: 0;
        transform: translate3d(0, -200vh, 0) scaleY(3);
    }
}

/* played on mistake */
@keyframes shake {
    0% {
        transform: translateY(0);
    }

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

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

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

    to {
        transform: translateY(0);
    }
}

@keyframes quiver {
    0% {
        transform: rotate(0);
    }

    25% {
        transform: rotate(-5deg);
    }

    50% {
        transform: rotate(5deg);
    }

    75% {
        transform: rotate(-5deg);
    }

    to {
        transform: rotate(0);
    }
}

/* played on stars */
@keyframes swirl-in {
    0% {
        transform: translateY(var(--translate)) rotate(-540deg) scale(0);
        opacity: 0;
    }

    100% {
        transform: translateY(var(--translate)) rotate(var(--rotation)) scale(var(--scale));
        opacity: 1;
    }
}

.win #dfjk-container .key {
    animation: bounceAway 1s ease forwards;
}

.beat.falling {
    animation: fall 0.05s ease;
}

#back-button {
    position: fixed;
    top: 1rem;
    right: 2rem;
    width: 6rem;
    text-align: center;
    padding: 0.5rem;
    background-color: transparent;
    border-radius: 0.5rem;
    color: var(--fg);
    font-size: 2rem;
    user-select: none;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease;
    z-index: 1;
}

#back-button:hover {
    background-color: var(--blue);
}

.status-bar-button {
    position: absolute;
    box-sizing: border-box;
    height: calc(var(--status-height) - 1rem);
    width: calc(var(--status-height) - 1rem);
    margin: 0.5rem;
    bottom: 0;
    border-radius: 15px;
    background-color: transparent;
    color: var(--bg);
    font-size: 2rem;
    border: none;
    cursor: pointer;
    user-select: none;
    font-family: var(--icon-font);
    transition: background-color 0.2s ease;
}

#settings-button {
    right: 0;
}

.play .status-bar-button,
.fail .status-bar-button,
.hidden .status-bar-button {
    color: var(--fg);
}

#help-icon {
    display: flex;
    justify-content: center;
    align-items: center;
    left: 0;
    right: auto;
}

#help-dialog {
    box-sizing: border-box;
    position: absolute;
    bottom: calc(var(--status-height));
    margin: 1rem;
    width: 25rem;
    max-width: 100vw;
    background-color: var(--bg);
    color: var(--fg);
    border: 2px solid var(--fg);
    border-radius: 0.5rem;
    padding: 2rem;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    opacity: 0;
    line-height: 1.5;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

#mobile-help {
    display: none;
}

kbd {
    background: #eee;
    color: #333;
    border: 1px solid var(--mid);
    border-radius: 0.2rem;
    padding: 0.1rem 0.3rem;
}

#settings-button:hover {
    background-color: #0003;
}

.level-select {
    position: absolute;
    display: flex;
    justify-content: center;
    margin-left: 2rem;
    margin-top: 1rem;
    color: var(--fg);
    font-size: 2rem;
    user-select: none;
    align-items: center;
    z-index: 1;
}

#seed {
    font-size: inherit;
    padding: 0.5rem;
    border-radius: 0.5rem;
    background-color: transparent;
    border: 2px solid transparent;
    max-width: 20rem;
    overflow-y: hidden;
    text-align: center;
    color: inherit;
    font-family: inherit;
    transition: border-color 0.5s ease;
}

#seed::before {
    content: "#";
    margin-right: 0.5rem;
}

input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#seed:focus {
    outline: none;
    border-color: var(--blue);
}

#settings-dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg);
    color: var(--fg);
    border: 2px solid var(--fg);
    border-radius: 0.5rem;
    padding: 2rem;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    text-align: center;
    transition: inherit;
}

#settings-dialog h1 {
    font-size: 2.5rem;
    padding: 0.5rem;
    margin: 0;
    user-select: none;
}

#settings-dialog div {
    width: 100%;
    padding: 0.5rem;
    display: flex;
    justify-content: space-between;
}

#key-input {
    display: inline-block;
    margin-top: 1rem;
    margin-bottom: 0;
    width: auto;
    color: var(--mid);
    text-transform: uppercase;
    letter-spacing: 0.5rem;
}

#key-input:focus {
    outline: none;
}

#settings-dialog div label {
    font-size: 1.5rem;
    padding: 0 0.5rem;
    flex: 1;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 1rem;
}

input[type="checkbox"] {
    appearance: none;
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid var(--fg);
    border-radius: 0.25rem;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

input[type="checkbox"]:checked::before {
    font-size: 1.5rem;
    color: var(--bg);
    position: absolute;
    left: 0.2rem;
    top: 0;
}

input[type="checkbox"]:checked {
    background-color: var(--blue);
}

input[type="checkbox"]:disabled {
    background-color: var(--mid);
}

input[type="checkbox"]:disabled:active {
    background-color: var(--fg);
}

select {
    font-size: 1.5rem;
    padding: 0.5rem;
    border: 2px solid var(--fg);
    background-color: var(--bg);
    color: var(--fg);
    font-family: inherit;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

select:focus {
    outline: none;
}

select:disabled {
    background-color: var(--shadow);
}

input[type="number"] {
    font-size: 1.5rem;
    padding: 0.5rem;
    border: 2px solid var(--fg);
    background-color: transparent;
    color: var(--fg);
    font-family: inherit;
    border-radius: 0.25rem;
    width: 4rem;
    text-align: center;
}

input[type="number"]:focus {
    outline: none;
}

input[type="number"]:disabled {
    background-color: var(--shadow);
}

#settings-dialog input[type="range"] {
    width: 10rem;
    margin-left: 2rem;
}

#settings-dialog menu {
    display: flex;
    justify-content: center;
    padding: 0;
    margin-top: 2rem;
}

#settings-dialog button {
    background-color: var(--blue);
    color: var(--fg);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#settings-dialog button:hover {
    background-color: var(--fg);
    color: var(--bg);
}

#hp-indicator {
    width: 2ch;
    color: var(--blue);
}

#results {
    background-color: var(--bg);
    color: var(--fg);
    border: 2px solid var(--fg);
    position: absolute;
    top: 50%;
    left: 50%;
    min-width: 32rem;
    transform: translate(-50%, -50%);
    border-radius: 0.5rem;
    padding: 2rem;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    text-align: center;
    transition: inherit;
}

#result-chart-no {
    position: absolute;
    top: -0.5rem;
    right: 1rem;
    color: #999;
    padding: 0.5rem;
    border-radius: 0.5rem;
}

#result-chart-no.hard {
    background-color: var(--yellow);
    color: var(--bg);
}

#result-title {
    font-size: 2.5rem;
    font-family: inherit;
    user-select: none;
}

.perfect #result-title {
    color: var(--yellow);
}

#results p {
    margin: 1rem 0;
    font-size: 1.5rem;
}

#results #result-time {
    font-size: 2rem;
}

#star-field {
    margin-top: 2rem;
}

.star {
    fill: var(--shadow);
    width: 10rem;
    height: 10rem;
    opacity: 0;
    animation: swirl-in 1s forwards;
}

.star.fill {
    fill: var(--yellow);
}

.perfect .star {
    fill: var(--red);
}

.star:nth-of-type(1) {
    --rotation: -20deg;
    --scale: 0.9;
    --translate: 1.5rem;
    animation-delay: 0.2s;
}

.star:nth-of-type(2) {
    --rotation: 0deg;
    --scale: 1.1;
    --translate: 0;
    animation-delay: 0.4s;
}

.star:nth-of-type(3) {
    --rotation: 20deg;
    --scale: 0.9;
    --translate: 1.5rem;
    animation-delay: 0.6s;
}

#share-button {
    position: absolute;
    bottom: 0;
    right: 0;
    padding: 20px;
    border-radius: 15px;
    background-color: transparent;
    color: var(--fg);
    font-size: 2rem;
    border: none;
    cursor: pointer;
    font-family: var(--icon-font);
    transition: background-color 0.2s ease;
}

@media (max-width: 600px) {
    :root {
        --key-gap: calc(100vw / 20);
        --key-width: calc((100vw - (var(--key-gap) * (var(--letters) + 1))) / var(--letters));
        --key-height: var(--key-width);
    }

    #status-bar {
        position: fixed;
        top: 0;
        width: 100%;
        height: 4rem;
        line-height: 4rem;
    }

    .level-select {
        top: 5rem;
        left: 50%;
        margin: 0;
        transform: translateX(-50%);
        background-color: color-mix(in srgb, var(--bg) 100%, transparent 25%);
        padding: 0 1rem;
        border-radius: 0.5rem;

    }

    #back-button {
        display: none;
    }

    #settings-button,
    #help-icon {
        top: 4rem;
        padding: .5rem 1.5rem;
        right: 0;
        bottom: auto;
        color: var(--fg);
        background-color: transparent;
        z-index: 1;
    }

    #settings-button:hover {
        background-color: transparent;
    }

    #help-icon {
        left: 0;
        right: auto;
    }

    #dfjk-container .key {
        height: calc(10rem);
        border-radius: 8rem;
    }

    #results {
        z-index: 1;
        width: 80vw;
        min-width: 80vw;
    }

    #star-field {
        margin-top: 0;
    }

    .star {
        width: 6rem;
        height: 6rem;
    }

    #help-dialog {
        left: 50%;
        bottom: 50%;
        transform: translate(-50%, 50%);
        margin: 0;
    }

    #mobile-help {
        display: block;
    }

    #desktop-help {
        display: none;
    }
}