/*
  무궁화 꽃이 피었습니다 — 게임 박스와 HTML 패널(참가자 입력·결과).

  캔버스(#mg-canvas)는 입력을 받지 않는다. 그래서 폰에서 게임 화면 위를 밀어도 페이지가 스크롤된다.
  박스 비율은 mugunghwa.js 의 배치와 같은 기준(폭 600px)으로 바뀐다: PC 1000:720, 폰 540:720.
*/

#game-container.mg-stage {
    --mg-pink: #ec4f9a;
    --mg-pink-hi: #ff8cc2;
    --mg-pink-lo: #a3245f;
    --mg-ink: #16121f;
    --mg-font: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', 'Hiragino Sans', sans-serif;
    position: relative;
    display: block;
    width: 100%;
    max-width: 1000px;
    height: auto;
    aspect-ratio: 1000 / 720;
    margin: 0 auto 1.25rem;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--bw-border);
    border-radius: 1.1rem;
    background: #3f7d36;
    box-shadow: var(--bw-shadow);
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
    font-family: var(--mg-font);
}

@media (max-width: 600px) {
    #game-container.mg-stage {
        aspect-ratio: 540 / 720;
        border-radius: 0.9rem;
    }
}

#mg-canvas {
    position: absolute;
    inset: 0;
}

#mg-canvas canvas {
    display: block;
}

/* ── 전체화면: 게임 박스만 키운다 ── */
#game-container.mg-stage:fullscreen,
#game-container.mg-stage:-webkit-full-screen {
    width: 100%;
    height: 100%;
    max-width: none;
    aspect-ratio: auto;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: #0b0912;
}

.mg-fs-exit {
    display: none;
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    z-index: 6;
    min-width: 44px;
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 999px;
    background: rgba(11, 9, 18, 0.75);
    color: #fff;
    font: 700 14px var(--mg-font);
    cursor: pointer;
}

#game-container.mg-stage.is-fs .mg-fs-exit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ── 패널 공통 ── */
.mg-panel {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    box-sizing: border-box;
}

.mg-panel[hidden] {
    display: none;
}

#mg-setup {
    background: radial-gradient(ellipse at 50% 45%, rgba(14, 10, 22, 0.25), rgba(14, 10, 22, 0.62));
}

.mg-card {
    width: min(520px, 100%);
    max-height: 100%;
    box-sizing: border-box;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 18px 20px;
    border: 1px solid rgba(236, 79, 154, 0.38);
    border-radius: 18px;
    background: rgba(22, 17, 32, 0.9);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
    color: #f3f1ec;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.mg-card button {
    font-family: var(--mg-font);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mg-card button:focus-visible,
#mgNamesInput:focus-visible {
    outline: 3px solid #ffd23f;
    outline-offset: 2px;
}

/* ── 참가자 입력 ── */
.mg-setup-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mg-setup-title {
    margin: 0;
    color: var(--mg-pink-hi);
    font-size: clamp(1.15rem, 3.2vw, 1.6rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    text-align: center;
}

.mg-setup-sub {
    color: #cfc8dc;
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.45;
    text-align: center;
    word-break: keep-all;
}

#mgNamesInput {
    width: 100%;
    /* 예시(엔터 3줄 + 쉼표 1줄)가 다 보이게 5줄 */
    height: 9.3em;
    min-height: 92px;
    box-sizing: border-box;
    padding: 10px 14px;
    border: 2px solid #4a2d4a;
    border-radius: 12px;
    background: #0f0b17;
    color: #ffe3f1;
    /* 16px 미만이면 아이폰이 입력할 때 화면을 확대함 */
    font: 600 16px/1.55 var(--mg-font);
    resize: none;
    outline: none;
}

#mgNamesInput::placeholder {
    color: #7d7390;
}

#mgNamesInput:focus {
    border-color: var(--mg-pink);
    box-shadow: 0 0 0 3px rgba(236, 79, 154, 0.25);
}

.mg-count {
    color: #a79fb8;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
}

.mg-count.ok {
    color: #6ee7a0;
}

.mg-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.mg-mode button {
    min-height: 46px;
    padding: 6px 8px;
    border: 2px solid #4a2d4a;
    border-radius: 12px;
    background: #1d1528;
    color: #e9e2f3;
    font-size: 0.93rem;
    font-weight: 700;
    word-break: keep-all;
    transition: background-color 0.15s, border-color 0.15s, transform 0.12s;
}

.mg-mode button[aria-checked="true"] {
    border-color: var(--mg-pink-hi);
    background: var(--mg-pink);
    color: #fff;
    box-shadow: 0 4px 0 var(--mg-pink-lo);
}

