/* 마피아게임 — 숲속 마을의 비밀 */
/* 학생(태블릿/폰)과 선생님(프로젝터) 화면 공용 스타일 */

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

:root {
  --card: #ffffff;
  --ink: #2d2a26;
  --sub: #8a8378;
  --line: #eee7db;
  --accent: #ff8c42;      /* 낮 주황 */
  --accent2: #7c5cff;     /* 보라 포인트 */
  --good: #34a853;
  --bad: #e5484d;
  --night-ink: #eaf0ff;
  --night-sub: #93a0c4;
  --night-card: #1b2447;
  --night-line: #2c3763;
}

html, body { height: 100%; }

body {
  font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #fff7e8 0%, #ffeccc 100%);
  transition: background 0.8s ease;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ── 단계별 배경 테마 ── */
body.ph-night, body.ph-reveal {
  background: linear-gradient(180deg, #0b1130 0%, #1a2350 100%);
  color: var(--night-ink);
}
body.ph-dawn {
  background: linear-gradient(180deg, #2c2a5e 0%, #ff9d6c 130%);
  color: var(--night-ink);
}
body.ph-end {
  background: linear-gradient(180deg, #fff3d6 0%, #ffd9a8 100%);
}

/* 밤 하늘의 별 */
body.ph-night::before, body.ph-reveal::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(2px 2px at 20% 25%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70% 15%, #ffe9a8 50%, transparent 51%),
    radial-gradient(2px 2px at 85% 40%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40% 10%, #cfe0ff 50%, transparent 51%),
    radial-gradient(2px 2px at 10% 60%, #ffe9a8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 35%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 92% 70%, #cfe0ff 50%, transparent 51%);
  animation: twinkle 3s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }

#app { position: relative; z-index: 1; }

.wrap {
  max-width: 540px; margin: 0 auto;
  padding: 20px 16px 120px;
  text-align: center;
}
.host .wrap { max-width: 1080px; }

/* ── 공통 요소 ── */
h1 { font-size: 1.9em; margin: 12px 0 4px; letter-spacing: -1px; }
.sub { color: var(--sub); font-size: 1em; margin-bottom: 18px; }
body.ph-night .sub, body.ph-reveal .sub, body.ph-dawn .sub { color: var(--night-sub); }

.card {
  background: var(--card); color: var(--ink);
  border-radius: 20px;
  padding: 22px 18px;
  margin: 14px 0;
  box-shadow: 0 6px 24px rgba(60, 40, 10, 0.10);
  text-align: center;
}
body.ph-night .card, body.ph-reveal .card, body.ph-dawn .card {
  background: var(--night-card); color: var(--night-ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

.btn {
  display: inline-block;
  font-family: inherit;
  font-size: 1.15em; font-weight: 700;
  color: #fff; background: var(--accent);
  border: none; border-radius: 16px;
  padding: 15px 26px; margin: 6px 4px;
  min-height: 54px; min-width: 120px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  transition: transform 0.06s ease, filter 0.15s;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.btn:disabled { filter: grayscale(0.8) opacity(0.55); cursor: default; }
.btn.violet { background: var(--accent2); }
.btn.green { background: var(--good); }
.btn.red { background: var(--bad); }
.btn.ghost {
  background: transparent; color: inherit;
  border: 2px solid currentColor; box-shadow: none;
  opacity: 0.75;
}
.btn.big { font-size: 1.35em; padding: 18px 34px; width: 100%; }
.btn.small { font-size: 0.95em; min-height: 40px; padding: 9px 16px; min-width: 0; }

input[type=text], input[type=tel] {
  font-family: inherit; font-size: 1.3em; text-align: center;
  width: 100%; padding: 15px;
  border: 3px solid var(--line); border-radius: 16px;
  outline: none; background: #fffdf8; color: var(--ink);
}
input:focus { border-color: var(--accent); }

.err { color: var(--bad); font-weight: 700; margin: 10px 0; min-height: 1.2em; }

/* ── 플레이어 칩 ── */
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 14px 0; }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--card); color: var(--ink);
  border-radius: 16px; padding: 10px 8px 8px;
  min-width: 86px;
  box-shadow: 0 3px 10px rgba(60, 40, 10, 0.10);
  border: none; font-family: inherit; cursor: default;
  position: relative;
}
body.ph-night .chip, body.ph-reveal .chip, body.ph-dawn .chip {
  background: var(--night-card); color: var(--night-ink);
}
.chip .face { font-size: 2em; line-height: 1.1; }
.chip .nm { font-size: 0.95em; font-weight: 700; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .tag { font-size: 0.75em; color: var(--sub); }
.chip.dead { opacity: 0.45; filter: grayscale(1); }
.chip.dead .face::after { content: ' 👻'; }
.chip.off { outline: 2px dashed #d8b24a; }
.chip.kickable { cursor: pointer; }
.host .chip { min-width: 104px; }
.host .chip .face { font-size: 2.5em; }
.host .chip .nm { font-size: 1.1em; }

/* ── 대상 고르기 버튼 격자 ── */
.targets { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 16px 0; }
.tbtn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: inherit; font-weight: 700; font-size: 1em;
  background: var(--card); color: var(--ink);
  border: 3px solid transparent; border-radius: 18px;
  padding: 14px 10px; min-width: 96px; min-height: 88px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: transform 0.06s;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.tbtn:active { transform: scale(0.96); }
.tbtn .face { font-size: 2.2em; }
.tbtn.sel { border-color: var(--accent); background: #fff1e2; }
body.ph-night .tbtn { background: var(--night-card); color: var(--night-ink); }
body.ph-night .tbtn.sel { border-color: #ffd166; background: #2a3157; }

/* ── 직업 카드 (꾹 눌러 확인) ── */
.rolecard {
  width: 240px; height: 320px; margin: 18px auto;
  perspective: 900px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.rolecard .inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.3, 1.1);
}
.rolecard.peek .inner { transform: rotateY(180deg); }
.rolecard .side {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 22px;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 10px; padding: 18px;
}
.rolecard .back {
  background: repeating-linear-gradient(45deg, #5b43c9 0 14px, #6a52dd 14px 28px);
  color: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.rolecard .back .q { font-size: 3.2em; }
.rolecard .front {
  transform: rotateY(180deg);
  background: #fffdf4; color: var(--ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  border: 4px solid #ffd166;
}
.rolecard .front .re { font-size: 3.6em; }
.rolecard .front .rn { font-size: 1.6em; font-weight: 800; }
.rolecard .front .rd { font-size: 0.92em; color: #6b6355; line-height: 1.5; }

/* ── 타이머 ── */
.timer { margin: 10px auto 16px; max-width: 420px; }
.timer .tnum { font-size: 3em; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer .tnum.hurry { color: var(--bad); animation: pulse 1s infinite; }
.timer .tbar-wrap { height: 12px; border-radius: 8px; background: rgba(128, 128, 128, 0.25); overflow: hidden; margin-top: 6px; }
.timer .tbar { height: 100%; border-radius: 8px; background: var(--accent); transition: width 0.25s linear; }
.host .timer .tnum { font-size: 4.5em; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ── 발표(아침/투표 결과) ── */
.announce { font-size: 1.25em; line-height: 1.7; }
.announce .big { font-size: 1.6em; font-weight: 800; display: block; margin: 8px 0; }
.host .announce { font-size: 1.6em; }
.pop { animation: popin 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes popin { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── 투표 현황 막대 ── */
.bars { text-align: left; max-width: 560px; margin: 10px auto; }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-row .who { width: 130px; text-align: right; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .track { flex: 1; height: 26px; background: rgba(128, 128, 128, 0.18); border-radius: 8px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent2); border-radius: 8px; transition: width 0.3s; min-width: 2px; }
.bar-row .cnt { width: 44px; font-weight: 800; font-size: 1.2em; }

/* ── 표 (투표 상세, 최종 직업 공개) ── */
table.list { width: 100%; max-width: 560px; margin: 10px auto; border-collapse: collapse; font-size: 1.05em; }
table.list td { padding: 7px 8px; border-bottom: 1px solid rgba(128, 128, 128, 0.25); }
.host table.list { font-size: 1.25em; }

/* ── 상단 고정 배너들 ── */
#banner { position: fixed; top: 0; left: 0; right: 0; z-index: 50; text-align: center; }
#banner .msg {
  display: block; padding: 10px; font-weight: 700; color: #fff;
}
#banner .conn { background: var(--bad); }
#banner .ghost-msg { background: #5b6478; }
#banner .watch-msg { background: var(--accent2); }

/* ── 선생님 하단 조작줄 ── */
.controlbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap;
  padding: 12px 14px;
  background: rgba(20, 20, 30, 0.82);
  backdrop-filter: blur(6px);
}
.controlbar .btn { margin: 0; }

/* 방장(학생) 하단 바 — 감독 바보다 얇게, 살짝 다른 색 */
.ownerbar { padding: 9px 12px; background: rgba(60, 40, 90, 0.9); gap: 8px; }
.ownerbar .obtag { color: #ffe9a8; font-size: 1.3em; }

/* ── 접속 주소 안내 (감독/방장) ── */
.addr {
  font-size: 2em; font-weight: 800; letter-spacing: 0.5px;
  background: #2d2a26; color: #ffe9a8;
  padding: 16px 20px; border-radius: 16px;
  display: inline-block; margin: 8px 0;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* ── 방 태그(상단 작은 라벨) + 큰 방 번호 ── */
.roomtag {
  display: inline-block; margin: 4px 0 2px;
  font-size: 1.05em; font-weight: 700; opacity: 0.9;
}
.roomtag b { color: var(--accent2); font-variant-numeric: tabular-nums; }
body.ph-night .roomtag b, body.ph-reveal .roomtag b, body.ph-dawn .roomtag b { color: #ffd166; }
.bigcode { font-size: 1.5em; letter-spacing: 2px; }

/* ── 감독: 방 목록 격자 ── */
.roomgrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin: 16px 0;
}
.roomcard {
  background: var(--card); color: var(--ink);
  border-radius: 18px; padding: 16px 12px;
  box-shadow: 0 4px 16px rgba(60, 40, 10, 0.12);
  cursor: pointer; border: 3px solid transparent;
  transition: transform 0.08s, border-color 0.15s;
  text-align: center;
}
.roomcard:active { transform: scale(0.97); }
.roomcard:hover { border-color: var(--accent2); }
.rc-code {
  font-size: 2.2em; font-weight: 800; letter-spacing: 2px;
  color: var(--accent2); font-variant-numeric: tabular-nums;
}
.rc-info { font-size: 0.95em; font-weight: 700; margin: 4px 0 2px; }
.rc-owner { font-size: 0.85em; color: var(--sub); }

/* ── 설정 패널 ── */
.settings { text-align: left; max-width: 560px; margin: 0 auto; }
.set-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
  font-size: 1.05em; gap: 10px;
}
.set-row label { font-weight: 700; }
.set-row select {
  font-family: inherit; font-size: 1em; padding: 8px 10px;
  border-radius: 10px; border: 2px solid var(--line); background: #fff;
}
.set-row .hint { font-size: 0.82em; color: var(--sub); font-weight: 400; display: block; }

/* 켜기/끄기 토글 */
.toggle { position: relative; display: inline-block; width: 58px; height: 32px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .knob {
  position: absolute; inset: 0; border-radius: 32px;
  background: #ccc; transition: 0.2s; cursor: pointer;
}
.toggle .knob::before {
  content: ''; position: absolute; width: 24px; height: 24px;
  left: 4px; top: 4px; border-radius: 50%; background: #fff; transition: 0.2s;
}
.toggle input:checked + .knob { background: var(--good); }
.toggle input:checked + .knob::before { transform: translateX(26px); }

/* ── 별똥별 이펙트: 하늘의 별이 되어 사라질 때 ── */
.sstar {
  position: fixed; left: 50%; top: 42%; z-index: 70;
  pointer-events: none;
  animation: sstar-fly 2.4s cubic-bezier(0.5, 0, 0.75, 0.35) forwards;
}
.sstar .body {
  display: block; font-size: 3.6em;
  filter: drop-shadow(0 0 14px rgba(255, 235, 150, 0.95));
  animation: sstar-pop 2.4s ease forwards;
}
.sstar .trail {
  position: absolute; top: 50%; right: 50%;
  width: 150px; height: 5px; border-radius: 5px;
  background: linear-gradient(to left, rgba(255, 240, 170, 0.95), rgba(255, 240, 170, 0));
  transform-origin: right center;
  opacity: 0;
  animation: sstar-trail 2.4s ease forwards;
}
@keyframes sstar-fly {
  0%, 38% { transform: translate(-50%, -50%); }
  100% { transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))); }
}
@keyframes sstar-pop {
  0% { transform: scale(0.1); opacity: 0; }
  16% { transform: scale(1.6); opacity: 1; }
  32% { transform: scale(1.15); }
  88% { opacity: 1; }
  100% { transform: scale(0.4); opacity: 0; }
}
@keyframes sstar-trail {
  0%, 36% { opacity: 0; }
  55% { opacity: 1; }
  100% { opacity: 0; }
}

/* ── 내 직업 몰래 보기 (꾹 누르는 동안만) ── */
.minirole {
  display: inline-block; margin: 10px auto;
  padding: 12px 18px; border-radius: 14px;
  background: rgba(124, 92, 255, 0.18);
  border: 2px dashed var(--accent2);
  font-weight: 700; cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.minirole .secret { display: none; }
.minirole.peek .secret { display: inline; }

/* ── 기타 ── */
.moon { font-size: 4em; display: block; margin: 6px 0; }
.zzz { animation: floaty 2.5s ease-in-out infinite; display: inline-block; }
@keyframes floaty { 50% { transform: translateY(-8px); } }
.winbanner { font-size: 2.2em; font-weight: 800; margin: 14px 0; }
.host .winbanner { font-size: 3.4em; }
.mini { font-size: 0.85em; color: var(--sub); }
body.ph-night .mini, body.ph-reveal .mini, body.ph-dawn .mini { color: var(--night-sub); }
.spacer { height: 10px; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #2d2a26; color: #fff; padding: 12px 22px; border-radius: 14px;
  font-weight: 700; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  animation: popin 0.3s;
}

@media (max-width: 420px) {
  h1 { font-size: 1.55em; }
  .tbtn { min-width: 84px; }
  .addr { font-size: 1.3em; }
}
