/* Tsumiki: pale wooden blocks in a chestnut frame, laid on indigo cloth. */

:root {
    --game-container-width: 120vmin;
    --game-container-height: 100vmin;

    --aizome: #1f2d47;      /* indigo cloth: the page */
    --aizome-light: #2f4268;
    --kiri: #f0dcb4;        /* pale block wood */
    --kiri-edge: #b9975f;   /* block thickness */
    --honey: #d3a45c;       /* pegged block */
    --sugi: #c9a36f;        /* backboard, light panel */
    --sugi-dark: #b28955;   /* backboard, dark panel */
    --kuri: #54361f;        /* frame, chutes, tray */
    --kuri-deep: #38230f;
    --shu: #c23b22;         /* seal vermilion */
    --brass: #d9b45a;
    --paper: #f5ecd9;       /* text on the cloth */

    --button-color: var(--kuri); /* sidebar background, read by navbar.css */

    --cell: 8.8vmin;
    --mini: calc(var(--cell) * 0.72);
    --gap: calc(var(--cell) * 0.06);
    --groove: calc(var(--cell) * 0.1);
    --pip: calc(var(--cell) * 0.2);

    --text: clamp(15px, 2.3vmin, 22px);
    --text-small: clamp(13px, 1.8vmin, 17px);
    --text-large: clamp(22px, 4.6vmin, 44px);

    --bounce: linear(0, 0.214 14.7%, 0.386 23.7%, 0.598 31.9%, 0.999 44.7%, 0.807 52.6%, 0.762 56%, 0.747 59.4%, 0.758 62.4%, 0.793 65.6%, 0.999 77.4%, 0.961 81.2%, 0.949 84.8%, 0.956 88%, 0.993 95.5%, 1);
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background-color: var(--aizome);
    /* a faint weave, so the cloth is not a flat fill */
    background-image:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 4px),
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.06) 0 1px, transparent 1px 4px);
    color: var(--paper);
    font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Arial Rounded MT Bold', system-ui, sans-serif;
    font-weight: 500;
    font-size: var(--text);
    line-height: 1.5;
}

a {
    color: inherit;
}

[hidden] {
    display: none !important;
}

.sidebar a,
.sidebar ul {
    text-decoration: none;
    list-style: none;
}

.visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
}

:where(a:any-link, button):focus-visible {
    outline: 3px solid var(--paper);
    outline-offset: 3px;
}

/* ---------- Layout ---------- */

.container {
    display: flex;
    justify-content: center;
}

.game-container {
    width: var(--game-container-width);
    min-height: var(--game-container-height);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3vmin;
    -webkit-user-select: none;
    user-select: none;
}

.table {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas:
        "chutes board"
        ".      tray"
        "status status";
    column-gap: calc(var(--cell) * 0.4);
    row-gap: calc(var(--cell) * 0.3);
    align-items: end;
}

.options-container {
    width: 30vmin;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1.6vmin;
}

/* ---------- Blocks ---------- */

.block {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    border-radius: 12%;
    background-color: var(--kiri);
    /* wood grain: a few soft bands across the face */
    background-image: repeating-linear-gradient(
        96deg,
        rgba(120, 80, 30, 0) 0 9%,
        rgba(120, 80, 30, 0.07) 9% 11%,
        rgba(120, 80, 30, 0) 11% 23%,
        rgba(120, 80, 30, 0.05) 23% 24%
    );
    box-shadow:
        0 calc(var(--cell) * 0.045) 0 var(--kiri-edge),
        0 calc(var(--cell) * 0.08) calc(var(--cell) * 0.1) rgba(0, 0, 0, 0.35),
        inset 0 calc(var(--cell) * 0.02) 0 rgba(255, 255, 255, 0.55);
    overflow: hidden;
}

.block svg {
    width: 64%;
    height: 64%;
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.45));
}

