:root {
  /* 맑은 하늘 톤. 색을 바꾸려면 이 묶음만 고치면 된다. */
  --bg: #e9f6ff;
  --panel: #ffffff;
  --line: #b3d8f2;
  --edge: #b3d8f2; /* 버튼·카드 아래에 깔리는 두께 */
  --text: #15344f;
  --muted: #5e7c94;
  --accent: #ffc531;
  --accent-text: #3b2800;
  --accent-edge: #db9d00;
  --money: #0b78c9; /* 밝은 바탕에서 읽히는 금액·강조 글자 */
  --danger: #e5484d;
  --danger-edge: #b4282d;
  --turn: #ffb300; /* 차례인 사람 표시 */
  --mine: #fff8dc;
  --tile: #ffffff;
  --tile-text: #15344f;
  --tile-special: #f1f9df;
  --tile-corner: #ffe27a;
  /* 보드는 여행 지도의 풀빛: 칸 사이로 보이는 판, 판의 옆면, 가운데 땅의 색 */
  --board-gap: #4c9f63;
  --board-side: #2f7a48;
  --land-light: #dcf3bb;
  --land-mid: #b7e4a1;
  --land-deep: #8ed39b;
  --shadow: rgba(21, 52, 79, 0.28);
  /* 보드는 한 변에 11칸(모서리 포함)이다. */
  --board-size: min(100vw, calc(100dvh - 292px), 620px);
  --die: calc(var(--board-size) * 0.105);
  --slab: 12px; /* 보드 아래로 보이는 판의 두께 */
  /* 눕힌 보드가 화면에서 차지하는 높이는 한 변 길이의 이 비율이다(윗줄 말이 솟는 여유 포함). */
  --board-rise: 0.935;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
/* 하늘 배경. 스크롤해도 따라 움직이지 않게 화면에 고정한다. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, #bfe4ff 0%, #e9f6ff 55%, #f6fbff 100%);
}

[hidden] { display: none !important; }

.screen {
  min-height: 100dvh;
  max-width: 620px;
  /* 효과가 옆으로 조금 삐져나가도 화면이 좌우로 밀리지 않게 한다. */
  overflow-x: clip;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
}

/* ---------- 홈 / 로비 ---------- */
#home, #lobby { padding: 32px 24px; gap: 12px; justify-content: center; }
.logo { font-size: 64px; text-align: center; }
h1 { margin: 0; text-align: center; font-size: 40px; letter-spacing: 2px; color: var(--money); }
.tagline { margin: 0 0 20px; text-align: center; color: var(--muted); font-size: 14px; }
.divider { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0; }
.label { margin: 8px 0 0; color: var(--muted); font-size: 13px; text-align: center; display: block; }
.hint { color: var(--muted); font-size: 13px; text-align: center; }

input, select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  text-align: center;
}
input::placeholder { color: var(--muted); }
#codeInput { text-transform: uppercase; letter-spacing: 6px; }

.btn {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  word-break: keep-all;
  box-shadow: 0 3px 0 var(--edge);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); box-shadow: 0 3px 0 var(--accent-edge); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: 0 3px 0 var(--danger-edge); }
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn:disabled { opacity: 0.45; }

.room-code { text-align: center; font-size: 56px; font-weight: 800; letter-spacing: 10px; color: var(--money); }
.lobby-players { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 8px; }
.lobby-players li {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
}
.badge { margin-left: auto; font-size: 12px; color: var(--muted); }
#hostControls { display: grid; gap: 10px; }

/* ---------- 게임 ---------- */
#game { gap: 6px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
/* 라운드·기금·시간 묶음. 세로 화면에서는 묶지 않고 상단 줄에 고르게 편다(가로 화면에서는 세로로 쌓는다). */
.status { display: contents; }
#fundLabel { color: var(--money); }
#timerLabel { color: var(--money); font-variant-numeric: tabular-nums; }
#timerLabel.urgent { color: var(--danger); }
.chip {
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-family: inherit; font-size: 13px;
}

/* 보드를 담는 틀. 보드를 뒤로 눕히면 화면에서 차지하는 높이가 줄어들므로 그만큼 낮게 잡는다
   (눕힌 보드의 높이 약 89% + 윗줄 말이 솟는 여유 + 아래 두께). */
#boardWrap {
  position: relative;
  width: var(--board-size);
  height: calc(var(--board-size) * var(--board-rise) + var(--slab));
  margin: 0 auto;
}

/* 보드를 아래 변을 축으로 살짝 뒤로 눕혀, 위쪽이 멀어 보이게 한다. */
#board {
  position: absolute;
  left: 0;
  bottom: var(--slab);
  width: var(--board-size);
  height: var(--board-size);
  transform: perspective(calc(var(--board-size) * 2.8)) rotateX(14deg);
  transform-origin: 50% 100%;
  box-shadow: 0 var(--slab) 0 var(--board-side), 0 calc(var(--slab) * 2) 26px rgba(21, 52, 79, 0.32);
  display: grid;
  grid-template: repeat(11, 1fr) / repeat(11, 1fr);
  gap: 2px;
  padding: 2px;
  border-radius: 12px;
  background: var(--board-gap);
  /* 칸 안 글자 크기의 기준. 네 글자 이름이 한 칸에 들어가는 크기다. */
  font-size: calc(var(--board-size) / 52);
}

