/* 팥빙수 똑같이 나눠주기 작전! (1탄)
   2026-10-24 사용자: 제빵냥처럼 장면 하나. 마우스 PC는 16:10 장면을 화면 가운데에 맞추고(폭 1280까지),
   폰·태블릿은 화면을 꽉 채운다. 페이지는 어디서도 스크롤되지 않는다. */
:root {
  --ink: #2b1d14;
  --muted: #7c6a5c;
  --bean: #7a2e1a;
  --bean-dark: #4a1a0e;
  --milk: #fffaf3;
  --cream: #fbefe2;
  --line: #efdccb;
  --berry: #ec4899;
  --berry-soft: #fdf2f8;
  --ice: #f3faff;
  --sky: #0284c7;
  --happy: #10b981;
  --upset: #f59e0b;
  --angry: #ef4444;
  --radius-lg: 22px;
  --radius-md: 14px;
  --font: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, -apple-system, sans-serif;
  --font-title: 'Jua', 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* 아이폰 사파리: 입력칸은 글자를 고를 수 있어야 하고, 16px보다 작으면 누를 때 화면이 확대된다 */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
  font-size: 16px;
}

button, a { touch-action: manipulation; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--ink);
  word-break: keep-all;
  background-color: #fde8ef;
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.9) 1.6px, transparent 1.7px),
    radial-gradient(rgba(255, 255, 255, 0.6) 1.2px, transparent 1.3px),
    linear-gradient(160deg, #fde8ef 0%, #e6f4ff 55%, #dff1ff 100%);
  background-size: 34px 34px, 34px 34px, 100% 100%;
  background-position: 0 0, 17px 17px, 0 0;
}

/* ---------- 장면 ---------- */
.game-app {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  background: var(--milk);
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  gap: 8px;
}

/* 마우스 PC 가로 창: 16:10 장면 하나를 가운데에, 폭 1280까지. 세로로 긴 창은 폰처럼 꽉 채운다 */
@media (hover: hover) and (pointer: fine) and (min-width: 760px) and (min-height: 500px) and (min-aspect-ratio: 5/4) {
  .game-app {
    right: auto;
    bottom: auto;
    left: 50%;
    top: 50%;
    width: min(calc(100vw - 32px), 1280px, calc((100vh - 32px) * 1.6));
    height: min(calc((100vw - 32px) / 1.6), 800px, calc(100vh - 32px));
    transform: translate(-50%, -50%);
    border-radius: 28px;
    padding: 14px 18px 16px;
    gap: 12px;
    border: 3px solid #fff;
    box-shadow: 0 0 0 1px rgba(122, 46, 26, 0.08), 0 24px 60px -18px rgba(122, 46, 26, 0.35);
  }
}

/* ---------- 위쪽 띠 ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: none;
  min-height: 48px;
  position: relative;
  z-index: 2;
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hud-logo {
  width: 46px;
  height: 46px;
  flex: none;
}

.hud-logo svg { width: 100%; height: 100%; display: block; }

.hud-brand h1 {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 1.45rem;
  color: var(--bean);
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-stats {
  display: flex;
  align-items: stretch;
  gap: 6px;
  flex: none;
}

.hud-chip,
.hud-player {
  position: relative;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 70px;
}

.hud-chip .label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.2;
}

.hud-chip .value {
  font-family: var(--font-title);
  font-size: 1.25rem;
  color: var(--bean);
  line-height: 1.1;
  white-space: nowrap;
}

.hud-chip .value small {
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.hud-chip.is-score {
  background: var(--berry-soft);
  border-color: #f9a8d4;
}

.hud-chip.is-score .value { color: #be185d; }

.round-gain {
  position: absolute;
  top: -9px;
  right: -8px;
  background: var(--happy);
  color: #fff;
  font-family: var(--font-title);
  font-size: 0.85rem;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 3px 8px rgba(16, 185, 129, 0.35);
  animation: gain-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.round-gain.is-low { background: var(--upset); box-shadow: 0 3px 8px rgba(245, 158, 11, 0.35); }
.round-gain.is-zero { background: #94a3b8; box-shadow: none; }

@keyframes gain-pop {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.hud-player {
  align-items: flex-start;
  min-width: 0;
  max-width: 150px;
  background: var(--cream);
}

.player-name {
  font-weight: 800;
  font-size: 0.88rem;
  color: var(--ink);
  line-height: 1.25;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-id {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- 보드 ---------- */
