:root {
  --bg: #0d1424;
  --panel: rgba(14, 22, 40, 0.86);
  --line: rgba(217, 178, 90, 0.35);
  --gold: #d9b25a;
  --gold-hi: #f1d28a;
  --text: #efe6d2;
  --dim: #a9a28f;
  --reform: #30c191;
  --empire: #fecb44;
  --noble: #f04b4a;
  --danger: #c8443f;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg) url('/img/bg.webp') center / cover fixed;
  color: var(--text);
  font-family: 'Noto Serif KR', 'Nanum Myeongjo', 'Apple SD Gothic Neo', 'Malgun Gothic', serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--gold); }
button:disabled { cursor: default; opacity: 0.55; }
button.gold { background: linear-gradient(#e7c574, #b48a3a); color: #1b1408; border-color: #f1d28a; font-weight: 700; }
button.danger { background: var(--danger); border-color: #ef8a84; font-weight: 700; }
button.ghost { background: transparent; }
button.small { padding: 3px 8px; font-size: 13px; }
button.on { border-color: var(--gold-hi); background: rgba(217, 178, 90, 0.25); }
input {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
h2, h3 { margin: 0 0 8px; color: var(--gold-hi); font-weight: 700; }
h3 { font-size: 15px; }
.hint { color: var(--dim); font-size: 13px; margin: 6px 0; }
.err { color: #ff9b8f; }
.center { text-align: center; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.badge { font-size: 11px; border: 1px solid var(--gold); color: var(--gold-hi); border-radius: 99px; padding: 0 7px; margin-left: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.on { background: #5bd17f; }
.dot.off { background: #666; }

/* 머리 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 16px; background: rgba(5, 9, 18, 0.7); border-bottom: 1px solid var(--line); }
.top .logo { height: 40px; }
.roomcode { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.roomcode b { letter-spacing: 2px; font-size: 16px; color: var(--gold-hi); }

/* 첫 화면 */
.home { max-width: 420px; margin: 0 auto; padding: 24px 16px; text-align: center; }
.biglogo { width: min(320px, 80vw); }
.tag { color: var(--dim); margin: 0 0 16px; }
.home .panel { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.home label { font-size: 13px; color: var(--dim); }
.or { text-align: center; color: var(--dim); font-size: 12px; margin: 6px 0; }

/* 배치 */
.layout { display: grid; gap: 12px; padding: 12px 16px 24px; max-width: 1280px; margin: 0 auto; }
.layout.ingame { grid-template-columns: 1fr; }
@media (min-width: 980px) {
  .layout { grid-template-columns: 1fr 320px; align-items: start; }
  .chat { position: sticky; top: 12px; }
}
.lobby { display: flex; flex-direction: column; gap: 10px; }
.seats { margin: 0; padding-left: 22px; }
.seats li { padding: 4px 0; }
.seats li.me { color: var(--gold-hi); }
.botx { margin-left: 8px; }

/* 채팅 */
.chat { display: flex; flex-direction: column; }
.chatlog { list-style: none; margin: 0 0 8px; padding: 0; height: 160px; overflow-y: auto; font-size: 14px; }
@media (min-width: 980px) { .chatlog { height: 60vh; } }
.chatlog li { padding: 2px 0; word-break: break-word; }
.chatlog li b { color: var(--gold); }
.chatlog li.me b { color: var(--gold-hi); }
.chatform { display: flex; gap: 6px; }
.chatform button { white-space: nowrap; }

/* 게임 */
.game { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.pl { text-align: left; background: var(--panel); padding: 8px 10px; border-radius: 10px; opacity: 1; }
.pl:disabled { opacity: 1; }
.pl.turn { border-color: var(--gold-hi); box-shadow: 0 0 0 2px rgba(241, 210, 138, 0.45); }
.pl.me .pname { color: var(--gold-hi); }
.pl.fixed { opacity: 0.8; }
.pl.pickable { border-style: dashed; border-color: var(--gold-hi); }
.pl.picked { background: rgba(217, 178, 90, 0.3); }
.pl.win { border-color: #5bd17f; box-shadow: 0 0 0 2px rgba(91, 209, 127, 0.5); }
.pname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backs { display: flex; align-items: center; gap: 2px; font-size: 12px; color: var(--dim); margin-top: 4px; }
.backs span { margin-left: 6px; }
.mini { display: inline-block; width: 11px; height: 16px; border-radius: 2px; background: url('/img/back.webp') center / cover; border: 1px solid rgba(0, 0, 0, 0.4); }
.toks { display: flex; gap: 2px; margin-top: 4px; min-height: 22px; }
.tok { width: 22px; height: 22px; }
.final { display: flex; align-items: center; gap: 6px; margin-top: 4px; }

.card { display: block; border-radius: 6px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
.card.tiny { width: 34px; }
.card.slotcard { width: 86px; }
.card.mid { width: 110px; }
.card.hand { width: 100%; }

.board {
  background: linear-gradient(rgba(8, 12, 22, 0.35), rgba(8, 12, 22, 0.55)), url('/img/board.webp') center / cover;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.zonehead, .pilehead { font-size: 13px; color: var(--gold-hi); margin-bottom: 6px; text-shadow: 0 1px 2px #000; }
.slots { display: flex; gap: 12px; justify-content: center; }
.slot { position: relative; padding: 4px; background: rgba(0, 0, 0, 0.3); border-radius: 10px; }
.slot:disabled { opacity: 1; }
.slot.picked { border-color: var(--gold-hi); box-shadow: 0 0 0 3px rgba(241, 210, 138, 0.6); }
.slot.lit { box-shadow: 0 0 0 3px rgba(200, 68, 63, 0.7); }
.slotno { position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); font-size: 11px; background: #000a; padding: 0 6px; border-radius: 99px; }
.piles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pile { background: rgba(0, 0, 0, 0.35); border-radius: 10px; padding: 8px; min-width: 0; }
.pilecards { display: flex; flex-wrap: wrap; gap: 4px; min-height: 52px; }
.pc { padding: 2px; border-radius: 6px; display: flex; flex-direction: column; align-items: center; font-size: 10px; background: transparent; }
.pc:disabled { opacity: 1; }
.pc.picked { border-color: var(--gold-hi); background: rgba(217, 178, 90, 0.35); }
.pilenote { margin: 0; font-size: 11px; color: var(--dim); text-shadow: 0 1px 2px #000; }

.action { display: flex; flex-direction: column; gap: 10px; border-color: var(--gold); }
.action .big { font-size: 16px; margin: 0; }
.timer { font-variant-numeric: tabular-nums; color: var(--gold-hi); margin-left: 6px; }
.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rolebtn { border-left-width: 4px; text-align: left; font-size: 14px; }
.rolebtn.f-reform { border-left-color: var(--reform); }
.rolebtn.f-empire { border-left-color: var(--empire); }
.rolebtn.f-noble { border-left-color: var(--noble); }
.compare { display: flex; gap: 14px; }
.compare figure { margin: 0; text-align: center; font-size: 13px; }

.hand .cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; max-width: 620px; }
.hcard { padding: 3px; border-radius: 9px; background: transparent; transition: transform 0.12s; }
.hcard:disabled { opacity: 1; }
.hcard.picked { transform: translateY(-8px); border-color: var(--gold-hi); box-shadow: 0 0 0 3px rgba(241, 210, 138, 0.7); }
.infront { font-size: 13px; color: var(--dim); margin-bottom: 6px; }

.logs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .logs { grid-template-columns: 1fr; } .roles { grid-template-columns: repeat(2, 1fr); } }
.notes, .log { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; font-size: 13px; }
.notes li, .log li { padding: 2px 0; border-bottom: 1px dotted rgba(255, 255, 255, 0.06); }
.notes li { color: var(--gold-hi); }
time { color: var(--dim); font-size: 11px; }

#flash {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px);
  background: #2a1b12; border: 1px solid var(--gold); padding: 10px 16px; border-radius: 10px;
  opacity: 0; transition: 0.2s; pointer-events: none; z-index: 10; max-width: 90vw;
}
#flash.show { opacity: 1; transform: translate(-50%, 0); }

/* 규칙서 */
.rulesbtn { margin-right: auto; margin-left: 4px; }
#rules { position: fixed; inset: 0; z-index: 20; background: rgba(4, 7, 14, 0.94); display: flex; flex-direction: column; }
.rbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #0b1120; }
.rbar b { color: var(--gold-hi); white-space: nowrap; }
.rtoc { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.rtoc button { white-space: nowrap; }
.rscroll { overflow-y: auto; flex: 1; padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.rpage { width: min(800px, 100%); height: auto; aspect-ratio: 800 / 1134; border-radius: 4px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6); }

/* 3D 탁자 */
.board3d { display: flex; flex-direction: column; gap: 8px; }
.stage3d { position: relative; width: 100%; height: min(62vh, 112vw); min-height: 320px; max-height: 760px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: #070a12; touch-action: manipulation; }
@media (min-width: 980px) { .stage3d { height: 70vh; } }
.scene3d { display: block; width: 100%; height: 100%; }
.board3d .piles { grid-template-columns: 1fr 1fr; }
.board3d .pile { background: var(--panel); border: 1px solid var(--line); }
.board3d .pilecards { min-height: 0; }

.top button, .roomcode span, .roomcode b { white-space: nowrap; }
@media (max-width: 420px) { .top { padding: 8px 10px; gap: 6px; } .top .logo { height: 34px; } .roomcode { gap: 4px; font-size: 12px; } .roomcode b { font-size: 14px; letter-spacing: 1px; } }
