/*
 * Multi Dice Roller: the tool's own components, styled in the site's design language (6 Oct 2026, on the UltraCompress Pro
 * template, the first of the twelve older tools brought onto it). Base: /libs/site-pages.css (tokens, Inter and Space
 * Grotesk, buttons, theme toggle, focus rings) and /libs/shared-nav.css (the site's header and footer). This file holds the
 * toolbar (die type pills, the count control), the dice card with the 3D dice table and the result line, and the
 * information sections. The dice themselves (geometry, faces, pips, the D4 tetrahedron, the roll animations and the
 * per-count sizes) are the original's rules, kept unchanged below the marked line; the dice keep their cream faces and red
 * pips in both themes. The original's fixed, glass-styled controls, its own theme (dice-roller-theme) and the About window
 * are gone: the site's toggle owns the theme and the shared footer carries the links.
 */

/* ----- Tokens the tool adds ----- */
:root {
    --surface: #ffffff;
    --surface-2: #f3f4f8;
    --ring: rgba(139, 92, 246, 0.18);
    --app-max: 1600px;
    --table: radial-gradient(ellipse at 50% 40%, #ffffff 0%, #f3f1fb 55%, #ebe8f7 100%);
}
:root:not([data-theme="light"]) {
    --surface: #14141f;
    --surface-2: rgba(255, 255, 255, 0.05);
    --table: radial-gradient(ellipse at 50% 40%, #2a2740 0%, #1b1a2b 60%, #14141f 100%);
}

/* ----- Page: full width, the page provides the side space ----- */
.container.app-container {
    max-width: calc(var(--app-max) + 2 * var(--content-gutter));
    margin-top: 16px;
}
@media (min-width: 640px) { .container.app-container { margin-top: 24px; } }

/* ----- The site header is the first thing on the page and stays at the top (11 Oct 2026: the Tools bar above it was removed; the header's own Tools link leads to the same page) ----- */
body { padding-top: 0; }
body > header { position: sticky; top: 0; z-index: 50; }
header .site-nav { position: relative; top: auto; }
.theme-toggle { top: 90px; }
@media (max-width: 639.98px) { .theme-toggle { top: 75px; } } /* the header is 81 px tall from 640 px, 65 px below */

/* ----- Hero: brand row, headline, tagline ----- */
.app-hero { margin: 0 0 2rem; text-align: center; }
.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.25rem;
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-strong);
}
.app-brand img { width: 44px; height: 44px; border-radius: 12px; display: block; }
.app-hero h1 { margin-bottom: 0.75rem; }
.app-tagline { color: var(--text-2); font-size: 1.125rem; line-height: 1.6; max-width: 46rem; margin: 0 auto; }

/* ----- Buttons: the site's pills in the tool's sizes ----- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 9999px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    padding: 12px 24px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--gradient-brand); color: #fff; box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3); }
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4); color: #fff; }
.btn-lg { font-size: 1.05rem; padding: 14px 32px; }

/* ----- The app: the toolbar above the dice card ----- */
.app-shell { margin: 0 0 3rem; scroll-margin-top: 90px; }
.app-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; margin: 0 0 1.25rem; }
.dice-selector { display: inline-flex; gap: 4px; padding: 4px; border-radius: 9999px; background: var(--surface); border: 1px solid var(--surface-border); box-shadow: var(--surface-shadow); }
.dice-type-btn {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 9px 18px;
    border: 0;
    border-radius: 9999px;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.dice-type-btn small { font-size: 0.75rem; font-weight: 500; opacity: 0.8; }
.dice-type-btn:hover { color: var(--link); }
.dice-type-btn.active { background: var(--gradient-brand); color: #fff; box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3); }
.dice-type-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.dice-count-selector { display: inline-flex; align-items: center; gap: 6px; padding: 4px; border-radius: 9999px; background: var(--surface); border: 1px solid var(--surface-border); box-shadow: var(--surface-shadow); }
.dice-count-control {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--chip-border);
    background: var(--chip);
    color: var(--text-strong);
    font-family: inherit;
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.dice-count-control:hover:not(:disabled) { border-color: var(--brand); color: var(--link); transform: translateY(-1px); }
.dice-count-control:disabled { opacity: 0.4; cursor: not-allowed; }
.dice-count-control:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.dice-count-display { min-width: 84px; text-align: center; font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; }

/* ----- The dice card: a table for the dice, the result line and the Roll button ----- */
.card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    box-shadow: var(--surface-shadow);
    overflow: hidden;
}
.dice-stage {
    min-height: 420px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    background: var(--table);
    overflow: hidden;
}
.dice-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; padding: 16px 20px; border-top: 1px solid var(--surface-border); }
.result-display { flex: 1 1 260px; }
#result { font-family: 'Space Grotesk', 'Inter', sans-serif; font-size: 1.15rem; font-weight: 700; color: var(--text-strong); overflow-wrap: anywhere; }

