:root {
  --green: #37d67a;
  --green-d: #1fae5e;
  --pink: #ff4d84;
  --pink-d: #e0326a;
  --ink: #17161c;
  --ink-soft: #2a2833;
  --cream: #fdf6ee;
  --sand: #f4e7d6;
  --accent: var(--pink);
  --accent-2: #ffd23f;
  --shadow: 0 6px 0 rgba(0,0,0,.28);
  --shadow-lg: 0 10px 0 rgba(0,0,0,.28);
  --radius: 20px;
  --border: 4px solid var(--ink);
  --font-disp: 'Black Han Sans', 'Jua', 'Pretendard Variable', sans-serif;
  --font-num: 'Fredoka', 'Pretendard Variable', sans-serif;
  --font-body: 'Pretendard Variable', Pretendard, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* [hidden] 우선 (author display 규칙에 덮이는 문제 방지) */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(55,214,122,.28), transparent 42%),
    radial-gradient(circle at 82% 78%, rgba(255,77,132,.28), transparent 45%),
    linear-gradient(160deg, #201d2b 0%, #17161c 60%, #221a24 100%);
  overflow: hidden;
}

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 999; opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.screen { position: fixed; inset: 0; display: none; overflow-y: auto; }
.screen.active { display: block; }

/* 버튼 */
.btn {
  font-family: var(--font-disp); font-size: 18px; color: var(--ink); letter-spacing: .5px;
  border: var(--border); border-radius: 999px; padding: 13px 22px; cursor: pointer;
  background: #fff; box-shadow: var(--shadow); transition: transform .08s, box-shadow .08s;
  user-select: none; white-space: nowrap;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.28); }
