/*
 * Ma di? (/ma-di): the game's page (its own page for search engines too) and the game over the whole screen. The site's
 * look (square blocks, ink borders, Archivo for headings and numbers, the red as an accent, never a solid black button)
 * with the gold of the games. Phones first: the postcard on top, the map in the middle, one big button under the thumb;
 * after a pin a sheet rises from the bottom. Every column is minmax(0, 1fr).
 */

.md {
    --md-ink: #16171c;
    --md-soft: #3d4250;
    --md-muted: #5f6673;
    --md-accent: #b42318;
    --md-accent-dark: #8f1c13;
    --md-pin: #d92d20;
    --md-gold: #f5b800;
    --md-gold-deep: #c99400;
    --md-gold-soft: #fff6d6;
    --md-rule: #dfe3e8;
    --md-rule-strong: #c4cbd4;
    --md-paper: #ffffff;
    --md-wash: #f4f5f7;
    --md-hot: #f04438;
    --md-warm: #f79009;
    --md-cold: #2e90fa;
    --md-ice: #7cd4fd;
    --md-perfect: #12b76a;
    width: min(var(--news-width, 1180px), calc(100% - 32px));
    margin: 0 auto;
    padding: 0.85rem 0 3rem;
    color: var(--md-ink);
}

.md [hidden] {
    display: none !important;
}

/* ---------- buttons ---------- */

.md-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 46px;
    padding: 0.55rem 1.1rem;
    color: var(--md-ink);
    background: var(--md-paper);
    border: 2px solid var(--md-ink);
    border-radius: 0;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
}

.md-btn:hover,
.md-btn:focus-visible {
    color: var(--md-ink);
    background: var(--md-wash);
}

.md-btn.is-primary {
    color: #fff;
    background: var(--md-accent);
    border-color: var(--md-accent);
}

.md-btn.is-primary:hover,
.md-btn.is-primary:focus-visible {
    color: #fff;
    background: var(--md-accent-dark);
    border-color: var(--md-accent-dark);
}

.md-btn.is-gold {
    background: var(--md-gold);
    border-color: var(--md-ink);
}

.md-btn.is-gold:hover,
.md-btn.is-gold:focus-visible {
    background: #ffcf33;
}

.md-btn.is-big {
    min-height: 54px;
    padding: 0.7rem 1.3rem;
    font-family: var(--news-font-head);
    font-size: 1.08rem;
    font-weight: 900;
}

.md-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ---------- the page ---------- */

.md-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 0.6rem 1.6rem;
    padding: 1.1rem 1rem 1.3rem;
    text-align: center;
    background: var(--md-gold-soft);
    border: 1px solid var(--md-rule-strong);
    border-top: 4px solid var(--md-gold);
}

.md-hero-host {
    width: 150px;
    height: 150px;
    object-fit: contain;
    filter: drop-shadow(0 6px 10px rgba(22, 23, 28, 0.16));
    animation: md-bob 3.2s ease-in-out infinite;
}

.md-hero-text {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.55rem;
    min-width: 0;
}

.md-kicker {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.md-kicker a {
    color: var(--md-accent);
    text-decoration: none;
}

.md-title {
    margin: 0;
    font-family: var(--news-font-head);
    font-size: clamp(2.6rem, 11vw, 4.2rem);
    font-weight: 900;
    line-height: 0.95;
    letter-spacing: -0.02em;
}

.md-lead,
.md-challenge-lead {
    margin: 0;
    color: var(--md-soft);
    font-size: 1.05rem;
    line-height: 1.5;
}

.md-challenge-row {
    display: block;
    margin-top: 0.25rem;
    font-size: 1.15rem;
    letter-spacing: 0.08em;
}

.md-challenge-lead {
    padding: 0.55rem 0.75rem;
    color: var(--md-ink);
    background: var(--md-paper);
    border: 2px solid var(--md-ink);
}

.md-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.55rem;
    margin-top: 0.3rem;
}

.md-today {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.2rem 0.9rem;
    margin: 0.2rem 0 0;
    color: var(--md-muted);
    font-size: 0.86rem;
}