/* ----- Information sections below the tool ----- */
.info-section { margin: 0 0 2.5rem; }
.info-section h2 { font-size: 1.75rem; margin: 0 0 1.25rem; }
.info-section > p { max-width: 70ch; color: var(--text-2); }
.info-section .info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.info-three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 1rem 0 1.5rem; }
.info-stack { display: grid; gap: 12px; }
.info-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    box-shadow: var(--surface-shadow);
    padding: 20px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.info-card:hover { transform: translateY(-4px); box-shadow: var(--surface-hover-shadow); }
.info-card--small { padding: 16px; box-shadow: none; }
.info-card h3 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.info-card p { color: var(--text-2); margin-bottom: 0.75rem; }
.info-card p:last-child { margin-bottom: 0; }
.step-card { position: relative; padding-top: 24px; }
.step-num {
    position: absolute;
    top: -16px;
    left: 20px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 0.75rem; }
.step-head h3 { margin: 0; }
.step-emoji { font-size: 1.6rem; line-height: 1; }
.info-section details.info-card { padding: 0; }
.info-section details.info-card summary {
    cursor: pointer;
    padding: 16px 20px;
    font-weight: 600;
    color: var(--text-strong);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.info-section details.info-card summary::-webkit-details-marker { display: none; }
.info-section details.info-card summary::after { content: '+'; color: var(--link); font-weight: 700; font-size: 1.2rem; line-height: 1; flex-shrink: 0; }
.info-section details.info-card[open] summary::after { content: '\2212'; }
.info-section details.info-card p { padding: 0 20px 16px; margin: 0; color: var(--text-2); }

/* ----- Tablets and phones ----- */
@media (max-width: 1023px) {
    .info-section .info-grid, .info-three { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 639px) {
    .app-hero { margin-bottom: 1.5rem; }
    .app-tagline { font-size: 1rem; }
    .app-toolbar { gap: 10px; }
    .dice-selector, .dice-count-selector { width: 100%; justify-content: center; }
    .dice-type-btn { flex: 1; justify-content: center; }
    .dice-stage { min-height: 360px; padding: 50px 12px; }
    .dice-footer { padding: 14px 16px; }
    .dice-footer .btn { width: 100%; }
    #result { font-size: 1rem; }
    .info-section h2 { font-size: 1.4rem; }
    .info-section .info-grid, .info-three { grid-template-columns: 1fr; }
    .info-card { padding: 16px; }
    .step-num { left: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .btn, .info-card, .dice-count-control { transition: none; }
}

/* =====================================================================================================================
   The dice: the original's geometry, faces, animations and per-count sizes, unchanged (the only edit: the mobile block
   below is the original's 768 px rules for the dice alone). The throw is drawn over the whole screen: see "The roll in
   full view" after this section.
   ===================================================================================================================== */
.dice-container {
    width: 150px;
    height: 150px;
    perspective: 1000px;
    margin: 0 auto 50px;
    position: relative;
    overflow: visible;
}

.dice-wrapper {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s ease;
}

.dice-wrapper.active {
    opacity: 1;
    visibility: visible;
}

/* Dynamic dice layout */
.dice-display-flex {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    width: 100%;
    height: 100%;
    flex-wrap: wrap;
    transform: translate3d(0, 0, 0);
}

/* Linear layout for 1-3 dice */
.dice-container.count-1 { width: 150px; height: 150px; }
.dice-container.count-2 { width: 280px; height: 150px; }
.dice-container.count-3 { width: 420px; height: 150px; }

/* Grid layout for 4-6 dice */
.dice-container.count-4,
.dice-container.count-5,
.dice-container.count-6 {
    width: 420px;
    height: 300px;
}

.dice-container.count-4 .dice-display-flex,
.dice-container.count-5 .dice-display-flex,
.dice-container.count-6 .dice-display-flex {
    display: grid;
    grid-template-columns: repeat(3, 120px);
    gap: 30px;
}

/* Dice sizing based on count */
.dice-container.count-1 .dice { width: 150px; height: 150px; }
.dice-container.count-2 .dice,
.dice-container.count-3 .dice { width: 120px; height: 120px; }
.dice-container.count-4 .dice,
.dice-container.count-5 .dice,
.dice-container.count-6 .dice { width: 120px; height: 120px; }

/* Face sizing */
.dice-container.count-1 .face { width: 150px; height: 150px; }
.dice-container.count-2 .face,
.dice-container.count-3 .face,
.dice-container.count-4 .face,
.dice-container.count-5 .face,
.dice-container.count-6 .face { width: 120px; height: 120px; }

/* Adjust translateZ for different sizes */
.dice-container.count-1 .front  { transform: rotateY(0deg) translateZ(75px); }
.dice-container.count-1 .back   { transform: rotateX(180deg) translateZ(75px); }
.dice-container.count-1 .right  { transform: rotateY(90deg) translateZ(75px); }
.dice-container.count-1 .left   { transform: rotateY(-90deg) translateZ(75px); }
.dice-container.count-1 .top    { transform: rotateX(90deg) translateZ(75px); }
.dice-container.count-1 .bottom { transform: rotateX(-90deg) translateZ(75px); }

.dice-container.count-2 .front,
.dice-container.count-3 .front,
.dice-container.count-4 .front,
.dice-container.count-5 .front,
.dice-container.count-6 .front  { transform: rotateY(0deg) translateZ(60px); }

.dice-container.count-2 .back,
.dice-container.count-3 .back,
.dice-container.count-4 .back,
.dice-container.count-5 .back,
.dice-container.count-6 .back   { transform: rotateX(180deg) translateZ(60px); }

.dice-container.count-2 .right,
.dice-container.count-3 .right,
.dice-container.count-4 .right,
.dice-container.count-5 .right,
.dice-container.count-6 .right  { transform: rotateY(90deg) translateZ(60px); }

.dice-container.count-2 .left,
.dice-container.count-3 .left,
.dice-container.count-4 .left,
.dice-container.count-5 .left,
.dice-container.count-6 .left   { transform: rotateY(-90deg) translateZ(60px); }

.dice-container.count-2 .top,
.dice-container.count-3 .top,
.dice-container.count-4 .top,
.dice-container.count-5 .top,
.dice-container.count-6 .top    { transform: rotateX(90deg) translateZ(60px); }

.dice-container.count-2 .bottom,
.dice-container.count-3 .bottom,
.dice-container.count-4 .bottom,
.dice-container.count-5 .bottom,
.dice-container.count-6 .bottom { transform: rotateX(-90deg) translateZ(60px); }

/* Dot sizing */
.dice-container.count-1 .dot { width: 20px; height: 20px; }
.dice-container.count-2 .dot,
.dice-container.count-3 .dot,
.dice-container.count-4 .dot,
.dice-container.count-5 .dot,
.dice-container.count-6 .dot { width: 16px; height: 16px; }

/* Dot positions for single dice (150px face) - Desktop */
.dice-container.count-1 .face-1 .dot:nth-child(1) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-1 .face-2 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-2 .dot:nth-child(2) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-3 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-3 .dot:nth-child(2) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.dice-container.count-1 .face-3 .dot:nth-child(3) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-4 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-4 .dot:nth-child(2) { top: 35px; right: 35px; }
.dice-container.count-1 .face-4 .dot:nth-child(3) { bottom: 35px; left: 35px; }
.dice-container.count-1 .face-4 .dot:nth-child(4) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-5 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-5 .dot:nth-child(2) { top: 35px; right: 35px; }
.dice-container.count-1 .face-5 .dot:nth-child(3) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.dice-container.count-1 .face-5 .dot:nth-child(4) { bottom: 35px; left: 35px; }
.dice-container.count-1 .face-5 .dot:nth-child(5) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-6 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-6 .dot:nth-child(2) { top: 35px; right: 35px; }
.dice-container.count-1 .face-6 .dot:nth-child(3) { top: 50%; left: 35px; transform: translateY(-50%); }
.dice-container.count-1 .face-6 .dot:nth-child(4) { top: 50%; right: 35px; transform: translateY(-50%); }
.dice-container.count-1 .face-6 .dot:nth-child(5) { bottom: 35px; left: 35px; }
.dice-container.count-1 .face-6 .dot:nth-child(6) { bottom: 35px; right: 35px; }

/* Adjust dot positions for 120px dice */
.dice-container.count-2 .face-1 .dot:nth-child(1),
.dice-container.count-3 .face-1 .dot:nth-child(1),
.dice-container.count-4 .face-1 .dot:nth-child(1),
.dice-container.count-5 .face-1 .dot:nth-child(1),
.dice-container.count-6 .face-1 .dot:nth-child(1) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-2 .face-2 .dot:nth-child(1),
.dice-container.count-3 .face-2 .dot:nth-child(1),
.dice-container.count-4 .face-2 .dot:nth-child(1),
.dice-container.count-5 .face-2 .dot:nth-child(1),
.dice-container.count-6 .face-2 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-2 .dot:nth-child(2),
.dice-container.count-3 .face-2 .dot:nth-child(2),
.dice-container.count-4 .face-2 .dot:nth-child(2),
.dice-container.count-5 .face-2 .dot:nth-child(2),
.dice-container.count-6 .face-2 .dot:nth-child(2) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-3 .dot:nth-child(1),
.dice-container.count-3 .face-3 .dot:nth-child(1),
.dice-container.count-4 .face-3 .dot:nth-child(1),
.dice-container.count-5 .face-3 .dot:nth-child(1),
.dice-container.count-6 .face-3 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-3 .dot:nth-child(2),
.dice-container.count-3 .face-3 .dot:nth-child(2),
.dice-container.count-4 .face-3 .dot:nth-child(2),
.dice-container.count-5 .face-3 .dot:nth-child(2),
.dice-container.count-6 .face-3 .dot:nth-child(2) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-2 .face-3 .dot:nth-child(3),
.dice-container.count-3 .face-3 .dot:nth-child(3),
.dice-container.count-4 .face-3 .dot:nth-child(3),
.dice-container.count-5 .face-3 .dot:nth-child(3),
.dice-container.count-6 .face-3 .dot:nth-child(3) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(1),
.dice-container.count-3 .face-4 .dot:nth-child(1),
.dice-container.count-4 .face-4 .dot:nth-child(1),
.dice-container.count-5 .face-4 .dot:nth-child(1),
.dice-container.count-6 .face-4 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(2),
.dice-container.count-3 .face-4 .dot:nth-child(2),
.dice-container.count-4 .face-4 .dot:nth-child(2),
.dice-container.count-5 .face-4 .dot:nth-child(2),
.dice-container.count-6 .face-4 .dot:nth-child(2) { top: 24px; right: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(3),
.dice-container.count-3 .face-4 .dot:nth-child(3),
.dice-container.count-4 .face-4 .dot:nth-child(3),
.dice-container.count-5 .face-4 .dot:nth-child(3),
.dice-container.count-6 .face-4 .dot:nth-child(3) { bottom: 24px; left: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(4),
.dice-container.count-3 .face-4 .dot:nth-child(4),
.dice-container.count-4 .face-4 .dot:nth-child(4),
.dice-container.count-5 .face-4 .dot:nth-child(4),
.dice-container.count-6 .face-4 .dot:nth-child(4) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(1),
.dice-container.count-3 .face-5 .dot:nth-child(1),
.dice-container.count-4 .face-5 .dot:nth-child(1),
.dice-container.count-5 .face-5 .dot:nth-child(1),
.dice-container.count-6 .face-5 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(2),
.dice-container.count-3 .face-5 .dot:nth-child(2),
.dice-container.count-4 .face-5 .dot:nth-child(2),
.dice-container.count-5 .face-5 .dot:nth-child(2),
.dice-container.count-6 .face-5 .dot:nth-child(2) { top: 24px; right: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(3),
.dice-container.count-3 .face-5 .dot:nth-child(3),
.dice-container.count-4 .face-5 .dot:nth-child(3),
.dice-container.count-5 .face-5 .dot:nth-child(3),
.dice-container.count-6 .face-5 .dot:nth-child(3) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-2 .face-5 .dot:nth-child(4),
.dice-container.count-3 .face-5 .dot:nth-child(4),
.dice-container.count-4 .face-5 .dot:nth-child(4),
.dice-container.count-5 .face-5 .dot:nth-child(4),
.dice-container.count-6 .face-5 .dot:nth-child(4) { bottom: 24px; left: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(5),
.dice-container.count-3 .face-5 .dot:nth-child(5),
.dice-container.count-4 .face-5 .dot:nth-child(5),
.dice-container.count-5 .face-5 .dot:nth-child(5),
.dice-container.count-6 .face-5 .dot:nth-child(5) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(1),
.dice-container.count-3 .face-6 .dot:nth-child(1),
.dice-container.count-4 .face-6 .dot:nth-child(1),
.dice-container.count-5 .face-6 .dot:nth-child(1),
.dice-container.count-6 .face-6 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(2),
.dice-container.count-3 .face-6 .dot:nth-child(2),
.dice-container.count-4 .face-6 .dot:nth-child(2),
.dice-container.count-5 .face-6 .dot:nth-child(2),
.dice-container.count-6 .face-6 .dot:nth-child(2) { top: 24px; right: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(3),
.dice-container.count-3 .face-6 .dot:nth-child(3),
.dice-container.count-4 .face-6 .dot:nth-child(3),
.dice-container.count-5 .face-6 .dot:nth-child(3),
.dice-container.count-6 .face-6 .dot:nth-child(3) { top: 50%; left: 24px; transform: translateY(-50%); }

.dice-container.count-2 .face-6 .dot:nth-child(4),
.dice-container.count-3 .face-6 .dot:nth-child(4),
.dice-container.count-4 .face-6 .dot:nth-child(4),
.dice-container.count-5 .face-6 .dot:nth-child(4),
.dice-container.count-6 .face-6 .dot:nth-child(4) { top: 50%; right: 24px; transform: translateY(-50%); }

.dice-container.count-2 .face-6 .dot:nth-child(5),
.dice-container.count-3 .face-6 .dot:nth-child(5),
.dice-container.count-4 .face-6 .dot:nth-child(5),
.dice-container.count-5 .face-6 .dot:nth-child(5),
.dice-container.count-6 .face-6 .dot:nth-child(5) { bottom: 24px; left: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(6),
.dice-container.count-3 .face-6 .dot:nth-child(6),
.dice-container.count-4 .face-6 .dot:nth-child(6),
.dice-container.count-5 .face-6 .dot:nth-child(6),
.dice-container.count-6 .face-6 .dot:nth-child(6) { bottom: 24px; right: 24px; }

/* Container transitions */
.dice-container {
    transition: width 0.5s ease, height 0.5s ease;
}

.dice {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
    backface-visibility: hidden;
}

.dice.rolling {
    animation: rollAnimation 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes rollAnimation {
    0% {
        transform: translate3d(0, 0, -75px) scale(1);
    }
    25% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(180deg) rotateY(180deg);
    }
    50% {
        transform: translate3d(0, 0, 500px) scale(4.0) rotateX(360deg) rotateY(360deg);
    }
    75% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(540deg) rotateY(540deg);
    }
    100% {
        transform: translate3d(0, 0, -75px) scale(1);
    }
}

/* D4-specific animation with correct base position */
@keyframes rollAnimationD4 {
    0% {
        transform: translate3d(0, 0, -50px) scale(1);
    }
    25% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(180deg) rotateY(180deg);
    }
    50% {
        transform: translate3d(0, 0, 500px) scale(4.0) rotateX(360deg) rotateY(360deg);
    }
    75% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(540deg) rotateY(540deg);
    }
    100% {
        transform: translate3d(0, 0, -50px) scale(1);
    }
}

.d4-dice.rolling {
    animation: rollAnimationD4 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Two-dice animation with adjusted base position */
@keyframes rollAnimationTwoDice {
    0% {
        transform: translate3d(0, 0, -60px) scale(1);
    }
    25% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(180deg) rotateY(180deg);
    }
    50% {
        transform: translate3d(0, 0, 500px) scale(4.0) rotateX(360deg) rotateY(360deg);
    }
    75% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(540deg) rotateY(540deg);
    }
    100% {
        transform: translate3d(0, 0, -60px) scale(1);
    }
}

#d6-double .dice.rolling {
    animation: rollAnimationTwoDice 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* D6 Dice Styles - Enhanced 3D Realism */
.d6-dice .face {
    position: absolute;
    width: 150px;
    height: 150px;
    border: 2px solid #c62828;
    background: #faf8f4;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    box-shadow:
        0 8px 20px rgba(0,0,0,0.3),
        0 2px 6px rgba(0,0,0,0.2);
    overflow: hidden;
    will-change: transform;
    backface-visibility: hidden;
}

/* Simplify shadows during rolling for better performance */
.dice.rolling .face {
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.d6-dice .front  { transform: rotateY(0deg) translateZ(75px); }
.d6-dice .back   { transform: rotateX(180deg) translateZ(75px); }
.d6-dice .right  { transform: rotateY(90deg) translateZ(75px); }
.d6-dice .left   { transform: rotateY(-90deg) translateZ(75px); }
.d6-dice .top    { transform: rotateX(90deg) translateZ(75px); }
.d6-dice .bottom { transform: rotateX(-90deg) translateZ(75px); }

.dot {
    width: 20px;
    height: 20px;
    background: radial-gradient(circle at 35% 35%, #b33030, #8b1e1e 60%, #6b1010);
    border-radius: 50%;
    position: absolute;
    box-shadow:
        inset 0 2px 4px rgba(0,0,0,0.6),
        inset 0 -1px 2px rgba(255,255,255,0.2),
        inset 0 0 8px rgba(0,0,0,0.4),
        0 1px 2px rgba(0,0,0,0.3);
    will-change: transform;
}

/* Enhanced recessed dot effect with pseudo-element */
.dot::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    background: radial-gradient(circle at 40% 40%, rgba(200,80,80,0.3), transparent 60%);
    border-radius: 50%;
    pointer-events: none;
}

/* D6 Dot Positions */
.face-1 .dot:nth-child(1) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.face-2 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-2 .dot:nth-child(2) { bottom: 30px; right: 30px; }

.face-3 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-3 .dot:nth-child(2) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.face-3 .dot:nth-child(3) { bottom: 30px; right: 30px; }

.face-4 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-4 .dot:nth-child(2) { top: 30px; right: 30px; }
.face-4 .dot:nth-child(3) { bottom: 30px; left: 30px; }
.face-4 .dot:nth-child(4) { bottom: 30px; right: 30px; }

.face-5 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-5 .dot:nth-child(2) { top: 30px; right: 30px; }
.face-5 .dot:nth-child(3) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.face-5 .dot:nth-child(4) { bottom: 30px; left: 30px; }
.face-5 .dot:nth-child(5) { bottom: 30px; right: 30px; }

.face-6 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-6 .dot:nth-child(2) { top: 30px; right: 30px; }
.face-6 .dot:nth-child(3) { top: 50%; left: 30px; transform: translateY(-50%); }
.face-6 .dot:nth-child(4) { top: 50%; right: 30px; transform: translateY(-50%); }
.face-6 .dot:nth-child(5) { bottom: 30px; left: 30px; }
.face-6 .dot:nth-child(6) { bottom: 30px; right: 30px; }

/* D4 Dice Styles (Proper Tetrahedron) - Based on flipsimu.com implementation */
.d4-dice {
    transform-style: preserve-3d;
    transform: translateZ(-50px);
}

.d4-face {
    position: absolute;
    width: 0;
    height: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    transform-origin: center top;
    left: 50%;
    top: 50%;
    margin-left: -75px;
    margin-top: -65px;
    /* CSS border triangle: creates equilateral triangle - scaled 1.5x */
    border-left: 75px solid transparent;
    border-right: 75px solid transparent;
    border-bottom: 129.9px solid #faf8f4;
    /* Red edge lines to show separate pyramid faces */
    filter:
        drop-shadow(-2px -2px 0 #c62828)
        drop-shadow(2px -2px 0 #c62828)
        drop-shadow(0 2px 0 #c62828);
    will-change: transform;
    backface-visibility: hidden;
}

/* Simplify D4 filters during rolling for better performance */
.d4-dice.rolling .d4-face {
    filter: drop-shadow(0 0 1px #c62828);
}

.d4-face .number {
    position: absolute;
    top: 67px;
    font-size: 2.3em;
    font-weight: bold;
    color: #a82a2a;
    text-shadow:
        0 1px 0 rgba(255,255,255,0.3),
        0 -1px 2px rgba(0,0,0,0.8),
        1px 0 2px rgba(0,0,0,0.6),
        -1px 0 2px rgba(0,0,0,0.6),
        0 2px 4px rgba(0,0,0,0.5),
        inset 0 1px 1px rgba(0,0,0,0.4);
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}

.d4-face-4 .number {
    transform: rotateZ(-180deg);
}

/* Position the 4 triangular faces using proper tetrahedron geometry */
/* Faces 1-3: Three sides at 120° intervals with 19.471221° tilt */
.d4-face-1 {
    border-bottom-color: #faf8f4;
    transform: rotateY(0deg) rotateX(19.471221deg);
}

.d4-face-2 {
    border-bottom-color: #faf8f4;
    transform: rotateY(120deg) rotateX(19.471221deg);
}

.d4-face-3 {
    border-bottom-color: #faf8f4;
    transform: rotateY(240deg) rotateX(19.471221deg);
}

/* Face 4 - Bottom face with complex transform - scaled 1.5x */
.d4-face-4 {
    border-bottom-color: #faf8f4;
    transform: rotateX(-90deg) rotateZ(180deg) translateY(-86.6px) translateZ(122.37px);
    /* Red edge lines for bottom face */
    filter:
        drop-shadow(-2px 2px 0 #c62828)
        drop-shadow(2px 2px 0 #c62828)
        drop-shadow(0 -2px 0 #c62828);
}

/* Override for bottom face during rolling */
.d4-dice.rolling .d4-face-4 {
    filter: drop-shadow(0 0 1px #c62828);
}

/* Cast shadow beneath dice - creates ground shadow effect */
.dice-container::before {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 20px;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.4), rgba(0,0,0,0.2) 40%, transparent 70%);
    border-radius: 50%;
    opacity: 0.8;
    transition: all 0.5s ease;
    z-index: -1;
    filter: blur(8px);
}

/* Disable shadow during rolling for better performance */
.dice-container.rolling::before {
    opacity: 0;
}

/* ----- Original mobile rules for the dice (from the 768 px block) ----- */
@media (max-width: 768px) {
    /* Mobile: Vertical dice layout for 1-3 dice */
    .dice-display-flex {
        flex-direction: column;
        gap: 20px;
        flex-wrap: nowrap;
    }

    /* Mobile: Single column for 1-3 dice */
    .dice-container.count-1 {
        width: 150px;
        height: 150px;
    }

    .dice-container.count-2 {
        width: 150px;
        height: 290px; /* 120px * 2 + 20px gap + padding */
    }

    .dice-container.count-3 {
        width: 150px;
        height: 410px; /* 120px * 3 + 40px gaps + padding */
    }

    /* Mobile: 2-column grid layout for 4-6 dice */
    .dice-container.count-4,
    .dice-container.count-5,
    .dice-container.count-6 {
        width: 270px; /* 120px * 2 + 30px gap */
    }

    .dice-container.count-4 {
        height: 270px; /* 2x2 grid: 120px * 2 + 30px gap */
    }

    .dice-container.count-5 {
        height: 390px; /* 2 cols, 3 rows: 120px * 3 + 60px gaps */
    }

    .dice-container.count-6 {
        height: 390px; /* 2x3 grid: 120px * 3 + 60px gaps */
    }

    .dice-container.count-4 .dice-display-flex,
    .dice-container.count-5 .dice-display-flex,
    .dice-container.count-6 .dice-display-flex {
        display: grid;
        grid-template-columns: repeat(2, 120px);
        gap: 30px;
        justify-content: center;
        align-items: center;
    }

    /* Mobile: All dice use same size (120px) */
    .dice-container.count-1 .dice {
        width: 120px;
        height: 120px;
    }

    .dice-container.count-2 .dice,
    .dice-container.count-3 .dice,
    .dice-container.count-4 .dice,
    .dice-container.count-5 .dice,
    .dice-container.count-6 .dice {
        width: 120px;
        height: 120px;
    }

    /* Mobile: All faces use 120px */
    .dice-container.count-1 .face {
        width: 120px;
        height: 120px;
    }

    .dice-container.count-2 .face,
    .dice-container.count-3 .face,
    .dice-container.count-4 .face,
    .dice-container.count-5 .face,
    .dice-container.count-6 .face {
        width: 120px;
        height: 120px;
    }

    /* Mobile: All dice use -60px translateZ */
    .dice-container.count-1 .front  { transform: rotateY(0deg) translateZ(60px); }
    .dice-container.count-1 .back   { transform: rotateX(180deg) translateZ(60px); }
    .dice-container.count-1 .right  { transform: rotateY(90deg) translateZ(60px); }
    .dice-container.count-1 .left   { transform: rotateY(-90deg) translateZ(60px); }
    .dice-container.count-1 .top    { transform: rotateX(90deg) translateZ(60px); }
    .dice-container.count-1 .bottom { transform: rotateX(-90deg) translateZ(60px); }

    /* Dot positions for single dice on mobile (120px face when resized) */
    .dice-container.count-1 .face-2 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-2 .dot:nth-child(2) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-3 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-3 .dot:nth-child(3) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-4 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-4 .dot:nth-child(2) { top: 24px; right: 24px; }
    .dice-container.count-1 .face-4 .dot:nth-child(3) { bottom: 24px; left: 24px; }
    .dice-container.count-1 .face-4 .dot:nth-child(4) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-5 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-5 .dot:nth-child(2) { top: 24px; right: 24px; }
    .dice-container.count-1 .face-5 .dot:nth-child(4) { bottom: 24px; left: 24px; }
    .dice-container.count-1 .face-5 .dot:nth-child(5) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-6 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-6 .dot:nth-child(2) { top: 24px; right: 24px; }
    .dice-container.count-1 .face-6 .dot:nth-child(3) { top: 50%; left: 24px; transform: translateY(-50%); }
    .dice-container.count-1 .face-6 .dot:nth-child(4) { top: 50%; right: 24px; transform: translateY(-50%); }
    .dice-container.count-1 .face-6 .dot:nth-child(5) { bottom: 24px; left: 24px; }
    .dice-container.count-1 .face-6 .dot:nth-child(6) { bottom: 24px; right: 24px; }
}

/* =====================================================================================================================
   The roll in full view (Milan, 12 Oct 2026): the throw grows a die to 4 times its size (150 px to 600 px at the top
   of the throw), and the card cut it off. During a throw app.js moves the dice into this layer over
   the whole screen, as the original filled the screen, and puts them back on the table when the throw ends. The veil
   is the table's own colour, spread over the page. The layer sits above the site header and the theme button and
   below the cookie banner, and it takes the clicks, so nothing under it is clicked by accident while the dice fly.
   ===================================================================================================================== */
.roll-layer {
    position: fixed;
    inset: 0;
    z-index: 5000;
    overflow: hidden;
    overscroll-behavior: contain;
}
.roll-layer-veil {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 45%, rgba(255, 255, 255, 0.94) 0%, rgba(243, 241, 251, 0.92) 55%, rgba(235, 232, 247, 0.92) 100%);
    opacity: 0;
}
:root:not([data-theme="light"]) .roll-layer-veil {
    background: radial-gradient(ellipse at 50% 45%, rgba(42, 39, 64, 0.94) 0%, rgba(27, 26, 43, 0.94) 60%, rgba(20, 20, 31, 0.94) 100%);
}
.roll-flyer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.roll-layer .dice-container { margin: 0; }

/* Reduced motion: no throw; the die turns in place to its new face (app.js skips the layer and the wait) */
@media (prefers-reduced-motion: reduce) {
    .dice.rolling, .d4-dice.rolling, #d6-double .dice.rolling { animation: none; }
}

/* Phones: 16 px text, 44 px tap targets (AdSense audit H-04, 8 Oct 2026) */
@media (max-width: 639.98px) {
    main button, main select, main summary, main [role="button"],
    main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]) { min-height: 44px; }
    main button#decrease-dice, main button#increase-dice { min-width: 44px; }
}