.tile {
  position: relative;
  background: var(--tile);
  color: var(--tile-text);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.15;
  cursor: pointer;
  border: 1.5px solid transparent;
  /* 칸이 판 위에 얹힌 조각처럼 보이도록 아래쪽에 얇은 그늘을 둔다. */
  box-shadow: inset 0 -2px 0 rgba(21, 52, 79, 0.1);
}
/* 도시 칸: 위에 지역 색 띠와 이름, 아래에 건물이 선다. */
.tile:not(.special):not(.corner) { justify-content: flex-start; padding-top: 22%; }
.tile .bar { position: absolute; inset: 0 0 auto 0; height: 16%; }
.tile .name { font-weight: 800; white-space: nowrap; letter-spacing: -0.06em; }
/* 다섯 글자가 넘는 이름은 조금 작게 두 줄로 쓴다. */
.tile .name.long { white-space: normal; word-break: break-all; font-size: 0.86em; line-height: 1.05; }
.tile .icon { font-size: 1.7em; line-height: 1; }
.tile .marks { font-size: 0.9em; font-weight: 700; color: var(--money); letter-spacing: -0.06em; }
.tile .marks:empty { display: none; }
.tile .bld { position: absolute; left: 50%; bottom: 0; width: 50%; aspect-ratio: 1; translate: -50% 0; pointer-events: none; }
.tile .bld svg, .piece svg, .build-base svg, .build-rise svg { width: 100%; height: 100%; display: block; }
.tile.special { background: var(--tile-special); }
.tile.corner { background: var(--tile-corner); }
.tile.owned { border-color: var(--owner); background: color-mix(in srgb, var(--owner) 32%, var(--tile)); }
/* 주인의 얼굴을 칸 오른쪽 아래 귀퉁이에 붙이고, 건물은 그만큼 왼쪽으로 비켜 세운다. */
.tile .own {
  position: absolute; right: 2%; bottom: 3%; width: 36%; aspect-ratio: 1; pointer-events: none;
  border-radius: 50%; overflow: hidden; background: #fff; box-shadow: 0 0 0 1px var(--owner);
}
.tile .own:empty { display: none; }
.tile .own svg { width: 100%; height: 100%; display: block; }
.tile.owned .bld { left: 36%; }
/* 내 땅은 굵은 테두리와 빛, 별 표시로 남의 땅과 한눈에 구별되게 한다. */
.tile.mine { border-width: 2.5px; box-shadow: 0 0 0 1.5px #fff, 0 0 9px 2px var(--owner); z-index: 1; }
.tile.mine::before {
  content: "★"; position: absolute; left: 3%; top: 15%; font-size: 1.2em; line-height: 1;
  color: var(--accent); -webkit-text-stroke: 0.5px #7a5200;
}
.tile.festival::after { content: "🎉"; position: absolute; top: 0; right: 0; font-size: 1.1em; }
.tile.sel { animation: pulse 0.9s infinite alternate; z-index: 2; }
@keyframes pulse {
  from { box-shadow: 0 0 0 2px var(--turn); }
  to { box-shadow: 0 0 0 4px var(--turn), 0 0 14px var(--turn); }
}

#center {
  position: relative;
  grid-area: 2 / 2 / 11 / 11;
  /* 여행 지도: 풀빛 땅 위에 위도·경도 선, 점선 여행 경로와 핀, 비행기, 나침반(board-map.svg) */
  background:
    url("/board-map.svg") center / 100% 100% no-repeat,
    linear-gradient(160deg, var(--land-light) 0%, var(--land-mid) 48%, var(--land-deep) 100%);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 주사위가 놓이는 자리가 버튼 수에 따라 오르내리지 않게 위에서부터 쌓는다. */
  justify-content: flex-start;
  /* 가운데 영역의 글자·버튼·여백은 모두 이 글자 크기(em)를 따라 보드와 함께 커지고 작아진다.
     보드가 작아지는 가로 화면에서도 버튼이 영역 밖으로 넘치지 않게 하려는 것이다. */
  font-size: clamp(9px, calc(var(--board-size) / 27), 15px);
  gap: 0.42em;
  padding: 3% 0.7em 0.7em;
  text-align: center;
}
/* 멈춘 주사위가 놓이는 자리. 주사위 자체는 보드 전체를 덮는 #diceStage 안에서 움직인다. */
#dice { width: 100%; height: calc(var(--die) * 1.55); flex: none; }
/* 안내 문구는 하늘 바탕에 묻히지 않게 흰 판 위에 굵게 쓴다. */
#message {
  margin: 0; width: 92%; min-height: 2.9em; padding: 0.4em 0.8em; border-radius: 0.8em;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.9); box-shadow: 0 2px 0 var(--edge);
  color: var(--text); font-size: 1.05em; font-weight: 800; line-height: 1.3; word-break: keep-all;
}
#message.veiled { visibility: hidden; }
/* 지금 내가 답해야 하는 일 */
#message.attn { background: #fff3c4; box-shadow: 0 0 0 2px var(--turn); animation: attn 0.9s infinite alternate; }
@keyframes attn {
  from { scale: 1; }
  to { scale: 1.04; }
}

