:root {
  --bg: #fff6e5;
  --ink: #2d2a3e;
  --muted: #7a7590;
  --card: #fffdf8;
  --line: #ecdfc6;
  --red: #ef5b5b;
  --red-d: #c43d3d;
  --red-bg: #ffe3e1;
  --blue: #3d8bfd;
  --blue-d: #2a69c9;
  --blue-bg: #dfeeff;
  --neutral: #e9dfca;
  --accent: #ffb703;
  --accent-d: #d68f00;
  --radius: 16px;
  --gutter: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  word-break: keep-all;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

#app { max-width: 560px; margin: 0 auto; padding: 0 var(--gutter) calc(var(--actions-h, 0px) + 40px + env(safe-area-inset-bottom)); min-height: 100dvh; }
.home { padding-bottom: 24px; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px;
  background: var(--card); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 800; cursor: pointer;
  transition: transform .06s, box-shadow .06s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.btn.small { min-height: 42px; padding: 6px 12px; font-size: .95rem; flex: 1; }
.btn.on { background: var(--ink); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; text-decoration: underline; width: 100%; color: var(--muted); }
.btn.red { background: var(--red); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }

/* 홈 */
.logo { text-align: center; padding: 36px 0 18px; }
.logo svg { width: 120px; height: 120px; }
.logo h1 { font-size: 2.4rem; letter-spacing: -1px; margin-top: 4px; }
.logo p { color: var(--muted); margin-top: 4px; font-weight: 600; }
.field { display: block; font-weight: 800; margin: 14px 0 12px; }
.field input, .join input {
  display: block; width: 100%; height: 52px; margin-top: 6px; padding: 0 14px;
  background: #fff; border: 2px solid var(--ink); border-radius: 14px; font-size: 1.05rem;
}
.or { text-align: center; color: var(--muted); font-size: .92rem; margin: 22px 0 10px; font-weight: 600; }
.join { display: flex; gap: 10px; }
.join input { margin: 0; text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 800; }
.join .btn { width: 110px; }
.home .btn.ghost { margin-top: 18px; }
.home footer { text-align: center; color: var(--muted); font-size: .88rem; margin-top: 18px; }
.home .btn.primary { margin-top: 4px; }

/* 상단 바 */
.top { display: flex; align-items: center; gap: 8px; padding: 12px 0 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top .code { flex: 1; text-align: center; font-weight: 700; color: var(--muted); font-size: .9rem; }
.top .code b { color: var(--ink); font-size: 1.15rem; letter-spacing: 3px; margin-left: 4px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--ink); background: var(--card); font-weight: 900; cursor: pointer; font-size: 1.1rem; }

/* 대기실 */
.share { margin: 6px 0 14px; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team { border: 2px solid var(--ink); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.team.red { background: var(--red-bg); }
.team.blue { background: var(--blue-bg); }
.team h2 { font-size: 1.15rem; }
.team.red h2 { color: var(--red-d); }
.team.blue h2 { color: var(--blue-d); }
.slot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 30px; }
.slot .label { font-size: .78rem; font-weight: 800; color: var(--muted); width: 100%; }
.slot em { color: var(--muted); font-size: .9rem; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: #fff; border: 2px solid var(--ink); font-weight: 700; font-size: .92rem; }
.pill.me { background: var(--accent); }
.pill.off { opacity: .45; }
.team .row { display: flex; gap: 6px; margin-top: auto; flex-direction: column; }
.spectators { margin-top: 12px; padding: 12px; border: 2px dashed var(--line); border-radius: var(--radius); }
.spectators h3 { font-size: .9rem; color: var(--muted); margin-bottom: 8px; }
.spectators .slot { margin-bottom: 8px; }
.start-area { margin-top: 18px; text-align: center; }
.start-area p { color: var(--muted); margin-top: 10px; font-size: .95rem; }
.warn { color: var(--red-d) !important; font-weight: 700; }

/* 게임 */
.scorebar { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.chip { flex: 1; text-align: center; padding: 8px 6px; border-radius: 12px; border: 2px solid var(--ink); font-weight: 800; line-height: 1.2; }
.chip small { display: block; font-size: .72rem; font-weight: 700; opacity: .85; }
.chip b { font-size: 1.5rem; }
.chip.red { background: var(--red); color: #fff; }
.chip.blue { background: var(--blue); color: #fff; }
.chip.turn-on { outline: 4px solid var(--accent); outline-offset: 1px; }
.turnbar { text-align: center; font-weight: 800; padding: 8px; border-radius: 12px; margin-bottom: 8px; border: 2px solid var(--ink); }
.turnbar.red { background: var(--red-bg); color: var(--red-d); }
.turnbar.blue { background: var(--blue-bg); color: var(--blue-d); }
.turnbar .clueword { font-size: 1.35rem; color: var(--ink); }
.log { font-size: .8rem; color: var(--muted); margin: 0 2px 8px; min-height: 2.4em; }
.log div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.card {
  position: relative; aspect-ratio: 1 / 0.82; min-width: 0;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 2px; background: var(--card); border: 2px solid var(--ink); border-radius: 10px;
  box-shadow: 0 3px 0 var(--ink);
  font-weight: 800; font-size: clamp(11px, 3.5vw, 16px); line-height: 1.15; cursor: pointer;
  overflow: hidden; overflow-wrap: break-word;
}
.card:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
/* 대장에게만 보이는 색 힌트 */
.card.hint.red { background: #fff1f0; border-color: var(--red); box-shadow: 0 3px 0 var(--red); color: var(--red-d); }
.card.hint.blue { background: #eef6ff; border-color: var(--blue); box-shadow: 0 3px 0 var(--blue); color: var(--blue-d); }
.card.hint.neutral { background: #f3ecdc; color: #8a7f66; }
.card.hint.assassin { background: var(--ink); color: #fff; }
/* 열린 카드 */
.card.rev { box-shadow: none; transform: translateY(3px); cursor: default; }
.card.rev.red { background: var(--red); color: #fff; border-color: var(--red-d); }
.card.rev.blue { background: var(--blue); color: #fff; border-color: var(--blue-d); }
.card.rev.neutral { background: var(--neutral); color: #8a7f66; border-color: #cbbf9f; }
.card.rev.assassin { background: var(--ink); color: #fff; }
.card.dim { opacity: .55; }
.card.sel { outline: 4px solid var(--accent); outline-offset: 1px; transform: translateY(-2px); }
.card .mk { position: absolute; top: 1px; right: 3px; font-size: .75rem; }

/* 하단 행동 바 */
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 2px solid var(--ink);
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
}
.actions .inner { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.actions .msg { text-align: center; font-weight: 700; }
.actions .msg.warn { color: var(--red-d); }
.actions .msg small { display: block; color: var(--muted); font-weight: 600; }
.actions .row { display: flex; gap: 10px; }
.clue-form input { width: 100%; height: 50px; padding: 0 14px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; font-size: 1.1rem; }
.nums { display: flex; gap: 4px; }
.nums button { flex: 1; height: 42px; border: 2px solid var(--ink); border-radius: 10px; background: #fff; font-weight: 900; cursor: pointer; }
.nums button.on { background: var(--accent); }

.result { text-align: center; }
.result h2 { font-size: 1.5rem; }
.result.red h2 { color: var(--red-d); }
.result.blue h2 { color: var(--blue-d); }
.result p { color: var(--muted); font-weight: 600; margin: 4px 0 10px; }

/* 팝업 */
.modal { position: fixed; inset: 0; background: rgba(45, 42, 62, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto; border-radius: 22px 22px 0 0; padding: 20px var(--gutter) calc(20px + env(safe-area-inset-bottom)); border: 2px solid var(--ink); border-bottom: 0; }
.modal h2 { margin-bottom: 10px; }
.modal ol { padding-left: 22px; margin: 0 0 12px; }
.modal li { margin-bottom: 8px; }
.modal .tip { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: .95rem; margin-bottom: 14px; }

.banner { position: fixed; top: 0; left: 0; right: 0; background: var(--ink); color: #fff; text-align: center; padding: 6px; font-size: .9rem; z-index: 100; }
.toast { position: fixed; left: 50%; bottom: 130px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 120; max-width: 90vw; text-align: center; font-weight: 700; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.center { text-align: center; padding-top: 80px; }
.center p { margin: 12px 0 20px; color: var(--muted); }

@media (min-width: 560px) {
  .card { font-size: 17px; }
}

.note { margin-top: 12px; padding: 10px 12px; background: #fff; border: 2px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: .88rem; line-height: 1.5; }

/* ----- 언어 ----- */
.homebar { display: flex; justify-content: flex-end; padding-top: 12px; }
.lang-btn { min-height: 40px; padding: 6px 14px; background: var(--card); border: 2px solid var(--ink); border-radius: 999px; font-weight: 800; font-size: .92rem; cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.lang-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.wordlang { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; padding: 8px 12px; background: var(--card); border: 2px solid var(--ink); border-radius: 14px; font-weight: 700; }
.wordlang .btn.small { flex: 0 0 auto; min-height: 38px; }
.lang-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 14px; }
.lang-item { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 48px; padding: 8px 14px; background: #fff; border: 2px solid var(--ink); border-radius: 12px; font-weight: 800; font-size: 1.02rem; cursor: pointer; text-align: start; }
.lang-item.on { background: var(--accent); }
.picker-note { color: var(--muted); font-size: .9rem; margin: 0 0 6px; }

/* 카드 판은 어느 언어에서도 같은 위치로 보이게 고정하고, 단어는 그 글자의 방향대로 그린다 */
.board { direction: ltr; }
.card .w { unicode-bidi: plaintext; max-width: 100%; }

/* 오른쪽에서 왼쪽으로 쓰는 언어(아랍어) */
[dir="rtl"] .top .code { text-align: center; }
[dir="rtl"] .slot { direction: rtl; }
[dir="rtl"] .actions .msg { direction: rtl; }

/* 긴 단어는 작게, 라틴 문자 언어는 하이픈으로 줄바꿈 */
.card .w { hyphens: auto; -webkit-hyphens: auto; }
.card.s .w { font-size: .8em; }
.card.xs .w { font-size: .66em; }

.clue-form input:disabled { background: #f3ecdc; color: var(--muted); border-color: var(--line); cursor: not-allowed; }

/* ----- 소리 메뉴 ----- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; font-weight: 800; font-size: 1.05rem; }
.switch { min-width: 92px; min-height: 46px; padding: 0 14px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; font-weight: 900; cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.switch.on { background: var(--accent); }
.switch:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
/* 위쪽 버튼이 늘어나서 조금 줄인다 */
.top { gap: 6px; }
.top .icon-btn { width: 40px; height: 40px; }


/* 초대: "보내기" 옆에 "복사" */
.share { display: flex; gap: 8px; }
.share .btn.big { width: auto; flex: 1; }
.share .btn.copy { flex: 0 0 auto; padding: 0 14px; background: var(--card); }