.mg-start {
    min-height: 54px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(180deg, #ff5fa2, #e23a86);
    color: #fff;
    font-size: 1.18rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    box-shadow: 0 5px 0 var(--mg-pink-lo);
    transition: transform 0.12s, box-shadow 0.12s, filter 0.2s;
}

.mg-start:not(.ready) {
    filter: saturate(0.55) brightness(0.8);
}

.mg-start:active,
.mg-mode button:active,
.mg-result-actions button:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--mg-pink-lo);
}

.mg-msg {
    min-height: 1.2em;
    margin: 0;
    color: #ff7a8a;
    font-size: 0.88rem;
    font-weight: 700;
    text-align: center;
}

/* ── 결과 카드 ── */
.mg-result-card {
    display: flex;
    max-height: 100%;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
    animation: mg-pop 0.42s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}

.mg-result-card.is-winner {
    border-color: rgba(255, 210, 63, 0.65);
}

.mg-result-card.is-loser {
    border-color: rgba(224, 53, 90, 0.75);
}

.mg-result-kicker {
    color: #ffd23f;
    font-size: 1.05rem;
    font-weight: 800;
}

.is-loser .mg-result-kicker {
    color: #ff6b86;
}

.mg-result-avatar {
    width: 80px;
    height: 100px;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45));
    animation: mg-bounce 1.1s ease-in-out infinite;
}

.mg-result-avatar[hidden] {
    display: none;
}

.mg-result-name {
    max-width: 100%;
    color: #fff;
    font-size: clamp(1.8rem, 7vw, 2.6rem);
    font-weight: 900;
    line-height: 1.1;
    text-shadow: 0 3px 0 var(--mg-c, #ec4f9a), 0 6px 14px rgba(0, 0, 0, 0.5);
    overflow-wrap: anywhere;
}

.mg-result-reason {
    color: #cfc8dc;
    font-size: 0.92rem;
    font-weight: 600;
}

.mg-rank-title {
    margin-top: 4px;
    color: #ffd23f;
    font-size: 0.85rem;
    font-weight: 800;
}

.mg-rank-title[hidden] {
    display: none;
}

.mg-rank-list {
    display: grid;
    flex: 0 1 auto;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr));
    align-content: start;
    gap: 2px 10px;
    width: 100%;
    min-height: 4.6em;
    max-height: 16em;
    margin: 0;
    padding: 8px;
    box-sizing: border-box;
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.25);
    list-style: none;
}

.mg-rank-list:empty {
    display: none;
}

.mg-rank-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 3px 4px;
    font-size: 0.92rem;
    font-weight: 700;
    text-align: left;
}

.mg-rank-list .rk {
    flex: none;
    min-width: 2.6em;
    color: #b9b3c9;
}

.mg-rank-list .dot {
    flex: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.mg-rank-list .nm {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-rank-list .st {
    flex: none;
    font-size: 0.85em;
}

.mg-rank-list li.top1 .rk,
.mg-rank-list li.top1 .nm { color: #ffd23f; }
.mg-rank-list li.top2 .rk { color: #e4e4ea; }
.mg-rank-list li.top3 .rk { color: #e3a15f; }
.mg-rank-list li.out { opacity: 0.6; }

.mg-result-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 8px;
}

.mg-result-actions button {
    flex: 1 1 180px;
    min-height: 48px;
    padding: 8px 12px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(180deg, #ff5fa2, #e23a86);
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    box-shadow: 0 4px 0 var(--mg-pink-lo);
}

.mg-result-actions button.sub {
    background: #2a2138;
    color: #e9e2f3;
    box-shadow: 0 4px 0 #120d1a;
}

@keyframes mg-pop {
    from { opacity: 0; transform: scale(0.72) translateY(12px); }
    to { opacity: 1; transform: none; }
}

@keyframes mg-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@media (max-width: 600px) {
    .mg-panel { padding: 10px; }
    .mg-card { padding: 14px 14px; border-radius: 16px; }
    .mg-setup-card { gap: 8px; }
    .mg-mode button { font-size: 0.88rem; }
    .mg-result-card { gap: 4px; }
    .mg-result-avatar { width: 60px; height: 75px; }
    .mg-result-card.long .mg-result-avatar { width: 44px; height: 55px; }
    .mg-result-name { font-size: 1.9rem; }
    .mg-rank-list { max-height: none; }
    .mg-result-actions { margin-top: 4px; }
    .mg-result-actions button { min-height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
    .mg-result-card,
    .mg-result-avatar {
        animation: none;
    }
}

/* ── 설명 본문 ── */
.mg-description h2 {
    margin: 22px 0 8px;
    color: #e84393;
    font-size: 17px;
}

.mg-description p,
.mg-description li {
    color: var(--bw-text);
    font-size: 14px;
    line-height: 1.7;
}

.mg-description strong {
    color: var(--bw-text);
    font-weight: 800;
}

.mg-description .mg-desc-note {
    margin-top: 14px;
    color: var(--bw-muted);
    font-size: 13px;
}
