.contests-page {
    --contest-radius: 12px;
    --contest-gutter: 28px;
    font-size: 14px;
}

.contest-container { padding-block: 30px 48px; }
.contest-page-title, .contest-section-head, .contest-titlebar, .contest-heading-meta, .contest-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.contest-page-title, .contest-section-head, .contest-titlebar { justify-content: space-between; }
.contest-page-title { margin-bottom: 20px; }
.contest-page-title h1 { font-size: clamp(27px, 3.2vw, 36px); letter-spacing: -.04em; line-height: 1.15; }
.contests-page .btn, .contests-page .form-input, .contests-page .form-select {
    min-height: 40px;
    border-radius: 7px;
    font-size: 14px;
}
.contests-page .btn { font-weight: 650; }
.contests-page .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.contest-layout {
    display: grid;
    grid-template-columns: clamp(300px, 27vw, 370px) minmax(0, 1fr);
    align-items: start;
    gap: 24px;
}
.contest-sidebar { display: grid; gap: 10px; position: sticky; top: 16px; }
.contest-main, .contest-sidebar { min-width: 0; }
.contest-surface, .contest-dialog {
    border: 1px solid var(--line);
    border-radius: var(--contest-radius);
    background: var(--surface);
    box-shadow: 0 2px 5px #0000000b;
}
.contest-directory > summary { display: none; }
.contest-directory > summary, .readiness-panel > summary, .contest-older > summary {
    cursor: pointer;
    list-style: none;
}
.contest-directory > summary::-webkit-details-marker,
.readiness-panel > summary::-webkit-details-marker, .contest-older > summary::-webkit-details-marker,
.problem-menu > summary::-webkit-details-marker { display: none; }
.contest-directory > summary::after, .readiness-panel > summary::after,
.problem-version-button::after {
    content: '';
    width: 7px;
    height: 7px;
    margin-left: auto;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    flex: 0 0 auto;
}
.contest-surface[open] > summary::after, .contest-directory[open] > summary::after {
    transform: rotate(225deg) translate(-1px, -2px);
}
.directory-head {
    display: grid;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}
.directory-head .contest-sort { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; }
.directory-head .contest-sort label { grid-column: auto; white-space: nowrap; }
.contest-list {
    display: grid;
    gap: 4px;
    max-height: min(59vh, 620px);
    overflow-y: auto;
    scrollbar-width: thin;
    margin-block: 6px;
    padding: 4px 8px;
}
.contest-list:empty { display: none; }
.contest-choice {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    text-align: left;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.4;
}
.contest-choice:hover { background: var(--soft); text-decoration: none; }
.contest-choice:focus-visible { outline-offset: -2px; }
.contest-choice[aria-current] { background: var(--selected); border-color: var(--selected-line); font-weight: 650; }
.contest-choice strong { font-weight: 630; overflow-wrap: anywhere; }
.contest-choice small, .directory-message { color: var(--muted); font-size: 12px; }
.directory-message { padding: 8px 14px 14px; }
.contest-directory .contest-pages {
    gap: 6px;
    padding: 10px;
    border-top: 1px solid var(--line);
    border-radius: 0 0 var(--contest-radius) var(--contest-radius);
    background: var(--canvas);
}
.contest-directory .contest-pages .btn { min-height: 44px; white-space: nowrap; }
.contest-directory .contest-pages [data-range] { font-variant-numeric: tabular-nums; }
.contest-directory > summary {
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    font-weight: 650;
}

