:root {
    --tile-size: 60px;
    --tile-gap: 3px;
    --dot-size: 6px;
    --plan-margin: 30px;
    --color-a: #ecf0f1ff;
    --color-b: #f1c40f96;
    --color-c: #3498db96;
    --color-d: #e74c3c96;
}

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

#playGround {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#exercise #instructions {
    background-color: white;
    border-radius: 6px;
    min-width: 500px;
    margin-bottom: 20px;
    line-height: 1.3;
}

#exercise #instructions-content {
    margin: 15px;
}

#exercise #instructions:empty {
    display: none;
}

#exercise #interface {
    display: flex;
    gap: 45px;
    background-color: white;
    padding: var(--plan-margin);
    margin: 0 2px 10px;
    border-radius: 6px;

    flex-wrap: wrap;
    align-items: flex-start;

    justify-content: center;
    max-width: 100%;
}

/****************************** CORRECT AND WRONG ******************************/
.wrong {
    box-shadow: 0 0 0 2px var(--red);
    animation: var(--animation-shake);
}

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

.correct .tile .character:not(.active) .character-icon,
.wrong .tile .character:not(.active) .character-icon {
    filter: none;
}

/****************************** PLAN ******************************/
#plan {
    display: grid;
    gap: var(--tile-gap);
    --min-width: calc((100% - 2 * var(--plan-margin)) / var(--plan-width));
    grid-template-rows: repeat(var(--plan-height), var(--tile-size));
    grid-template-columns: repeat(var(--plan-width), minmax(var(--min-width) , var(--tile-size)));
}

#plan .tile {
    border-radius: 3px;
    position: relative;
}

#plan .tile.color-a {
    background-color: var(--color-a);
}
#plan .tile.color-b {
    background-color: var(--color-b);
}
#plan .tile.color-c {
    background-color: var(--color-c);
}
#plan .tile.color-d {
    background-color: var(--color-d);
}

.tile.k-dot::after {
    content: '';
    position: absolute;
    width: var(--dot-size);
    height: var(--dot-size);
    border-radius: calc(var(--dot-size) / 2);
    top: calc(50% - var(--dot-size) / 2);
    left: calc(50% - var(--dot-size) / 2);
    background-color: var(--blackHover);
    z-index: 1;
}

/****************************** CHARACTER ******************************/
.tile .character {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 2;
    border-radius: 3px;
}

.tile .character .character-icon {
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.tile .character:not(.active) .character-icon {
    filter: invert(100%) brightness(50%) invert(100%);
}

.tile .character.done .character-icon {
    animation: var(--animation-blink);
}

#exercise .tile .character {
    background-color: transparent;
}

/****************************** CHARACTER MOBILE CONTROLS ******************************/
.tile .character .control {
    position: absolute;
    width: 100%;
    height: 100%;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--black);
    border-radius: 3px;

    --control-position: calc(100% + var(--tile-gap));
}
.tile .character:not(.active) .control {
    display: none;
}

.has-special .tile .character.active {
    box-shadow: 0 0 0 1px var(--black);
}

.tile .character .control.up,
.tile .character .control.down {
    left: 0;
}

.tile .character .control.up {
    bottom: var(--control-position);
}

.tile .character .control.down {
    top: var(--control-position);
}

.tile .character .control.left,
.tile .character .control.right {
    top: 0;
}

.tile .character .control.left {
    right: var(--control-position);
}

.tile .character .control.right {
    left: var(--control-position);
}

.tile[data-y="0"] .control.up,
.tile[data-x="0"] .control.left,
.tile.last-column .control.right,
.tile.last-row .control.down {
    display: none;
}

/****************************** CODE DISPLAY ******************************/
.code {
    font-size: 20px;
    max-width: 100%;
    padding: 1px;
    overflow-x: auto;
}

#interface .code:empty {
    display: none;
}

#code {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    white-space: nowrap;

    font-family: monospace;

    color: var(--blackHover);

    background-color: var(--lightGray);
    padding: 15px 1em;
    border-radius: 6px;

    line-height: 1.2;
}

