:root {
  --wood: #3b2314;
  --wood2: #5a361e;
  --gold: #f2cf72;
  --paper: #fbf3e2;
  --ink: #2a1a0a;
  --red: #c62828;
  --green: #2e7d32;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #24170f; color: var(--ink); overscroll-behavior: none; }
button, input { font: inherit; }
button { cursor: pointer; border: 0; }
.hidden { display: none !important; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ── 화면과 패널 ── */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.panel {
  background: var(--paper); border-radius: 20px; padding: 24px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45), inset 0 0 0 3px rgba(122, 46, 29, .15);
  width: 100%;
}
.panel.narrow { max-width: 380px; }
.panel.center { text-align: center; }
h1 { margin: 6px 0 4px; font-size: 34px; text-align: center; letter-spacing: 4px; color: var(--wood); font-family: "Nanum Myeongjo", "Batang", serif; }
h2 { margin: 0 0 12px; font-size: 22px; color: var(--wood); }
.sub { text-align: center; margin: 0 0 18px; color: #7a5a3a; font-size: 14px; }
.logo { display: flex; justify-content: center; gap: 4px; }
.logo .st { width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 2px 3px rgba(0, 0, 0, .4); }
.st.b { background: radial-gradient(circle at 35% 30%, #555, #111 60%); }
.st.w { background: radial-gradient(circle at 35% 30%, #fff, #ddd 70%); }

form { display: flex; flex-direction: column; gap: 10px; }
input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 2px solid #e2cfae; background: #fff;
  font-size: 16px; outline: none;
}
input:focus { border-color: #c99a3c; }
input:disabled { background: #f1e8d6; color: #7a5a3a; }
.msg { min-height: 18px; margin: 0; color: var(--red); font-size: 13px; }
.primary {
  padding: 13px 18px; border-radius: 12px; background: linear-gradient(#8e2430, #6d1a24); color: #fff;
  font-weight: 700; font-size: 16px; box-shadow: 0 3px 0 #4a1018;
}
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #4a1018; }
.primary:disabled { background: #a99; box-shadow: none; }
.ghost { padding: 13px 18px; border-radius: 12px; background: #eadbc0; color: var(--wood); font-weight: 700; font-size: 16px; }
.link { background: none; color: #7a2e1d; text-decoration: underline; font-size: 14px; padding: 6px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row.small > * { flex: none; }

/* ── 캐릭터 꾸미기 ── */
#make { align-items: flex-end; justify-content: center; pointer-events: none; }
#make .panel { pointer-events: auto; max-width: 440px; padding: 18px; max-height: 62vh; overflow-y: auto; }
@media (orientation: landscape) {
  #make { justify-content: flex-end; align-items: center; padding-right: 5vw; }
  #make .panel { max-height: 92vh; }
}
.pick { margin-bottom: 12px; }
.pick label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; color: var(--wood2); }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.swatches button {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid rgba(0, 0, 0, .12);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18); transition: transform .1s;
}
.swatches button.on { border-color: var(--wood); transform: scale(1.12); box-shadow: 0 0 0 3px var(--gold); }

/* ── HUD 공통 ── */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud > *, .hud button { pointer-events: auto; }
.hud.seated .reacts, .hud.seated .joy, .hud.seated .hint, .hud.seated .corner.tl { display: none !important; }
.corner { position: absolute; display: flex; flex-direction: column; gap: 8px; }
.tl { top: max(12px, env(safe-area-inset-top)); left: 12px; }
.tr { top: max(12px, env(safe-area-inset-top)); right: 12px; align-items: flex-end; }
.br { bottom: max(16px, env(safe-area-inset-bottom)); right: 14px; }
.chip {
  background: rgba(30, 18, 10, .72); color: #fff; padding: 8px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600; backdrop-filter: blur(4px);
}
.chip.static { pointer-events: none; }
.me-card {
  background: rgba(251, 243, 226, .94); padding: 8px 14px; border-radius: 14px; display: flex; gap: 10px; align-items: baseline;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
}
.me-card b { font-size: 16px; color: var(--wood); }
.me-card span { font-size: 13px; color: #7a5a3a; }
.hint {
  position: absolute; top: 90px; left: 50%; transform: translateX(-50%); width: min(92vw, 420px);
  background: rgba(30, 18, 10, .78); color: #fff; padding: 10px 14px; border-radius: 12px;
  font-size: 13px; text-align: center; line-height: 1.5; pointer-events: none; transition: opacity .6s;
}
.hint b { color: #a5d6a7; }
.reacts { flex-direction: row; gap: 10px; }
.react {
  width: 66px; height: 66px; border-radius: 50%; background: rgba(251, 243, 226, .94); color: var(--wood);
  font-size: 12px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .35);
}
.react span { font-size: 26px; line-height: 1.1; }
.react:active { transform: scale(.92); }

.joy {
  position: absolute; left: 22px; bottom: max(22px, env(safe-area-inset-bottom)); width: 128px; height: 128px; border-radius: 50%;
  background: rgba(255, 255, 255, .14); border: 2px solid rgba(255, 255, 255, .3); touch-action: none;
}
.joy .knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%;
  background: rgba(251, 243, 226, .85); box-shadow: 0 3px 8px rgba(0, 0, 0, .4);
}

/* ── 대국 HUD ── */
.leave { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; }
.card {
  position: absolute; width: min(34vw, 200px); background: rgba(251, 243, 226, .94); border-radius: 14px; padding: 8px 12px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35); border: 3px solid transparent; transition: border-color .2s, transform .2s;
}
.card.opp { top: max(12px, env(safe-area-inset-top)); right: 12px; }
.card.me { bottom: max(14px, env(safe-area-inset-bottom)); left: 12px; }
.card.turn { border-color: #ffb300; transform: scale(1.04); }
.card.empty { opacity: .5; }
.who { display: flex; align-items: center; gap: 8px; }
.who b { font-size: 15px; color: var(--wood); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stone { width: 18px; height: 18px; border-radius: 50%; flex: none; background: #ccc; }
.stone.black { background: radial-gradient(circle at 35% 30%, #666, #111 60%); }
.stone.white { background: radial-gradient(circle at 35% 30%, #fff, #d8d8d8 70%); border: 1px solid #aaa; }
.timer { position: relative; height: 16px; margin-top: 6px; background: #e8dcc4; border-radius: 8px; overflow: hidden; }
.timer .bar { position: absolute; inset: 0; width: 0; background: linear-gradient(90deg, #43a047, #9ccc65); border-radius: 8px; }
.timer .bar.low { background: linear-gradient(90deg, #e53935, #ff7043); }
.timer .sec { position: absolute; right: 6px; top: 0; font-size: 11px; line-height: 16px; font-weight: 700; color: var(--ink); }
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(30, 18, 10, .82); color: #fff;
  padding: 16px 26px; border-radius: 16px; font-size: 17px; font-weight: 700; text-align: center; pointer-events: none;
}
.dots { display: flex; justify-content: center; gap: 6px; margin-bottom: 8px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); animation: bounce 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-7px); opacity: 1; } }
.turn-toast {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(30, 18, 10, .85); color: var(--gold);
  padding: 12px 22px; border-radius: 14px; font-size: 18px; font-weight: 800; pointer-events: none; animation: fade 1.6s forwards;
}
@keyframes fade { 0% { opacity: 0; transform: translate(-50%, -40%); } 15%, 75% { opacity: 1; transform: translate(-50%, -50%); } 100% { opacity: 0; } }

/* ── 팝업, 알림 ── */
.popup { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.popup h2 { font-size: 30px; margin-bottom: 6px; }
.popup h2.win { color: #b8860b; }
.popup h2.lose { color: #455a64; }
.popup p { margin: 0 0 8px; color: #5a3d22; }
.popup .note { color: var(--green); font-weight: 700; min-height: 20px; }
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(20, 12, 6, .9); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; pointer-events: none; white-space: nowrap;
}
.conn {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(20, 12, 6, .9); color: #fff;
  padding: 14px 22px; border-radius: 14px;
}
/* 가로 화면에서는 돌 통이 왼쪽 아래, 오른쪽 위에 오므로 이름 카드를 반대 구석으로 옮긴다 */
@media (orientation: landscape) {
  .card.me { top: calc(max(12px, env(safe-area-inset-top)) + 46px); bottom: auto; left: 12px; }
  .card.opp { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); right: 12px; }
}

/* ── 모닥불 메뉴 ── */
.camp-title {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  color: #ffd9a0; font-weight: 800; font-size: 16px; text-shadow: 0 2px 6px rgba(0, 0, 0, .7); pointer-events: none;
}
.camp-menu {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 10px;
}
.camp-act {
  width: 96px; height: 96px; border-radius: 22px; background: rgba(30, 18, 10, .78); color: #fff4e0;
  font-size: 13px; font-weight: 700; line-height: 1.25; border: 2px solid rgba(255, 180, 90, .55);
  box-shadow: 0 0 18px rgba(255, 140, 50, .25); backdrop-filter: blur(4px);
}
.camp-act .ic { display: block; font-size: 30px; margin-bottom: 2px; }
.camp-act:active { transform: scale(.94); }
.camp-act:disabled { opacity: .45; }

/* ── 10초 시계 (화면 위 가운데) ── */
.clock {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: 76px; display: flex; flex-direction: column; align-items: center; pointer-events: none;
}
.clock svg { width: 64px; height: 64px; transform: rotate(-90deg); filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .5)); }
.clock circle { fill: rgba(30, 18, 10, .82); stroke-width: 6; }
.clock .bg { stroke: rgba(255, 255, 255, .15); }
.clock .ring { fill: none; stroke: #9ccc65; stroke-linecap: round; stroke-dasharray: 163.36; transition: stroke .2s; }
.clock.mine .ring { stroke: #ffca28; }
.clock.low .ring { stroke: #ef5350; }
.clock b { position: absolute; top: 0; height: 64px; line-height: 64px; font-size: 28px; font-weight: 900; color: #fff; }
.clock.low b { color: #ff8a80; animation: beat .5s infinite alternate; }
.clock span {
  margin-top: 4px; font-size: 12px; font-weight: 800; color: #fff; background: rgba(30, 18, 10, .78); padding: 2px 8px; border-radius: 999px;
  white-space: nowrap;
}
.clock.mine span { color: #ffd54f; }
@keyframes beat { to { transform: scale(1.15); } }

/* ── WIN / LOSE ── */
.result {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle, rgba(0, 0, 0, .35), rgba(0, 0, 0, .7)); overflow: hidden;
}
.result.lose { background: radial-gradient(circle, rgba(20, 25, 40, .5), rgba(5, 8, 15, .85)); }
.res-box { text-align: center; position: relative; animation: popin .45s cubic-bezier(.2, 1.6, .4, 1); }
.result .big {
  font-size: min(30vw, 150px); font-weight: 900; letter-spacing: 6px; line-height: 1; font-family: "Arial Black", Impact, sans-serif;
}
.result.win .big {
  color: #ffd54f; text-shadow: 0 0 30px rgba(255, 193, 7, .8), 0 6px 0 #b8860b, 0 10px 20px rgba(0, 0, 0, .6);
  animation: glow 1.2s ease-in-out infinite alternate;
}
.result.lose .big { color: #90a4ae; text-shadow: 0 6px 0 #37474f, 0 10px 20px rgba(0, 0, 0, .6); }
.result.draw .big { color: #e0e0e0; text-shadow: 0 6px 0 #616161; }
.result p { color: #fff; margin: 14px 0 6px; font-size: 16px; text-shadow: 0 2px 4px rgba(0, 0, 0, .7); }
.result .note { color: #a5d6a7; font-weight: 700; min-height: 22px; margin: 0 0 12px; }
.result .row { max-width: 340px; margin: 0 auto; }
@keyframes popin { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes glow { to { text-shadow: 0 0 50px rgba(255, 213, 79, 1), 0 6px 0 #b8860b, 0 10px 20px rgba(0, 0, 0, .6); } }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* 남자 / 여자 고르기 */
.genders { display: flex; gap: 10px; }
.genders button {
  flex: 1; padding: 10px; border-radius: 14px; background: #fff; border: 3px solid #e2cfae;
  font-weight: 800; font-size: 15px; color: var(--wood); display: flex; align-items: center; justify-content: center; gap: 8px;
}
.genders button span { font-size: 26px; }
.genders button.on { border-color: var(--wood); background: #fff4d6; box-shadow: 0 0 0 3px var(--gold); }

/* 처음 온 사람에게 보이는 게임 이름 */
.brand { text-align: center; margin-bottom: 6px; }
.brand h1 { margin: 4px 0 2px; font-size: 28px; }
.brand .sub { margin: 0 0 6px; }
@media (orientation: portrait) {
  .brand .logo, .brand .sub { display: none; }
  .brand h1 { font-size: 22px; margin: 0; }
  #make-title { display: none; }
}

/* ── 게임 설명 ── */
.intro {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(20, 12, 6, .72); backdrop-filter: blur(3px); z-index: 20;
}
.intro-box { max-width: 460px; max-height: 92vh; overflow-y: auto; text-align: center; animation: popin .4s cubic-bezier(.2, 1.4, .4, 1); }
.intro-box h2 { margin: 10px 0 14px; font-size: 21px; }
.intro-steps { list-style: none; margin: 0; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.intro-steps li { display: flex; gap: 12px; align-items: flex-start; background: #fff7e6; border: 2px solid #ecdcb8; border-radius: 14px; padding: 10px 12px; }
.intro-steps .ic { font-size: 30px; line-height: 1.1; flex: none; width: 38px; text-align: center; }
.intro-steps b { color: var(--wood); font-size: 15px; }
.intro-steps p { margin: 3px 0 0; font-size: 13px; line-height: 1.5; color: #5a3d22; }
.intro-tip { font-size: 12px; color: #8a6a48; margin: 12px 0; }
.intro-box .primary { width: 100%; }