.contest-placeholder { padding: 52px 24px; text-align: center; }
.contest-placeholder h2 { font-size: 20px; letter-spacing: -.02em; }
.contest-placeholder p { margin-top: 5px; color: var(--muted); }
.contest-titlebar { padding: 24px var(--contest-gutter) 18px; align-items: flex-start; }
.contest-titlebar > div { min-width: 0; }
.contest-titlebar h2 {
    font-size: clamp(22px, 3vw, 34px);
    font-weight: 680;
    line-height: 1.16;
    letter-spacing: -.038em;
    overflow-wrap: anywhere;
    text-wrap: balance;
}
.contest-titlebar .btn { flex: 0 0 auto; }
.contest-heading-meta { margin-top: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.contest-ready-pill, .member-role {
    border: 0;
    border-radius: 5px;
    padding: 3px 8px;
    background: var(--warning-soft);
    color: #775320;
    font-size: 12px;
    font-weight: 650;
}
.contest-ready-pill.ready { background: var(--positive-soft); color: var(--positive); }
.contest-ready-pill:hover { text-decoration: underline; }
.contest-tabs { display: flex; gap: 20px; padding-inline: var(--contest-gutter); }
.contest-tabs a {
    display: inline-flex;
    align-items: center;
    min-height: 46px;
    padding: 0 2px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}
.contest-tabs a:hover { color: var(--link); text-decoration: none; }
.contest-tabs a[aria-current] { color: var(--ink); border-bottom-color: #c7a310; }
.contest-tabs a[aria-disabled] { opacity: .42; cursor: default; }
.mobile-label { display: none; }

.contest-view { display: grid; gap: 16px; margin-top: 16px; }
.contest-section-head, .contest-section-body { padding: 18px var(--contest-gutter); }
.contest-section-head h3, .contest-section-body h3 { font-size: 17px; font-weight: 680; letter-spacing: -.02em; }
.contest-section-head .contest-note { margin-top: 2px; }
.contest-note, .render-status, .dialog-status { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.render-status { margin-block: 10px; }
.render-status:empty, .dialog-status:empty, .contest-note:empty { display: none; }
.contest-alert {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid #eed4d1;
    border-radius: 8px;
    background: var(--negative-soft);
    color: var(--negative);
}
.contest-alert:empty { display: none; }

.problem-rows, .member-rows, .render-rows { list-style: none; }
.problem-list .contest-section-head { flex-wrap: wrap; }
.problem-row, .problem-columns {
    display: grid;
    grid-template-columns: var(--problem-index-width, 32px) minmax(0, 1fr) clamp(160px, 25%, 230px) 40px;
    align-items: center;
    gap: 12px;
    padding-inline: var(--contest-gutter);
}
.problem-columns { min-height: 36px; background: #f4f5f6; color: var(--muted); font-size: 12px; font-weight: 650; }
.problem-row { min-height: 57px; padding-block: 7px; border-top: 1px solid var(--line); }
.problem-row:hover { background: #fafafb; }
.problem-row:last-child { border-radius: 0 0 var(--contest-radius) var(--contest-radius); }
.problem-letter {
    display: grid;
    place-items: center;
    align-self: center;
    justify-self: start;
    min-width: 32px;
    max-width: 100%;
    min-height: 30px;
    padding-inline: 5px;
    border-radius: 6px;
    background: var(--soft);
    color: var(--muted);
    font: 650 12px/1.25 var(--font-ui);
    text-align: center;
    overflow-wrap: anywhere;
}
.problem-name { min-width: 0; color: var(--ink); font-weight: 620; overflow-wrap: anywhere; }
.problem-name:hover { color: var(--link); }
.problem-version-cell { display: grid; justify-items: start; gap: 3px; min-width: 0; }
.problem-version { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.problem-validation { border: 0; background: transparent; color: var(--muted); text-align: left; font-size: 12px; }
.problem-validation:hover { text-decoration: underline; }
.problem-validation.validation-missing { color: var(--negative); }
.problem-validation code, .readiness-row code { font-family: var(--font-code); }
.problem-version-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 0;
    text-align: left;
}
.contests-page .problem-version-button { width: 100%; font-size: 13px; font-weight: 550; }
.problem-version-button span { min-width: 0; overflow-wrap: anywhere; }
.problem-version-button::after { margin-inline: 5px 2px; color: var(--muted); }
.problem-version-button[data-pinned] { color: var(--accent-ink); background: var(--selected); border-color: var(--selected-line); }
.problem-menu { position: relative; }
.problem-menu > summary {
    display: grid;
    place-items: center;
    width: 40px;
    min-height: 40px;
    list-style: none;
    color: var(--muted);
    border-radius: 7px;
    font-size: 21px;
    line-height: 1;
    cursor: pointer;
}
.problem-menu[open] > summary, .problem-menu > summary:hover { background: var(--soft); color: var(--ink); }
.problem-menu-actions {
    position: absolute;
    z-index: 4;
    right: 0;
    top: calc(100% + 4px);
    min-width: 172px;
    padding: 5px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 4px 14px #0002;
}
.problem-menu-actions button {
    display: block;
    width: 100%;
    min-height: 40px;
    padding: 7px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    text-align: left;
    white-space: nowrap;
}
.problem-menu-actions button:hover { background: var(--soft); }
.problem-menu-actions .btn-danger { color: var(--negative); }
.problem-menu-actions .btn-danger:hover { background: var(--negative-soft); }

.readiness-panel > summary {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 14px var(--contest-gutter);
    font-weight: 650;
}
.readiness-panel > summary .contest-note { font-weight: 450; }
.readiness-panel .contest-section-body { padding-top: 0; }
.readiness-explanation { max-width: 70ch; margin-bottom: 12px; }
.readiness-list, .readiness-row { min-width: 0; }
.readiness-row { display: grid; gap: 4px; padding: 11px 0; border-top: 1px solid var(--line); }
.readiness-row small { color: var(--muted); overflow-wrap: anywhere; }
.readiness-ready { color: var(--positive); font-weight: 600; }
.readiness-needs-work { color: var(--negative); font-weight: 600; }

.contest-build-view { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; }
.contest-build-view .contest-note { margin-top: 5px; }
.contest-build-view .contest-form { margin-top: 14px; }
.contest-preview { grid-column: 1 / -1; }
.contest-preview:empty { display: none; }
.contest-document-preview { display: block; width: 100%; min-height: 70vh; border: 1px solid var(--line); border-radius: var(--contest-radius); background: var(--surface); }
.contest-older { margin-top: 10px; }
.contest-older summary { color: var(--link); font-weight: 600; }
.contest-older[open] summary { margin-bottom: 8px; }
.render-rows:not(:empty) { margin-top: 14px; }
.render-row, .member-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    overflow-wrap: anywhere;
}
.render-row { justify-content: space-between; font-size: 13px; }
.render-row > a { font-weight: 620; }
.member-row { min-height: 54px; padding-inline: var(--contest-gutter); }
.member-row > button { margin-left: auto; }
.member-role { background: var(--soft); color: var(--muted); }
.member-role[data-role="owner"], .member-role[data-role="editor"] { background: var(--selected); color: var(--link); }
.contest-empty { padding: 18px var(--contest-gutter); color: var(--muted); }
.contest-actions { flex-wrap: wrap; }
.contest-form { display: grid; gap: 12px; }
.contest-form label { display: grid; min-width: 0; gap: 5px; font-size: 13px; font-weight: 620; }
.contest-form > .btn { justify-self: start; }
#problemLabelFields { max-height: min(52vh, 420px); overflow-y: auto; padding-inline: 3px; }
#problemLabelFields label {
    grid-template-columns: minmax(0, 1fr) 7rem;
    align-items: center;
    gap: 12px;
    padding-block: 8px;
    border-top: 1px solid var(--line);
    overflow-wrap: anywhere;
}
#problemLabelFields .form-input { padding-inline: 6px; font-family: var(--font-code); text-align: center; }
.inline-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.contest-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(460px, calc(100% - 28px));
    max-height: calc(100% - 28px);
    padding: 22px;
    color: var(--ink);
    box-shadow: 0 20px 50px #0002;
}
.contest-dialog::backdrop { background: #25252595; }
.contest-dialog h2 { font-size: 21px; letter-spacing: -.025em; overflow-wrap: anywhere; }
.dialog-actions { justify-content: flex-end; margin-top: 4px; }
.dialog-status[data-error] { color: var(--negative); }
.contest-dialog mark { background: #faedc4; color: var(--ink); }
.contest-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (max-width: 1000px) {
    .contests-page { --contest-gutter: 20px; }
    .contest-layout { grid-template-columns: minmax(258px, 29%) minmax(0, 1fr); gap: 16px; }
    .contest-build-view { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
    .contest-container { padding: 20px 16px 32px; }
    .contest-layout { grid-template-columns: 1fr; }
    .contest-sidebar { position: static; }
    .contest-directory > summary { display: flex; min-height: 44px; }
    .contest-directory[open] > summary { border-bottom: 1px solid var(--line); }
    .contest-list { max-height: min(45vh, 360px); }
}
@media (max-width: 510px) {
    .contests-page { --contest-gutter: 14px; }
    .contest-titlebar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        padding-block: 16px 10px;
    }
    .contest-titlebar > div { display: contents; }
    .contest-titlebar h2, .contest-titlebar .context-links { grid-column: 1 / -1; }
    .contest-heading-meta { margin-top: 0; gap: 5px; }
    #copyLink { min-height: 36px; font-size: 12px; }
    .contest-tabs { gap: 18px; }
    .contest-tabs a { min-height: 44px; }
    .desktop-label, .problem-columns { display: none; }
    .mobile-label { display: inline; }
    .problem-row { grid-template-columns: var(--problem-index-width, 32px) minmax(0, 1fr) 40px; gap: 5px 10px; min-height: 0; padding-block: 10px; }
    .problem-row .problem-letter { grid-column: 1; grid-row: 1; }
    .problem-row .problem-name { grid-column: 2; grid-row: 1; }
    .problem-row .problem-menu { grid-column: 3; grid-row: 1 / 3; }
    .problem-row .problem-version-cell { grid-column: 2; grid-row: 2; }
    .problem-row .problem-version-button { width: auto; max-width: 100%; }
    .readiness-panel > summary { flex-wrap: wrap; gap: 4px 8px; }
}