#code .line {
    min-height: 1ex;
}

#code .indent {
    display: inline-block;
    width: calc(4ch - 5px);
    height: 1.2em;

    border-right: 2px solid white;
    margin-right: 5px;
    vertical-align: bottom;
}

#code .action {
}

#code .control {
    font-weight: 700;
    color: var(--violetHover);
}

#code .function {
    font-weight: 700;
}

#code .expression.color {
    display: inline-block;
    width: 1em;
    height: 1em;
    position: relative;
    border-radius: 3px;
    vertical-align: top;
}

#code .expression.color.color-a {
    background-color: var(--color-a);
}
#code .expression.color.color-b {
    background-color: var(--color-b);
}
#code .expression.color.color-c {
    background-color: var(--color-c);
}
#code .expression.color.color-d {
    background-color: var(--color-d);
}

#code .expression.color.negate::after {
    color: var(--redHover);
    content: '\274c';
    position: absolute;
    font-size: calc(1em - 4px);
    line-height: 1;
    top: 0;
    left: 0;
    padding: 2px;
}

#code .expression.k-dots {
    display: inline-block;
    border: 1px solid var(--blackHover);
    border-radius: 3px;
    width: 1em;
    height: 1em;
    vertical-align: top;
    background-color: white;

    position: relative;
}

#code .expression.k-dots::after {
    content: '?';
    font-size: 0.8em;
    line-height: 1.25;
    color: var(--blackHover);

    position: absolute;
    inset: 0;
}

#code .expression.male,
#code .expression.female,
#code .expression.fashion {
    display: inline-block;
    width: 1.5em;
    height: 1em;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    vertical-align: top;
}

#code .expression.fashion {
    height: 1.3em;
}

#code .expression.male {
    background-image: url("https://www.umimeto.org/asset/system/up/img/kostka/cube-isM.svg");
}
#code .expression.female {
    background-image: url("https://www.umimeto.org/asset/system/up/img/kostka/cube-isF.svg");
}

#code .expression.fashion.M-A {
    background-image: url("https://www.umimeto.org/asset/system/up/img/kostka/fashion-Ma.svg");
}
#code .expression.fashion.M-B {
    background-image: url("https://www.umimeto.org/asset/system/up/img/kostka/fashion-Mb.svg");
}
#code .expression.fashion.F-A {
    background-image: url("https://www.umimeto.org/asset/system/up/img/kostka/fashion-Fa.svg");
}
#code .expression.fashion.F-B {
    background-image: url("https://www.umimeto.org/asset/system/up/img/kostka/fashion-Fb.svg");
}

/****************************** MOBILE SCREENS ******************************/
@media screen and (max-width: 600px) {
    #exercise #instructions {
        min-width: 100%;
    }
    :root {
        --tile-size: 45px;
    }
    .small {
        --tile-size: 55px;
    }
    .code {
        font-size: 18px;
    }
}

@media screen and (min-width: 601px) and (max-width: 1000px) {
    :root {
        --tile-size: 50px;
    }
    .small {
        --tile-size: 60px;
    }
    .code {
        font-size: 18px;
    }
}

@media screen and (hover: hover) {
    .mobile {
        display: none;
    }
    .has-special #plan:not(.force-mobile) .tile .character.active {
        box-shadow: none;
    }
    #plan:not(.force-mobile) .tile .character.active .control {
        display: none;
    }
}

@media screen and (hover: none) {
    .desktop {
        display: none;
    }
}

/****************************** ADMIN CONSOLE ******************************/
#admin-console {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 20px 0;
    gap: 10px;
}

#admin-console textarea {
    font-size: 18px;
    font-family: monospace;
    width: auto;
}

#plan-editor {
    letter-spacing: 0.3em;
    line-height: 1;
}

#admin-console textarea.invalid {
    background-color: var(--faintRed);
}
#admin-console textarea.valid {
    background-color: var(--faintGreen);
}

#admin-console .CodeMirror {
    text-align: left;
}