html, body { height: 100%; }
body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.dt {
    --dt-mana: hsl(235 75% 60%);
    --dt-ready: hsl(175 85% 36%);
    --dt-cooldown: hsl(2 38% 50%);
    --dt-fire: hsl(22 95% 48%);
    /* triangles: the falling block (a blue wireframe) and placed ones (neutral, in two barely
       different shades: a/b = pointing left/right) */
    --dt-block: hsl(210 95% 45%);
    --dt-ghost: hsl(212 60% 54%);     /* its shadow, where it will land: thin and pale */
    --dt-placed-a: color-mix(in srgb, var(--bs-emphasis-color) 39%, var(--bs-body-bg));
    --dt-placed-b: color-mix(in srgb, var(--bs-emphasis-color) 36%, var(--bs-body-bg));
    /* hexagon UI pieces: outline, fill, outline width */
    --dt-line: color-mix(in srgb, var(--bs-emphasis-color) 30%, var(--bs-body-bg));
    --dt-fill: var(--bs-tertiary-bg);
    --dt-bw: 2px;
    flex: 1;
    min-height: 0;
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    justify-content: center;
}
[data-bs-theme="dark"] .dt {
    --dt-mana: hsl(235 95% 74%);
    --dt-ready: hsl(175 85% 55%);
    --dt-cooldown: hsl(2 42% 58%);
    --dt-fire: hsl(28 100% 58%);
    --dt-block: hsl(203 100% 62%);
    --dt-ghost: hsl(206 70% 72%);
}

/*
 * The two shapes everything is made of (both outlined: the element is the outline colour, its
 * ::before, slightly smaller, the fill):
 *   .dt-hex  a regular hexagon, pointy top like the arena and the power-up slots; set its width
 *   .dt-bar  a bar with pointed ends; set its height with --h
 */
.dt-hex, .dt-bar {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dt-line);
}
.dt-hex::before, .dt-bar::before {
    content: "";
    position: absolute;
    inset: var(--dt-bw);
    z-index: -2;
    clip-path: inherit;
    background: var(--dt-fill);
}
.dt-hex {
    flex-direction: column;
    aspect-ratio: 0.866;
    clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.dt-bar {
    --h: 30px;
    --p: calc(var(--h) * 0.289); /* depth of a point with 120 degree corners */
    height: var(--h);
    clip-path: polygon(var(--p) 0, calc(100% - var(--p)) 0, 100% 50%, calc(100% - var(--p)) 100%, var(--p) 100%, 0 50%);
}

.dt-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--bs-secondary-color);
}
.dt-value { font-size: 1.5rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.dt-value.dt-flash { animation: dt-flash 0.8s ease-out; }
@keyframes dt-flash { from { color: var(--dt-ready); transform: scale(1.3); } }

/* ---------- board ---------- */
.dt-board {
    position: relative;
    flex: 1 1 360px;
    max-width: 720px;
    min-width: 0;
    cursor: pointer;
}
.dt-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.dt-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 5%;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
/* Start and game over: the board is dimmed and the title banner shown above the box. */
.dt-overlay.dt-titled { background: color-mix(in srgb, var(--bs-body-bg) 78%, transparent); }
.dt-banner { display: none; width: min(92%, 560px); color: var(--dt-block); }
.dt-titled .dt-banner { display: block; }
.dt-banner svg { display: block; width: 100%; overflow: visible; }
.dt-banner line {
    stroke: currentColor;
    stroke-width: 0.17;
    stroke-linecap: round;
    stroke-dasharray: 1;
    animation: dt-draw 0.5s ease-out backwards;
    animation-delay: calc(var(--i) * 18ms);
}
[data-bs-theme="dark"] .dt-banner svg { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--dt-block) 70%, transparent)); }
@keyframes dt-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .dt-banner line { animation: none; } }
.dt-overlay-title:empty { display: none; }
.dt-overlay-box:has(.dt-overlay-title:empty) { --h: 52px; }
.dt-overlay[hidden] { display: none; }
.dt-overlay-box {
    --h: 104px;
    --dt-fill: color-mix(in srgb, var(--bs-body-bg) 92%, transparent);
    --dt-line: var(--bs-emphasis-color);
    flex-direction: column;
    padding: 0 calc(var(--p) + 18px);
    text-align: center;
    max-width: 96%;
}
.dt-overlay-title { font-size: 1.5rem; font-weight: 600; line-height: 1.3; }
#overlay-text { font-size: 0.9rem; line-height: 1.5; }

