:root {
  --bg: #f3e9d7;
  --bg2: #ead9bd;
  --ink: #3b2a1a;
  --muted: #7a6450;
  --card: #fffaf1;
  --line: #e3d2b6;
  --wood: #e4b979;
  --wood2: #d6a35f;
  --grid: #5a3b1c;
  --accent: #e2683f;
  --accent-ink: #fff;
  --gold: #f2b631;
  --me: #2f8f6b;
  --pick: rgba(226, 104, 63, .28);
  --shadow: 0 6px 20px rgba(80, 50, 20, .14);
  --font-title: "Jua", "Apple SD Gothic Neo", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1a15; --bg2: #2a231c; --ink: #f3e9d7; --muted: #b9a68f; --card: #2c251e; --line: #43382c;
    --shadow: 0 6px 20px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(circle at 20% 0%, var(--bg2), var(--bg) 60%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  word-break: keep-all;
  overflow-wrap: anywhere;
  min-height: 100dvh;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; color: inherit; }

.btn {
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 700; transition: transform .12s ease-out, background .15s;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: 0; text-decoration: underline; min-height: 36px; color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

/* 첫 화면 */
.screen { min-height: 100dvh; }
#home, #lobby { display: grid; place-items: center; padding: 24px 16px; }
.home-card { width: min(440px, 100%); text-align: center; }
.home-faces { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 8px; }
.home-faces img { width: 84px; height: 84px; filter: drop-shadow(0 4px 6px rgba(0,0,0,.18)); }
.home-faces img:last-child { animation: bob 2.4s ease-in-out infinite; }
.home-faces span { font-family: var(--font-title); color: var(--muted); font-size: 22px; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(4deg); } }
.title { font-family: var(--font-title); font-weight: 400; font-size: 40px; margin: 6px 0; letter-spacing: -0.01em; }
.title.small { font-size: 30px; }
.sub { color: var(--muted); margin: 0 0 18px; line-height: 1.6; }
.home-actions { display: grid; gap: 10px; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.join input {
  min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 0 14px; font-size: 16px; letter-spacing: .2em; text-transform: uppercase; text-align: center;
}
.err { color: var(--accent); min-height: 1.4em; margin: 0; font-size: 14px; }
.rules { text-align: left; margin-top: 18px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; }
.rules summary { cursor: pointer; font-weight: 700; min-height: 28px; }
.rules ol { padding-left: 20px; margin: 8px 0 0; line-height: 1.7; font-size: 14px; }
.code { font-family: var(--font-title); font-size: 56px; letter-spacing: .25em; margin: 4px 0 20px; padding-left: .25em; }

/* 게임 화면: 3D 판이 화면 전체, 정보는 그 위에 띄운다 */
.game { position: fixed; inset: 0; min-height: 0; overflow: hidden; background: linear-gradient(#8fd0f2, #cfeefb 55%, #4fb3e8 56%); }
.board3d { position: absolute; inset: 0; }
.board3d canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.board-err { position: absolute; left: 16px; right: 16px; top: 40%; z-index: 2; margin: 0; padding: 14px 16px; border-radius: 12px; background: var(--card); color: var(--accent); text-align: center; font-weight: 700; box-shadow: var(--shadow); }
.zoom-reset { position: absolute; left: 10px; top: 50%; z-index: 2; min-height: 40px; padding: 6px 12px; font-size: 13px; }
@media (min-width: 960px) { .zoom-reset { top: auto; bottom: 28px; } }
.side { display: contents; }
.hud { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px; display: grid; gap: 6px; }
.game .panel { position: absolute; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); max-height: 44dvh; overflow: auto; }
@media (min-width: 960px) {
  .side { display: grid; gap: 10px; position: absolute; top: 16px; right: 16px; width: 360px; max-height: calc(100dvh - 32px); align-content: start; }
  .hud, .game .panel { position: static; max-height: none; }
  .game .panel { overflow: auto; }
}
body.playing .credit { position: fixed; left: 10px; bottom: 6px; padding: 0; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); z-index: 1; }
@media (max-width: 959px) { body.playing .credit { display: none; } }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; align-items: center; }
.players .round { grid-column: 1 / -1; display: flex; justify-content: center; align-items: baseline; gap: 8px; color: #17364a; text-shadow: 0 1px 0 rgba(255,255,255,.6); }
.players .phase { color: #2c566f; }
.pcard { box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 6px 10px; min-width: 0; }
.pcard.opp { flex-direction: row-reverse; text-align: right; }
.pcard img { width: 40px; height: 40px; flex: none; }
.pcard.turn { border-color: var(--accent); box-shadow: 0 0 0 3px var(--pick); }
.pname { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pscore { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pscore b { color: var(--ink); font-size: 16px; }
.round { text-align: center; font-family: var(--font-title); font-size: 18px; }
.phase { font-family: inherit; font-size: 12px; color: var(--muted); }
.timer { position: relative; height: 22px; border-radius: 11px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.timer i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--gold), var(--accent)); }
.timer span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 4px; font-family: var(--font-title); font-weight: 400; font-size: 22px; }
.panel p { margin: 0 0 10px; color: var(--muted); line-height: 1.55; font-size: 14px; }
.dirs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.dirs .btn { padding: 8px 0; font-size: 20px; }
.dirs .btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: transparent; }
.row-actions { display: grid; gap: 8px; }
.bets { display: grid; gap: 6px; margin-bottom: 10px; }
.bet { display: grid; grid-template-columns: 30px 1fr 44px 52px 44px 52px; gap: 6px; align-items: center; }
.bet .tag { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 14px; }
.bet .what { font-size: 12px; color: var(--muted); }
.bet .val { text-align: center; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bet .btn { padding: 0; min-height: 44px; }
.left { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.left b { font-size: 18px; }
.status { font-size: 13px; color: var(--muted); text-align: center; margin-top: 8px; }
.results { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.results li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.results img { width: 28px; height: 28px; }
.results .tag { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 12px; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 14px;
  transition: opacity .25s, transform .25s; box-shadow: var(--shadow); white-space: nowrap; z-index: 5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(40, 25, 10, .45); padding: 16px; z-index: 10; }
.overlay .card { background: var(--card); border-radius: 20px; padding: 26px 24px; width: min(360px, 100%); text-align: center; box-shadow: var(--shadow); }
.overlay h2 { font-family: var(--font-title); font-weight: 400; font-size: 34px; margin: 6px 0; }
.overlay p { color: var(--muted); line-height: 1.6; margin: 0 0 16px; }
.over-img { width: 96px; height: 96px; }
.over-actions { display: grid; gap: 8px; }

.coin { width: 110px; height: 110px; margin: 8px auto 18px; position: relative; transform-style: preserve-3d; }
.coin.spin-heads { animation: flipH 1.6s cubic-bezier(.2, .7, .3, 1) both; }
.coin.spin-tails { animation: flipT 1.6s cubic-bezier(.2, .7, .3, 1) both; }
.coin .face {
  position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center; backface-visibility: hidden;
  font-family: var(--font-title); font-size: 34px; line-height: 1.1; text-align: center; color: #6b4a00;
  background: radial-gradient(circle at 35% 30%, #ffe8a3, var(--gold) 60%, #c98b10); box-shadow: inset 0 0 0 6px rgba(255,255,255,.35);
}
.coin .front { color: #fff; background: radial-gradient(circle at 35% 30%, #5f8a99, #2f5866 60%, #173440); }
.coin .back { transform: rotateY(180deg); color: #5a3d00; background: radial-gradient(circle at 35% 30%, #fff3b0, #ffd21f 60%, #d9a400); }
.coin .face { align-content: center; }
.coin .face img { width: 58px; height: 58px; display: block; margin: 0 auto; }
.coin .face small { display: block; font-family: inherit; font-size: 13px; line-height: 1.2; }
@keyframes flipH { from { transform: translateY(0) rotateY(0); } 40% { transform: translateY(-40px) rotateY(900deg); } to { transform: translateY(0) rotateY(1800deg); } }
@keyframes flipT { from { transform: translateY(0) rotateY(0); } 40% { transform: translateY(-40px) rotateY(900deg); } to { transform: translateY(0) rotateY(1980deg); } }
.coin-text { font-weight: 700; color: var(--ink) !important; }

.credit { text-align: center; font-size: 11px; color: var(--muted); padding: 8px 16px 16px; }

.lands { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13px; }
.lands-title { color: var(--muted); font-size: 12px; }
.land-row { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.land-row img { width: 20px; height: 20px; }
.chip { width: 22px; height: 22px; border-radius: 6px; background-size: cover; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.chip.normal { background: #b9773f; }
.chip.rich { background: #46b04a; }
.chip.barren { background: #6d7480; }
@media (max-width: 480px) {
  .bet { grid-template-columns: 30px 1fr 48px 1fr 1fr; }
  .bet .what { display: none; }
  .game .panel p, .game .panel .status { display: none; }
  .game .panel h3 { font-size: 19px; }
  .bet .btn { min-height: 40px; }
  .panel { padding: 12px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