.md-today strong {
    color: var(--md-ink);
    font-family: var(--news-font-head);
}

.md-panel {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--md-paper);
    border: 1px solid var(--md-rule-strong);
    border-top: 3px solid var(--md-accent);
}

.md-panel h2 {
    margin: 0 0 0.7rem;
    font-family: var(--news-font-head);
    font-size: 1.2rem;
    font-weight: 900;
}

.md-panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.6rem;
}

.md-panel-head a {
    color: var(--md-accent);
    font-weight: 800;
}

.md-panel-note {
    margin: 0.4rem 0 0;
    color: var(--md-muted);
    font-size: 0.9rem;
}

.md-panel-note a {
    color: var(--md-accent);
    font-weight: 800;
}

.md-steps {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.6rem;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: step;
}

.md-steps li {
    position: relative;
    padding: 0.2rem 0 0.2rem 2.6rem;
    color: var(--md-soft);
    line-height: 1.5;
    counter-increment: step;
}

.md-steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 0.15rem;
    display: grid;
    place-items: center;
    width: 1.9rem;
    height: 1.9rem;
    color: var(--md-ink);
    background: var(--md-gold);
    border: 2px solid var(--md-ink);
    font-family: var(--news-font-head);
    font-weight: 900;
}

.md-steps strong {
    color: var(--md-ink);
}

.md-topics {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
    margin-top: 0.7rem;
}

.md-topic {
    display: grid;
    grid-template-columns: 2.4rem minmax(0, 1fr);
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0.6rem 0.75rem;
    color: var(--md-ink);
    text-align: left;
    background: var(--md-paper);
    border: 1.5px solid var(--md-rule-strong);
    border-left: 4px solid var(--md-gold);
    border-radius: 0;
    cursor: pointer;
    touch-action: manipulation;
}

.md-topic:hover,
.md-topic:focus-visible {
    background: var(--md-gold-soft);
    border-color: var(--md-ink);
}

.md-topic i {
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    color: var(--md-accent);
    background: var(--md-wash);
    font-size: 1.1rem;
}

.md-topic span {
    display: grid;
    gap: 0.1rem;
    min-width: 0;
}

