/*
  프레지던트 · 다빈치코드: 입체 타일, 카드 기울기, 차례 강조, 손맛 효과.
  arcade.css 다음에 읽습니다. patch.css 토큰만 씁니다.
  - 다빈치코드 타일은 앞·뒤·위·아래·왼쪽·오른쪽 면과 둥근 모서리 속판을 가진 진짜 CSS 3D 덩어리입니다.
    줄(.tiles-row)마다 카메라 하나: 원근은 줄이 갖고, 내려다보는 각(--tilt)은 모든 타일이 같은 값을 씁니다.
    타일은 바닥 뒤 모서리를 축으로 섭니다. 공개되면 그 축으로 뒤로 넘어가 탁자에 눕습니다(--fall: 90deg).
  - 빛은 왼쪽 위 앞에서 옵니다: 윗면이 가장 밝고, 왼쪽 > 오른쪽 > 아랫면 순으로 어둡습니다.
  - 강조 테두리는 타일 면과 두께(옆면)에 칠하므로 타일과 함께 기웁니다.
  - 움직임은 prefers-reduced-motion에서 모두 멈춥니다(patch.css도 시간을 줄입니다).
*/

/* ===================== 다빈치코드: 3D 타일 ===================== */
/*
  보드게임 장난감 같은 둥근 덩어리: 상아색(흰) · 숯색(검정) 타일.
  앞·뒤 면은 둥근 모서리, 곧은 옆면 네 장은 모서리 반지름만큼 안쪽에 두고,
  모서리의 둥근 부분은 안쪽에 겹쳐 둔 얇은 판(.tile-core) 열 장이 채웁니다.
*/
.tiles-row,
.drawn-group {
  perspective: 1000px;
  perspective-origin: 50% 45%;
}
.code-tile {
  --tilt: 36deg;          /* 카메라가 탁자를 내려다보는 각: 윗면이 보입니다 */
  --stand-rest: 10deg;    /* 받침대에 기대 선 타일이 뒤로 젖혀진 각 */
  --rest: var(--stand-rest);
  --fall: 0deg;           /* 90deg = 탁자에 눕힘 */
  --rise: 0%;             /* 들어 올림 */
  --near: 0px;            /* 앞으로 당김 */
  --d: 32cqw;             /* 두께: 타일 폭의 32% */
  --r: 16cqw;             /* 모서리 반지름 */
  --hl: transparent;      /* 강조 색: 면 둘레와 두께에 칠합니다 */
  --hl-w: 0px;
  --hl-ink: 0px;
  --line: color-mix(in srgb, var(--tile-bg) 72%, var(--seam-strong));
  --line-w: 1px;
  --face-extra: 0 0 0 0 transparent;
  /* 흰 타일: 따뜻한 상아색 */
  --tile-bg: color-mix(in srgb, var(--sheet) 60%, var(--gardenia-tint));
  --tile-ink: var(--ink);
  --tile-edge: var(--line);
  --edge-top: color-mix(in srgb, var(--tile-bg) 45%, var(--on-dye));
  --edge-lip: var(--on-dye);
  --edge-left: color-mix(in srgb, var(--tile-bg) 80%, var(--seam));
  --edge-right: color-mix(in srgb, var(--tile-bg) 52%, var(--seam-strong));
  --edge-bottom: color-mix(in srgb, var(--tile-bg) 40%, var(--seam-strong));
  --edge-core: color-mix(in srgb, var(--tile-bg) 66%, var(--seam));
  --bevel-hi: color-mix(in srgb, var(--on-dye) 90%, transparent);
  --bevel-lo: color-mix(in srgb, var(--seam) 34%, transparent);
  --gloss: color-mix(in srgb, var(--on-dye) 70%, transparent);
  --engrave: var(--on-dye);
  --joker: var(--safflower);
  perspective: none;
  transform-style: preserve-3d;
}
/* 검정 타일: 순검정이 아닌 짙은 숯색 */
.code-tile.black {
  --tile-bg: color-mix(in srgb, var(--ink) 84%, var(--on-dye));
  --tile-ink: color-mix(in srgb, var(--on-dye) 80%, var(--gardenia-tint));
  --line: color-mix(in srgb, var(--ink) 92%, var(--on-dye));
  --edge-top: color-mix(in srgb, var(--ink) 56%, var(--on-dye));
  --edge-lip: color-mix(in srgb, var(--ink) 38%, var(--on-dye));
  --edge-left: color-mix(in srgb, var(--ink) 72%, var(--on-dye));
  --edge-right: color-mix(in srgb, var(--ink) 94%, var(--on-dye));
  --edge-bottom: var(--ink);
  --edge-core: color-mix(in srgb, var(--ink) 82%, var(--on-dye));
  --bevel-hi: color-mix(in srgb, var(--on-dye) 22%, transparent);
  --bevel-lo: color-mix(in srgb, var(--ink) 70%, transparent);
  --gloss: color-mix(in srgb, var(--on-dye) 16%, transparent);
  --engrave: var(--ink);
  --joker: var(--gardenia);
}
.tile-stand {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  transform-origin: 50% 100% calc(var(--d) / -2);
  transform: translate3d(0, var(--rise), var(--near)) rotateX(calc(var(--rest) + var(--fall) - var(--tilt)));
  transition: transform 320ms cubic-bezier(.3, 1.45, .5, 1);
}
.code-tile .tile-solid {
  position: absolute;
  inset: 0;
}
.code-tile .tile-face { transform: translateZ(calc(var(--d) / 2)); }
.code-tile .tile-back { transform: rotateY(180deg) translateZ(calc(var(--d) / 2)); }
.code-tile .tile-face,
.code-tile .tile-back {
  border: 0;
  border-radius: var(--r);
  background: var(--tile-bg);
  color: var(--tile-ink);
  font-size: 50cqw;
  font-weight: 820;
  letter-spacing: -.04em;
  /* 둥글게 부푼 면: 위쪽 맑은 테, 아래쪽 옅은 그늘. 바깥은 강조 테(먹 테 포함). */
  box-shadow:
    inset 0 0 0 var(--line-w) var(--line),
    inset 0 3cqw 0 var(--bevel-hi),
    inset 0 -4cqw 0 var(--bevel-lo),
    var(--face-extra),
    0 0 0 var(--hl-w) var(--hl),
    0 0 0 calc(var(--hl-w) + var(--hl-ink)) var(--ink);
}
/* 면의 광택 띠: 왼쪽 위에서 비스듬히 */
.code-tile .tile-face::after,
.code-tile .tile-back::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(155deg, transparent 10%, var(--gloss) 16%, var(--gloss) 22%, transparent 30%);
  pointer-events: none;
}
/* 숫자: 면에 찍어 새긴 것처럼 아래쪽에 맑은 선 하나 */
.tile-num {
  position: relative;
  display: inline-block;
  line-height: 1;
  text-shadow: 0 1px 0 var(--engrave);
}
.code-tile.black .tile-num { text-shadow: 0 -1px 0 var(--engrave); }
/* 6과 9를 가르는 밑줄 */
.tile-num-under::after {
  content: '';
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: -.1em;
  height: .09em;
  border-radius: 1em;
  background: currentColor;
}
/* 조커: 안쪽 색 테와 색 있는 −로 한눈에 */
.code-tile.joker-tile { --face-extra: inset 0 0 0 9cqw var(--tile-bg), inset 0 0 0 12cqw var(--joker); }
.code-tile.joker-tile .tile-face { color: var(--joker); }
/* 아직 상대에게 숨긴 내 타일: 둥근 점선 테 */
.code-tile:not(.revealed):not(.hidden-number) .tile-face::before {
  inset: 10%;
  border-radius: calc(var(--r) * .6);
  opacity: .4;
}
/* 뒷면: 둥근 테 안에 작은 마름모 무늬 */
.code-tile .tile-back-pattern,
.pool-tile .tile-back-pattern {
  inset: 13%;
  border: 1.5px solid currentColor;
  border-radius: calc(var(--r, 6px) * .6);
  opacity: .34;
}
.code-tile .tile-back-pattern i:nth-child(-n + 2),
.pool-tile .tile-back-pattern i:nth-child(-n + 2) {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  translate: -50% -50%;
}
.code-tile .tile-back-pattern i:nth-child(1),
.pool-tile .tile-back-pattern i:nth-child(1) {
  width: 40%;
  aspect-ratio: 1;
  border: 1.5px solid currentColor;
  border-radius: 24%;
  rotate: 45deg;
}
.code-tile .tile-back-pattern i:nth-child(2),
.pool-tile .tile-back-pattern i:nth-child(2) {
  width: 12%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
}
.tile-edges {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  pointer-events: none;
}
.tile-edge {
  position: absolute;
  display: block;
  background: var(--edge-left);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.tile-edge-top,
.tile-edge-bottom { left: var(--r); width: calc(100% - 2 * var(--r)); height: var(--d); }
.tile-edge-left,
.tile-edge-right { top: var(--r); height: calc(100% - 2 * var(--r)); width: var(--d); }
/* 윗면: 가장 밝고, 앞쪽 모서리에 맑은 빛 한 줄 */
.tile-edge-top { top: calc(var(--d) / -2); transform: rotateX(90deg); background: var(--edge-top); box-shadow: inset 0 -1.5px 0 var(--edge-lip); }
.tile-edge-bottom { top: calc(100% - var(--d) / 2); transform: rotateX(-90deg); background: var(--edge-bottom); }
.tile-edge-left { left: calc(var(--d) / -2); transform: rotateY(-90deg); background: var(--edge-left); }
.tile-edge-right { left: calc(100% - var(--d) / 2); transform: rotateY(90deg); background: var(--edge-right); }
/* 둥근 모서리를 채우는 속판 */
.tile-core {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: var(--r);
  background: var(--edge-core);
}
.tile-core:nth-of-type(1) { transform: translateZ(calc(var(--d) * 0.45)); }
.tile-core:nth-of-type(2) { transform: translateZ(calc(var(--d) * 0.35)); }
.tile-core:nth-of-type(3) { transform: translateZ(calc(var(--d) * 0.25)); }
.tile-core:nth-of-type(4) { transform: translateZ(calc(var(--d) * 0.15)); }
.tile-core:nth-of-type(5) { transform: translateZ(calc(var(--d) * 0.05)); }
.tile-core:nth-of-type(6) { transform: translateZ(calc(var(--d) * -0.05)); }
.tile-core:nth-of-type(7) { transform: translateZ(calc(var(--d) * -0.15)); }
.tile-core:nth-of-type(8) { transform: translateZ(calc(var(--d) * -0.25)); }
.tile-core:nth-of-type(9) { transform: translateZ(calc(var(--d) * -0.35)); }
.tile-core:nth-of-type(10) { transform: translateZ(calc(var(--d) * -0.45)); }
/* 뒷면을 보이는 타일은 상자가 반 바퀴 돌아 있으므로 왼쪽·오른쪽 면이 바뀝니다. 빛은 그대로 둡니다. */
.code-tile.hidden-number .tile-edge-left { background: var(--edge-right); }
.code-tile.hidden-number .tile-edge-right { background: var(--edge-left); }
/* 탁자에 닿는 그림자: 넓고 부드러운 그늘 + 닿는 자리의 진한 선(접지 그늘). 빛이 앞에서 오므로 뒤로 번집니다. */
.code-tile::before {
  content: '';
  position: absolute;
  left: -14%;
  right: -14%;
  bottom: 0;
  height: var(--shadow-depth, 58%);
  border-radius: 50%;
  background:
    radial-gradient(46% 16% at 50% var(--foot, 76%), color-mix(in srgb, var(--ink) 46%, transparent), transparent),
    radial-gradient(closest-side, color-mix(in srgb, var(--ink) 30%, transparent) 30%, transparent);
  transform-origin: 50% 100%;
  transform: translateZ(calc(var(--d) / -2)) rotateX(calc(90deg - var(--tilt))) translateY(var(--shadow-front, 22%)) translateZ(-1px);
  pointer-events: none;
}

/* 공개된 타일은 바닥 뒤 모서리를 축으로 넘어가 탁자에 눕습니다(앞면이 위, 숫자는 그대로 읽힙니다). */
.code-tile.revealed { --rest: 0deg; --fall: 90deg; --shadow-depth: 124%; --shadow-front: 8%; --foot: 50%; }
/* 공개된 숫자는 누운 채로도 읽히도록 조금 크게 새깁니다. */
.code-tile.revealed:not(.joker-tile) .tile-face { font-size: 60cqw; }
.code-tile.revealed .tile-slot { top: calc(100% - 100% * sin(var(--tilt)) - var(--d) - 15px); }
/* 누운 타일은 앞으로 보이는 아랫면이 두께가 됩니다: 탁자에서 받은 빛만큼 조금 밝게 */
.code-tile.revealed:not(.black) { --edge-bottom: color-mix(in srgb, var(--tile-bg) 70%, var(--seam)); }
.code-tile.revealed.black { --edge-bottom: color-mix(in srgb, var(--ink) 80%, var(--on-dye)); }
/* 내 타일이 공개되면 홍화 테두리: 지킬 수 없게 된 조각 */
.my-code .code-tile.revealed { --line: var(--safflower); --line-w: 2.5px; }
/* 날아가는 동안에는 아직 서 있습니다. 내려앉은 뒤 arcade.js가 넘어지는 움직임을 한 번 그립니다. */
.table-flight .code-tile.tile-upright { --rest: var(--stand-rest); --fall: 0deg; }

/* ---------- 강조: 면 둘레(먹 테 포함)와 두께를 함께 칠합니다 ---------- */
.code-tile.targetable { --hl: var(--indigo); --hl-w: 2px; }
.code-tile[data-reveal] { --hl: var(--safflower); --hl-w: 2px; --hl-ink: 2px; }
.code-tile.guess-targeted:not(.guess-hit):not(.guess-miss) { --hl: var(--gardenia); --hl-w: 3px; --hl-ink: 2px; }
.code-tile.last-guess-hit,
.code-tile.guess-hit { --hl: var(--mugwort); --hl-w: 3px; --hl-ink: 0px; }
.code-tile.last-guess-miss,
.code-tile.guess-miss { --hl: var(--safflower); --hl-w: 3px; --hl-ink: 0px; }
.code-tile.target { --hl: var(--indigo); --hl-w: 4px; --hl-ink: 2px; }
.code-tile.place-candidate { --hl: var(--gardenia); --hl-w: 3px; --hl-ink: 2px; }
.code-tile.place-candidate.place-rejected { --hl: var(--safflower); }
.code-tile.preview-ghost { --hl: var(--gardenia); --hl-w: 3px; --hl-ink: 2px; }
.code-tile.targetable:focus-visible,
.code-tile[data-reveal]:focus-visible,
.code-tile.place-candidate:focus-visible { --hl: var(--indigo); --hl-w: 4px; --hl-ink: 3px; outline: 0; }
.code-tile:focus-visible { outline: 0; }
/* 강하게 고른 타일은 두께도 강조 색입니다: 옆에서 봐도 테두리가 타일에 붙어 있습니다. */
.code-tile:is(.target, .guess-targeted, .guess-hit, .guess-miss, .place-candidate, .preview-ghost, :focus-visible) :is(.tile-edge, .tile-core) { background: var(--hl); }
.code-tile:is(.target, .guess-targeted, .guess-hit, .guess-miss, .place-candidate, .preview-ghost, :focus-visible) .tile-edge-top { background: color-mix(in srgb, var(--hl) 72%, var(--on-dye)); }
.code-tile:is(.target, .guess-targeted, .guess-hit, .guess-miss, .place-candidate, .preview-ghost, :focus-visible) .tile-edge-right { background: color-mix(in srgb, var(--hl) 80%, var(--ink)); }

/* 추측할 수 있는 타일: 손을 올리면 들썩입니다. */
@media (hover: hover) and (pointer: fine) {
  .code-tile.targetable:hover:not(:disabled),
  .code-tile[data-reveal]:hover:not(:disabled) { --rest: 2deg; --rise: -10%; --near: 10px; --hl-w: 3px; --hl-ink: 2px; }
  .pool-tile:enabled:hover { --pool-lift: 10px; }
}
.code-tile.targetable:focus-visible,
.code-tile[data-reveal]:focus-visible { --rest: 2deg; --rise: -10%; --near: 10px; }
.code-tile.target { --rest: 0deg; --rise: -14%; --near: 20px; }
.code-tile.target .tile-stand { animation: tile-wiggle 900ms ease-in-out infinite; }
@keyframes tile-wiggle {
  0%, 100% { rotate: 0deg; }
  25% { rotate: -3deg; }
  75% { rotate: 3deg; }
}
/* 방금 맞힌/틀린 타일 */
.code-tile.guess-hit .tile-stand { animation: tile-pop 520ms cubic-bezier(.3, 1.6, .5, 1); }
.code-tile.guess-miss .tile-stand { animation: tile-nope 420ms ease-in-out; }
@keyframes tile-pop {
  0% { scale: 1; }
  45% { scale: 1.22; }
  100% { scale: 1; }
}
@keyframes tile-nope {
  0%, 100% { translate: 0; }
  20% { translate: -5px 0; }
  45% { translate: 5px 0; }
  70% { translate: -3px 0; }
}

/* ---------- 가운데 더미: 같은 상아·숯색 둥근 타일을 탁자에 엎어 둡니다 ---------- */
.pool-zone { perspective: 1100px; perspective-origin: 50% 10%; }
.pool-scatter {
  transform: rotateX(40deg);
  transform-origin: 50% 60%;
  transform-style: preserve-3d;
}
.pool-tile {
  --pool-d: 9px;
  --pool-round: 6px;
  --pool-bg: color-mix(in srgb, var(--sheet) 60%, var(--gardenia-tint));
  --pool-line: color-mix(in srgb, var(--pool-bg) 72%, var(--seam-strong));
  --pool-side: color-mix(in srgb, var(--pool-bg) 62%, var(--seam));
  --pool-near: color-mix(in srgb, var(--pool-bg) 70%, var(--seam));
  --pool-far: color-mix(in srgb, var(--pool-bg) 45%, var(--on-dye));
  --pool-west: color-mix(in srgb, var(--pool-bg) 80%, var(--seam));
  --pool-east: color-mix(in srgb, var(--pool-bg) 50%, var(--seam-strong));
  border-width: 1px;
  border-radius: var(--pool-round);
  transform-style: preserve-3d;
  transform: translate(-50%, -50%) rotate(var(--pool-r, 0deg)) translateZ(calc(var(--pool-d) + var(--pool-lift, 0px)));
  transition: transform 260ms cubic-bezier(.3, 1.5, .5, 1), outline-color var(--quick) var(--ease);
}
.pool-tile.black {
  --pool-bg: color-mix(in srgb, var(--ink) 84%, var(--on-dye));
  --pool-line: color-mix(in srgb, var(--ink) 92%, var(--on-dye));
  --pool-side: color-mix(in srgb, var(--ink) 82%, var(--on-dye));
  --pool-near: color-mix(in srgb, var(--ink) 78%, var(--on-dye));
  --pool-far: color-mix(in srgb, var(--ink) 56%, var(--on-dye));
  --pool-west: color-mix(in srgb, var(--ink) 72%, var(--on-dye));
  --pool-east: var(--ink);
}
.pool-tile,
.pool-tile:disabled,
.pool-tile:hover:not(:disabled) {
  border-color: var(--pool-line);
  background: var(--pool-bg);
  box-shadow: inset 0 2px 0 color-mix(in srgb, var(--on-dye) 40%, transparent), inset 0 -2px 0 color-mix(in srgb, var(--ink) 14%, transparent);
}
.pool-tile:not(.black),
.pool-tile:not(.black):disabled,
.pool-tile:not(.black):hover:not(:disabled) { color: var(--ink); }
.pool-tile.black,
.pool-tile.black:disabled,
.pool-tile.black:hover:not(:disabled) { color: color-mix(in srgb, var(--on-dye) 80%, var(--gardenia-tint)); }
/* 탁자에 닿는 그림자: 들어 올려도 탁자에 남습니다. */
.pool-tile::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: calc(var(--pool-round) + 3px);
  background: radial-gradient(closest-side, color-mix(in srgb, var(--ink) 30%, transparent) 55%, transparent);
  transform: translateZ(calc(-1 * var(--pool-d) - var(--pool-lift, 0px) - 1px)) translate(1px, -2px);
  pointer-events: none;
}
.pool-edge,
.pool-core {
  position: absolute;
  display: block;
  pointer-events: none;
}
.pool-edge {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.pool-edge.near { background: var(--pool-near); }
.pool-edge.far { background: var(--pool-far); }
.pool-edge.west { background: var(--pool-west); }
.pool-edge.east { background: var(--pool-east); }
/* 곧은 옆면은 모서리 반지름만큼 안쪽, 둥근 모서리는 속판이 채웁니다(절대 위치는 테두리 안쪽 기준). */
.pool-edge.near { top: calc(100% + 1px); left: calc(var(--pool-round) - 1px); width: calc(100% - 2 * var(--pool-round) + 2px); height: var(--pool-d); transform-origin: top; transform: rotateX(-90deg); }
.pool-edge.far { bottom: calc(100% + 1px); left: calc(var(--pool-round) - 1px); width: calc(100% - 2 * var(--pool-round) + 2px); height: var(--pool-d); transform-origin: bottom; transform: rotateX(90deg); }
.pool-edge.west { right: calc(100% + 1px); top: calc(var(--pool-round) - 1px); height: calc(100% - 2 * var(--pool-round) + 2px); width: var(--pool-d); transform-origin: right; transform: rotateY(-90deg); }
.pool-edge.east { left: calc(100% + 1px); top: calc(var(--pool-round) - 1px); height: calc(100% - 2 * var(--pool-round) + 2px); width: var(--pool-d); transform-origin: left; transform: rotateY(90deg); }
.pool-core { inset: -1px; border-radius: var(--pool-round); background: var(--pool-side); }
.pool-core:nth-of-type(1) { transform: translateZ(calc(var(--pool-d) * -.25)); }
.pool-core:nth-of-type(2) { transform: translateZ(calc(var(--pool-d) * -.5)); }
.pool-core:nth-of-type(3) { transform: translateZ(calc(var(--pool-d) * -.75)); }
/* 고를 수 있는 타일: 테두리와 두께가 함께 쪽빛으로 */
.pool-tile:enabled:hover :is(.pool-edge, .pool-core),
.pool-tile:focus-visible :is(.pool-edge, .pool-core) { background: var(--indigo); }

/* ---------- 넣을 자리 고르기: 어디든 대 볼 수 있고, 확정할 때 검사합니다 ---------- */
.tile-placement-slots { --slot-w: 30px; }
.tile-placement-slot {
  border-width: var(--seam-width);
  background: color-mix(in srgb, var(--gardenia) 70%, transparent);
  transition: transform 180ms cubic-bezier(.3, 1.5, .5, 1), background-color var(--quick) var(--ease);
}
.tile-placement-slot svg { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .tile-placement-slot:hover:not(:disabled) { transform: scaleX(1.25) translateY(-4px); }
}
.code-tile.place-candidate {
  width: var(--hand-tile-w, 54px);
  cursor: pointer;
  outline: 0;
  border-radius: var(--radius-small);
}
.code-tile.place-candidate .tile-slot,
.code-tile.preview-ghost .tile-slot { display: none; }
.code-tile.place-candidate { --rest: 4deg; --rise: -16%; --near: 18px; }
.code-tile.place-candidate .tile-stand { animation: candidate-bob 1.4s ease-in-out infinite; }
@keyframes candidate-bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -5px; }
}
.candidate-cue,
.ghost-cue {
  position: absolute;
  left: 50%;
  bottom: -20px;
  translate: -50% 0;
  padding: 1px 6px;
  border-radius: var(--radius-small);
  background: var(--ink);
  color: var(--gardenia);
  font-size: var(--text-xs);
  font-weight: 800;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}