/* ---------- right: next block, level, lines, score ---------- */
/* same width as .dt-left, so that the board sits in the middle of the page */
.dt-side { flex: 0 100 240px; min-width: 220px; align-self: center; }
.dt-cluster {
    --w: 104px;               /* width of one hexagon */
    --hh: calc(var(--w) * 1.1547);
    display: grid;
    grid-template-columns: repeat(4, calc(var(--w) / 2 + 2px));
    grid-auto-rows: calc(var(--hh) * 0.75 + 3.5px); /* rows interlock, like a honeycomb */
    padding-bottom: calc(var(--hh) * 0.25);
    justify-content: center;
}
.dt-cluster .dt-hex { width: var(--w); grid-column-end: span 2; justify-self: center; align-self: start; }
.dt-cell-next { grid-area: 1 / 2; --dt-line: var(--bs-emphasis-color); }
.dt-cell-level { grid-area: 2 / 1; }
.dt-cell-lines { grid-area: 2 / 3; }
.dt-cell-score { grid-area: 3 / 2; }
.dt-cell-score .dt-value { font-size: 1.2rem; line-height: 1.4; }
#next { width: 80%; height: 50%; display: block; }

/* ---------- left: mana, power-ups, keys ---------- */
.dt-left {
    flex: 0 100 240px;
    min-width: 170px;
    align-self: center;
    display: flex;
    flex-direction: column;
    gap: 28px;
}
.dt-mana {
    --h: 38px;
    flex-direction: column; /* label on top, like everything else */
    margin: 0 6px 10px;
    font-size: 0.85rem;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}
.dt-mana .dt-label { font-size: 0.6rem; line-height: 1.3; color: inherit; opacity: 0.75; }
#mana-fill {
    position: absolute;
    inset: var(--dt-bw) auto var(--dt-bw) 0;
    width: 0;
    z-index: -1;
    background: color-mix(in srgb, var(--dt-mana) 65%, var(--dt-fill));
}
#powerups { width: 100%; aspect-ratio: 6.1 / 3.6; display: block; touch-action: manipulation; }

/* Keys as a picture: caps in their keyboard positions, each showing its action. */
.dt-cues {
    --w: 42px;
    --g: 4px;
    display: grid;
    /* half-key columns: the pause / new game row sits centred under the others */
    grid-template-columns: repeat(6, calc((var(--w) - var(--g)) / 2));
    grid-auto-rows: auto;
    gap: var(--g);
    justify-content: center;
}
.dt-key {
    --dt-fill: var(--bs-body-bg);
    font-size: 1.05rem;
    padding-top: 11px;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
}
.dt-key.dt-hex { width: var(--w); }
.dt-key.dt-bar { --h: 34px; align-self: start; }
/* Emphasis shared by every button (the power-up slots are drawn the same way in main.js):
   hovered = bright outline; triggered, by click or key = inverted. */
@media (hover: hover) { .dt-key:hover { --dt-line: var(--bs-emphasis-color); } }
.dt-key.dt-down { --dt-fill: var(--bs-emphasis-color); --dt-line: var(--bs-emphasis-color); color: var(--bs-body-bg); }
.dt-key.dt-down span { color: inherit; }
.dt-key span {
    position: absolute;
    top: 17%;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.6rem;
    line-height: 1;
    color: var(--bs-secondary-color);
}
.dt-key.dt-bar span { top: 4px; }

/*
 * Phones: information at the far top (next, level, lines, score), the board in the middle, and
 * everything that is touched at the bottom, within reach of the thumbs: mana and power-ups on
 * the left, the move / rotate / drop keys on the right. Tapping the board starts and pauses,
 * so the P and Enter caps are left out.
 */
@media (max-width: 640px) {
    .dt { flex-direction: column; padding: 6px 12px 10px; gap: 6px; }
    .dt-side { order: 1; flex: 0 0 auto; align-self: stretch; }
    .dt-board { order: 2; flex: 1 1 auto; width: 100%; }
    .dt-left { order: 3; flex: 0 0 auto; align-self: stretch; min-width: 0; flex-direction: row; align-items: center; gap: 10px; }
    .dt-cluster {
        --w: min(66px, 20vw);
        grid-template-columns: repeat(4, calc(var(--w) + 4px));
        grid-auto-rows: auto;
        padding-bottom: 0;
    }
    .dt-cluster .dt-hex { grid-area: auto; }
    .dt-value, .dt-cell-score .dt-value { font-size: 0.85rem; line-height: 1.2; }
    .dt-label { font-size: 0.55rem; }
    .dt-power { flex: 1 1 0; min-width: 0; }
    .dt-mana { margin: 0 0 8px; }
    #powerups { aspect-ratio: auto; height: 100px; }
    .dt-cues {
        --w: min(56px, 15.5vw);
        flex: 0 0 auto;
        --g: 5px;
    }
    .dt-key { font-size: 1.35rem; -webkit-tap-highlight-color: transparent; }
    .dt-key.dt-bar { --h: 44px; }
    .dt-key span { display: none; } /* key names mean nothing without a keyboard */
    .dt-key { padding-top: 0; }
    .dt-key[data-key="p"], .dt-key[data-key="Enter"] { display: none; }
}