.game-container {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.game-board {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--ice);
  border-radius: var(--radius-lg);
  border: 2px solid #d6ecfb;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.85), inset 0 6px 18px rgba(2, 132, 199, 0.06);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

.board-grid-pattern {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(2, 132, 199, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(2, 132, 199, 0.07) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: center center;
  pointer-events: none;
}

.line-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.elements-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  /* iOS clips transformed children inside overflow:hidden + border-radius
     unless this layer is composited on its own. */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* ---------- 친구 ---------- */
.student-pin {
  position: absolute;
  -webkit-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.student-emoji-box {
  background: #ffffff;
  border: 3.5px solid var(--sky);
  border-radius: 50%;
  width: 58px;
  height: 58px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 6px 14px rgba(43, 29, 20, 0.18);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

/* 친구 얼굴(shared/halomath-bingsoo-faces.js가 그리는 SVG) */
.student-emoji-box .friend-face {
  width: 100%;
  height: 100%;
  display: block;
}

.student-pin.mood-angry .student-emoji-box {
  border-color: var(--angry) !important;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.65);
  animation: shake-head 0.4s infinite ease-in-out;
}

.student-pin.mood-happy .student-emoji-box {
  border-color: var(--happy) !important;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.6);
  transform: scale(1.12);
}

.student-pin.mood-disappointed .student-emoji-box {
  border-color: var(--upset) !important;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.55);
}

.student-pin.mood-neutral .student-emoji-box {
  border-color: var(--sky) !important;
}

@keyframes shake-head {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}

/* ---------- 내 팥빙수 (점은 그릇 한가운데) ---------- */
.placed-bingsoo-pin {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: auto;
  cursor: grab;
  z-index: 20;
  transition: opacity 0.3s ease;
}

.bingsoo-icon {
  position: absolute;
  left: -28px;
  top: -28px;
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 5px 6px rgba(43, 29, 20, 0.25));
  transition: transform 0.08s ease-out;
}

.bingsoo-icon svg { width: 100%; height: 100%; display: block; }

.bingsoo-label {
  position: absolute;
  top: 27px;
  left: 0;
  transform: translateX(-50%);
  background: var(--bean);
  color: #fff;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(74, 26, 14, 0.3);
  transition: background 0.2s ease;
}

.placed-bingsoo-pin.is-answer .bingsoo-label {
  background: var(--happy);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.45);
}

.placed-bingsoo-pin.transparent-mode .bingsoo-icon {
  opacity: 0.88;
}

.placed-bingsoo-pin.is-dragging { cursor: grabbing !important; z-index: 30; }
.placed-bingsoo-pin.is-dragging .bingsoo-icon { transform: scale(1.15); }

/* ---------- 거리 표시 ---------- */
.distance-badge {
  position: absolute;
  transform: translate(-50%, -50%);
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--sky);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  pointer-events: none;
  z-index: 12;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(43, 29, 20, 0.15);
}

/* ---------- 라운드 점수 알림 ---------- */
.score-popup {
  position: absolute;
  top: 70px; /* 안내 말풍선 아래 */
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  pointer-events: none;
}

.score-card-inner {
  background: #fff;
  border: 3px solid #fbcfe8;
  border-radius: 20px;
  padding: 10px 30px 12px;
  text-align: center;
  box-shadow: 0 14px 30px -8px rgba(122, 46, 26, 0.35);
  animation: zoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: auto;
  cursor: pointer;
}

@keyframes zoomIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.rating-badge {
  background: var(--berry-soft);
  color: #be185d;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

.score-number {
  font-family: var(--font-title);
  font-size: 3rem;
  color: var(--bean);
  line-height: 1.05;
}

.distance-info {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
}

/* ---------- 아래쪽 띠 ---------- */
.controls-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 52px;
}

/* 지금 할 일: 원래처럼 보드 위쪽 가운데에 뜬 짙은 말풍선(2026-10-24 사용자).
   친구는 이 말풍선 아래에만 놓인다(game.js isPointInside의 +48) */
