#exercise{  
  max-width: 1000px;
  touch-action: manipulation;
}

#name {
    margin: 15px 0;
}

#end-message {
    display: flex;
    justify-content: center;
}

#rules {
    text-align: left;
}

#rules p {
    margin-bottom: 6px;
}

/****************** STATUS ******************/
:root {
    --limit-color: #90c840; /* mix between yellow and green */
}

#status {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
}

.status-row {
    display: flex;
    align-items: flex-end;
}

.status-row > * {
    flex: 0 0 auto;
}
.status-row > :first-child,
.status-row > :last-child {
    flex: 1 1 0;
}

#text-metrics :first-child {
    text-align: left;
}
#text-metrics :last-child {
    text-align: right;
}

/****************** SPEED GAUGE ******************/
.speed-gauge {
    --radius: 2.5em;
    --value: 0turn;

    width: calc(2* var(--radius));
    height: var(--radius);
    position: relative;
    z-index: 0;
}

.speed-gauge::before {
    content: '';
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;

    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);

    background: conic-gradient(from 270deg at 50% 100%, var(--red), 60deg, var(--yellow), 120deg, var(--green));
    --mask: radial-gradient(circle at 50% 100%, transparent 0, transparent 50%, black 50%),
        linear-gradient(to right, black 0, black calc(50% - 1px), transparent calc(50% - 1px), transparent calc(50% + 1px), black calc(50% + 1px));
    -webkit-mask-image: var(--mask);
    -webkit-mask-composite: source-in;
    mask-image: var(--mask);
    mask-composite: intersect;

    z-index: -1;
}

.speed-gauge::after {
    content: '';
    width: 0;
    height: 0;

    border-right: var(--radius) solid black;
    border-top: 2px solid transparent;
    border-bottom: 2px solid transparent;
    border-top-right-radius: 2px;
    border-bottom-right-radius: 2px;

    z-index: 1;
    position: absolute;
    left: 0;
    bottom: -2px;
    transform-origin: right center;

    transform: rotate(var(--value));
}

/****************** PROGRESS BAR ******************/
.progress-bar {
    --value: 0;

    width: 100%;
    height: 5px;
    border-radius: 3px;

    animation-name: progress-bg;
    animation-duration: 1500ms;
}

.progress-bar::after {
    content: '';
    display: block;
    height: 100%;
    width: calc(var(--value) * 100%);
    border-radius: 3px;

    animation-name: progress-fg;
    animation-duration: 1000ms;

    transition: width 250ms ease-in-out;
}

.progress-bar, .progress-bar::after {
    animation-delay: calc(var(--value) * -1000ms);
    animation-fill-mode: forwards;
    animation-play-state: paused;
}

@keyframes progress-bg {
    0% {
        background-color: var(--faintRed);
    }
    50% {
        background-color: var(--faintYellow);
    }
    100% {
        background-color: var(--faintGreen);
    }
}

@keyframes progress-fg {
    0% {
        background-color: var(--red);
    }
    75% {
        background-color: var(--yellow);
    }
    99.5% {
        background-color: var(--limit-color);
    }
    100% {
        background-color: var(--green);
    }
}

/****************** ERRORS ******************/
.error-bar {
    display: flex;
    flex-direction: row-reverse;
    flex-wrap: wrap;

    gap: 2px;
}

#status .error {
    width: 1em;
    height: 1em;
    padding: 3px;
    box-sizing: content-box;
    border: 2px solid transparent;
    border-radius: 50%;
    position: relative;
}

#status .error.red {
    background-color: var(--red);
    border-color: var(--red);
}
#status .error.orange {
    background-color: var(--orange);
    border-color: var(--orange);
}
#status .error.green {
    border-color: var(--grayHover);
}

#status .error::before, #status .error::after {
    content: '';
    position: absolute;
    width: 1em;
    height: 5px;
    border-radius: 2px;
    top: calc(.5em + 1px);
    left: 3px;
    transform-origin: center;
}

#status .error.green::before,
#status .error.green::after {
    background-color: var(--grayHover);
}

#status .error:not(.green)::before,
#status .error:not(.green)::after {
    background-color: white;
}

#status .error::before {
    transform: rotate(45deg);
}
#status .error::after {
    transform: rotate(-45deg);
}

/****************** ERROR MESSAGES ******************/
.error-message {
    display: flex;
    align-items: flex-start;
    gap: 2px;
    color: var(--redHover);
    text-align: left;
}

.error-message::before {
    content: '';
    background-image: url("https://www.umimeto.org/asset/system/up/img/psani/error-icon.svg");
    height: 1.1em;
    width: 1.1em;
    background-size: 100%;
    background-position: 0 0;
    background-repeat: no-repeat;
    flex: 0 0 auto;
}

.error-message:empty {
    visibility: hidden;
}

/****************** INTERFACE ******************/
#interface {
    max-width: 700px;
    margin: 0 auto;
}

.frame {
    width: 100%;

    margin-bottom: 30px;

    background-color: white;
    border-radius: 3px;
    padding: 20px;

    font-size: 20px;
    font-family: "Roboto Mono", sans-serif;
    line-height: 1.4;

    text-align: left;
}

.frame.correct {
    box-shadow: 0 0 0 2px var(--greenHover);
    animation: var(--animation-blink);
}

.frame.error {
    box-shadow: 0 0 0 2px var(--redHover);
}

.frame .content {
    box-sizing: content-box;
    height: 1.4em;
    overflow: hidden;
    user-select: none;
}

.frame .text {
    position: relative;
}

#assignment .text .char.selected {
    text-decoration: underline;
    color: var(--orangeHover);
}

#input .content {
    white-space: pre;
}

#input .text, #input .typos {
    display: inline;
}

#input .typos {
    color: var(--redHover);
}

#input .text::after {
    content: '';
    border-right: 1px solid transparent;
}

#input:not(.writing):focus .text::after {
    border-right-color: var(--blue);

    animation-name: blink-inverse;
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

@keyframes blink-inverse {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/****************** KEYBOARDS ******************/
#layout {
    display: flex;
    align-items: flex-start;

    margin: 10px 0;
}

#exercise #hand-left,
#exercise #hand-right {
    flex: 0 1 150px;
}

#exercise #keyboards {
    flex: 0 1 700px;
}

#layout svg {
    width: 100%;
    height: auto;
}

#layout-switch {
    margin: 10px 0;
    display: flex;
    gap: 5px;
    justify-content: center;
}

/****************** KEYBOARDS ******************/

.key_bg, .text_bg {
    transform-box: fill-box;
    transform-origin: center;
}
.key_bg.selected {
    fill: var(--blue) !important;
    stroke: var(--blueHover) !important;
}
.finger.selected {
    fill: var(--blue) !important;
    fill-opacity: 1 !important;
}
.key_bg.wrong {
    fill: var(--red) !important;
    stroke: var(--redHover) !important;
}
.text_bg.selected, .text_bg.wrong {
    fill: white !important;
}
.key_bg.wrong, .text_bg.wrong {
    animation: shake-key 100ms 2 ease-in-out;
}
.key_bg.correct, .text_bg.correct {
    animation: pulse-key 200ms ease-in-out;
}

@keyframes shake-key {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}
@keyframes pulse-key {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.95); }
}