.md-topic small {
    color: var(--md-muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.md-table {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.md-table li {
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.2rem;
    border-bottom: 1px solid var(--md-rule);
}

.md-table li.is-me {
    background: var(--md-gold-soft);
}

.md-table-rank {
    color: var(--md-muted);
    font-family: var(--news-font-head);
    font-weight: 900;
}

.md-table-name {
    overflow: hidden;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.md-table strong {
    font-family: var(--news-font-head);
    font-weight: 900;
}

.md-faq details {
    border-bottom: 1px solid var(--md-rule);
}

.md-faq summary {
    padding: 0.65rem 0;
    font-weight: 800;
    cursor: pointer;
}

.md-faq p {
    margin: 0 0 0.75rem;
    color: var(--md-soft);
    line-height: 1.55;
}

.md-reads {
    display: grid;
    gap: 0.45rem;
    margin: 0;
    padding-left: 1.1rem;
}

.md-reads a {
    color: var(--md-accent);
    font-weight: 800;
}

/* ---------- the game ---------- */

html.md-lock,
html.md-lock body {
    overflow: hidden;
    overscroll-behavior: none;
}

.md-game {
    position: fixed;
    inset: 0;
    z-index: 1085;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    height: 100dvh;
    background: var(--md-paper);
    overscroll-behavior: contain;
}

.md-bar {
    grid-row: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.5rem;
    padding: calc(0.4rem + env(safe-area-inset-top, 0px)) 0.55rem 0.4rem;
    background: var(--md-paper);
    border-bottom: 1px solid var(--md-rule-strong);
}

.md-icon {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    color: var(--md-ink);
    background: var(--md-paper);
    border: 1.5px solid var(--md-ink);
    border-radius: 0;
    cursor: pointer;
    touch-action: manipulation;
}

.md-progress {
    display: flex;
    gap: 0.45rem;
    align-items: center;
    min-width: 0;
    overflow: hidden;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.md-total {
    padding: 0.25rem 0.55rem;
    color: var(--md-ink);
    background: var(--md-gold);
    border: 1.5px solid var(--md-ink);
    font-family: var(--news-font-head);
    font-size: 1rem;
    font-weight: 900;
    white-space: nowrap;
}

/* The postcard. */
.md-card {
    grid-row: 2;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.65rem;
    align-items: start;
    margin: 0.5rem 0.55rem 0.45rem;
    padding: 0.6rem 0.7rem;
    background: var(--md-gold-soft);
    border: 2px solid var(--md-ink);
    box-shadow: 4px 4px 0 var(--md-ink);
}

.md-card.is-in {
    animation: md-card-in 0.35s ease-out;
}

.md-card-host {
    width: 56px;
    height: 56px;
    object-fit: contain;
}

.md-card-body {
    min-width: 0;
}

.md-card-meta {
    margin: 0 0 0.2rem;
    color: var(--md-accent);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.md-card-clue {
    margin: 0;
    color: var(--md-ink);
    font-size: clamp(1rem, 3.9vw, 1.12rem);
    font-weight: 700;
    line-height: 1.38;
}

.md-stage {
    grid-row: 3;
    position: relative;
    min-height: 0;
}

.md-map {
    position: absolute;
    inset: 0;
    z-index: 0;
    /* Leaflet's own layers and controls (z-index up to 1000) stay inside the map, under the sheets. */
    isolation: isolate;
    background: #e6ecef;
}

.md-tip {
    position: absolute;
    font-size: 0.82rem;
    top: 0.6rem;
    left: 50%;
    z-index: 500;
    max-width: calc(100% - 1.6rem);
    margin: 0;
    padding: 0.4rem 0.75rem;
    color: var(--md-ink);
    background: rgba(255, 255, 255, 0.94);
    border: 1.5px solid var(--md-ink);
    font-weight: 700;
    text-align: center;
    transform: translateX(-50%);
    pointer-events: none;
}

.md-actionbar {
    grid-row: 4;
    padding: 0.55rem 0.55rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
    background: var(--md-paper);
    border-top: 1px solid var(--md-rule-strong);
}

.md-go {
    width: 100%;
    min-height: 58px;
    color: #fff;
    background: var(--md-muted);
    border: 2px solid var(--md-muted);
    border-radius: 0;
    font-family: var(--news-font-head);
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: 0.02em;
    cursor: pointer;
    touch-action: manipulation;
}

.md-go:disabled {
    color: var(--md-soft);
    background: var(--md-paper);
    border: 2px dashed var(--md-rule-strong);
    box-shadow: none;
    cursor: default;
}

.md-go.is-ready:not(:disabled) {
    background: var(--md-accent);
    border-color: var(--md-accent);
    animation: md-pulse 1.4s ease-in-out infinite;
}

/* The map's pins and labels. */
.md-pin {
    filter: drop-shadow(0 3px 2px rgba(22, 23, 28, 0.35));
}

.md-pin svg {
    display: block;
    animation: md-drop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.md-answer img {
    display: block;
    width: 44px;
    height: 44px;
    margin: 2px;
    background: var(--md-gold);
    border: 2px solid var(--md-ink);
    border-radius: 50%;
    animation: md-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.md-stop span {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    color: #fff;
    background: var(--md-ink);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(22, 23, 28, 0.4);
    font-family: var(--news-font-head);
    font-size: 0.85rem;
    font-weight: 900;
}

.md-stop.is-perfect span { background: var(--md-perfect); }
.md-stop.is-hot span { background: var(--md-hot); }
.md-stop.is-warm span { background: var(--md-warm); }
.md-stop.is-cold span { background: var(--md-cold); }
.md-stop.is-ice span { background: #53b1fd; }

.leaflet-tooltip.md-label {
    padding: 0.2rem 0.5rem;
    color: var(--md-ink);
    background: var(--md-paper);
    border: 1.5px solid var(--md-ink);
    border-radius: 0;
    box-shadow: none;
    font-weight: 800;
}

.leaflet-tooltip.md-label::before {
    display: none;
}

/* After a pin: the sheet from the bottom. */
.md-sheet,
.md-end {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 600;
    background: var(--md-paper);
    border-top: 4px solid var(--md-gold);
    box-shadow: 0 -12px 30px rgba(22, 23, 28, 0.2);
}

.md-sheet {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.45rem;
    max-height: 64%;
    overflow-y: auto;
    padding: 0.8rem 0.9rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
    overscroll-behavior: contain;
}

.md-sheet.is-in,
.md-end.is-in {
    animation: md-rise 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.md-sheet-top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem;
}

.md-sheet-host {
    width: 72px;
    height: 72px;
    object-fit: contain;
    animation: md-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.md-sheet-km {
    margin: 0;
    font-family: var(--news-font-head);
    font-size: clamp(1.7rem, 8vw, 2.2rem);
    font-weight: 900;
    line-height: 1;
}

.md-sheet[data-tier="perfect"] .md-sheet-km { color: var(--md-perfect); }
.md-sheet[data-tier="hot"] .md-sheet-km { color: var(--md-hot); }
.md-sheet[data-tier="warm"] .md-sheet-km { color: #c4320a; }
.md-sheet[data-tier="cold"] .md-sheet-km { color: #1570ef; }
.md-sheet[data-tier="ice"] .md-sheet-km { color: #175cd3; }

.md-sheet-line {
    margin: 0.3rem 0 0;
    font-weight: 700;
    line-height: 1.35;
}

.md-sheet-place {
    margin: 0;
    font-family: var(--news-font-head);
    font-size: clamp(1.05rem, 4.6vw, 1.2rem);
    font-weight: 900;
}

.md-sheet-place small {
    display: block;
    color: var(--md-muted);
    font-family: var(--news-font, inherit);
    font-size: 0.82rem;
    font-weight: 700;
}

.md-sheet-fact {
    margin: 0;
    color: var(--md-soft);
    font-size: 0.95rem;
    line-height: 1.45;
}

.md-sheet-crowd {
    margin: 0;
    padding: 0.4rem 0.6rem;
    color: var(--md-ink);
    background: var(--md-wash);
    border-left: 4px solid var(--md-ink);
    font-size: 0.9rem;
    font-weight: 700;
}

/* Always in reach: a long fact scrolls under it, the button stays at the sheet's bottom. */
.md-sheet-next {
    position: sticky;
    bottom: 0;
    width: 100%;
    margin-top: 0.2rem;
    box-shadow: 0 -10px 12px rgba(255, 255, 255, 0.95);
}

/* The round's end: the postcard steps aside so the route map gets the room above the results. */
.md-game.is-end .md-card {
    display: none;
}

/* The round's end. */
.md-end {
    max-height: 66%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
}

.md-end-scroll {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.7rem;
    min-height: 0;
    overflow-y: auto;
    padding: 0.9rem 0.9rem calc(1rem + env(safe-area-inset-bottom, 0px));
    overscroll-behavior: contain;
}

.md-end-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 0.8rem;
}

.md-end-host {
    width: 104px;
    height: 104px;
    object-fit: contain;
    animation: md-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.md-end-label {
    margin: 0;
    color: var(--md-accent);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.md-end-total {
    margin: 0.1rem 0;
    font-family: var(--news-font-head);
    font-size: clamp(2.4rem, 12vw, 3.4rem);
    font-weight: 900;
    line-height: 1;
}

.md-end-row {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 1.35rem;
    letter-spacing: 0.08em;
}

.md-end-verdict {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
}

.md-end-notice {
    margin: 0;
    padding: 0.5rem 0.65rem;
    background: var(--md-gold-soft);
    border-left: 4px solid var(--md-gold);
    font-size: 0.92rem;
}

.md-end-facts {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.35rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.md-end-facts li {
    overflow-wrap: anywhere;
    padding: 0.45rem 0.6rem;
    background: var(--md-wash);
    border-left: 4px solid var(--md-accent);
    font-weight: 600;
    line-height: 1.4;
}

.md-versus {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.45rem;
    padding: 0.7rem;
    border: 2px solid var(--md-ink);
}

.md-versus-line {
    margin: 0;
    font-family: var(--news-font-head);
    font-size: 1.1rem;
    font-weight: 900;
}

.md-versus-line.is-won { color: var(--md-perfect); }
.md-versus-line.is-lost { color: var(--md-accent); }

.md-versus-rows {
    display: grid;
    gap: 0.2rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.9rem;
}

.md-versus-rows li.is-won { font-weight: 800; }
.md-versus-rows li.is-lost { color: var(--md-muted); }

.md-versus-title {
    margin: 0.3rem 0 0;
    font-weight: 900;
}

.md-end-share {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.45rem;
}

.md-end-name {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.25rem;
    font-weight: 700;
}

.md-end-name input,
.md-county select {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 0 0.7rem;
    color: var(--md-ink);
    background: var(--md-paper);
    border: 2px solid var(--md-ink);
    border-radius: 0;
    font-size: max(16px, 1rem);
}

.md-end-copied {
    margin: 0;
    color: var(--md-perfect);
    font-weight: 800;
}

.md-end-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.5rem;
}

.md-end-board {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    justify-self: start;
    color: var(--md-accent);
    font-weight: 800;
}

.md-county {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.25rem;
    font-weight: 700;
}

.md-end-login,
.md-end-next {
    margin: 0;
    color: var(--md-muted);
    font-size: 0.9rem;
}

.md-end-login a {
    color: var(--md-accent);
    font-weight: 800;
}

/* Confetti and the toast. */
.md-confetti {
    position: fixed;
    inset: 0;
    z-index: 1100;
    overflow: hidden;
    pointer-events: none;
}

.md-confetti i {
    position: absolute;
    top: -16px;
    width: 8px;
    height: 14px;
    animation: md-fall 2s ease-in forwards;
}

.md-toast {
    position: absolute;
    top: calc(3.6rem + env(safe-area-inset-top, 0px));
    left: 50%;
    z-index: 900;
    max-width: calc(100% - 1.6rem);
    padding: 0.55rem 0.8rem;
    color: #fff;
    background: var(--md-ink);
    font-weight: 700;
    transform: translateX(-50%);
}

/* ---------- motion ---------- */

@keyframes md-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes md-card-in {
    from { opacity: 0; transform: translateY(-8px) rotate(-1deg); }
    to { opacity: 1; transform: none; }
}

@keyframes md-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.45); }
    50% { box-shadow: 0 0 0 8px rgba(180, 35, 24, 0); }
}

@keyframes md-drop {
    from { transform: translateY(-26px); opacity: 0.4; }
    to { transform: none; opacity: 1; }
}

@keyframes md-pop {
    0% { transform: scale(0.3); opacity: 0; }
    100% { transform: none; opacity: 1; }
}

@keyframes md-rise {
    from { transform: translateY(40%); opacity: 0.5; }
    to { transform: none; opacity: 1; }
}

@keyframes md-fall {
    to { transform: translate3d(var(--drift, 0), 110vh, 0) rotate(var(--spin, 540deg)); }
}

@media (prefers-reduced-motion: reduce) {
    .md-hero-host,
    .md-card.is-in,
    .md-go.is-ready:not(:disabled),
    .md-pin svg,
    .md-answer img,
    .md-sheet.is-in,
    .md-end.is-in,
    .md-sheet-host,
    .md-end-host {
        animation: none;
    }
}

/* ---------- wider screens ---------- */

@media (max-width: 767.98px) and (max-height: 740px) {
    .md-hero-host {
        width: 110px;
        height: 110px;
    }
}

@media (min-width: 600px) {
    .md-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .md-topics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 768px) {
    .md-hero {
        grid-template-columns: auto minmax(0, 1fr);
        justify-items: start;
        align-items: center;
        padding: 1.5rem 1.8rem;
        text-align: left;
    }

    .md-hero-host {
        width: 210px;
        height: 210px;
    }

    .md-today {
        justify-content: flex-start;
    }

    .md-steps {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    /* The game on a computer: the postcard and the sheets keep a readable width over the map. */
    .md-card {
        width: min(760px, calc(100% - 1.1rem));
        justify-self: center;
    }

    .md-sheet,
    .md-end {
        left: 50%;
        right: auto;
        width: min(560px, calc(100% - 2rem));
        bottom: 1rem;
        transform: translateX(-50%);
        border: 2px solid var(--md-ink);
        border-top: 4px solid var(--md-gold);
    }

    .md-sheet.is-in,
    .md-end.is-in {
        animation: md-rise-center 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
    }

    .md-end {
        top: 4.6rem;
        bottom: 1rem;
        left: auto;
        right: 1rem;
        width: min(480px, 46vw);
        max-height: none;
        transform: none;
    }

    .md-end.is-in {
        animation: md-rise 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
    }

    .md-game {
        grid-template-rows: auto auto minmax(0, 1fr);
    }

    .md-actionbar {
        position: absolute;
        left: 50%;
        bottom: 1.1rem;
        z-index: 550;
        width: min(420px, calc(100% - 2rem));
        padding: 0;
        background: transparent;
        border: 0;
        transform: translateX(-50%);
    }

    .md-go {
        width: 100%;
        box-shadow: 4px 4px 0 var(--md-ink);
    }
}

@media (min-width: 1100px) {
    .md-topics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* A wide screen, or a phone held sideways: every card on the right, the map (the pin, the line, the place, the route)
   on the left. ma-di.js uses the same query when it frames the map. */
@media (min-width: 1100px), (orientation: landscape) and (max-height: 520px) {
    .md-sheet,
    .md-end {
        left: auto;
        right: 1rem;
        transform: none;
    }

    .md-sheet {
        width: min(440px, 40vw);
        max-height: calc(100% - 5.6rem);
    }

    .md-end {
        width: min(480px, 42vw);
    }

    .md-sheet.is-in,
    .md-end.is-in {
        animation: md-rise 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
    }
}

/* A phone held sideways: little height, so the bar, the postcard and the cards are compact. */
@media (orientation: landscape) and (max-height: 520px) {
    .md-bar {
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .md-icon {
        width: 40px;
        height: 40px;
    }

    .md-card {
        margin: 0.3rem 0.55rem;
        padding: 0.35rem 0.6rem;
        box-shadow: 3px 3px 0 var(--md-ink);
    }

    .md-card-host,
    .md-sheet-host {
        display: none;
    }

    .md-card-clue {
        font-size: 0.95rem;
    }

    /* While the answer shows, the map takes the postcard's place (the card on the right would cover its text). */
    .md-game.is-reveal .md-card {
        display: none;
    }

    .md-sheet,
    .md-end {
        top: 3.3rem;
        bottom: 0.5rem;
        right: 0.5rem;
        max-height: none;
        width: min(380px, 46vw);
    }

    .md-sheet {
        top: auto;
        max-height: calc(100% - 1rem);
    }

    .md-end-host {
        width: 64px;
        height: 64px;
    }

    .md-actionbar {
        left: 0.6rem;
        width: min(260px, 40vw);
        bottom: 0.6rem;
        transform: none;
    }

    .md-go {
        min-height: 48px;
        font-size: 1.1rem;
    }
}

/* A phone: while the answer is shown, the postcard steps aside so the map shows the pin and the place above the sheet. */
@media (max-width: 767.98px) and (orientation: portrait), (max-width: 767.98px) and (min-height: 521px) {
    .md-game.is-reveal .md-card {
        display: none;
    }
}

/* A very narrow phone (a folded one): smaller pictures and numbers, nothing wider than the screen. */
@media (max-width: 359.98px) {
    .md-card-host {
        width: 44px;
        height: 44px;
    }

    .md-card-clue {
        font-size: 0.98rem;
    }

    .md-progress-marks {
        display: none;
    }

    .md-total {
        padding: 0.2rem 0.4rem;
        font-size: 0.9rem;
    }

    .md-sheet-host {
        width: 56px;
        height: 56px;
    }

    .md-sheet-km {
        font-size: 1.6rem;
    }

    /* The sheet keeps to what matters, so some map shows above it. */
    .md-sheet-line {
        font-size: 0.92rem;
    }

    .md-sheet-fact {
        font-size: 0.88rem;
    }

    .md-sheet-crowd {
        display: none;
    }

    .md-end-head {
        grid-template-columns: minmax(0, 1fr);
        justify-items: center;
        text-align: center;
    }

    .md-end-host {
        width: 72px;
        height: 72px;
    }

    .md-end-total {
        font-size: clamp(1.9rem, 11vw, 2.6rem);
    }

    .md-end-actions {
        grid-template-columns: minmax(0, 1fr);
    }
}

@keyframes md-rise-center {
    from { transform: translate(-50%, 30%); opacity: 0.5; }
    to { transform: translateX(-50%); opacity: 1; }
}

/* The leaderboard page. */
.md-hero-small {
    grid-template-columns: minmax(0, 1fr);
}

.md-table-note {
    color: var(--md-muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.md-boards {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0 1rem;
}

@media (min-width: 900px) {
    .md-boards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ---------- the rules' and the topics' pages (/ma-di/pravila, /ma-di/tema/{key}) ---------- */

.md-title-sub {
    font-size: clamp(1.9rem, 7.5vw, 3rem);
    line-height: 1.02;
}

.md-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 1rem;
}

.md-toc a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0.3rem 0.75rem;
    color: var(--md-ink);
    background: var(--md-paper);
    border: 1.5px solid var(--md-rule-strong);
    font-size: 0.88rem;
    font-weight: 800;
    text-decoration: none;
}

.md-toc a:hover,
.md-toc a:focus-visible {
    background: var(--md-gold-soft);
    border-color: var(--md-ink);
}

.md-sub .md-panel {
    scroll-margin-top: 5rem;
}

.md-prose p,
.md-prose li {
    color: var(--md-soft);
    line-height: 1.6;
}

.md-prose p {
    margin: 0 0 0.7rem;
}

.md-prose p:last-child {
    margin-bottom: 0;
}

.md-prose ul {
    margin: 0 0 0.8rem;
    padding-left: 1.2rem;
}

.md-prose li + li {
    margin-top: 0.3rem;
}

.md-prose h3 {
    margin: 1rem 0 0.4rem;
    font-family: var(--news-font-head);
    font-size: 1.02rem;
    font-weight: 900;
}

.md-prose strong,
.md-prose em {
    color: var(--md-ink);
}

.md-prose a {
    color: var(--md-accent);
    font-weight: 800;
}

.md-steps.md-steps-wide {
    grid-template-columns: minmax(0, 1fr);
    margin-bottom: 0.8rem;
}

.md-tiers {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
    margin: 0.8rem 0 0;
    padding: 0;
    list-style: none;
}

.md-tiers li {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.7rem;
    background: var(--md-wash);
    border-left: 4px solid var(--md-gold);
}

.md-tiers li:nth-child(1) { border-left-color: var(--md-perfect); }
.md-tiers li:nth-child(2) { border-left-color: var(--md-hot); }
.md-tiers li:nth-child(3) { border-left-color: var(--md-warm); }
.md-tiers li:nth-child(4) { border-left-color: var(--md-cold); }
.md-tiers li:nth-child(5) { border-left-color: var(--md-ice); }

.md-tiers img {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.md-tier-text {
    display: grid;
    gap: 0.1rem;
    min-width: 0;
}

.md-tier-text strong {
    font-family: var(--news-font-head);
    font-size: 1.08rem;
    font-weight: 900;
}

.md-tier-text small {
    color: var(--md-ink);
    font-size: 0.88rem;
    font-weight: 700;
}

.md-tier-text em {
    color: var(--md-muted);
    font-size: 0.86rem;
}

.md-modes {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.6rem;
}

.md-modes > div {
    padding: 0.75rem 0.85rem;
    background: var(--md-wash);
    border-top: 3px solid var(--md-gold);
}

.md-modes h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.35rem;
}

.md-modes h3 i {
    color: var(--md-accent);
}

.md-topic-links {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.45rem;
    margin: 0.7rem 0 0;
    padding: 0;
    list-style: none;
}

.md-topic-links a {
    display: grid;
    grid-template-columns: 2.2rem minmax(0, 1fr);
    align-items: center;
    gap: 0.6rem;
    min-height: 52px;
    padding: 0.45rem 0.7rem;
    color: var(--md-ink);
    background: var(--md-paper);
    border: 1.5px solid var(--md-rule-strong);
    border-left: 4px solid var(--md-gold);
    text-decoration: none;
}

.md-topic-links a:hover,
.md-topic-links a:focus-visible {
    background: var(--md-gold-soft);
    border-color: var(--md-ink);
}

.md-topic-links i {
    display: grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    color: var(--md-accent);
    background: var(--md-wash);
}

.md-topic-links span {
    display: grid;
    min-width: 0;
}

.md-topic-links small {
    color: var(--md-muted);
    font-size: 0.8rem;
}

.md-topic-pages a {
    white-space: nowrap;
}

.md-cta {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 0.6rem;
    text-align: center;
    background: var(--md-gold-soft);
    border-top-color: var(--md-gold);
}

.md-cta img {
    width: 110px;
    height: 110px;
    object-fit: contain;
}

.md-cta h2 {
    margin-bottom: 0.2rem;
}

.md-cta .md-actions {
    margin-top: 0.7rem;
}

.md-examples {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.7rem;
    margin: 0.8rem 0 0;
    padding: 0;
    list-style: none;
}

.md-example {
    background: var(--md-paper);
    border: 1.5px solid var(--md-rule-strong);
}

.md-example-card {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 0.7rem;
    align-items: start;
    margin: 0;
    padding: 0.75rem 0.8rem;
    color: var(--md-ink);
    background: var(--md-gold-soft);
    border-bottom: 1.5px solid var(--md-rule-strong);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.45;
}

.md-example-card img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.md-example details {
    padding: 0 0.8rem;
}

.md-example summary {
    display: flex;
    align-items: center;
    min-height: 46px;
    color: var(--md-accent);
    font-weight: 900;
    cursor: pointer;
}

.md-example-place {
    margin: 0 0 0.3rem;
    font-size: 1.05rem;
}

.md-example-place i {
    color: var(--md-pin);
}

.md-example-place small {
    color: var(--md-muted);
    font-size: 0.85rem;
}

.md-example-fact {
    margin: 0 0 0.8rem;
    color: var(--md-soft);
    line-height: 1.55;
}

@media (min-width: 600px) {
    .md-tiers,
    .md-topic-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .md-modes {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 768px) {
    .md-cta {
        grid-template-columns: auto minmax(0, 1fr);
        justify-items: start;
        text-align: left;
        padding: 1.2rem 1.5rem;
    }

    .md-cta .md-actions {
        justify-content: start;
    }
}

@media (min-width: 1000px) {
    .md-topic-links {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .md-tiers {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .md-tiers li {
        grid-template-columns: minmax(0, 1fr);
        justify-items: center;
        text-align: center;
        padding: 0.8rem 0.6rem;
        border-left: 0;
        border-top: 4px solid var(--md-gold);
    }

    .md-tiers li:nth-child(1) { border-top-color: var(--md-perfect); }
    .md-tiers li:nth-child(2) { border-top-color: var(--md-hot); }
    .md-tiers li:nth-child(3) { border-top-color: var(--md-warm); }
    .md-tiers li:nth-child(4) { border-top-color: var(--md-cold); }
    .md-tiers li:nth-child(5) { border-top-color: var(--md-ice); }

    .md-tiers img {
        width: 96px;
        height: 96px;
    }
}