.instruction-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  max-width: 92%;
  width: max-content;
  background: rgba(43, 29, 20, 0.9);
  color: #fff8ef;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  word-break: keep-all;
  padding: 7px 18px;
  border-radius: 18px;
  box-shadow: 0 6px 16px -6px rgba(43, 29, 20, 0.55);
  pointer-events: none;
  animation: banner-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), pulse-bounce 2s 0.35s infinite ease-in-out;
}

.instruction-banner b {
  font-family: var(--font-title);
  font-weight: 400;
  color: #fbcfe8;
  font-size: 1.1em;
}

@keyframes banner-pop {
  0% { transform: translateX(-50%) scale(0.92); opacity: 0.4; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes pulse-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-3px); }
}

.controls-buttons {
  flex: none;
  display: flex;
  gap: 8px;
}

/* ---------- 단추 ---------- */
.btn {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease, opacity 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: inherit;
}

.btn-primary {
  background: linear-gradient(180deg, #8f3b22, var(--bean));
  color: #fff7ee;
  box-shadow: 0 4px 0 var(--bean-dark), 0 8px 16px -6px rgba(74, 26, 14, 0.5);
}

.btn-accent {
  background: linear-gradient(180deg, #fcd34d, #fbbf24);
  color: #5a3300;
  box-shadow: 0 4px 0 #b7791f, 0 8px 16px -6px rgba(183, 121, 31, 0.55);
}

.btn-secondary {
  background: #0d9488;
  color: #fff;
  box-shadow: 0 4px 0 #0f5f58;
}

.btn-primary:active:not(:disabled),
.btn-accent:active:not(:disabled),
.btn-secondary:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

@media (hover: hover) {
  .btn-primary:hover:not(:disabled),
  .btn-accent:hover:not(:disabled) { filter: brightness(1.06); }
}

.controls-buttons .btn {
  min-width: 170px;
  min-height: 48px;
  font-size: 1.05rem;
}

.btn-outline {
  background: #fff;
  border: 2px solid var(--line);
  color: var(--ink);
}

@media (hover: hover) {
  .btn-outline:hover { background: var(--cream); }
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 1.05rem;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* ---------- 창 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 29, 20, 0.55);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
}

.modal-card {
  background: var(--milk);
  border: 3px solid #fff;
  border-radius: 24px;
  max-width: 520px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 20px;
  box-shadow: 0 30px 60px -20px rgba(43, 29, 20, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card.modal-lg { max-width: 640px; }

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-header {
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.modal-trophy { font-size: 1.6rem; }

.modal-header h2 {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 1.7rem;
  color: var(--bean);
}

.modal-footer.centered-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

/* 첫 창: 1위·게임 소개·이름 */
.modal-opening {
  max-width: 440px;
  text-align: center;
  gap: 10px;
}

.opening-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.opening-banner h2 {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 1.3rem;
  color: var(--bean);
}

.opening-subtitle {
  font-size: 0.74rem;
  font-weight: 800;
  color: #b45309;
  background: #fef3c7;
  padding: 2px 10px;
  border-radius: 999px;
}

.champ-card {
  position: relative;
  width: 100%;
  background: linear-gradient(135deg, #fff7d6, #fde68a);
  border: 2px solid #f6c453;
  border-radius: 16px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  overflow: hidden;
}

.champ-gold-shimmer {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent 0%, rgba(255, 255, 255, 0.45) 50%, transparent 100%);
  transform: rotate(30deg);
  animation: gold-sweep 3.5s infinite;
  pointer-events: none;
}

@keyframes gold-sweep {
  0% { transform: translateX(-100%) rotate(30deg); }
  100% { transform: translateX(100%) rotate(30deg); }
}

.champ-trophy { font-size: 1.7rem; z-index: 2; }

.champ-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 1 1 auto;
  min-width: 0;
  z-index: 2;
}

.champ-name {
  font-size: 1rem;
  font-weight: 800;
  color: #78350f;
}

.champ-id {
  font-size: 0.74rem;
  color: #92400e;
  font-weight: 700;
}

.champ-score {
  font-family: var(--font-title);
  font-size: 1.7rem;
  color: #b45309;
  z-index: 2;
}

.champ-score small { font-size: 0.9rem; }

.style-toggle-btn {
  font-size: 0.8rem;
  padding: 5px 14px;
  border-radius: 999px;
}

.opening-leaderboard-box {
  width: 100%;
  margin-top: 4px;
}

.opening-leaderboard-box .leaderboard-table-wrapper {
  max-height: 34vh;
  overflow-y: auto;
}

.game-guide-box.short-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 8px 12px;
  text-align: left;
}

.guide-bowl {
  flex: none;
  width: 44px;
  height: 44px;
}

.guide-bowl svg { width: 100%; height: 100%; display: block; }

.game-guide-box.short-banner .guide-title {
  font-family: var(--font-title);
  font-size: 1.08rem;
  color: var(--bean);
}

.game-guide-box.short-banner .guide-desc {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  margin-bottom: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink);
}

.form-input {
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.form-input:focus { border-color: #f9a8d4; }

.profile-lead {
  margin: 0 0 8px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.profile-err {
  margin: 6px 0 0;
  min-height: 1.2em;
  font-size: 0.82rem;
  font-weight: 700;
  color: #b91c1c;
}

.style-sparkle-btn { width: 100%; }

.privacy-link-btn {
  display: inline-block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-decoration: underline;
}

.privacy-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.84rem;
  color: #3f3128;
  line-height: 1.5;
  text-align: left;
}

/* 끝 창 */
.final-score-box {
  background: linear-gradient(160deg, #8f3b22, var(--bean));
  color: #fff7ee;
  border-radius: 18px;
  padding: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.final-label {
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0.9;
}

.final-score {
  font-family: var(--font-title);
  font-size: 3rem;
  line-height: 1;
}

.final-score small {
  font-size: 1rem;
  opacity: 0.8;
}

.new-record-badge {
  background: #fbbf24;
  color: #5a3300;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}

.send-action-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-locked-player-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #fff;
  border: 2px solid var(--line);
  padding: 7px 12px;
  border-radius: 12px;
  font-size: 0.86rem;
  color: var(--ink);
}

.locked-text strong { color: var(--bean); }

.api-status-msg {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  min-height: 18px;
}

.api-status-msg.success { color: #15803d; }
.api-status-msg.error { color: #dc2626; }

.leaderboard-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-header h3,
.round-breakdown h3 {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink);
}

.leaderboard-table-wrapper {
  border-radius: 12px;
  border: 2px solid var(--line);
  overflow: hidden;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 0.84rem;
}

.leaderboard-table th {
  background: var(--cream);
  color: var(--bean);
  padding: 6px;
  font-weight: 800;
  position: sticky;
  top: 0;
}

.leaderboard-table td {
  padding: 6px 8px;
  border-top: 1px solid #f4e7da;
  background: #fff;
}

.leaderboard-table tr.current-player-row td {
  background: var(--berry-soft) !important;
  font-weight: 800;
  color: #be185d;
}

@keyframes lb-skeleton-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.lb-skeleton-row td { vertical-align: middle; }

.lb-skeleton-bar {
  display: block;
  height: 0.85em;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(160, 130, 110, 0.2) 25%, rgba(160, 130, 110, 0.4) 37%, rgba(160, 130, 110, 0.2) 63%);
  background-size: 400% 100%;
  animation: lb-skeleton-shimmer 1.15s ease-in-out infinite;
}

.lb-skeleton-bar.w-xs { width: 22%; }
.lb-skeleton-bar.w-sm { width: 36%; }
.lb-skeleton-bar.w-md { width: 58%; }
.lb-skeleton-bar.w-lg { width: 44%; }

.champ-name .lb-skeleton-bar,
.champ-id .lb-skeleton-bar,
.champ-score .lb-skeleton-bar { margin: 0.15em 0; }

.rank-1 { color: #d97706; font-weight: 800; }
.rank-2 { color: #64748b; font-weight: 800; }
.rank-3 { color: #b45309; font-weight: 800; }

/* 라운드별 성적: 다섯 칸 한 줄 */
.history-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.history-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 6px 2px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.history-item .round-tag {
  font-weight: 800;
  color: var(--bean);
  font-size: 0.68rem;
}

.history-item .score-tag {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: #be185d;
  order: -1;
}

.hidden { display: none !important; }

/* ---------- 폰 세로·좁은 화면 ---------- */
@media (max-width: 640px) {
  .hud { gap: 6px; min-height: 0; }
  .hud-brand h1 { display: none; }
  .hud-logo { width: 40px; height: 40px; }
  .hud-stats { flex: 1 1 auto; min-width: 0; gap: 4px; justify-content: flex-end; }
  .hud-chip { min-width: 0; flex: 0 1 64px; padding: 3px 6px; }
  .hud-chip .value { font-size: 1.05rem; }
  .hud-player { flex: 0 1 92px; padding: 3px 8px; }
  .round-gain { top: auto; bottom: -9px; right: -6px; font-size: 0.72rem; padding: 2px 6px; }
  .player-name { font-size: 0.78rem; }

  .controls-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .instruction-banner {
    font-size: 0.84rem;
    padding: 6px 12px;
  }
  .score-popup { top: 62px; }
  .controls-buttons .btn { flex: 1 1 auto; min-width: 0; }

  .student-emoji-box { width: 46px; height: 46px; border-width: 3px; }
  .bingsoo-icon { left: -24px; top: -24px; width: 48px; height: 48px; }
  .bingsoo-label { top: 23px; }
  .score-number { font-size: 2.4rem; }
  .score-card-inner { padding: 8px 22px 10px; }

  .modal-card { padding: 14px 14px; gap: 10px; }
  .history-item .score-tag { font-size: 0.95rem; }
}

/* ---------- 낮은 화면(폰 가로) ---------- */
@media (max-height: 520px) {
  .game-app { gap: 6px; }
  .hud { min-height: 0; }
  .hud-logo { width: 34px; height: 34px; }
  .hud-brand h1 { font-size: 1.15rem; }
  .hud-chip { padding: 2px 10px; }
  .hud-chip .label { font-size: 0.62rem; }
  .hud-chip .value { font-size: 1rem; }
  .controls-bar { min-height: 0; flex-direction: row; align-items: center; }
  .instruction-banner { top: 6px; font-size: 0.8rem; padding: 4px 12px; }
  .score-popup { top: 52px; }
  .controls-buttons .btn { min-height: 40px; min-width: 150px; padding: 6px 16px; flex: none; }
  .student-emoji-box { width: 44px; height: 44px; border-width: 3px; }
  .bingsoo-icon { left: -22px; top: -22px; width: 44px; height: 44px; }
  .bingsoo-label { top: 21px; font-size: 0.66rem; }
  .score-number { font-size: 2rem; }
  .score-card-inner { padding: 6px 18px 8px; }

  /* 창 안을 내리지 않게 두 칸으로 */
  .modal-card { padding: 12px 16px; gap: 8px; }
  .modal-card.modal-opening { max-width: 760px; }
  #player-modal .modal-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    column-gap: 16px;
  }
  #player-modal .opening-banner { grid-column: 1; grid-row: 1 / span 2; }
  #player-modal .game-guide-box { grid-column: 2; grid-row: 1; }
  #player-modal .modal-body { grid-column: 2; grid-row: 2; }
  #player-modal .opening-leaderboard-box .leaderboard-table-wrapper { max-height: 40vh; }
  .opening-banner h2 { font-size: 1.1rem; }

  /* 왼쪽: 제목·점수·참가자·라운드별, 오른쪽: 순위표와 새 게임 단추 */
  #result-modal .modal-card {
    max-width: 820px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    grid-template-rows: auto auto auto 1fr;
    column-gap: 14px;
    row-gap: 6px;
    align-items: start;
  }
  #result-modal .modal-body { display: contents; }
  #result-modal .modal-header { grid-column: 1; grid-row: 1; }
  #result-modal .modal-header h2 { font-size: 1.2rem; }
  #result-modal .modal-trophy { font-size: 1.2rem; }
  #result-modal .final-score-box { grid-column: 1; grid-row: 2; padding: 6px; }
  #result-modal .send-action-box { grid-column: 1; grid-row: 3; }
  #result-modal .round-breakdown { grid-column: 1; grid-row: 4; }
  #result-modal .leaderboard-section { grid-column: 2; grid-row: 1 / span 3; }
  #result-modal .leaderboard-table-wrapper { max-height: 55vh; overflow-y: auto; }
  #result-modal .modal-footer { grid-column: 2; grid-row: 4; align-self: end; }
  #result-modal .modal-footer .btn { width: 100%; padding: 9px 20px; }
  .final-score { font-size: 2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .instruction-banner,
  .student-pin.mood-angry .student-emoji-box,
  .champ-gold-shimmer,
  .lb-skeleton-bar { animation: none; }
}
