/* Math Tower - css/chess.css: the Chess Tower screens (v7, js/chessui.js). Uses the tokens and the .btn / .card /
   .modal-head / .rank-tag / .icon-btn components of style.css. */

.chess-layer { position: fixed; inset: 0; z-index: 32; pointer-events: none; font-family: var(--font-body); color: var(--ink); }
.chess-layer [hidden] { display: none !important; }

/* While you walk the hall: the tower-only parts of the HUD rest. While you play: the HUD rests completely. */
#ui-root.in-chess .hud-meter, #ui-root.in-chess .chip-skip, #ui-root.in-chess .chip-per, #ui-root.in-chess .chip-carry,
#ui-root.in-chess .power-dock, #ui-root.in-chess .btn-down, #ui-root.in-chess .wand-rescue { display: none !important; }
#ui-root.in-match .hud, #ui-root.in-match .station-prompt, #ui-root.in-match .ch-hallchip { visibility: hidden; }
#ui-root.in-match .toasts { top: calc(var(--safe-t) + 128px); }

/* ---------------- the flash (doors and teleport squares) ---------------- */
.ch-flash {
  position: absolute; inset: 0; pointer-events: auto; opacity: 0;
  background: radial-gradient(circle at 50% 55%, #ffffff 0%, #ffffff 16%, var(--flash, #ffffff) 70%);
  transition: opacity 0.26s ease;
}
.ch-flash.is-in { opacity: 1; }
.ch-flash.is-out { opacity: 0; transition-duration: 0.42s; }

/* ---------------- the hall chip ---------------- */
.ch-hallchip {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 12px); transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px 5px 10px;
  border: 3px solid var(--ink); border-radius: 999px; background: #2b1468; color: #fff; box-shadow: 0 4px 0 var(--ink);
  font-family: var(--font-display); font-size: 16px; letter-spacing: 0.04em; white-space: nowrap;
  animation: ch-pop-in 0.35s cubic-bezier(0.2, 1.35, 0.4, 1);
}
.ch-hallchip > .icon { width: 22px; height: 22px; color: #ffe14d; }
.ch-hc-xp { display: inline-flex; align-items: center; gap: 4px; padding: 1px 10px 0 6px; border-radius: 999px; background: #ffe14d; color: var(--ink); }
.ch-hc-xp .icon { width: 18px; height: 18px; }
@media (max-width: 720px) {
  .ch-hallchip { top: auto; bottom: calc(var(--safe-b) + 150px); font-size: 14px; }
  .ch-hc-name { display: none; }
}

/* ---------------- the match bar ---------------- */
.ch-hud {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 10px); transform: translateX(-50%);
  width: min(780px, calc(100vw - 20px)); display: grid; gap: 6px; justify-items: stretch;
  animation: ch-drop-in 0.4s cubic-bezier(0.2, 1.35, 0.4, 1);
}
.ch-bar {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 8px;
  border: var(--line) solid var(--ink); border-radius: 22px; background: var(--paper); box-shadow: 0 5px 0 var(--ink);
}
.ch-lv {
  flex: none; padding: 4px 12px 2px; border: 3px solid var(--ink); border-radius: 12px; background: var(--lv, #4fd16b);
  color: #fff; text-shadow: var(--o-sm); font-family: var(--font-display); font-size: 18px; letter-spacing: 0.05em; box-shadow: 0 3px 0 var(--ink);
}
.ch-lv.rainbow { color: #fff; }
.ch-vs { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-family: var(--font-display); font-size: 18px; }
.ch-vs b { font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.ch-vs i { font-style: normal; color: var(--ink-3); font-size: 14px; }
.ch-status {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 3px; border: 3px solid var(--ink); border-radius: 999px;
  font-family: var(--font-display); font-size: 17px; white-space: nowrap; background: var(--grass); color: #fff; text-shadow: var(--o-sm);
}
.ch-status.pop { animation: ch-pop 0.3s ease; }
.ch-status.is-bot { background: #b9a6ff; }
.ch-status.is-over { background: var(--paper-3); color: var(--ink); text-shadow: none; }
.ch-status.is-check { background: var(--coral); animation: ch-pulse 0.8s ease-in-out infinite; }
.ch-dots { display: none; gap: 3px; }
.ch-status.is-bot .ch-dots { display: inline-flex; }
.ch-dots i { width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1.5px var(--ink); animation: ch-dot 1s ease-in-out infinite; }
.ch-dots i:nth-child(2) { animation-delay: 0.15s; }
.ch-dots i:nth-child(3) { animation-delay: 0.3s; }
.ch-btns { flex: none; display: flex; gap: 8px; }
.ch-btns .icon-btn { width: 44px; height: 44px; border-radius: 13px; }
.ch-btns .icon-btn .icon { width: 24px; height: 24px; }
.ch-leave { background: var(--paper-2); }
.ch-takenbar { display: flex; justify-content: space-between; gap: 10px; pointer-events: none; }
.ch-taken { display: inline-flex; align-items: center; gap: 0; min-height: 30px; padding: 2px 8px; border-radius: 999px; background: rgba(21, 17, 58, 0.45); }
.ch-taken:empty { visibility: hidden; }
.ch-mini { width: 26px; height: 26px; margin-right: -6px; filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.4)); }
.ch-plus { margin-left: 10px; font-family: var(--font-display); font-weight: 400; color: #ffe14d; font-size: 16px; text-shadow: var(--o-sm); }
@media (max-width: 600px) {
  .ch-bar { flex-wrap: wrap; gap: 8px; border-radius: 18px; }
  .ch-vs { order: 3; flex-basis: 100%; font-size: 15px; justify-content: center; display: none; }
  .ch-status { flex: 1; justify-content: center; font-size: 16px; }
  .ch-leave > span:not(.icon) { display: none; }
  .ch-leave { width: 44px; min-height: 44px; padding: 0; border-radius: 13px; }
  .ch-leave .icon { width: 24px; height: 24px; }
}

/* the first-game tip */
.ch-tip {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 20px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; width: max-content; max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px; border: 3px solid var(--ink); border-radius: 18px; background: #fffbe6; box-shadow: 0 5px 0 var(--ink);
  font-size: 17px; font-weight: 700; line-height: 1.25; animation: ch-rise-in 0.4s cubic-bezier(0.2, 1.35, 0.4, 1);
}
.ch-tip .icon { width: 30px; height: 30px; color: var(--sun-d); }
.ch-tip.is-leaving { animation: fade-out 0.25s ease forwards; }

/* ---------------- cards (welcome, level, confirm, promotion, result) ---------------- */
.ch-card-layer { position: absolute; inset: 0; display: grid; place-items: center; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px); pointer-events: auto; }
.ch-scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade-in 0.2s ease; }
.ch-card-layer.is-leaving, .ch-puzzle-layer.is-leaving { animation: fade-out 0.2s ease forwards; }
.ch-card {
  position: relative; width: min(520px, 100%); max-height: 100%; overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 20px 20px; display: grid; gap: 12px; justify-items: center; text-align: center; outline: none;
  animation: modal-in 0.32s cubic-bezier(0.2, 1.35, 0.4, 1);
}
.ch-card-icon {
  display: grid; place-items: center; width: 74px; height: 74px; margin-top: -4px;
  border: var(--line) solid var(--ink); border-radius: 24px; background: #b9a6ff; box-shadow: 0 5px 0 var(--ink);
}
.ch-card-icon .icon { width: 44px; height: 44px; }
.ch-card-title { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 30px; line-height: 1.1; }
.ch-card-lead { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.3; }
.ch-card-sub { margin: 0; display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; font-size: 17px; line-height: 1.3; }
.ch-card-sub .icon { width: 24px; height: 24px; }
.ch-muted { color: var(--ink-2); font-weight: 600; }
.ch-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }
.ch-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; text-align: left; width: 100%; }
.ch-list li { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; line-height: 1.25; }
.ch-list li > .icon { width: 30px; height: 30px; color: #7b5cff; }
.ch-lvchips { flex-wrap: wrap; justify-content: center; gap: 6px !important; }
.ch-lvchip {
  display: inline-flex; gap: 4px; padding: 3px 9px 1px; border: 3px solid var(--ink); border-radius: 10px; background: var(--lv);
  color: #fff; text-shadow: var(--o-sm); font-family: var(--font-display); font-size: 14px; letter-spacing: 0.04em;
}
.ch-lvchip b { font-weight: 400; color: #ffe14d; }
.ch-lvchip.rainbow, .ch-lv.rainbow, .ch-lvbig.rainbow { background: var(--rainbow); background-size: 200% 100%; animation: rainbow-move 3s linear infinite; }
.ch-lvbig {
  padding: 8px 26px 4px; border: var(--line) solid var(--ink); border-radius: 22px; background: var(--lv, #4fd16b); box-shadow: 0 6px 0 var(--ink);
  color: #fff; text-shadow: var(--o-md); font-family: var(--font-display); font-size: clamp(36px, 10vw, 58px); letter-spacing: 0.05em;
}
.ch-card-level .ch-lvbig { animation: ch-pop-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); }

.ch-promo { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; width: 100%; }
.ch-promo-btn {
  display: grid; justify-items: center; gap: 2px; padding: 10px 4px 8px; border: var(--line) solid var(--ink); border-radius: 18px;
  background: var(--paper-2); box-shadow: 0 5px 0 var(--ink); cursor: pointer; font-family: var(--font-display); font-size: 15px; color: var(--ink);
  touch-action: manipulation;
}
.ch-promo-btn:hover { background: #fff6c8; transform: translateY(-1px); }
.ch-promo-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.ch-promo-btn .pc-svg { width: 64px; height: 64px; }
.ch-promo-btn kbd { font-family: var(--font-body); font-size: 12px; color: var(--ink-3); }

.ch-result { display: grid; gap: 10px; justify-items: center; width: 100%; }
.ch-result.is-win .ch-result-icon { background: var(--sun); animation: ch-bounce 1.2s ease-in-out infinite; }
.ch-result.is-draw .ch-result-icon { background: #7fd8ff; }
.ch-result.is-lose .ch-result-icon { background: var(--paper-3); }
.ch-result.is-win .ch-card-title { font-size: clamp(34px, 9vw, 46px); color: #fff; text-shadow: var(--o-md); }
.ch-xpline { display: inline-flex; align-items: center; gap: 8px; padding: 6px 18px 4px; border: var(--line) solid var(--ink); border-radius: 999px;
  background: #ffe14d; box-shadow: 0 5px 0 var(--ink); font-family: var(--font-display); font-size: 30px; }
.ch-xpline .icon { width: 34px; height: 34px; }
.ch-xpline b { font-weight: 400; }
.ch-xpline span { font-size: 20px; }
.ch-xpline.is-zero { background: var(--paper-2); }
.ch-rankwrap { width: 100%; }
.ch-rank { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "tag bar" "count count"; align-items: center; gap: 6px 10px; width: 100%; }
.ch-rank .rank-tag { grid-area: tag; }
.ch-rankbar { grid-area: bar; position: relative; height: 20px; border: 3px solid var(--ink); border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.ch-rankbar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--bar, var(--grass)); border-radius: 999px; transition: width 0.9s cubic-bezier(0.3, 0.9, 0.3, 1); }
.ch-rankbar.rainbow i { background: transparent; }
.ch-rankcount { grid-area: count; font-size: 15px; font-weight: 700; color: var(--ink-2); }
.ch-rankcount b { color: var(--ink); }
.ch-rankup { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 4px; border: 3px solid var(--ink); border-radius: 14px; background: #2b1468; color: #ffe14d;
  font-family: var(--font-display); font-size: 20px; box-shadow: 0 4px 0 var(--ink); animation: ch-pop-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); }
.ch-rankup .icon { width: 26px; height: 26px; }

/* ---------------- the puzzle desk ---------------- */
.ch-puzzle-layer { position: absolute; inset: 0; display: grid; place-items: center; padding: calc(var(--safe-t) + 12px) 12px calc(var(--safe-b) + 12px); pointer-events: auto; }
.ch-puzzle {
  position: relative; display: flex; flex-direction: column; width: min(940px, 100%); max-height: 100%; overflow: hidden; outline: none;
  border-radius: 28px; animation: modal-in 0.32s cubic-bezier(0.2, 1.35, 0.4, 1);
}
.ch-pz-head { --head: #2f9c58; }
.ch-pz-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px;
  display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 16px; align-items: start;
}
.ch-pz-left { display: grid; gap: 10px; justify-items: center; min-width: 0; }
.ch-pz-goal { display: grid; gap: 2px; width: 100%; padding: 10px 14px; border: 3px solid var(--ink); border-radius: 16px; background: #eafbea; text-align: left; }
.ch-pz-goal-title { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 400; font-size: 24px; line-height: 1.1; }
.ch-pz-goal-title .icon { width: 28px; height: 28px; }
.ch-pz-goal span { font-size: 16px; font-weight: 700; }
.ch-pz-goal small { font-size: 13px; font-weight: 700; color: var(--ink-3); }
.ch-board-wrap { position: relative; width: min(100%, 470px, 62vh); aspect-ratio: 1; }
.ch-board {
  position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border: var(--line) solid var(--ink); border-radius: 14px; overflow: hidden; box-shadow: 0 6px 0 var(--ink); touch-action: none; background: #5a381b;
}
.ch-sq { position: relative; display: grid; place-items: center; touch-action: none; }
.ch-sq.light { background: #f6e2b8; }
.ch-sq.dark { background: #9c6436; }
.ch-sq.is-last.light { background: #f7f08a; }
.ch-sq.is-last.dark { background: #c9b23f; }
.ch-sq.is-sel { box-shadow: inset 0 0 0 4px #ffe14d, inset 0 0 18px rgba(255, 225, 77, 0.9); }
.ch-sq.is-good { box-shadow: inset 0 0 0 5px #2fe07a, inset 0 0 22px rgba(47, 224, 122, 0.95); }
.ch-sq.is-bad { box-shadow: inset 0 0 0 5px #ff4d5e, inset 0 0 22px rgba(255, 77, 94, 0.95); }
.ch-sq.is-hint { box-shadow: inset 0 0 0 4px #ffe14d; animation: ch-hint 0.9s ease-in-out infinite; }
.ch-sq.is-dot::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(30, 160, 80, 0.7); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); pointer-events: none; }
.ch-sq.is-cap::after { content: ""; position: absolute; inset: 6%; border-radius: 50%; border: 5px solid rgba(255, 90, 61, 0.8); pointer-events: none; }
.ch-pc { position: relative; z-index: 1; width: 92%; height: 92%; display: grid; place-items: center; pointer-events: none; transition: transform 0.12s ease; }
.ch-pc .pc-svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35)); }
.ch-pc.is-mine { cursor: grab; }
.ch-sq.is-sel .ch-pc { transform: translateY(-4%) scale(1.06); }
.ch-coord { position: absolute; z-index: 0; font-size: clamp(9px, 1.6vw, 12px); font-weight: 800; line-height: 1; pointer-events: none; opacity: 0.8; }
.ch-sq.light .ch-coord { color: #9c6436; }
.ch-sq.dark .ch-coord { color: #f6e2b8; }
.ch-rk { left: 3px; top: 3px; }
.ch-fl { right: 4px; bottom: 2px; }
.ch-arrow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.ch-arrow-g { fill: #2fe07a; stroke: #2fe07a; opacity: 0.85; animation: ch-arrow 0.6s ease; }
.ch-arrow-g line { stroke-width: 22; stroke-linecap: round; }
.ch-arrow-g polygon { stroke-width: 4; stroke-linejoin: round; }
.ch-ghost { position: fixed; left: 0; top: 0; z-index: 200; pointer-events: none; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.35)); }
.ch-ghost .pc-svg { width: 100%; height: 100%; }
.ch-confetti { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; border-radius: 14px; }
.ch-confetti i { position: absolute; top: -12px; width: 9px; height: 13px; border-radius: 2px; animation: ch-fall 1.5s cubic-bezier(0.3, 0.6, 0.5, 1) var(--d) forwards; }

.ch-pz-right { display: grid; gap: 14px; align-content: start; }
.ch-lampbox { display: grid; justify-items: center; gap: 12px; padding: 16px 14px 14px; border: 3px solid var(--ink); border-radius: 18px; background: #1d1748; overflow: hidden; }
.ch-lamp {
  position: relative; width: 96px; height: 96px; border-radius: 50%; border: var(--line) solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #ffffff 0 12%, #e7e3f3 30%, #9d97b8 100%); box-shadow: 0 5px 0 var(--ink), inset 0 -8px 14px rgba(0, 0, 0, 0.25);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.ch-lamp i { position: absolute; left: 22%; top: 16%; width: 26%; height: 18%; border-radius: 50%; background: rgba(255, 255, 255, 0.85); }
.ch-lamp.is-green {
  background: radial-gradient(circle at 35% 30%, #ffffff 0 10%, #9dffc4 28%, #19c95c 100%);
  box-shadow: 0 5px 0 var(--ink), 0 0 26px 8px rgba(47, 224, 122, 0.85), 0 0 54px 12px rgba(47, 224, 122, 0.35); animation: ch-lamp 0.7s ease-in-out 3;
}
.ch-lamp.is-red {
  background: radial-gradient(circle at 35% 30%, #ffffff 0 10%, #ffb0b8 28%, #e0263a 100%);
  box-shadow: 0 5px 0 var(--ink), 0 0 26px 8px rgba(255, 77, 94, 0.85), 0 0 54px 12px rgba(255, 77, 94, 0.3); animation: ch-lamp 0.7s ease-in-out 3;
}
.ch-pz-feedback { min-height: 46px; display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center; color: #fff; font-size: 17px; font-weight: 700; line-height: 1.25; }
.ch-pz-feedback .icon { width: 26px; height: 26px; flex: none; }
.ch-pz-feedback b { font-family: var(--font-display); font-weight: 400; font-size: 21px; }
.ch-pz-feedback.is-good { color: #7fffb0; }
.ch-pz-feedback.is-bad { color: #ffb0b8; }
.ch-pz-feedback.is-hint { color: #ffe98a; }
.ch-pz-feedback small { font-size: 13px; color: #d9d4f0; }
.ch-pz-stats { display: grid; gap: 10px; padding: 12px; border: 3px solid var(--ink); border-radius: 18px; background: var(--paper-2); }
.ch-pz-nums { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 15px; font-weight: 700; }
.ch-pz-nums span { display: inline-flex; align-items: center; gap: 4px; }
.ch-pz-nums .icon { width: 20px; height: 20px; }
.ch-pz-nums b { font-family: var(--font-display); font-weight: 400; font-size: 18px; }
.ch-pz-nums .is-hot { color: var(--coral-d); }
.ch-pz-btns { display: grid; gap: 10px; }
.ch-pz-btns .btn-go.is-ready { animation: ch-ready 1s ease-in-out infinite; }
@media (max-width: 760px) {
  .ch-pz-body { grid-template-columns: minmax(0, 1fr); padding: 10px; gap: 10px; }
  .ch-pz-goal { padding: 8px 12px; }
  .ch-pz-goal-title { font-size: 20px; }
  .ch-board-wrap { width: min(100%, 58vh); }
  .ch-lampbox { grid-template-columns: auto 1fr; justify-items: start; align-items: center; padding: 10px; }
  .ch-lamp { width: 64px; height: 64px; }
  .ch-pz-feedback { justify-content: flex-start; text-align: left; }
  .ch-pz-btns { grid-template-columns: auto 1fr; }
  .ch-pz-head .modal-titles p { display: none; }
  .ch-pz-head { padding: 8px 10px; }
  .ch-pz-head .modal-icon { width: 42px; height: 42px; }
  .ch-pz-head .modal-titles h2 { font-size: 26px; }
  .ch-pz-goal span { font-size: 14px; }
  .ch-pz-right { gap: 10px; }
  .ch-pz-stats { padding: 8px 10px; }
  .ch-pz-stats .ch-rank { display: none; }
  .ch-pz-btns .btn { min-height: 52px; }
}

/* ---------------- motion ---------------- */
@keyframes ch-pop-in { from { opacity: 0; transform: scale(0.6); } }
@keyframes ch-drop-in { from { opacity: 0; transform: translate(-50%, -30px); } }
@keyframes ch-rise-in { from { opacity: 0; transform: translate(-50%, 30px); } }
@keyframes ch-pop { 40% { transform: scale(1.12); } }
@keyframes ch-pulse { 50% { transform: scale(1.08); } }
@keyframes ch-dot { 50% { transform: translateY(-4px); } }
@keyframes ch-bounce { 50% { transform: translateY(-8px) rotate(-6deg); } }
@keyframes ch-hint { 50% { box-shadow: inset 0 0 0 4px #ffe14d, inset 0 0 26px rgba(255, 225, 77, 0.95); } }
@keyframes ch-lamp { 50% { transform: scale(1.1); } }
@keyframes ch-ready { 50% { transform: translateY(-2px) scale(1.03); } }
@keyframes ch-arrow { from { opacity: 0; } }
@keyframes ch-fall { to { transform: translate(var(--x), 520px) rotate(var(--r)); opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) {
  .ch-status.is-check, .ch-dots i, .ch-result.is-win .ch-result-icon, .ch-sq.is-hint, .ch-lamp.is-green, .ch-lamp.is-red, .ch-pz-btns .btn-go.is-ready { animation: none; }
}
