@import url('https://fonts.googleapis.com/css2?family=Jua&family=Noto+Sans+KR:wght@400;700;900&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Jua', 'Noto Sans KR', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================
   셋업 화면
   ============================ */
#setup-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 20px 50px;
    min-height: 100vh;
    background: linear-gradient(160deg, #fff0f6 0%, #ffd6e7 40%, #ffecd2 100%);
    gap: 22px;
}

.title-area {
    text-align: center;
}

.game-title {
    font-size: clamp(1.8rem, 5vw, 3rem);
    color: #c0392b;
    text-shadow: 3px 3px 0 #fff, 5px 5px 0 rgba(192, 57, 43, 0.25);
    animation: titleBounce 2.2s ease-in-out infinite;
    line-height: 1.3;
}

.game-subtitle {
    color: #888;
    font-size: 0.95rem;
    margin-top: 6px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 400;
}

.add-form {
    background: white;
    border-radius: 28px;
    padding: 22px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 8px 30px rgba(240, 100, 100, 0.15);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-row {
    display: flex;
    gap: 10px;
}

.input-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.input-label {
    font-size: 0.8rem;
    color: #aaa;
    padding-left: 12px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 700;
}

input[type="text"] {
    width: 100%;
    padding: 13px 18px;
    border: 2.5px solid #ffc0cb;
    border-radius: 50px;
    font-family: 'Jua', sans-serif;
    font-size: 1rem;
    outline: none;
    color: #333;
    background: #fff9fb;
    transition: all 0.3s;
}

input[type="text"]:focus {
    border-color: #e84393;
    background: white;
    box-shadow: 0 0 0 4px rgba(232, 67, 147, 0.1);
}

.add-btn {
    background: linear-gradient(135deg, #fd79a8, #e84393);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 13px;
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.25s;
    box-shadow: 0 5px 18px rgba(232, 67, 147, 0.35);
    letter-spacing: 1px;
}

.add-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(232, 67, 147, 0.5); }
.add-btn:active { transform: translateY(0); }

.chars-header {
    width: 100%;
    max-width: 520px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #888;
    font-size: 0.88rem;
    padding: 0 4px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 400;
}

.chars-header strong { color: #e84393; font-family: 'Jua', sans-serif; }
.hint { font-size: 0.82rem; color: #bbb; }

#character-list {
    width: 100%;
    max-width: 520px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.character-card {
    background: white;
    border-radius: 22px;
    padding: 18px 10px 14px;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.07);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    position: relative;
    transition: all 0.25s;
    border: 2.5px solid transparent;
    cursor: default;
}

.character-card:hover {
    transform: translateY(-5px);
    border-color: #ffc0cb;
    box-shadow: 0 8px 24px rgba(232, 67, 147, 0.18);
}

.avatar-wrapper { position: relative; cursor: pointer; width: 64px; height: 64px; }

.avatar-emoji {
    font-size: 2.8rem;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffecd2, #fcb69f);
    transition: transform 0.2s;
    user-select: none;
}

.avatar-wrapper:hover .avatar-emoji { transform: scale(1.12); }

.avatar-img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #ffc0cb;
    transition: transform 0.2s;
}

.avatar-wrapper:hover .avatar-img { transform: scale(1.05); }

.avatar-change-hint {
    position: absolute;
    bottom: -4px;
    right: -4px;
    font-size: 0.85rem;
    background: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.char-name { font-weight: 700; color: #333; text-align: center; font-size: 0.95rem; word-break: keep-all; line-height: 1.3; }

.char-location {
    font-size: 0.72rem;
    color: #999;
    text-align: center;
    background: #f8f0ff;
    border-radius: 50px;
    padding: 3px 9px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 400;
}

.delete-btn {
    position: absolute;
    top: 7px;
    right: 7px;
    background: #ff7675;
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 0.65rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(255, 118, 117, 0.35);
    line-height: 1;
}

.delete-btn:hover { background: #d63031; transform: scale(1.15) rotate(90deg); }

#start-btn {
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 18px 65px;
    font-family: 'Jua', sans-serif;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 7px 28px rgba(108, 92, 231, 0.45);
    letter-spacing: 2px;
    margin-top: 10px;
}

#start-btn:not(:disabled):hover { transform: translateY(-4px) scale(1.03); box-shadow: 0 12px 36px rgba(108, 92, 231, 0.55); }
#start-btn:not(:disabled):active { transform: translateY(0) scale(0.97); }
#start-btn:disabled { background: linear-gradient(135deg, #dfe6e9, #b2bec3); cursor: not-allowed; box-shadow: none; opacity: 0.7; }

.back-link {
    color: #bbb;
    font-size: 0.9rem;
    text-decoration: none;
    font-family: 'Noto Sans KR', sans-serif;
    transition: color 0.2s;
}

.back-link:hover { color: #e84393; }

/* ============================
   배틀 화면
   ============================ */
#battle-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    background: radial-gradient(ellipse at 50% 0%, #2d1b69 0%, #1a0a3e 50%, #0d0020 100%);
    padding: 22px 16px;
    gap: 18px;
}

.battle-header { text-align: center; }

.battle-title {
    font-size: clamp(1.5rem, 4vw, 2.2rem);
    color: white;
    text-shadow: 0 0 20px rgba(162, 155, 254, 0.9), 0 0 40px rgba(162, 155, 254, 0.4);
    animation: glowPulse 2s ease-in-out infinite;
}

.alive-count { color: #a29bfe; margin-top: 6px; font-size: 1.1rem; }

#arena {
    position: relative;
    width: 100%;
    max-width: 720px;
    height: 420px;
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid rgba(162, 155, 254, 0.35);
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(108, 92, 231, 0.25), inset 0 0 60px rgba(0, 0, 0, 0.4);
}

#arena-stars { position: absolute; inset: 0; pointer-events: none; }

.arena-star {
    position: absolute;
    background: white;
    border-radius: 50%;
    animation: twinkle var(--dur) ease-in-out infinite alternate;
    animation-delay: var(--delay);
}

.arena-character {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    z-index: 2;
    transition: left 0.08s linear, top 0.08s linear;
}

.arena-avatar-wrap {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 2.5px solid rgba(162, 155, 254, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.6rem;
    box-shadow: 0 0 18px rgba(162, 155, 254, 0.3), 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s;
    user-select: none;
    animation: charFloat var(--float-dur, 2.5s) ease-in-out infinite;
    animation-delay: var(--float-delay, 0s);
}

.arena-avatar-wrap img { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; }

.arena-name-badge {
    background: rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(6px);
    color: white;
    font-size: 0.72rem;
    padding: 3px 10px;
    border-radius: 50px;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.arena-character.pre-fight .arena-avatar-wrap {
    animation: preFightPulse 0.18s ease-in-out infinite !important;
    border-color: #ff9f43 !important;
    box-shadow: 0 0 22px rgba(255, 159, 67, 0.9), 0 0 44px rgba(255, 159, 67, 0.4) !important;
    background: rgba(255, 159, 67, 0.12) !important;
}

.clash-effect {
    position: absolute;
    font-size: 2.8rem;
    z-index: 30;
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: clashAnim 0.85s ease-out forwards;
    filter: drop-shadow(0 0 8px rgba(255, 220, 50, 0.9));
}

.arena-character.ko-shake .arena-avatar-wrap {
    animation: koShake 0.45s ease-in-out !important;
    border-color: #ff6b6b !important;
    box-shadow: 0 0 25px rgba(255, 107, 107, 0.9), 0 0 50px rgba(255, 107, 107, 0.4) !important;
    background: rgba(255, 107, 107, 0.15) !important;
}

.arena-character.ko-fade { animation: koFade 0.7s ease-in forwards !important; z-index: 10; }

.ko-text {
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.3rem;
    color: #ff6b6b;
    font-weight: bold;
    animation: koTextAnim 1s ease-out forwards;
    pointer-events: none;
    text-shadow: 0 0 12px rgba(255, 107, 107, 0.9), 0 2px 4px rgba(0,0,0,0.5);
    white-space: nowrap;
    z-index: 20;
}

#battle-log {
    width: 100%;
    max-width: 720px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    padding: 14px 18px;
}

.log-title { color: rgba(255, 255, 255, 0.4); font-size: 0.8rem; margin-bottom: 8px; font-family: 'Noto Sans KR', sans-serif; font-weight: 400; }

#log-entries { display: flex; flex-direction: column; gap: 5px; max-height: 130px; overflow: hidden; }

.log-entry {
    background: rgba(255, 255, 255, 0.07);
    color: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    padding: 7px 13px;
    font-size: 0.88rem;
    animation: logSlide 0.3s ease;
    border-left: 3px solid #fd79a8;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 400;
}

/* ============================
   결과 화면
   ============================ */
#result-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(150deg, #fff0f6 0%, #ffd6e7 40%, #ffecd2 80%, #d7f9fa 100%);
    position: relative;
    overflow: hidden;
}

#confetti-container { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece { position: absolute; top: -20px; }

.result-content { display: flex; flex-direction: column; align-items: center; gap: 18px; z-index: 10; padding: 20px; }

.result-title {
    font-size: clamp(2rem, 6vw, 3.5rem);
    color: #c0392b;
    text-shadow: 3px 3px 0 white, 5px 5px 0 rgba(192, 57, 43, 0.2);
    animation: resultTitleAnim 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-align: center;
}

.winner-card {
    background: white;
    border-radius: 32px;
    padding: 32px 48px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: 0 20px 60px rgba(225, 112, 85, 0.25), 0 0 0 3px rgba(255, 192, 203, 0.5);
    animation: winnerCardAnim 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both;
}

.winner-avatar-large {
    font-size: 5rem;
    width: 115px;
    height: 115px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffecd2, #fcb69f);
    box-shadow: 0 8px 28px rgba(225, 112, 85, 0.4);
    animation: winnerFloat 2.2s ease-in-out infinite;
    position: relative;
    user-select: none;
}

.winner-avatar-large img { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; }

.winner-crown-badge {
    position: absolute;
    top: -24px;
    font-size: 2.2rem;
    animation: crownSpin 1s ease-in-out infinite alternate;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.2));
}

.winner-name-large { font-size: 2.2rem; color: #2d3436; font-weight: 900; text-align: center; }

.winner-location-large {
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: white;
    border-radius: 50px;
    padding: 6px 20px;
    font-size: 0.9rem;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 700;
}

.winner-slogan { font-size: 1.1rem; color: #e17055; text-align: center; }

.restart-btn {
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 17px 52px;
    font-family: 'Jua', sans-serif;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 6px 22px rgba(108, 92, 231, 0.35);
    letter-spacing: 1px;
}

.restart-btn:hover { transform: translateY(-4px); box-shadow: 0 10px 30px rgba(108, 92, 231, 0.5); }
.restart-btn:active { transform: translateY(0); }

/* ============================
   애니메이션
   ============================ */
@keyframes titleBounce {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-7px) rotate(1deg); }
}
@keyframes glowPulse {
    0%, 100% { text-shadow: 0 0 20px rgba(162, 155, 254, 0.8); }
    50% { text-shadow: 0 0 40px rgba(162, 155, 254, 1), 0 0 70px rgba(162, 155, 254, 0.5); }
}
@keyframes charFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}
@keyframes twinkle {
    from { opacity: 0.15; transform: scale(0.8); }
    to { opacity: 0.9; transform: scale(1.3); }
}
@keyframes preFightPulse {
    0%, 100% { transform: scale(1) rotate(0deg); }
    30% { transform: scale(1.18) rotate(-7deg); }
    70% { transform: scale(1.18) rotate(7deg); }
}
@keyframes clashAnim {
    0%   { transform: translate(-50%, -50%) scale(0.2) rotate(-20deg); opacity: 1; }
    35%  { transform: translate(-50%, -50%) scale(2.0) rotate(10deg);  opacity: 1; }
    70%  { transform: translate(-50%, -50%) scale(1.6) rotate(-5deg);  opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(2.8) rotate(5deg);   opacity: 0; }
}
@keyframes koShake {
    0%, 100% { transform: translateX(0) rotate(0deg) scale(1); }
    15% { transform: translateX(-14px) rotate(-10deg) scale(1.1); }
    30% { transform: translateX(14px) rotate(10deg) scale(1.1); }
    45% { transform: translateX(-10px) rotate(-6deg) scale(1.05); }
    60% { transform: translateX(10px) rotate(6deg) scale(1.05); }
    75% { transform: translateX(-5px) rotate(-3deg); }
    90% { transform: translateX(5px) rotate(3deg); }
}
@keyframes koFade {
    0% { opacity: 1; transform: scale(1); }
    20% { transform: scale(1.25) rotate(5deg); }
    100% { opacity: 0; transform: scale(0) rotate(-25deg) translateY(20px); }
}
@keyframes koTextAnim {
    0% { transform: translateX(-50%) scale(0.3) rotate(-15deg); opacity: 0; }
    25% { transform: translateX(-50%) scale(1.4) rotate(5deg); opacity: 1; }
    55% { transform: translateX(-50%) scale(1.1) rotate(-2deg); opacity: 1; }
    100% { transform: translateX(-50%) translateY(-45px) scale(1.6); opacity: 0; }
}
@keyframes logSlide {
    from { transform: translateX(-18px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes resultTitleAnim {
    from { transform: scale(0.3) rotate(-10deg); opacity: 0; }
    to { transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes winnerCardAnim {
    from { transform: translateY(40px) scale(0.8); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes winnerFloat {
    0%, 100% { transform: translateY(0) rotate(-4deg); }
    50% { transform: translateY(-14px) rotate(4deg); }
}
@keyframes crownSpin {
    from { transform: rotate(-18deg) scale(1); }
    to { transform: rotate(18deg) scale(1.25); }
}
@keyframes confettiFall {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(110vh) rotate(var(--rot)); opacity: 0.2; }
}

@media (max-width: 480px) {
    #character-list { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); }
    #arena { height: 340px; }
    .arena-avatar-wrap { width: 58px; height: 58px; font-size: 2.2rem; }
    .winner-card { padding: 24px 30px 22px; }
}

/* ── Setup row inputs ───────────────────────── */
.row-header {
    display: flex;
    gap: 10px;
    padding: 0 0 6px 0;
    margin-bottom: 2px;
}
.row-header-name,
.row-header-location {
    flex: 1;
    font-size: 0.72rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.row-header::after {
    content: '';
    width: 34px;
    flex-shrink: 0;
}

.participant-row-input {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
}
.row-name-input,
.row-location-input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    color: #fff;
    font-size: 0.95rem;
    padding: 10px 14px;
    outline: none;
    font-family: 'Jua', 'Noto Sans KR', sans-serif;
    transition: border-color 0.2s;
}
.row-name-input:focus,
.row-location-input:focus {
    border-color: rgba(162,155,254,0.6);
}
.row-delete-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: rgba(255,255,255,0.35);
    width: 34px;
    height: 34px;
    cursor: pointer;
    font-size: 0.85rem;
    flex-shrink: 0;
    transition: color 0.2s, border-color 0.2s;
}
.row-delete-btn:hover {
    color: #ff6b6b;
    border-color: rgba(255,107,107,0.4);
}
.add-row-btn {
    display: block;
    width: 100%;
    background: transparent;
    border: 1px dashed rgba(162,155,254,0.35);
    border-radius: 10px;
    color: rgba(162,155,254,0.7);
    font-size: 0.9rem;
    font-family: 'Jua', 'Noto Sans KR', sans-serif;
    padding: 10px;
    cursor: pointer;
    margin-bottom: 20px;
    transition: border-color 0.2s, color 0.2s;
}
.add-row-btn:hover {
    border-color: rgba(162,155,254,0.7);
    color: #a29bfe;
}

/* ── Share URL box ──────────────────────────── */
.share-url-box {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(162, 155, 254, 0.3);
    border-radius: 12px;
    padding: 12px 16px;
    margin-top: 4px;
}
.share-url-label {
    display: block;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.45);
    margin-bottom: 8px;
    letter-spacing: 0.04em;
}
.share-url-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.share-url-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #a29bfe;
    font-size: 0.78rem;
    padding: 7px 10px;
    outline: none;
    font-family: monospace;
    min-width: 0;
}
.share-url-copy-btn {
    background: #a29bfe;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
    font-family: 'Jua', sans-serif;
}
.share-url-copy-btn:hover { background: #6c5ce7; }

/* ── Emoji picker ──────────────────────────── */
.row-emoji-btn {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.row-emoji-btn:hover {
    background: rgba(162,155,254,0.2);
    transform: scale(1.12);
}

.emoji-picker-popup {
    position: fixed;
    z-index: 1000;
    background: #2d1b69;
    border: 1px solid rgba(162,155,254,0.4);
    border-radius: 16px;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 280px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    max-height: 220px;
    overflow-y: auto;
}

.emoji-option {
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 8px;
    padding: 4px;
    transition: background 0.15s, transform 0.1s;
    line-height: 1;
}
.emoji-option:hover {
    background: rgba(162,155,254,0.25);
    transform: scale(1.2);
}