:root {
    --bg: #0d1117;
    --panel: #161b22;
    --line: #2b333d;
    --fg: #e6edf3;
    --muted: #8b949e;
    --accent: #2f81f7;
    --ac: #2ea043;
    --wrong: #d1242f;
    --pending: #d29922;
    --focus: #a371f7;
    --row-h: 108px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 15px/1.5 system-ui, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
}

#app { max-width: none; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; margin: 0 0 16px; }

.hint { color: var(--muted); font-size: 13px; max-width: 52ch; }
code { background: var(--panel); padding: 1px 5px; border-radius: 4px; }

/* --- 폼 --- */
.view label { display: block; margin: 10px 0; }
.view input[type=text], .view input[type=password] {
    display: block; width: 360px; max-width: 100%; margin-top: 4px;
    padding: 8px 10px; background: var(--panel); border: 1px solid var(--line);
    border-radius: 6px; color: var(--fg); font-size: 15px;
}
button {
    margin-top: 12px; padding: 8px 16px; font-size: 14px; cursor: pointer;
    background: var(--accent); color: #fff; border: 0; border-radius: 6px;
}
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--fg); }
button:disabled { opacity: .5; cursor: default; }
.err { color: var(--wrong); font-size: 13px; white-space: pre-line; }

/* --- 대회 목록 --- */
#contest-list { list-style: none; padding: 0; margin: 0; }
#contest-list li {
    padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
    margin-bottom: 8px; cursor: pointer; background: var(--panel);
}
#contest-list li:hover { border-color: var(--accent); }
#contest-list .c-name { font-weight: 600; }
#contest-list .c-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
#contest-list .c-nofreeze { color: var(--pending); }

/* --- resolver --- */
#view-resolver { max-width: none; }
#resolver-bar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
#resolver-bar .spacer { flex: 1; }
#resolver-title { font-weight: 700; }
#resolver-status { color: var(--muted); font-size: 13px; }
#speed { vertical-align: middle; }

#resolver-sticky {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    box-shadow: 0 8px 14px -8px rgba(0, 0, 0, .55);
}

/* 소속 필터 드롭다운 */
#org-filter { position: relative; }
#org-filter > summary {
    cursor: pointer;
    list-style: none;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 14px;
    user-select: none;
}
#org-filter > summary::-webkit-details-marker { display: none; }
#org-filter[open] > summary { border-color: var(--accent); }
#org-filter-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    min-width: 230px;
    max-height: 340px;
    overflow-y: auto;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .6);
}
#org-filter-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 5px;
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
}
#org-filter-list label:hover { background: rgba(255, 255, 255, .05); }
#org-filter-list .org-count { margin-left: auto; color: var(--muted); font-size: 11px; }
#org-filter-list hr { border: 0; border-top: 1px solid var(--line); margin: 6px 2px; }
#board-wrap {
    position: relative;
    /* 최하위 팀도 sticky 헤더 아래 가시 영역 중앙까지 스크롤할 수 있게 한다. */
    padding-bottom: calc(50vh - var(--row-h) / 2);
}
#board-head, .row { display: grid; align-items: center; }
#board-head {
    color: var(--muted); font-size: 12px; text-transform: uppercase;
    letter-spacing: .04em; padding: 0 8px 6px; border-bottom: 1px solid var(--line);
}
#board { position: relative; }