.code-tile.place-candidate.place-rejected .tile-stand { animation: tile-nope 420ms ease-in-out 2; }
.code-tile.place-candidate.place-rejected .candidate-cue { background: var(--safflower); color: var(--on-dye); }
.action-hint.placement-rejected { color: var(--safflower); font-weight: 800; }
/* 상대가 지금 대 보고 있는 자리: 뒷면 유령 타일 */
.code-tile.preview-ghost { --rest: 4deg; --rise: -14%; --near: 14px; }
.code-tile.preview-ghost .tile-stand { animation: candidate-bob 1.1s ease-in-out infinite; }
.ghost-cue { bottom: auto; top: -22px; background: var(--gardenia); color: var(--ink); animation: ghost-cue 1.1s ease-in-out infinite; }
@keyframes ghost-cue {
  0%, 100% { scale: 1; }
  50% { scale: 1.15; }
}

/* ===================== 프레지던트: 카드 기울기 ===================== */
.my-cards { perspective: 900px; }
.playing-card {
  transform-style: preserve-3d;
  --lift: 0px;
}
.my-cards .playing-card.selectable {
  transform: translateY(var(--lift)) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateZ(var(--tz, 0px));
  transition: transform 260ms cubic-bezier(.3, 1.5, .5, 1), background-color var(--quick) var(--ease), border-color var(--quick) var(--ease), box-shadow var(--steady) var(--ease);
}
.my-cards .playing-card.selectable.tilting { transition: transform 70ms linear, background-color var(--quick) var(--ease), border-color var(--quick) var(--ease); }
/* 광택: 포인터를 따라가는 빛 */
.my-cards .playing-card.selectable::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 0%), rgb(255 255 255 / .55), rgb(255 255 255 / 0) 55%);
  opacity: 0;
  transition: opacity var(--steady) var(--ease);
  pointer-events: none;
}
@media (hover: hover) and (pointer: fine) {
  .my-cards .playing-card.selectable:hover:not(:disabled) { --lift: -10px; --tz: 24px; z-index: 3; box-shadow: 0 14px 18px -10px rgb(0 0 0 / .45); }
  .my-cards .playing-card.selectable:hover:not(:disabled)::after { opacity: 1; }
}
.my-cards .playing-card.selected,
.my-cards .playing-card.selected:hover:not(:disabled),
.my-cards .playing-card.selected:disabled { --lift: -20px; --tz: 16px; transform: translateY(var(--lift)) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateZ(var(--tz, 0px)); box-shadow: inset 0 0 0 2px var(--indigo), 0 10px 0 -6px var(--indigo); }
.my-cards .playing-card.selected { animation: card-pick 340ms cubic-bezier(.3, 1.6, .5, 1); }
@keyframes card-pick {
  0% { scale: 1; }
  40% { scale: 1.08; }
  100% { scale: 1; }
}
/* 테이블에 막 놓인 맨 위 카드 */
.trick-layer.top-play .playing-card { box-shadow: 0 6px 0 -3px rgb(0 0 0 / .2); }

