/* Tilt Maze: page-specific styles, loaded after games.css. */

.tm-wrap {
    max-width: 600px;
    margin-top: 18px;
}

/* HUD: four stats on one row, buttons tucked to the right */
.tm-hud {
    gap: 8px 14px;
    margin-bottom: 10px;
}

.tm-hud .hud-stat { min-width: 52px; }
.tm-hud .hud-stat .v { min-width: 3.2em; }
#hud-par.is-over { color: #a5481c; }

.tm-hud .hud-btn { padding: 7px 12px; }
.tm-hud .hud-btn[hidden] { display: none; }

/* The board frame shrinks to the board so the whole maze fits the screen.
   Board height = viewport minus room for the HUD; width follows at 11:15. */
.tm-frame {
    width: min(100%, max(280px, calc((100vh - 170px) * 11 / 15 + 20px)));
    width: min(100%, max(280px, calc((100svh - 170px) * 11 / 15 + 20px)));
    margin: 0 auto;
    box-sizing: border-box;
}

.tm-frame canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 11 / 15;
    cursor: crosshair;
    background: #e3c897;
}

/* Overlays sit over the board without hiding it completely */
.tm-start {
    background: radial-gradient(120% 90% at 50% 20%, rgba(23, 58, 49, 0.78), rgba(13, 32, 27, 0.9));
    gap: 12px;
}

.tm-start .play-btn { min-width: 160px; }

.tm-result {
    gap: 10px;
    padding: 18px 16px;
    background: radial-gradient(120% 90% at 50% 10%, rgba(23, 58, 49, 0.9), rgba(13, 32, 27, 0.95));
    animation: tm-card-in 0.28s ease-out both;
}

.tm-result h2 { font-size: clamp(1.35rem, 5vw, 1.9rem); }

.tm-stars {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.tm-star {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 76px;
    color: rgba(242, 237, 226, 0.4);
}

.tm-star .g {
    font-size: 2.3rem;
    line-height: 1;
}

.tm-star .t {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: rgba(242, 237, 226, 0.6);
    white-space: nowrap;
}

.tm-star.is-on { color: #ffd86b; }
.tm-star.is-on .g { text-shadow: 0 0 14px rgba(255, 216, 107, 0.55); }
.tm-star.is-on .t { color: rgba(242, 237, 226, 0.9); }
.tm-star.is-on .g { animation: tm-star-pop 0.42s cubic-bezier(.2, 1.6, .4, 1) both; animation-delay: var(--d, 0s); }
.tm-star.is-new .g { position: relative; }
.tm-star.is-new .t { color: #7ff5d0; font-weight: 700; }

.tm-result .tm-detail { font-size: 0.92rem; }

.tm-result .tm-unlock {
    font-size: 0.86rem;
    font-weight: 700;
    color: #7ff5d0;
}

.tm-result .tm-unlock[hidden] { display: none; }

.tm-result .tm-goal {
    font-size: 0.86rem;
    color: #ffe3a3;
}

.tm-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.tm-actions .play-btn { padding: 13px 28px; }

.tm-retry {
    background: transparent;
    color: #f2ede2;
    border-color: rgba(242, 237, 226, 0.4);
    padding: 11px 18px;
}

.tm-retry:hover { border-color: #f2ede2; }

@keyframes tm-card-in {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: none; }
}

@keyframes tm-star-pop {
    0% { transform: scale(0.2) rotate(-30deg); opacity: 0; }
    100% { transform: none; opacity: 1; }
}

/* Star total and progress toward the next ball */
.tm-progress {
    margin: 12px auto 0;
    max-width: 420px;
    font-family: 'Inter', sans-serif;
}

.tm-progress-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--ink-mut, #65786e);
}

.tm-total {
    font-weight: 700;
    color: var(--ink, #1c2b26);
    white-space: nowrap;
}

.tm-total [aria-hidden] { color: #b97f1f; }

.tm-next { text-align: right; }

.tm-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--sand, #efe7d6);
    margin-top: 6px;
    overflow: hidden;
}

.tm-bar span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 3px;
    background: linear-gradient(90deg, #d39a2c, #ffd86b);
    transition: width 0.5s ease-out;
}

/* Board chips with their stars */
.level-chips {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 6px;
    margin: 12px auto 0;
    max-width: 520px;
    font-family: 'Inter', sans-serif;
}

.level-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 5px 0 4px;
    border-radius: 8px;
    border: 1px solid var(--line-strong, #cfc6b2);
    background: var(--paper, #fff);
    color: var(--ink, #1c2b26);
    cursor: pointer;
    min-width: 0;
}

.level-chip .n { font-size: 0.82rem; font-weight: 700; line-height: 1.1; }
.level-chip .s { font-size: 0.6rem; letter-spacing: -0.04em; color: #b97f1f; line-height: 1; }
.level-chip[disabled] { opacity: 0.4; cursor: not-allowed; }
.level-chip.is-done { border-color: var(--emerald, #0e7a55); }
.level-chip.is-perfect { background: #fff7e0; border-color: #d39a2c; }
.level-chip.is-current { background: var(--brand, #134e3b); color: #fff; border-color: var(--brand, #134e3b); }
.level-chip.is-current .s { color: #ffd86b; }
.level-chip:focus-visible { outline: 3px solid var(--gold, #b97f1f); outline-offset: 2px; }

/* Ball skins */
.tm-skins {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin: 10px auto 0;
    max-width: 520px;
    font-family: 'Inter', sans-serif;
}

.tm-skin {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    border: 1px solid var(--line-strong, #cfc6b2);
    background: var(--paper, #fff);
    color: var(--ink, #1c2b26);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.tm-skin .dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.25);
    flex: none;
}

.tm-skin.is-on { border-color: var(--brand, #134e3b); box-shadow: 0 0 0 2px var(--brand, #134e3b) inset; }
.tm-skin.is-locked { opacity: 0.62; cursor: not-allowed; border-style: dashed; }
.tm-skin:focus-visible { outline: 3px solid var(--gold, #b97f1f); outline-offset: 2px; }

@media (max-width: 480px) {
    .tm-wrap { margin-left: -14px; margin-right: -14px; }
    .tm-frame { padding: 6px; border-radius: 14px; }
    .tm-frame .stage-overlay { inset: 6px; }
    .tm-hud { gap: 6px 10px; }
    .tm-hud .hud-stat { min-width: 0; }
    .tm-hud .hud-stat .v { font-size: 1rem; }
    .tm-hud .hud-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
    .tm-star { width: 66px; }
    .tm-star .g { font-size: 2rem; }
    .level-chips { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .tm-progress-top { font-size: 0.76rem; }
}

@media (prefers-reduced-motion: reduce) {
    .tm-result, .tm-star.is-on .g { animation: none; }
    .tm-bar span { transition: none; }
}