.row {
    position: absolute; left: 0; right: 0; height: var(--row-h);
    padding: 0 8px; border-bottom: 1px solid var(--line);
    transition: transform .55s cubic-bezier(.22,.7,.16,1), opacity .8s ease;
    will-change: transform, opacity;
}
.row.entering { opacity: 0; }
.row.selected { background: rgba(163,113,247,.12); }
.row.rank-confirm-step {
    z-index: 4;
    background: rgba(255,255,255,.12);
    outline: 2px solid rgba(255,255,255,.42);
    outline-offset: -2px;
    box-shadow: 0 10px 30px rgba(0,0,0,.32);
}
.row.rank-confirm-step::after {
    content: attr(data-confirm-label);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 10px 20px;
    border-radius: 999px;
    background: rgba(255,255,255,.94);
    color: #111827;
    font-size: clamp(17px, 1.8vw, 26px);
    font-weight: 900;
    letter-spacing: -.02em;
    white-space: nowrap;
    box-shadow: 0 10px 28px rgba(0,0,0,.3);
    pointer-events: none;
}
.row .rank { font-variant-numeric: tabular-nums; color: var(--muted); }
.row .team { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .org { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .solved { text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }
.row .pen { text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }

.cell {
    position: relative; text-align: center; font-size: 15px;
    font-variant-numeric: tabular-nums;
    border-radius: 6px; margin: 0 3px; padding: 20px 0; min-width: 42px;
}
.cell-result { display: inline-block; }
.frozen-trace {
    position: absolute;
    right: 3px;
    bottom: 2px;
    padding: 1px 3px;
    border-radius: 3px;
    background: rgba(0, 0, 0, .3);
    color: currentColor;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: 0;
    opacity: .9;
    white-space: nowrap;
}
.cell.ac { background: var(--ac); color: #fff; }
.cell.wrong { background: rgba(209,36,47,.18); color: #ff7b72; }
.cell.pending { background: rgba(210,153,34,.22); color: var(--pending); }
.cell.focus { outline: 2px solid var(--focus); outline-offset: 1px; }

@keyframes flash-ac { from { background: #fff; } to { } }
@keyframes flash-wrong { from { background: #ff7b72; } to { } }
.cell.flash-ac { animation: flash-ac .6s ease-out; }
.cell.flash-wrong { animation: flash-wrong .6s ease-out; }

/* 공개 시 셀 위로 떠오르는 판정 라벨 (WA / CE / TLE / AC ...) */
.verdict-pop {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .05em;
    padding: 2px 7px;
    border-radius: 5px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 8;
    animation: verdict-pop 1.15s cubic-bezier(.2, .7, .2, 1) forwards;
}
.verdict-pop.vp-ac { background: var(--ac); color: #fff; }
.verdict-pop.vp-wrong { background: var(--wrong); color: #fff; }
.verdict-pop.vp-ce { background: var(--muted); color: #0d1117; }
@keyframes verdict-pop {
    0%   { opacity: 0; transform: translate(-50%, -10%) scale(.7); }
    18%  { opacity: 1; transform: translate(-50%, -60%) scale(1.06); }
    70%  { opacity: 1; transform: translate(-50%, -120%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -165%) scale(1); }
}

/* AC 후 다음 스텝: 행이 움직이기 전에 # 숫자가 먼저 튀며 바뀜 */
@keyframes rank-bump {
    0%   { transform: scale(1);   color: var(--focus); }
    35%  { transform: scale(1.6); color: var(--focus); }
    100% { transform: scale(1);   color: var(--fg); }
}
.row .rank.rank-bump {
    display: inline-block;
    transform-origin: left center;
    animation: rank-bump .45s ease-out;
}

/* 내부팀 순위상: 해당 팀의 순위 확정 스텝에서 표시하고 ESC 전까지 유지 */
#award-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 32px;
    background: rgba(255, 255, 255, .88);
    color: #111827;
    pointer-events: auto;
    backdrop-filter: blur(4px);
    animation: award-overlay-in .4s ease-out forwards;
}
#award-overlay::after {
    content: "ESC 키를 눌러 계속";
    position: absolute;
    left: 50%;
    bottom: clamp(28px, 6vh, 72px);
    transform: translateX(-50%);
    color: rgba(17, 24, 39, .58);
    font-size: clamp(13px, 1.4vw, 18px);
    font-weight: 700;
    letter-spacing: .08em;
    white-space: nowrap;
}
#award-overlay[hidden] { display: none; }
.award-card {
    width: min(760px, 92vw);
    text-align: center;
    animation: award-card-in .5s cubic-bezier(.2, .8, .2, 1) forwards;
}
.award-icon {
    font-size: clamp(84px, 14vw, 170px);
    line-height: 1;
    filter: drop-shadow(0 16px 20px rgba(17, 24, 39, .18));
}
.award-name {
    margin-top: 24px;
    font-size: clamp(34px, 5vw, 68px);
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: -.04em;
}
.award-team {
    margin-top: 18px;
    font-size: clamp(22px, 3vw, 38px);
    font-weight: 700;
    line-height: 1.3;
    word-break: keep-all;
}
@keyframes award-overlay-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes award-card-in {
    from { opacity: 0; transform: translateY(28px) scale(.92); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