/* ===================== 차례 강조 ===================== */
/* 지금 차례인 자리: 두꺼운 먹 테 + 치자 바탕. 깜빡이지 않고 한눈에 보입니다. */
.opponent.active,
.code-rack.active,
.player-row.active {
  position: relative;
  background: color-mix(in srgb, var(--gardenia) 46%, var(--sheet));
  box-shadow: inset 0 0 0 3px var(--ink);
}
.code-rack.active { box-shadow: inset 0 0 0 4px var(--ink); }
.opponent.active .opponent-name,
.code-rack.active .rack-label > .rack-identity > b,
.player-row.active .player-name { font-weight: 850; }
/* 차례 꼬리표: 먹 바탕에 치자 글자, 앞에 화살표 */
.opponent.active .seat-turn-label,
.code-rack.active .seat-turn-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 7px;
  background: var(--ink);
  color: var(--gardenia);
  font-weight: 850;
  transform-origin: 0 50%;
  animation: label-nudge 1.2s ease-in-out infinite;
}
.opponent.active .seat-turn-label::before,
.code-rack.active .seat-turn-label::before {
  content: '';
  flex: none;
  width: 7px;
  height: 9px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
@keyframes label-nudge {
  0%, 100% { translate: 0 0; }
  50% { translate: 3px 0; }
}
/* 다른 사람 차례에는 차례가 아닌 상대 줄이 한 걸음 물러납니다(내 차례에는 모두 추측 대상이므로 그대로). */
body:not([data-my-turn="true"]) .code-opponents:has(.code-rack.active) .code-rack:not(.active) { background: var(--cloth); }
body:not([data-my-turn="true"]) .code-opponents:has(.code-rack.active) .code-rack:not(.active) :is(.rack-tiles, .rack-label) { opacity: .5; filter: saturate(.4); }
.in-game:not([data-my-turn="true"]):has(.code-rack.active) .my-panel { background: var(--cloth); }
.in-game:not([data-my-turn="true"]):has(.code-rack.active) .my-code { opacity: .8; filter: saturate(.6); }
/* 머리줄: 누구 차례인지 이름표로 */
.turn-other {
  display: inline-block;
  padding: 0 8px;
  border: var(--seam-width) solid var(--ink);
  border-radius: var(--radius-small);
  background: var(--gardenia-tint);
}
/* 좁은 화면에서 긴 이름이 머리줄 밖으로 밀려나지 않게 말줄임으로 자릅니다. */
#turnTitle { min-width: 0; max-width: 100%; overflow: hidden; white-space: nowrap; }
.turn-other, .turn-mine { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
/* 내 차례: 머리줄 문구와 내 패 조각 */
.turn-mine {
  display: inline-block;
  padding: 0 8px;
  border-radius: var(--radius-small);
  background: var(--ink);
  color: var(--gardenia);
  animation: mine-stamp 520ms cubic-bezier(.3, 1.7, .5, 1);
}
@keyframes mine-stamp {
  0% { scale: 1.8; rotate: -8deg; opacity: 0; }
  60% { scale: .94; rotate: 2deg; opacity: 1; }
  100% { scale: 1; rotate: 0deg; }
}
.in-game[data-my-turn="true"] .my-panel {
  background: color-mix(in srgb, var(--gardenia) 46%, var(--sheet));
  box-shadow: inset 0 0 0 4px var(--ink);
}
.in-game[data-my-turn="true"] .my-panel .seat-turn-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px 2px 8px;
  background: var(--ink);
  color: var(--gardenia);
  font-size: var(--text-sm);
  font-weight: 850;
  animation: label-pop 1.6s ease-in-out infinite;
}
.in-game[data-my-turn="true"] .my-panel .seat-turn-label::before {
  content: '';
  flex: none;
  width: 9px;
  height: 7px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
@keyframes label-pop {
  0%, 100% { scale: 1; }
  50% { scale: 1.08; }
}

/* ===================== 손맛 효과 (arcade.js가 띄웁니다) ===================== */
.fx-layer {
  position: fixed;
  inset: 0;
  z-index: 170;
  overflow: hidden;
  pointer-events: none;
}
.fx-stamp {
  position: absolute;
  left: 50%;
  top: 42%;
  padding: 6px 18px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--gardenia);
  color: var(--ink);
  font-size: clamp(1.6rem, 1rem + 4vw, 3.4rem);
  font-weight: 900;
  letter-spacing: -.02em;
  white-space: nowrap;
  translate: -50% -50%;
  box-shadow: 6px 6px 0 var(--ink);
}
.fx-stamp.good { background: var(--mugwort); color: var(--on-dye); }
.fx-stamp.bad { background: var(--safflower); color: var(--on-dye); }
.fx-stamp.cool { background: var(--indigo); color: var(--on-dye); }
.fx-bit {
  position: absolute;
  width: 10px;
  height: 14px;
  border-radius: 1px;
}
.fx-flash { position: absolute; inset: 0; }
.fx-shake { animation: fx-shake 380ms ease-in-out; }
@keyframes fx-shake {
  0%, 100% { translate: 0 0; }
  20% { translate: -6px 2px; }
  40% { translate: 5px -2px; }
  60% { translate: -3px 1px; }
  80% { translate: 2px 0; }
}
.trick-zone.fx-slam { animation: fx-slam 360ms cubic-bezier(.3, 1.6, .5, 1); }
@keyframes fx-slam {
  0% { scale: 1; }
  35% { scale: 1.035; }
  100% { scale: 1; }
}

/* 결과창 */
.result-panel[data-winner="me"] h2 { animation: mine-stamp 700ms cubic-bezier(.3, 1.7, .5, 1); color: var(--mugwort); }

/* ===================== 휴대폰 ===================== */
@media (max-width: 680px) {
  .tiles-row,
  .drawn-group { perspective: 900px; }
  .code-tile { --tilt: 33deg; --stand-rest: 8deg; --d: 30cqw; }
  .tile-placement-slots { --slot-w: 24px; }
  .my-code .tile-placement-slots { --tile-gap: 4px; padding-left: 2px; padding-right: 2px; }
  .my-code .tile-placement-slots .code-tile { width: clamp(28px, calc((100% - var(--placement-count) * var(--slot-w) - (var(--tile-count) + var(--placement-count)) * var(--tile-gap)) / var(--tile-count)), 42px); }
  .pool-scatter { transform: rotateX(30deg); }
  .pool-tile { --pool-d: 6px; --pool-round: 4px; }
  .candidate-cue { bottom: -18px; padding: 0 4px; }
  .ghost-cue { top: -19px; padding: 0 4px; }
  .code-rack.active,
  .in-game[data-my-turn="true"] .my-panel { box-shadow: inset 0 0 0 3px var(--ink); }
  .in-game[data-my-turn="true"] .my-panel .seat-turn-label { font-size: var(--text-xs); padding: 1px 8px 1px 6px; }
}
@media (max-height: 500px) and (min-width: 681px) {
  .pool-scatter { transform: rotateX(24deg); }
}

/* ===================== 동작 줄이기 ===================== */
@media (prefers-reduced-motion: reduce) {
  .tile-stand,
  .my-cards .playing-card.selectable,
  .pool-tile,
  .tile-placement-slot { transition: none; }
  .code-tile .tile-stand,
  .pool-tile,
  .opponent.active,
  .code-rack.active,
  .player-row.active,
  .seat-turn-label,
  .turn-mine,
  .ghost-cue,
  .my-cards .playing-card.selected,
  .in-game[data-my-turn="true"] .my-panel,
  .result-panel[data-winner="me"] h2 { animation: none !important; }
  .my-cards .playing-card.selectable { --rx: 0deg !important; --ry: 0deg !important; }
  .fx-layer { display: none; }
}
