.kg {
    --kg-ink: #342a20;
    --kg-deep: #39291d;
    --kg-muted: #685f52;
    --kg-border: #dfd8ca;
    --kg-soft: #faf7f0;
    --kg-teal: #086b71;
    --kg-gold: #ebc962;
    width: 100%;
    max-width: 1140px;
    min-width: 0;
    margin-inline: auto;
    color: var(--kg-ink);
}
.kg *, .kg *::before, .kg *::after { box-sizing: border-box; }
.kg .kg-main { display: grid; gap: clamp(18px, 3vw, 30px); min-width: 0; }
.kg h2, .kg h3, .kg h4, .kg p, .kg ol { margin: 0; color: inherit; }
.kg h2, .kg h3, .kg h4 { line-height: 1.55; overflow-wrap: anywhere; }
.kg h2 { font-size: clamp(1.27rem, 2.5vw, 1.85rem); }
.kg h3 { font-size: 1.13rem; }
.kg .icon { width: 19px; height: 19px; flex: none; }

.kg-hero {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 18px 28px;
    overflow: hidden;
    padding: clamp(22px, 4vw, 38px);
    border-radius: 16px;
    color: #fffbef;
    background: linear-gradient(112deg, #36271c, #4a3421 55%, #423520);
}
.kg-hero::before {
    position: absolute;
    z-index: -1;
    inset-block: 0;
    inset-inline-end: 0;
    width: 60%;
    content: '';
    pointer-events: none;
    background: repeating-radial-gradient(ellipse at 80% 135%, transparent 0 29px, #efcf7a1f 30px, transparent 32px 51px);
    mask-image: linear-gradient(90deg, transparent, #000 35%);
}
[dir=rtl] .kg-hero::before { transform: scaleX(-1); }
.kg-hero > * { min-width: 0; }
.kg .kg-hero h2 { margin-block: 4px 0; color: #fffdf5; }
.kg-kicker, .kg-card-meta, .kg-badge, .kg-timer, .kg-section-icon { display: inline-flex; align-items: center; gap: 7px; }
.kg-kicker { color: #f7d97f; font-size: .86rem; font-weight: 700; }
.kg-room-hero { padding-block: clamp(16px, 2.5vw, 24px); }
.kg-code { padding-inline-start: 18px; border-inline-start: 2px solid #e9c968a3; }
.kg-code strong { display: block; font-size: clamp(1.45rem, 4vw, 2.1rem); letter-spacing: .12em; line-height: 1.35; }
.kg-row small, .kg-choice small, .kg-results span, .kg-code span { display: block; font-size: .84rem; }

.kg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 16px;
    border: 1px solid var(--kg-border);
    border-radius: 9px;
    background: #fff;
    color: var(--kg-deep);
    font: inherit;
    font-weight: 700;
    font-size: .92rem;
    line-height: 1.5;
    text-align: center;
    cursor: pointer;
}
.kg-btn.kg-primary { background: var(--kg-teal); color: #fff; border-color: var(--kg-teal); }
.kg-btn.kg-light { background: var(--kg-gold); border-color: var(--kg-gold); color: #332714; }
.kg-btn.kg-text, .kg-btn.kg-back { padding-inline: 3px; background: transparent; border-color: transparent; text-decoration: underline; text-underline-offset: 4px; }
.kg-btn.kg-back { justify-self: start; }
.kg-btn:disabled { opacity: .65; cursor: default; }
.kg-btn[aria-busy=true], .kg form[aria-busy=true] button[type=submit] { opacity: .7; cursor: progress; }
.kg :is(button, input, select, textarea, summary):focus-visible { outline: 3px solid #05676d; outline-offset: 3px; }
.kg-hero :is(button, input):focus-visible { outline-color: #ffdc78; }
.kg label { display: grid; gap: 5px; min-width: 0; font-size: .92rem; font-weight: 700; }
.kg input:not([type=checkbox]), .kg select, .kg textarea {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 9px 12px;
    border: 1px solid #bcb3a4;
    border-radius: 8px;
    background: #fff;
    color: var(--kg-ink);
    font: inherit;
    font-weight: 400;
}
.kg textarea { resize: vertical; }
.kg .kg-join { display: flex; align-items: end; gap: 10px; }
.kg-join input { max-width: 185px; text-align: center; letter-spacing: .15em; font-variant-numeric: tabular-nums; }
.kg-section { display: grid; gap: 12px; min-width: 0; }
.kg-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.kg-card, .kg-list, .kg-question, .kg-stage, .kg-editor, .kg-ranking, .kg-review, .kg-analytics { border: 1px solid var(--kg-border); border-radius: 14px; background: #fff; }
.kg-card { display: flex; flex-direction: column; align-items: flex-start; gap: 13px; min-width: 0; padding: 20px; }
.kg-card h3 { font-size: 1.23rem; }
.kg-card .kg-actions { margin-block-start: auto; padding-block-start: 7px; }
.kg-card-meta { color: var(--kg-muted); flex-wrap: wrap; font-size: .86rem; }
.kg-card-meta .icon { color: var(--kg-teal); }
.kg-actions, .kg-toolbar, .kg-question-head, .kg-question-foot, .kg-edit-controls, .kg-row, .kg-result-actions, .kg-stats-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.kg-toolbar, .kg-question-head, .kg-question-foot, .kg-row, .kg-stats-heading { justify-content: space-between; }
.kg-toolbar + .kg-room-hero { margin-block-start: -11px; }
.kg-badge { padding: 2px 10px; border-radius: 20px; background: #f1eadb; color: #614a2a; font-size: .8rem; }
.kg-list, .kg-ranking, .kg-review, .kg-breakdown, .kg-analytics { padding: 0; list-style: none; }
.kg-row, .kg-ranking > li, .kg-review > li, .kg-analytics > li { min-width: 0; padding: 14px 20px; overflow-wrap: anywhere; }
.kg-row + .kg-row, .kg-ranking > li + li, .kg-review > li + li, .kg-analytics > li + li { border-block-start: 1px solid #ece6da; }
.kg-row small, .kg-question-foot small, .kg-review p, .kg-played-count, .kg-metrics { color: var(--kg-muted); }
.kg-stage { display: grid; justify-items: center; gap: 14px; padding: clamp(22px, 4vw, 40px); text-align: center; }
.kg-section-icon { padding: 12px; border-radius: 50%; background: #f6eed6; color: #725924; }
.kg-question, .kg-editor { display: grid; gap: 18px; min-width: 0; padding: clamp(17px, 3vw, 30px); }
.kg-question-head { color: var(--kg-muted); font-size: .95rem; }
.kg-question h2 { font-size: clamp(1.2rem, 2.3vw, 1.67rem); }
.kg-question progress { appearance: none; width: 100%; height: 6px; overflow: hidden; border: 0; border-radius: 8px; background: #ede9df; color: var(--kg-teal); }
.kg-question progress::-webkit-progress-bar { background: #ede9df; }
.kg-question progress::-webkit-progress-value { background: var(--kg-teal); }
.kg-question progress::-moz-progress-bar { background: var(--kg-teal); }
.kg-timer { justify-content: center; min-width: 74px; padding: 3px 10px; border-radius: 7px; background: #e9f3ef; color: #135858; font-variant-numeric: tabular-nums; }
.kg-timer.kg-low, .kg-question.kg-low .kg-timer { color: #852e20; background: #fce9df; }
.kg-choices, .kg-options-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.kg-choice {
    --kg-choice-ink: #77541d;
    --kg-choice-bg: #fbf4e3;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 74px;
    padding: 13px 15px;
    border: 1px solid var(--kg-border);
    border-radius: 10px;
    background: var(--kg-choice-bg);
    color: var(--kg-ink);
    font: inherit;
    font-weight: 700;
    line-height: 1.6;
    text-align: start;
    cursor: pointer;
}
.kg-c1 { --kg-choice-ink: #20676b; --kg-choice-bg: #edf6f4; }
.kg-c2 { --kg-choice-ink: #545681; --kg-choice-bg: #f2f1f8; }
.kg-c3 { --kg-choice-ink: #8b4b39; --kg-choice-bg: #faf0e9; }
.kg-choice > b { display: grid; place-items: center; flex: 0 0 33px; height: 33px; border-radius: 8px; background: var(--kg-choice-ink); color: white; line-height: 1; }
.kg-choice > span { min-width: 0; overflow-wrap: anywhere; }
.kg-choice small { font-weight: 400; }
.kg-choice:disabled { opacity: 1; cursor: default; }
.kg-choice.kg-picked { box-shadow: inset 0 0 0 1px var(--kg-choice-ink); border-color: var(--kg-choice-ink); }
.kg-choice.kg-correct { --kg-choice-ink: #216448; border-color: #216448; background: #e6f5ec; box-shadow: inset 0 0 0 1px #216448; color: #174a36; }
.kg-choice.kg-wrong { --kg-choice-ink: #8c3f32; border-color: #8c3f32; background: #fbece6; color: #682c22; }
.kg-question-foot { min-width: 0; }
.kg-question-foot:empty, .kg-question-foot:has(> :only-child:empty) { display: none; }
.kg-explanation { display: grid; gap: 5px; min-width: 0; padding: 12px 15px; border-inline-start: 3px solid var(--kg-teal); border-radius: 4px; background: #edf5f2; text-align: start; overflow-wrap: anywhere; }
.kg-explanation strong { color: #194f4e; }
.kg-explanation p { font-size: .94rem; }
.kg-ranking > li { display: grid; grid-template-columns: minmax(30px, auto) minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.kg-ranking > li > b { display: grid; place-items: center; min-width: 30px; height: 30px; padding-inline: 4px; border-radius: 8px; color: var(--kg-muted); background: #f5f2eb; font-variant-numeric: tabular-nums; }
.kg-ranking > li.kg-you { background: #f9f4e3; box-shadow: inset 0 1px #fff; }
.kg-ranking > li.kg-you > b { background: #e9d797; color: #4c3916; }
.kg-results { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; width: 100%; }
.kg-results > div { flex: 1 1 108px; max-width: 200px; padding: 12px 9px; background: var(--kg-soft); border-radius: 10px; }
.kg-results b { display: block; color: var(--kg-teal); font-size: clamp(1.3rem, 2.5vw, 1.85rem); font-variant-numeric: tabular-nums; line-height: 1.45; }
.kg-results span { color: var(--kg-muted); }
.kg-result-actions { justify-content: center; }
.kg-review > li, .kg-analytics > li { display: grid; gap: 6px; }
.kg-review p { font-size: .92rem; }
.kg-review-state { justify-self: start; font-weight: 700; font-size: .82rem; }
.kg-review-state.kg-right { color: #216448; }
.kg-review-state.kg-wrong { color: #8a3a28; }
.kg-review-state.kg-missed { color: #67552e; }
.kg .kg-analytics h4 { font-size: 1rem; }
.kg-analytics details { min-width: 0; }
.kg-analytics summary { width: fit-content; max-width: 100%; padding-block: 9px; color: var(--kg-teal); font-weight: 700; font-size: .9rem; cursor: pointer; }
.kg-metrics, .kg-played-count { font-size: .9rem; }
.kg-breakdown { display: grid; gap: 10px; min-width: 0; }
.kg-breakdown li { display: grid; gap: 4px; min-width: 0; }
.kg-breakdown li > strong { font-size: .92rem; }
.kg-bar-line { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 12px; color: var(--kg-muted); font-size: .84rem; line-height: 1.5; font-variant-numeric: tabular-nums; }
.kg-bar { flex: 1 1 72px; height: 8px; overflow: hidden; border-radius: 6px; background: #ebe7dd; }
.kg-bar > i { display: block; height: 100%; border-radius: inherit; background: var(--kg-teal); }
.kg-editor fieldset { display: grid; gap: 14px; min-width: 0; margin: 0; padding: 16px; border: 1px solid var(--kg-border); border-radius: 10px; }
.kg-editor legend { padding-inline: 6px; font-weight: 700; }
.kg-editor .kg-check { display: flex; align-items: center; gap: 9px; }
.kg-check input { flex: none; width: 18px; height: 18px; accent-color: var(--kg-teal); }
.kg-error { margin-block-end: 12px; padding: 11px 15px; border: 1px solid #c99580; border-radius: 8px; background: #fff0e9; color: #782d1a; }
.kg-error[hidden] { display: none; }

@media (hover: hover) {
    .kg-btn:not(:disabled):hover { border-color: #887966; background: #fbf8f0; }
    .kg-btn.kg-primary:not(:disabled):hover { border-color: #064d52; background: #064d52; }
    .kg-btn.kg-light:not(:disabled):hover { border-color: #ffdb73; background: #ffdb73; }
    .kg-choice:not(:disabled):hover { border-color: var(--kg-choice-ink); box-shadow: inset 0 0 0 1px var(--kg-choice-ink); }
}
@media (prefers-reduced-motion: no-preference) {
    .kg-choice, .kg-btn { transition: background-color .14s ease, border-color .14s ease, box-shadow .14s ease; }
    .kg-choice:not(:disabled):active, .kg-btn:not(:disabled):active { transform: translateY(1px); }
}
@media (max-width: 650px) {
    .kg-choices, .kg-options-form { grid-template-columns: minmax(0, 1fr); }
    .kg-hero, .kg-card { padding: 17px; }
    .kg-join { width: 100%; }
    .kg-join label { flex: 1; }
    .kg-join input { max-width: none; }
    .kg-code { padding-inline-start: 12px; }
    .kg-edit-controls label { flex: 1 1 115px; }
    .kg-question-foot { align-items: start; }
    .kg-choice { min-height: 58px; }
    .kg-results > div { flex-basis: 95px; }
    .kg-row, .kg-review > li, .kg-ranking > li, .kg-analytics > li { padding-inline: 13px; }
}
@media (max-width: 380px) {
    .kg-card, .kg-hero, .kg-stage, .kg-editor, .kg-question { padding-inline: 13px; }
    .kg-join { flex-wrap: wrap; }
    .kg-review > li, .kg-ranking > li, .kg-analytics > li { padding-inline: 10px; }
    .kg-edit-controls { align-items: stretch; }
}
@media (forced-colors: active) {
    .kg-choice.kg-correct, .kg-choice.kg-picked, .kg-choice.kg-wrong { outline: 2px solid Highlight; outline-offset: -3px; }
    .kg-bar { border: 1px solid CanvasText; }
    .kg-bar > i { background: Highlight; forced-color-adjust: none; }
}

.kg-standings { min-width: 0; }
.kg-podium {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr));
    gap: 10px;
    padding: 0;
    list-style: none;
}
.kg-podium > li {
    --kg-medal: #b99b54;
    display: grid;
    align-content: start;
    gap: 3px;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--kg-border);
    border-block-start: 3px solid var(--kg-medal);
    border-radius: 10px;
    background: #fff;
    overflow-wrap: anywhere;
}
.kg-podium .kg-place-1 { --kg-medal: #b79639; background: #fcf7e8; }
.kg-podium .kg-place-2 { --kg-medal: #899a98; background: #f3f7f6; }
.kg-podium .kg-place-3 { --kg-medal: #b28566; background: #faf4ee; }
.kg-podium > li > b {
    display: grid;
    place-items: center;
    justify-self: start;
    min-width: 30px;
    height: 30px;
    margin-block-end: 3px;
    padding-inline: 5px;
    border: 1px solid var(--kg-medal);
    border-radius: 50%;
    font-size: .88rem;
}
.kg-podium > li > span { font-weight: 700; }
.kg-podium > li > strong { font-size: .93rem; }
.kg-award { font-size: .83rem; }
.kg-award { display: block; color: var(--kg-muted); font-weight: 400; }
.kg-own-place { padding: 0; border-inline-start: 3px solid var(--kg-teal); background: #eef5f1; color: var(--kg-deep); }
.kg-sound { font-size: .86rem; }
.kg-sound[aria-pressed=true] { border-color: #9cbab6; background: #edf5f2; color: #174e4b; }

.kg-roster {
    display: grid;
    width: 100%;
    min-width: 0;
    gap: 12px;
    padding: clamp(15px, 2.5vw, 24px);
    border: 1px solid var(--kg-border);
    border-radius: 14px;
    background: #fff;
    text-align: start;
}
.kg-stage .kg-roster { margin-block-start: 4px; }
.kg-players {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
    gap: 7px;
    padding: 0;
    list-style: none;
}
.kg-players li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px 12px;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid #e8e2d6;
    border-radius: 8px;
    background: var(--kg-soft);
}
.kg-players li > span { min-width: 0; overflow-wrap: anywhere; font-weight: 700; }
.kg-player-ready, .kg-player-waiting {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: .84rem;
    line-height: 1.6;
}
.kg-player-ready { color: #206244; }
.kg-player-waiting { color: #6a5a3c; }
.kg-player-ready::before, .kg-player-waiting::before {
    content: '';
    flex: none;
    width: 8px;
    height: 8px;
    border: 1.5px solid currentColor;
    border-radius: 50%;
}
.kg-player-ready::before { background: currentColor; }
.kg-ready[aria-pressed=true] { background: #e7f4eb; border-color: #72a489; color: #215a3f; }
.kg-question.kg-paused { border-color: #c6a65b; }
.kg-timer.kg-paused, .kg-question.kg-paused .kg-timer { color: #654a12; background: #faf0ce; }
.kg-question.kg-paused progress { color: #957531; }
.kg-question.kg-paused progress::-webkit-progress-value { background: #957531; }
.kg-question.kg-paused progress::-moz-progress-bar { background: #957531; }
.kg-pause { gap: 6px; }
.kg-pause[aria-pressed=true] { color: #5d4315; background: #faf0ce; border-color: #bfa467; }
@media (hover: hover) {
    .kg-btn.kg-ready[aria-pressed=true]:hover { color: #19492e; background: #d8eddf; border-color: #659276; }
    .kg-btn.kg-pause[aria-pressed=true]:hover { color: #533b11; background: #f4e5b8; border-color: #a88d52; }
}
@media (max-width: 650px) {
    .kg-players { grid-template-columns: minmax(0, 1fr); }
    .kg-roster .kg-stats-heading { align-items: baseline; }
    .kg-players li { padding: 7px 10px; }
    .kg-toolbar:has(.kg-pause) { justify-content: start; gap: 4px 8px; }
}