.btn.big { font-size: 22px; padding: 16px 28px; width: 100%; }
.btn.small { font-size: 15px; padding: 8px 14px; box-shadow: 0 4px 0 rgba(0,0,0,.25); }
.btn-primary { background: var(--green); color: #06381f; }
.btn-accent { background: var(--pink); color: #fff; }
.btn-ghost { background: var(--cream); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.4); }

/* 오징어게임 딱지 심볼 데코 */
.card {
  background: var(--cream); border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 22px;
}

/* ===== 홈 ===== */
.home-wrap { min-height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 22px; padding: 32px 20px; }
.title-block { text-align: center; }
.doll-emoji { font-size: 52px; animation: peek 2.4s ease-in-out infinite; filter: drop-shadow(0 4px 0 rgba(0,0,0,.3)); }
@keyframes peek { 0%,40%,100%{transform:rotate(0)} 50%{transform:rotate(-14deg)} 60%{transform:rotate(14deg)} 70%{transform:rotate(0)} }
.game-title {
  font-family: var(--font-disp); font-size: clamp(38px, 10vw, 68px); line-height: 1.0;
  color: #fff; text-shadow: 3px 3px 0 var(--pink), 6px 6px 0 rgba(0,0,0,.4); margin-top: 10px;
  letter-spacing: 1px;
}
.game-title span { color: var(--green); text-shadow: 3px 3px 0 var(--ink), 6px 6px 0 rgba(0,0,0,.3); }
.subtitle { margin-top: 14px; font-size: 16px; color: #fff; background: rgba(0,0,0,.35);
  display: inline-block; padding: 7px 16px; border-radius: 999px; border: 2px solid rgba(255,255,255,.2); }
.subtitle b { color: var(--green); }

.home-card { width: min(440px, 100%); display: flex; flex-direction: column; gap: 16px; }
.fld { display: flex; flex-direction: column; gap: 6px; font-family: var(--font-disp); font-size: 16px; }
.fld input, .join-row input {
  font-family: var(--font-body); font-size: 18px; font-weight: 600;
  border: 3px solid var(--ink); border-radius: 14px; padding: 13px 16px; background: #fff; color: var(--ink);
  outline: none; width: 100%;
}
.fld input:focus, .join-row input:focus { border-color: var(--pink); }
.divider { display: flex; align-items: center; gap: 10px; color: #9a8a76; font-size: 14px; }
.divider::before, .divider::after { content:''; flex:1; height: 2px; background: rgba(0,0,0,.14); }
.join-row { display: flex; gap: 10px; }
.join-row input { text-align: center; letter-spacing: 6px; font-family: var(--font-num); text-transform: uppercase; }
.join-row .btn { flex: none; }
.err-msg { color: #d3341d; font-weight: 700; min-height: 18px; font-size: 14px; text-align: center; }
.foot { color: rgba(255,255,255,.55); font-size: 13px; text-align: center; max-width: 460px; }

/* ===== 로비 ===== */
.lobby-wrap { max-width: 1000px; margin: 0 auto; padding: 18px 16px 40px; }
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px; }
.room-badge { display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff;
  border-radius: 999px; padding: 8px 18px; box-shadow: var(--shadow); border: 3px solid var(--pink); }
.rb-label { font-size: 13px; opacity: .7; }
.rb-code { font-family: var(--font-num); font-size: 28px; font-weight: 700; letter-spacing: 4px; color: var(--green); }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.member-count { font-family: var(--font-disp); background: #fff; border: 2px solid var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: 14px; }

.lobby-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 780px) { .lobby-grid { grid-template-columns: 1fr; } }

.panel-title { font-family: var(--font-disp); font-size: 20px; display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 14px; letter-spacing: .5px; }
.host-tag { font-size: 12px; background: var(--pink); color: #fff; padding: 3px 10px; border-radius: 999px; display: none; }
body.is-host .host-tag { display: inline-block; }

.participant-list { display: flex; flex-wrap: wrap; gap: 8px; max-height: 46vh; overflow-y: auto; }
.p-chip { display: flex; align-items: center; gap: 8px; background: #fff; border: 3px solid var(--ink);
  border-radius: 999px; padding: 6px 8px 6px 12px; box-shadow: 0 3px 0 rgba(0,0,0,.2); animation: pop .2s ease; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.p-chip .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.p-chip .p-emoji { font-size: 18px; }
.p-chip .p-name { font-weight: 700; font-size: 15px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-chip .x { border: none; background: none; cursor: pointer; font-size: 16px; color: #b33; padding: 0 4px; font-weight: 800; }

/* 설정 */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 0; border-bottom: 2px dashed rgba(0,0,0,.12); flex-wrap: wrap; }
.setting:last-of-type { border-bottom: none; }
.s-label { font-family: var(--font-disp); font-size: 16px; letter-spacing: .3px; }
.s-label small { font-family: var(--font-body); font-size: 11px; font-weight: 600; color: #9a8a76; }
.seg { display: flex; background: #fff; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; }
.seg-btn { font-family: var(--font-disp); border: none; background: none; padding: 8px 12px; cursor: pointer; font-size: 14px; }
.seg-btn.active { background: var(--pink); color: #fff; }
.stepper { display: flex; align-items: center; gap: 10px; font-family: var(--font-num); font-size: 20px; }
.st-btn { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--ink); background: #fff;
  font-size: 20px; font-weight: 800; cursor: pointer; line-height: 1; }
.st-suffix { font-size: 15px; }
body:not(.is-host) .seg-btn, body:not(.is-host) .st-btn { pointer-events: none; opacity: .85; }

.hint { font-size: 13px; color: #9a8a76; margin-top: 8px; }
.hint.center { text-align: center; }
.setting-desc { font-size: 12.5px; color: #6a5c4a; line-height: 1.55; margin-top: 12px;
  background: #fff3e0; border: 2px solid rgba(0,0,0,.12); border-radius: 12px; padding: 10px 12px; }
.setting-desc b { color: var(--ink); }
.start-btn, .ready-btn { margin-top: 16px; }
.ready-btn.is-ready { background: var(--green); color: #06381f; }

/* 링크 입장 뷰 */
.join-room-badge { font-family: var(--font-disp); font-size: 20px; text-align: center;
  background: var(--ink); color: #fff; border-radius: 14px; padding: 10px; margin-bottom: 4px; }
.join-room-badge b { color: var(--green); font-family: var(--font-num); letter-spacing: 3px; }
#btn-back-home { align-self: center; }

/* 방장 안내 + 잠금 */
.notice { background: #fff3e0; border: 2px solid var(--ink); border-radius: 12px;
  padding: 10px 12px; font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.settings-body.locked { opacity: .7; pointer-events: none; filter: grayscale(.2); }

/* 참가자 태그 */
.ready-count { font-size: 13px; background: var(--ink); color: #fff; padding: 3px 10px; border-radius: 999px; }
.p-chip.me { border-color: var(--green); box-shadow: 0 0 0 2px rgba(55,214,122,.3), 0 3px 0 rgba(0,0,0,.2); }
.p-chip.ready { background: #e9fbef; }
.tag-host { font-size: 11px; background: var(--pink); color: #fff; padding: 1px 7px; border-radius: 999px; }
.tag-me { font-size: 11px; background: var(--green); color: #06381f; padding: 1px 7px; border-radius: 999px; }
.ready-badge { font-size: 14px; }

/* ===== 게임 화면 ===== */
#screen-game { background: #17161c; }
.game-topbar { position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 14px;
  background: rgba(23,22,28,.92); color: #fff; font-family: var(--font-disp); }
.game-status { font-size: 16px; flex: 1; }
.game-light { font-family: var(--font-disp); font-size: 17px; padding: 5px 14px; border-radius: 999px;
  border: 2px solid #fff; transition: background .15s, color .15s; }
.game-light.green { background: var(--green); color: #06381f; border-color: #06381f; }
.game-light.red { background: var(--pink); color: #fff; border-color: #fff; animation: lightpulse .5s ease-in-out infinite; }
@keyframes lightpulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.08)} }
.game-count { font-family: var(--font-num); font-size: 14px; color: var(--accent-2); text-align: right; }
#game-canvas { position: fixed; top: 52px; left: 0; width: 100vw; height: calc(100vh - 52px); display: block; }

/* 챈트 자막 */
.chant { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 6;
  font-family: var(--font-disp); font-size: clamp(16px, 4.5vw, 30px); letter-spacing: 2px;
  padding: 8px 22px; border-radius: 999px; white-space: nowrap; box-shadow: var(--shadow);
  border: 3px solid var(--ink); }
.chant.green { background: rgba(55,214,122,.95); color: #06381f; animation: chantbob 1.2s ease-in-out infinite; }
.chant.red { background: var(--pink); color: #fff; animation: shake .4s ease-in-out infinite; }
@keyframes chantbob { 0%,100%{transform:translateX(-50%) translateY(0)} 50%{transform:translateX(-50%) translateY(-4px)} }
@keyframes shake { 0%,100%{transform:translateX(-50%) rotate(-1deg)} 50%{transform:translateX(-50%) rotate(1deg)} }

/* 전진 홀드 버튼 */
.btn-move { position: fixed; right: 20px; bottom: 24px; z-index: 24; width: 128px; height: 128px;
  border-radius: 50%; border: 5px solid var(--ink); background: var(--green); color: #06381f;
  font-family: var(--font-disp); cursor: pointer; box-shadow: 0 8px 0 rgba(0,0,0,.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  touch-action: none; user-select: none; transition: transform .07s, box-shadow .07s, background .1s; }
.btn-move .move-ico { font-size: 40px; line-height: 1; }
.btn-move .move-txt { font-size: 14px; line-height: 1.1; text-align: center; }
.btn-move.pressing { transform: translateY(6px) scale(.97); box-shadow: 0 2px 0 rgba(0,0,0,.35); background: #29c06a; }

/* 방장 강제 종료 */
.btn-forceend { position: fixed; left: 16px; bottom: 24px; z-index: 24; font-family: var(--font-disp);
  font-size: 14px; color: #fff; background: rgba(23,22,28,.85); border: 3px solid var(--pink);
  border-radius: 999px; padding: 9px 16px; cursor: pointer; box-shadow: var(--shadow); }

.countdown { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45); }
.countdown span { font-family: var(--font-disp); font-size: 28vh; color: #fff;
  text-shadow: 6px 6px 0 var(--pink); animation: cd .95s ease-in-out; }
@keyframes cd { 0% { transform: scale(2.4); opacity: 0; } 40% { transform: scale(1); opacity: 1; } 100% { transform: scale(.4); opacity: 0; } }

/* 결과 */
.result-modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.62); padding: 20px; }
.result-card { position: relative; background: var(--cream); border: var(--border); border-radius: 26px;
  box-shadow: var(--shadow-lg); padding: 26px 24px; width: min(460px, 100%); text-align: center; overflow: hidden;
  animation: pop .3s ease; max-height: 92vh; display: flex; flex-direction: column; }
.trophy { font-size: 62px; animation: peek 2.4s ease-in-out infinite; }
.result-title { font-family: var(--font-disp); font-size: 30px; margin: 4px 0 16px; color: var(--pink); letter-spacing: .5px; }

.penalty-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; max-height: 32vh; overflow-y: auto; }
.penalty-head { font-family: var(--font-disp); font-size: 15px; color: var(--pink-d); text-align: left; }
.penalty-item { display: flex; align-items: center; gap: 12px; background: #fff; border: 3px solid var(--pink);
  border-radius: 16px; padding: 12px 16px; box-shadow: 0 4px 0 rgba(224,50,106,.25); }
.penalty-item.me { background: #ffeaf1; box-shadow: 0 0 0 2px rgba(255,77,132,.4), 0 4px 0 rgba(224,50,106,.25); }
.penalty-item .p-ice { font-size: 26px; }
.penalty-item .p-emoji { font-size: 24px; }
.penalty-item .p-name { font-family: var(--font-disp); font-size: 21px; }
.penalty-item .tag-me { margin-left: auto; }

.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.safe-rank { margin: 4px 0 14px; text-align: left; border-top: 2px dashed rgba(0,0,0,.2); padding-top: 12px;
  max-height: 30vh; overflow-y: auto; }
.sr-title { font-family: var(--font-disp); display: block; margin-bottom: 6px; color: var(--green-d); }
.sr-none { color: #9a8a76; font-size: 14px; padding: 6px 4px; }
.sr-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; font-size: 15px; }
.sr-row.me { background: #e9fbef; border-radius: 8px; font-weight: 700; }
.sr-row .sr-no { font-family: var(--font-num); font-weight: 700; width: 34px; color: var(--green-d); }
.sr-row .sr-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 31; overflow: hidden; }
.confetti i { position: absolute; width: 10px; height: 14px; top: -20px; opacity: .9;
  animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(120vh) rotate(720deg); } }

/* 토스트 */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 700;
  box-shadow: var(--shadow); animation: pop .2s ease; border: 2px solid var(--pink); max-width: 90vw; text-align: center; }

/* ===== 채팅 ===== */
.chat { position: fixed; left: 12px; bottom: 12px; z-index: 25; width: 280px; max-width: calc(100vw - 24px);
  background: rgba(253,246,238,.7); border: 3px solid rgba(23,22,28,.8); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden; font-family: var(--font-body);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.chat-head { background: rgba(23,22,28,.9); color: #fff; font-family: var(--font-disp); padding: 6px 12px;
  cursor: grab; font-size: 15px; display: flex; justify-content: space-between; align-items: center;
  touch-action: none; user-select: none; }
.chat-head:active { cursor: grabbing; }
.chat.collapsed .chat-body { display: none; }
.chat-log { height: 150px; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column;
  gap: 4px; font-size: 13px; }
.chat-msg { line-height: 1.35; word-break: break-word; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 2px solid rgba(0,0,0,.1); }
.chat-form input { flex: 1; min-width: 0; border: 2px solid var(--ink); border-radius: 10px;
  padding: 7px 10px; font-size: 14px; font-family: var(--font-body); outline: none; }
.chat-form input:focus { border-color: var(--pink); }
.chat-send { border: 2px solid var(--ink); background: var(--green); border-radius: 10px;
  padding: 0 12px; font-family: var(--font-disp); cursor: pointer; font-size: 13px; }

/* 게임 중엔 채팅이 홀드 버튼과 안 겹치게 살짝 위로 */
#screen-game.active ~ #chat { bottom: 12px; }