/* ---------- 굴리기 게이지 ---------- */
/* 꾹 누르면 표시가 좌우로 오간다. 칸마다 노리는 눈의 합이 적혀 있다. */
.gauge {
  position: relative; display: flex; height: 2.1em; border-radius: 13px;
  border: 2px solid var(--text); background: #fff; font-size: 0.85em; font-weight: 800;
}
.gauge .gz { flex: 1; display: grid; place-items: center; color: #fff; }
.gauge .gz:first-child { border-radius: 11px 0 0 11px; }
.gauge .gz:nth-last-child(2) { border-radius: 0 11px 11px 0; }
.gz0 { background: #4d8dff; }
.gz1 { background: #2fb37a; }
.gz2 { background: #ef5a5a; }
.gauge-mark {
  position: absolute; left: 0; top: -5px; bottom: -5px; width: 6px; margin-left: -3px;
  border-radius: 3px; background: var(--text); box-shadow: 0 0 0 2px #fff;
}
/* 길게 눌러도 화면이 밀리거나 글자가 선택되지 않게 한다. */
.btn.hold { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.btn.hold.holding { transform: translateY(3px); box-shadow: none; }
#actions { display: flex; flex-direction: column; gap: 0.55em; width: 88%; }
#actions .btn { padding: 0.76em 0.8em; font-size: 1.05em; border-radius: 0.85em; }
.row { display: flex; gap: 0.55em; }
/* 가운데 영역은 좁아서, 나란히 놓는 버튼은 글자와 여백을 줄인다. */
#actions .row .btn { padding: 0.7em 0.4em; font-size: 1em; line-height: 1.25; }
#actions .row.tight .btn { padding: 0.55em 0.15em; font-size: 0.92em; }

#tokens { position: absolute; inset: 0; pointer-events: none; }

/* ---------- 입체 주사위 ---------- */
.dice-clip { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 40; border-radius: inherit; }
/* 멈춘 주사위를 바로 위에서 조금 비껴 보는 것처럼 보이도록, 시점을 주사위가 놓이는 높이에 맞춘다. */
#diceStage {
  position: absolute; inset: 0;
  perspective: calc(var(--board-size) * 1.64);
  perspective-origin: 50% 21%;
}
.die, .dsh { position: absolute; left: 0; top: 0; }
.die {
  width: var(--die); height: var(--die);
  margin: calc(var(--die) / -2) 0 0 calc(var(--die) / -2);
  transform-style: preserve-3d;
}
.die .f, .die .c { position: absolute; backface-visibility: hidden; }
/* 바깥 면: 흰 바탕에 눈 9칸. 1의 눈만 크고 빨갛다. */
.die .f {
  inset: 0; border-radius: 17%; background: #fbfbf8; padding: 15%;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08), inset 0 0 calc(var(--die) * 0.16) rgba(70, 80, 110, 0.16);
}
.die .f i { margin: 9%; border-radius: 50%; }
.die .f i.on { background: radial-gradient(circle at 36% 30%, #4b5060, #15171e 68%); }
.die .f1 i.on { background: radial-gradient(circle at 36% 30%, #ff6a5e, #d92b20 68%); scale: 1.55; }
/* 빛을 등진 면을 덮는 그늘. 진하기는 dice.js 가 면의 방향에 맞춰 바꾼다. */
.die .f b { position: absolute; inset: 0; border-radius: inherit; background: #1b2440; opacity: 0; }
/* 안쪽 면: 둥근 모서리 사이로 속이 비어 보이지 않게 메운다. */
.die .c { inset: 6%; background: #d3d6de; }
.f1 { transform: translateZ(calc(var(--die) / 2)); }
.f6 { transform: rotateY(180deg) translateZ(calc(var(--die) / 2)); }
.f3 { transform: rotateY(90deg) translateZ(calc(var(--die) / 2)); }
.f4 { transform: rotateY(-90deg) translateZ(calc(var(--die) / 2)); }
.f2 { transform: rotateX(-90deg) translateZ(calc(var(--die) / 2)); }
.f5 { transform: rotateX(90deg) translateZ(calc(var(--die) / 2)); }
.c1 { transform: translateZ(calc(var(--die) * 0.44)); }
.c6 { transform: rotateY(180deg) translateZ(calc(var(--die) * 0.44)); }
.c3 { transform: rotateY(90deg) translateZ(calc(var(--die) * 0.44)); }
.c4 { transform: rotateY(-90deg) translateZ(calc(var(--die) * 0.44)); }
.c2 { transform: rotateX(-90deg) translateZ(calc(var(--die) * 0.44)); }
.c5 { transform: rotateX(90deg) translateZ(calc(var(--die) * 0.44)); }
.dsh {
  width: var(--die); height: calc(var(--die) * 0.6);
  margin: calc(var(--die) * -0.3) 0 0 calc(var(--die) / -2);
  border-radius: 50%; background: radial-gradient(closest-side, rgba(20, 28, 55, 0.5), rgba(20, 28, 55, 0));
}

/* ---------- 플레이어 카드 · 기록 ---------- */
#players { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 6px; }
.pcard {
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; align-items: center;
  /* 보유 목록 한 줄이 더 들어가므로 줄 간격과 안쪽 여백을 줄여 카드 높이를 지킨다. */
  padding: 5px 8px; border-radius: 12px; background: var(--panel); border: 2px solid transparent;
  box-shadow: 0 2px 0 var(--edge);
  font-size: 13px; line-height: 1.25;
}
/* 보유 목록: 가진 카드와 땅문서 조각. 세로 화면에서는 한 줄로 두고 넘치면 옆으로 밀어서 본다. */
.pholdings {
  grid-column: 1 / -1; display: flex; gap: 3px; margin-top: 4px; min-height: 17px;
  overflow-x: auto; scrollbar-width: none;
}
.pholdings::-webkit-scrollbar { display: none; }
.pholdings.none { align-items: center; color: var(--muted); font-size: 10.5px; }
.hchip {
  flex: none; display: inline-flex; align-items: center; gap: 2px; height: 17px; padding: 0 4px 0 3px;
  border-radius: 5px; border: 1px solid var(--line); border-left: 4px solid var(--gc, var(--line));
  background: #fff; color: var(--text); font-family: inherit; font-size: 10.5px; font-weight: 700;
  letter-spacing: -0.04em; white-space: nowrap; cursor: pointer;
}
.hchip.item { padding: 0 4px; border-left-width: 1px; background: var(--mine); cursor: default; }
.hchip .hbld { display: block; width: 13px; height: 13px; }
.hchip .hbld svg { display: block; width: 100%; height: 100%; }
/* 방금 얻은 땅문서는 튀어나오며 나타난다. */
.hchip.new { animation: chipPop 0.9s ease-out; }
@keyframes chipPop {
  0% { scale: 0; }
  55% { scale: 1.35; box-shadow: 0 0 0 3px var(--turn); }
  100% { scale: 1; box-shadow: 0 0 0 0 transparent; }
}
/* 얼굴은 이름·현금·총자산 세 줄 옆에 걸쳐 놓는다(한 줄에만 두면 그 줄이 얼굴 높이만큼 벌어진다). */
.pcard .piece { grid-row: 1 / span 3; }
.pcard.mine { background: var(--mine); }
.pcard.turn { border-color: var(--turn); }
.pcard.out { opacity: 0.4; }
.pcard .pname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .pmoney { grid-column: 2; color: var(--money); font-weight: 700; font-variant-numeric: tabular-nums; }
.pcard .psub { grid-column: 2; color: var(--muted); font-size: 11px; }

#log {
  flex: 1; min-height: 44px; max-height: 96px; overflow-y: auto;
  margin: 0 6px 6px; padding: 6px 10px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.78); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); line-height: 1.5;
}
#log div:first-child { color: var(--text); }

/* ---------- 오버레이 ---------- */
#modal {
  position: fixed; inset: 0; background: rgba(21, 52, 79, 0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 60;
}
#modalBox {
  width: 100%; max-width: 620px; max-height: 85dvh; overflow-y: auto;
  background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 10px;
}
#modalBox h2 { margin: 0; font-size: 20px; }
#modalBox p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
#modalBox table { width: 100%; border-collapse: collapse; font-size: 14px; }
#modalBox td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
#modalBox td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#modalBox tr.now td { color: var(--money); font-weight: 700; }
/* 땅문서 표: 단계 · 건설비 · 통행료 */
#modalBox table.deed td:nth-child(2) { text-align: right; color: var(--muted); }
.group-tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; color: #10182f; font-weight: 700; }

#toast, #conn {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 70;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; white-space: nowrap;
  background: var(--text); color: #fff;
}
#toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
#conn { top: calc(10px + env(safe-area-inset-top)); background: var(--danger); }

/* ---------- 말 ---------- */
.chips { display: flex; gap: 6px; }
/* '가로' 버튼이 보이는 휴대폰(전체 화면을 지원하는 기기)에서는 좁은 세로 화면의 상단 줄에
   버튼 하나가 더 들어가도록 글자와 여백을 조금 줄인다. */
@media (max-width: 420px) {
  #game.has-full .topbar { gap: 5px; padding: 8px; font-size: 12px; }
  #game.has-full .chips { gap: 4px; }
  #game.has-full .chip { padding: 4px 8px; font-size: 12px; }
}

/* 플레이어 카드 등에 쓰는 얼굴 배지 */
.piece {
  width: 28px; height: 28px; flex: none; display: block; overflow: hidden;
  border-radius: 50%; background: #fff; border: 3px solid var(--pc);
}

/* 보드 위의 말. 크기와 위치는 보드 한 변에 대한 비율이다(칸 하나는 약 9.1%).
   left/top 은 칸 중심이고, 발이 칸 아래쪽에 오도록 위로 당겨 놓는다. */
.token {
  position: absolute;
  width: 8.67%; height: 12.9%;
  margin: -7.7% 0 0 -4.34%;
  transform-origin: 50% 88%;
  transition: left 0.16s linear, top 0.16s linear;
  z-index: 3;
}
/* 뛸 때 받침 쪽을 축으로 늘었다 줄게 한다. */
.token svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; transform-origin: 50% 88%; }
/* 멀리 건너뛸 때(비행·카드 이동)는 천천히 날아간다. */
.token.fly { transition: left 0.42s ease-in-out, top 0.42s ease-in-out; }
/* 차례인 사람의 받침 둘레에 켜지는 고리 */
.token .ring {
  position: absolute; left: 50%; bottom: 3%; width: 84%; height: 20%; translate: -50% 0;
  border-radius: 50%; border: 2.5px solid var(--turn); box-shadow: 0 0 8px var(--turn); opacity: 0;
}
.token.active .ring { opacity: 1; }
.token.active { animation: bob 0.6s infinite alternate ease-in-out; }
@keyframes bob {
  from { translate: 0 0; }
  to { translate: 0 -8%; }
}
.token.me::before {
  content: "나"; position: absolute; left: 50%; top: var(--tag-top); transform: translate(-50%, -105%);
  padding: 0 4px; border-radius: 6px; background: var(--pc); color: #fff;
  font-size: 1.15em; font-weight: 800; line-height: 1.5; white-space: nowrap; z-index: 1;
}
.token.out { opacity: 0.3; filter: grayscale(1); }

/* ---------- 건설 장면 ---------- */
.build-scene { position: absolute; translate: -50% -50%; z-index: 42; pointer-events: none; }
.build-lot {
  position: absolute; inset: 0; overflow: hidden; border-radius: 50%;
  background: linear-gradient(180deg, #ffffff 0 70%, #bfe6a8 70% 100%);
  border: 3px solid var(--owner); box-shadow: 0 6px 18px var(--shadow);
}
/* 건물 그림의 바닥이 잔디 위에 닿도록 놓는다. */
.build-base, .build-rise { position: absolute; left: 19%; top: 16%; width: 62%; height: 62%; }
.build-frame {
  position: absolute; left: 16%; top: 12%; width: 68%; height: 58%;
  border: 2px dashed #8aa0b4; border-bottom: 0; border-radius: 4px 4px 0 0;
}
.build-hammer { position: absolute; right: 2%; top: 14%; font-size: calc(var(--board-size) * 0.07); transform-origin: 20% 80%; }
.build-spark { position: absolute; left: 50%; top: 2%; translate: -50% 0; font-size: calc(var(--board-size) * 0.09); opacity: 0; }

/* ---------- 가운데 알림과 분위기 효과 (effects.js) ---------- */
.fx-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 50; border-radius: inherit; }
.fx-fly { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 55; }
.fx-slot { position: absolute; left: 5%; right: 5%; top: 30%; display: flex; justify-content: center; }
.fx-banner {
  display: flex; align-items: center; gap: 12px; max-width: 100%;
  padding: 12px 18px; border-radius: 18px; border: 3px solid var(--line);
  background: #fff; color: var(--text); box-shadow: 0 10px 26px var(--shadow); text-align: left;
}
.fx-icon { font-size: 38px; line-height: 1; flex: none; }
.fx-text { display: grid; gap: 1px; min-width: 0; }
.fx-who { font-size: 12px; font-weight: 700; color: var(--muted); }
.fx-title { font-size: 20px; font-weight: 800; line-height: 1.25; word-break: keep-all; }
.fx-detail { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.fx-good { background: linear-gradient(180deg, #fffbe6, #ffe58a); border-color: var(--turn); }
.fx-good .fx-detail { color: #0f9d58; }
.fx-bad { background: linear-gradient(180deg, #eef2f7, #cbd5e2); border-color: #7d8da3; color: #2c3a4d; }
.fx-bad .fx-detail { color: var(--danger); }
.fx-short { padding: 8px 14px; gap: 8px; }
.fx-short .fx-icon { font-size: 26px; }
.fx-short .fx-title { font-size: 17px; }
.fx-short .fx-detail { font-size: 14px; }
.fx-long .fx-title { font-size: 17px; }
.fx-veil { position: absolute; inset: 0; }
.fx-veil.fx-bad { background: radial-gradient(circle at 50% 40%, rgba(44, 58, 77, 0.3), rgba(28, 38, 58, 0.68)); }
.fx-veil.fx-good { background: radial-gradient(circle at 50% 40%, rgba(255, 240, 160, 0.7), rgba(255, 200, 60, 0) 72%); }
.fx-confetti { position: absolute; top: -8%; width: 8px; height: 12px; border-radius: 2px; }
.fx-drop { position: absolute; top: -8%; width: 2px; height: 16px; border-radius: 2px; background: rgba(214, 228, 246, 0.9); }
.fx-coin {
  position: absolute; left: 0; top: 0; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #ffc531 60%, #db9d00); box-shadow: 0 0 0 1.5px #b77f00;
}
/* 화면 위를 날아다니는 조각들. 자리와 움직임은 effects.js 가 transform 으로 준다. */
.fx-spark { position: absolute; left: 0; top: 0; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 2px; }
.fx-ring {
  position: absolute; left: 0; top: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; border: 4px solid var(--turn);
}
.fx-trail {
  position: absolute; left: 0; top: 0; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%;
  background: radial-gradient(circle, #fff, var(--pc, #ffc531) 70%); box-shadow: 0 0 10px var(--pc, #ffc531);
}
/* 떠오르는 큰 글자(금액·주사위 합). 흰 테두리를 둘러 어떤 바탕에서도 읽히게 한다. */
.fx-pop {
  position: absolute; left: 0; top: 0; font-size: 22px; font-weight: 900; white-space: nowrap;
  color: var(--text); -webkit-text-stroke: 4px #fff; paint-order: stroke fill;
  text-shadow: 0 3px 0 rgba(21, 52, 79, 0.2);
}
.fx-pop-good { color: #0f9d58; }
.fx-pop-bad { color: var(--danger); }
.fx-pop-big { font-size: 46px; color: var(--money); }
/* 날아가는 땅문서 한 장 */
.fx-deed {
  position: absolute; left: 0; top: 0; padding: 6px 10px 6px 8px; border-radius: 8px;
  background: #fff; border: 2px solid var(--text); border-left: 8px solid var(--gc, var(--text));
  font-size: 13px; font-weight: 800; white-space: nowrap; box-shadow: 0 6px 14px var(--shadow);
}
/* 말·카드·칸의 반응 */
.token.fx-sad { animation: fxShake 0.5s 2; }
.token.fx-sad::after, .token.fx-happy::after { position: absolute; right: -14%; top: 14%; font-size: 1.5em; }
.token.fx-sad::after { content: "💧"; }
.token.fx-happy { animation: fxJump 0.5s 2; }
.token.fx-happy::after { content: "✨"; }
.pcard.fx-loss { animation: fxShake 0.4s 2; border-color: var(--danger); background: #ffe9e9; }
.pcard.fx-gain { animation: fxPulse 0.5s 2; border-color: #0f9d58; background: #e6f8ee; }
.tile.fx-claim { animation: fxClaim 1.1s; z-index: 3; }
.tile.fx-hit { animation: fxHit 0.9s; z-index: 3; }
@keyframes fxShake {
  0%, 100% { translate: 0 0; }
  25% { translate: -7% 0; }
  75% { translate: 7% 0; }
}
@keyframes fxJump {
  0%, 100% { translate: 0 0; }
  45% { translate: 0 -26%; }
}
@keyframes fxPulse {
  0%, 100% { scale: 1; }
  50% { scale: 1.05; }
}
@keyframes fxClaim {
  0% { scale: 1; box-shadow: 0 0 0 0 var(--turn); }
  35% { scale: 1.55; box-shadow: 0 0 0 4px var(--turn), 0 0 18px var(--turn); }
  100% { scale: 1; box-shadow: 0 0 0 0 transparent; }
}
@keyframes fxHit {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  40% { box-shadow: 0 0 0 4px var(--danger), 0 0 14px var(--danger); }
}

/* ---------- 채팅 · 효과 ---------- */
.delta {
  position: absolute; right: 8px; top: 4px; font-weight: 800; font-size: 14px;
  pointer-events: none; animation: floatUp 1.8s forwards;
}
.delta.plus { color: #0f9d58; }
.delta.minus { color: var(--danger); }
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(8px); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-18px); }
}

/* 말풍선: 말한 사람의 말 머리 위에 뜬다. 위치(left·top)는 app.js 가 말의 자리에 맞춰 넣는다. */
#bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 45; }
.say {
  position: absolute; translate: -50% calc(-100% - 8px); transform-origin: 50% 100%;
  /* 글 길이만큼만 넓어지되 보드의 60%를 넘으면 줄을 바꾼다. */
  width: max-content; max-width: 60%; padding: 6px 11px; border-radius: 14px;
  background: #fff; color: var(--text); font-size: 13px; font-weight: 700; line-height: 1.3;
  border: 2px solid var(--pc); box-shadow: 0 4px 12px var(--shadow);
  overflow-wrap: anywhere; text-align: center;
  animation: say 3.2s forwards;
}
/* 꼬리. 몸통이 보드 안으로 밀려 들어와도 말을 가리키도록 --tail 만큼 옆으로 옮긴다. */
.say::after {
  content: ""; position: absolute; left: calc(50% + var(--tail, 0px)); top: 100%; translate: -50% 0;
  border: 7px solid transparent; border-top-color: var(--pc); border-bottom: 0;
}
/* 윗줄에 있는 말은 머리 위에 자리가 없으므로 말 아래에 띄운다. */
.say.below { translate: -50% 8px; transform-origin: 50% 0; }
.say.below::after { top: auto; bottom: 100%; border-top: 0; border-bottom: 7px solid var(--pc); }
/* 감정 표현은 이모지만 크게 */
.say.emote { padding: 2px 9px; font-size: 32px; line-height: 1.2; border-radius: 20px; animation-name: sayEmote; }
@keyframes say {
  0% { opacity: 0; scale: 0.6; }
  7%, 86% { opacity: 1; scale: 1; }
  100% { opacity: 0; scale: 0.9; }
}
@keyframes sayEmote {
  0% { opacity: 0; scale: 0.3; }
  8% { opacity: 1; scale: 1.25; }
  16%, 84% { opacity: 1; scale: 1; }
  100% { opacity: 0; scale: 0.8; }
}

#log .chat { color: var(--text); }
#log .chat b { color: color-mix(in srgb, var(--pc) 70%, #000); }

.chatbar { position: relative; }
#chatForm { display: flex; gap: 6px; margin: 0 6px 8px; }
#chatForm input { flex: 1; min-width: 0; padding: 10px 14px; text-align: left; font-size: 16px; }
#chatForm .btn { width: auto; padding: 10px 16px; font-size: 14px; }
#chatForm #emoteBtn, #chatForm #tradeBtn { padding: 6px 10px; font-size: 20px; line-height: 1; }
/* 거래소 버튼: 내가 답할 제안이 있으면 그 수를 붙이고 들썩인다. */
#tradeBtn { position: relative; }
#tradeBtn.alert { border-color: var(--turn); background: #fff3c4; animation: attn 0.9s infinite alternate; }
#tradeBadge {
  position: absolute; right: -5px; top: -7px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 800; font-style: normal; line-height: 18px; text-align: center;
}
/* 감정 표현 고르기: 채팅창 바로 위에 뜨는 버튼판. 누르면 바로 보내진다. */
#emotes {
  position: absolute; left: 6px; right: 6px; bottom: calc(100% + 2px); z-index: 58;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px;
  padding: 8px; border-radius: 14px; background: var(--panel);
  border: 1px solid var(--line); box-shadow: 0 -6px 20px var(--shadow);
}
#emotes button {
  padding: 6px 0; border: 0; border-radius: 10px; background: transparent;
  font-size: 24px; line-height: 1.1; cursor: pointer;
}
#emotes button:active { background: var(--tile-special); scale: 0.9; }

/* ---------- 거래 창 ---------- */
#modalBox p.sect { margin-top: 6px; color: var(--text); font-weight: 700; }
.chiprow { display: flex; flex-wrap: wrap; gap: 6px; }
.pchip {
  padding: 9px 12px; border-radius: 10px;
  border: 2px solid var(--line); border-left: 6px solid var(--gc, var(--line));
  background: #f4faff; color: var(--text); font-family: inherit; font-size: 14px; font-weight: 600;
}
.pchip.on { background: var(--accent); border-color: var(--accent); border-left-color: var(--gc, var(--accent)); color: var(--accent-text); }
/* 거래소에 걸린 제안 한 건: 제안한 사람의 색 띠, 양쪽이 내놓는 것, 응답 버튼 */
.ocard {
  display: grid; gap: 6px; padding: 10px; border-radius: 12px;
  border: 2px solid var(--line); border-left: 6px solid var(--pc); background: #f7fbff;
}
.ocard.forme { border-color: var(--turn); border-left-color: var(--pc); background: #fffbe9; }
.ohead { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.ohead .oleft { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.oside { display: grid; gap: 4px; }
.olabel { color: var(--muted); font-size: 12px; font-weight: 700; }
.onone { color: var(--muted); font-size: 13px; }
.ocard .btn { padding: 10px 8px; font-size: 14px; }
/* 땅문서 조각(누를 수 없는 표시용) */
.dchip {
  display: inline-block; padding: 5px 9px; border-radius: 8px;
  border: 1px solid var(--line); border-left: 5px solid var(--gc, var(--line));
  background: #fff; font-size: 13px; font-weight: 700;
}
.dchip.cash { border-left-width: 1px; border-color: #9fd9b8; background: #e6f8ee; }
.gdot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; }
#modalBox table.deedlist tr { cursor: pointer; }
#modalBox p.owner-line { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; }
.cashrow { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.cashrow input { width: 120px; padding: 9px 12px; text-align: right; font-size: 16px; }

/* ---------- 가로 화면 ---------- */
/* 휴대폰을 가로로 눕혔거나 창이 옆으로 넓을 때의 배치.
   보드를 가운데 두고 플레이어를 네 귀퉁이(왼쪽 위에서 시계 방향으로 차례 순서)에 놓는다.
   왼쪽 가운데에는 기록, 오른쪽 가운데에는 라운드·기금·시간과 버튼, 보드 바로 아래에는 채팅 입력줄을 둔다. */
@media (orientation: landscape) and (min-width: 560px) {
  :root {
    --land-pad: 6px;
    --land-gap: 6px;
    --chat-h: 36px;
    /* 옆 칸의 너비: 플레이어 카드(얼굴 + 이름 + 금액)가 들어가는 최소 폭과, 넓은 화면에서 더 늘리지 않는 폭 */
    --side-min: 128px;
    --side-max: 300px;
    --safe-x: calc(env(safe-area-inset-left, 0px) + env(safe-area-inset-right, 0px));
    --safe-y: calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px));
    /* 가로 화면에서는 높이가 모자라다. 화면 높이에서 채팅 입력줄을 뺀 만큼, 그리고 양옆 칸을 남긴 너비 안에서 가장 크게 잡는다. */
    --board-size: min(
      calc((100dvh - var(--safe-y) - 2 * var(--land-pad) - var(--land-gap) - var(--chat-h) - var(--slab)) / var(--board-rise)),
      calc(100vw - var(--safe-x) - 2 * var(--land-pad) - 2 * var(--land-gap) - 2 * var(--side-min)),
      620px);
    --land-height: calc(var(--board-size) * var(--board-rise) + var(--slab) + var(--land-gap) + var(--chat-h)
      + 2 * var(--land-pad) + var(--safe-y));
  }

  #game {
    max-width: calc(var(--board-size) + 2 * var(--side-max) + 2 * var(--land-gap) + 2 * var(--land-pad) + var(--safe-x));
    min-height: 0;
    height: var(--land-height);
    /* 화면이 보드보다 훨씬 높으면(태블릿·컴퓨터) 위아래 가운데에 둔다.
       바깥 여백으로 밀면 그만큼 페이지가 길어져 스크롤이 생기므로 자리만 옮긴다. */
    position: relative;
    top: max(0px, calc((100dvh - var(--land-height)) / 2));
    padding:
      calc(var(--land-pad) + env(safe-area-inset-top, 0px))
      calc(var(--land-pad) + env(safe-area-inset-right, 0px))
      calc(var(--land-pad) + env(safe-area-inset-bottom, 0px))
      calc(var(--land-pad) + env(safe-area-inset-left, 0px));
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--board-size) minmax(0, 1fr);
    /* 위 카드 · 가운데(기록, 상황판) · 아래 카드의 윗부분 · 채팅 입력줄.
       아래 카드는 마지막 두 줄에 걸치고 보드는 채팅 입력줄 위까지만 차지한다. */
    grid-template-rows: auto minmax(0, 1fr) auto var(--chat-h);
    gap: var(--land-gap);
  }
  #boardWrap { grid-column: 2; grid-row: 1 / 4; margin: 0; }
  .chatbar { grid-column: 2; grid-row: 4; min-width: 0; }

  /* 플레이어 카드: 묶음 틀을 풀어 카드 하나하나를 귀퉁이에 놓는다. */
  #players { display: contents; }
  .pcard { min-width: 0; align-self: start; }
  /* 옆 칸에는 세로 자리가 있으므로 보유 목록을 두 줄까지 접어 보여 주고, 넘치면 그 안에서 밀어 본다. */
  .pholdings { flex-wrap: wrap; overflow: hidden auto; max-height: 37px; }
  .pcard:nth-child(1) { grid-column: 1; grid-row: 1; }
  .pcard:nth-child(2) { grid-column: 3; grid-row: 1; }
  .pcard:nth-child(3) { grid-column: 3; grid-row: 3 / 5; align-self: end; }
  .pcard:nth-child(4) { grid-column: 1; grid-row: 3 / 5; align-self: end; }

  #log { grid-column: 1; grid-row: 2; margin: 0; min-height: 0; max-height: none; }
  .topbar {
    grid-column: 3; grid-row: 2; min-height: 0; overflow: hidden;
    flex-direction: column; justify-content: center; gap: 8px;
    padding: 6px; border-radius: 12px;
    background: rgba(255, 255, 255, 0.78); border: 1px solid var(--line);
  }
  .status { display: grid; gap: 3px; justify-items: center; }
  #timerLabel { font-size: 17px; }
  .chips { flex-wrap: wrap; justify-content: center; }
  /* 세 번째·네 번째 플레이어가 없으면 그 자리까지 상황판과 기록을 늘린다. */
  #game:not(:has(.pcard:nth-child(3))) .topbar { grid-row: 2 / 5; }
  #game:not(:has(.pcard:nth-child(4))) #log { grid-row: 2 / 5; }

  /* 채팅 입력줄은 높이를 아껴 보드를 크게 쓴다. 3px 는 버튼 아래 그림자 자리다. */
  #chatForm { margin: 0; height: calc(var(--chat-h) - 3px); }
  #chatForm input, #chatForm .btn, #chatForm #emoteBtn, #chatForm #tradeBtn { padding-top: 0; padding-bottom: 0; }
  #emotes { left: 0; right: 0; }
}
/* 주소창 때문에 가로 화면이 아주 낮을 때는 보유 목록도 한 줄만 둔다(가운데 기록창과 상황판 자리를 남긴다). */
@media (orientation: landscape) and (min-width: 560px) and (max-height: 339px) {
  .pholdings { flex-wrap: nowrap; overflow: auto hidden; max-height: none; }
}

/* 가로로 눕힌 휴대폰처럼 높이가 낮을 때는 첫 화면과 대기실의 여백과 큰 글자를 줄인다. */
@media (orientation: landscape) and (max-height: 520px) {
  #home, #lobby { padding: 12px 24px; gap: 8px; }
  .logo { font-size: 36px; line-height: 1.1; }
  h1 { font-size: 28px; }
  .tagline { margin-bottom: 6px; }
  .room-code { font-size: 40px; }
  .lobby-players { margin: 6px 0; }
}