.glyph-0 { fill: #c23b22; } /* circle: vermilion */
.glyph-1 { fill: #27467f; } /* triangle: indigo */
.glyph-2 { fill: #2f6b4a; } /* square: pine */
.glyph-3 { fill: #9a5b12; } /* cross: ochre */
.glyph-4 { fill: #7a3668; } /* moon: plum */
.glyph-5 { fill: #2e2a26; } /* star: charcoal */

/* Pegged blocks: honey stain and two brass pins. */
.block.pegged {
    background-color: var(--honey);
    box-shadow:
        0 calc(var(--cell) * 0.045) 0 #a37a3d,
        0 calc(var(--cell) * 0.12) calc(var(--cell) * 0.14) rgba(0, 0, 0, 0.45),
        inset 0 calc(var(--cell) * 0.02) 0 rgba(255, 255, 255, 0.4);
}

.block.pegged::before,
.block.pegged::after {
    content: "";
    position: absolute;
    top: 7%;
    width: 13%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #f6e2a4, var(--brass) 55%, #8a6a22);
}

.block.pegged::before { left: 8%; }
.block.pegged::after { right: 8%; }

/* The light that crosses a block when its row, column or zone is complete. */
.sheen {
    position: absolute;
    inset: 0;
    background: #fff8e2;
    opacity: 0;
    pointer-events: none;
}

.block.drop {
    @media (prefers-reduced-motion: no-preference) {
        animation: drop 0.36s var(--bounce);
    }
}

@keyframes drop {
    from { translate: 0 -70%; }
    to { translate: 0 0; }
}

/* ---------- Frame ---------- */

.board {
    grid-area: board;
    position: relative;
    display: grid;
    grid-template-columns: var(--pip) repeat(3, var(--cell)) var(--groove) repeat(3, var(--cell));
    grid-template-rows:
        var(--pip) repeat(2, var(--cell)) var(--groove) repeat(2, var(--cell)) var(--groove) repeat(2, var(--cell));
    gap: var(--gap);
    padding: calc(var(--cell) * 0.16) calc(var(--cell) * 0.22) calc(var(--cell) * 0.22) calc(var(--cell) * 0.16);
    border-radius: calc(var(--cell) * 0.14);
    background: linear-gradient(100deg, var(--kuri) 0%, #5f3f25 45%, var(--kuri) 100%);
    box-shadow:
        0 calc(var(--cell) * 0.1) 0 var(--kuri-deep),
        0 calc(var(--cell) * 0.3) calc(var(--cell) * 0.4) rgba(0, 0, 0, 0.45);
}

.cell {
    position: relative;
    padding: 5%;
    border-radius: 8%;
    background: var(--sugi);
    box-shadow: inset 0 calc(var(--cell) * 0.03) calc(var(--cell) * 0.05) rgba(0, 0, 0, 0.28);
}

.cell.dark {
    background: var(--sugi-dark);
}

/* A space nothing can fill any more. */
.cell.dead::after {
    content: "";
    position: absolute;
    inset: 20%;
    background:
        linear-gradient(45deg, transparent 42%, var(--shu) 42% 58%, transparent 58%),
        linear-gradient(-45deg, transparent 42%, var(--shu) 42% 58%, transparent 58%);
}

/* A block that is not where it belongs (only with "Check for errors" on). */
.cell.wrong .block {
    outline: calc(var(--cell) * 0.07) solid var(--shu);
    outline-offset: calc(var(--cell) * -0.07);
}

/* Where the picked block would land. */
.ghost {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    border: calc(var(--cell) * 0.03) dashed rgba(56, 35, 15, 0.7);
    border-radius: 12%;
}

.ghost svg {
    width: 56%;
    height: 56%;
    opacity: 0.4;
}

.pip {
    place-self: center;
    width: calc(var(--pip) * 0.7);
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--kuri-deep);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.7);
    transition: background-color 0.4s, box-shadow 0.4s;
}

.pip.lit {
    background: var(--brass);
    box-shadow: 0 0 calc(var(--cell) * 0.12) rgba(217, 180, 90, 0.8);
}

.column {
    grid-row: 2 / -1;
    z-index: 1;
    padding: 0;
    border: 0;
    border-radius: 6%;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.board.aiming .column:hover {
    background: rgba(255, 248, 226, 0.14);
}

.clash {
    outline: calc(var(--cell) * 0.05) solid var(--shu);
    outline-offset: calc(var(--cell) * 0.02);
}

/* ---------- Chutes ---------- */

.chutes {
    grid-area: chutes;
    display: flex;
    gap: calc(var(--cell) * 0.25);
    align-items: stretch;
    align-self: stretch;
}

.chute {
    display: flex;
    flex-direction: column-reverse; /* the block to play sits at the foot */
    align-items: center;
    gap: calc(var(--mini) * 0.1);
    min-width: calc(var(--mini) * 1.28);
    min-height: calc(var(--mini) * 1.28);
    padding: calc(var(--mini) * 0.14);
    border-radius: calc(var(--cell) * 0.12);
    background: var(--kuri-deep);
    box-shadow: inset 0 calc(var(--cell) * 0.04) calc(var(--cell) * 0.08) rgba(0, 0, 0, 0.6);
}

.slot {
    flex: none;
    width: var(--mini);
    height: var(--mini);
    padding: 0;
    border: 0;
    border-radius: 12%;
    background: none;
    font: inherit;
    color: inherit;
}

button.slot {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* The blocks still waiting sit a little smaller than the one to play. */
.chute .slot:not(.front) .block {
    scale: 0.86;
}

.more {
    margin-bottom: auto;
    font-size: var(--text-small);
    color: rgba(245, 236, 217, 0.75);
}

/* Fits nowhere for the moment. */
.slot.homeless .block {
    opacity: 0.45;
    outline: calc(var(--cell) * 0.025) dashed var(--paper);
    outline-offset: calc(var(--cell) * -0.06);
}

.slot.selected .block {
    translate: 0 -8%;
    outline: calc(var(--cell) * 0.05) solid #fff8e2;
    outline-offset: calc(var(--cell) * 0.02);
}

.hinted {
    outline: calc(var(--cell) * 0.05) solid #fff8e2;
    outline-offset: calc(var(--cell) * 0.03);
    border-radius: 12%;

    @media (prefers-reduced-motion: no-preference) {
        animation: beckon 0.9s ease-in-out 3;
    }
}

@keyframes beckon {
    50% { outline-offset: calc(var(--cell) * 0.1); }
}

/* ---------- Tray and seals ---------- */

.tray-area {
    grid-area: tray;
    display: flex;
    align-items: center;
    gap: calc(var(--cell) * 0.3);
}

.tray {
    display: flex;
    gap: calc(var(--mini) * 0.14);
    padding: calc(var(--mini) * 0.14);
    border-radius: calc(var(--cell) * 0.12);
    background: linear-gradient(100deg, var(--kuri) 0%, #5f3f25 45%, var(--kuri) 100%);
    box-shadow: 0 calc(var(--cell) * 0.06) 0 var(--kuri-deep);
}

.tray .slot {
    background: var(--kuri-deep);
    box-shadow: inset 0 calc(var(--cell) * 0.04) calc(var(--cell) * 0.06) rgba(0, 0, 0, 0.6);
}

.tray .slot.inviting {
    outline: calc(var(--cell) * 0.03) dashed rgba(245, 236, 217, 0.8);
    outline-offset: calc(var(--cell) * -0.07);
}

.tray-note {
    margin: 0;
    font-size: var(--text-small);
    line-height: 1.35;
    min-height: 2.7em;
    max-width: 26ch;
}

.seals {
    display: flex;
    gap: 0.35em;
    margin-bottom: 0.3em;
}

/* Three seals spelling 積み木; a spent one is left as an empty outline. */
.seal {
    display: grid;
    place-items: center;
    width: 1.9em;
    height: 1.9em;
    border: 2px solid var(--shu);
    border-radius: 26%;
    background: var(--shu);
    color: var(--paper);
    font-weight: 700;
    line-height: 1;
    rotate: -3deg;
}

.seal.spent {
    border-style: dashed;
    border-color: rgba(245, 236, 217, 0.5);
    background: none;
    color: rgba(245, 236, 217, 0.4);
}

/* ---------- Status ---------- */

.status-line {
    grid-area: status;
    display: flex;
    align-items: center;
    gap: 1em;
    min-height: 3.2em;
    max-width: calc(var(--cell) * 9);
}

.status-line p {
    margin: 0;
}

/* ---------- Side panel ---------- */

.game-title {
    margin: 0;
    font-size: var(--text-large);
    font-weight: 700;
    line-height: 1.1;
}

.game-title .kanji {
    display: block;
    font-size: 0.5em;
    font-weight: 500;
    letter-spacing: 0.2em;
    opacity: 0.8;
}

.level {
    margin: 0 0 1vmin;
}

.plank {
    display: inline-block;
    min-height: 44px;
    padding: 0.55em 1.1em;
    border: 0;
    border-radius: 0.5em;
    background: var(--kiri);
    box-shadow: 0 0.22em 0 var(--kiri-edge);
    color: var(--kuri-deep);
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.plank:hover {
    background: #f7e8c8;
}

.plank:active {
    translate: 0 0.12em;
    box-shadow: 0 0.1em 0 var(--kiri-edge);
}

.plank:disabled {
    opacity: 0.45;
    cursor: default;
}

.plank.quiet {
    background: none;
    box-shadow: inset 0 0 0 2px rgba(245, 236, 217, 0.55);
    color: var(--paper);
}

/* A switch that is on. */
.plank[aria-pressed="true"] {
    background: var(--paper);
    box-shadow: none;
    color: var(--kuri-deep);
}

.plank[aria-pressed="true"]::before {
    content: "✓ ";
}

.actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.4vmin;
    width: 100%;
}

.page-links {
    display: flex;
    flex-direction: column;
    gap: 0.6vmin;
    margin: 1vmin 0 0;
    padding: 0;
    list-style: none;
}

/* ---------- Text sections ---------- */

hr {
    width: min(var(--game-container-width), 92vw);
    height: 1px;
    margin: 2em auto 0;
    border: 0;
    background: rgba(245, 236, 217, 0.3);
}

.text-container {
    width: min(70ch, 92vw);
    margin: 0 auto 3em;
}

.text-container h2 {
    margin: 1.2em 0 0.6em;
    font-size: var(--text-large);
    font-weight: 700;
}

.text-container h3 {
    margin: 1.2em 0 0.2em;
}

.text-container li {
    margin-bottom: 0.5em;
}

.levels {
    display: flex;
    flex-wrap: wrap;
    gap: 2vmin;
}

/* ---------- Win dialog ---------- */

dialog {
    max-width: min(34rem, 92vw);
    padding: 1.6em 1.8em;
    border: 0;
    border-radius: 0.8em;
    background: var(--paper);
    color: var(--kuri-deep);
    box-shadow: 0 1em 3em rgba(0, 0, 0, 0.5);
}

dialog h1 {
    margin: 0 0 0.4em;
    font-size: var(--text-large);
    line-height: 1.1;
}

dialog .seal.spent {
    border-color: rgba(56, 35, 15, 0.4);
    color: rgba(56, 35, 15, 0.35);
}

dialog .plank.quiet {
    box-shadow: inset 0 0 0 2px rgba(56, 35, 15, 0.5);
    color: var(--kuri-deep);
}

dialog:modal {
    overscroll-behavior: contain;
}

dialog::backdrop {
    overflow: hidden;
    overscroll-behavior: contain;
    background: rgba(15, 22, 36, 0.7);
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8em;
    margin-top: 0.6em;
}

/* ---------- Narrow screens: chutes lie flat above the frame ---------- */

@media (max-width: 900px) {
    :root {
        --cell: min(13.6vw, 10vh);
    }

    .game-container {
        flex-direction: column;
        width: 100%;
        min-height: 0;
        padding: 3vmin 0;
    }

    .table {
        grid-template-columns: auto;
        grid-template-areas:
            "chutes"
            "board"
            "tray"
            "status";
        justify-items: start;
    }

    .chutes {
        flex-direction: column;
    }

    .chute {
        flex-direction: row; /* the block to play sits at the left end */
    }

    .more {
        margin: 0 0 0 auto;
        padding: 0 0.4em;
    }

    .game-container {
        gap: 2vmin;
    }

    /* Undo and Hint stay within reach, right under the frame; the title follows. */
    .options-container {
        width: calc(var(--cell) * 6.9);
    }

    .game-title,
    .level {
        order: 1;
    }

    .page-links {
        order: 2;
    }

    .actions {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

@media (pointer: coarse) {
    .page-links a {
        display: inline-block;
        padding: 0.5em 0;
    }
}
