:root {
  --primary-color: #0284c7;
  --primary-hover: #0369a1;
  --secondary-color: #0d9488;
  --accent-color: #f59e0b;
  --bg-gradient-start: #e0f2fe;
  --bg-gradient-end: #bae6fd;
  --card-bg: rgba(255, 255, 255, 0.94);
  --card-border: rgba(255, 255, 255, 0.6);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --radius-lg: 24px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Pretendard', 'Outfit', sans-serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-main);
  padding: 12px;
  overflow-x: hidden;
}

.game-app {
  width: 100%;
  max-width: 980px;
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 2px solid rgba(226, 232, 240, 0.8);
  padding-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-emoji {
  font-size: 2.5rem;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.15));
}

.brand h1 {
  font-family: 'Jua', sans-serif;
  font-size: 1.6rem;
  color: #0369a1;
  letter-spacing: -0.5px;
}

.brand .subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Player Info Card */
.player-info-card {
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}

.player-icon {
  font-size: 1.2rem;
}

.player-details {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-main);
  line-height: 1.2;
}

.player-id {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.status-card {
  background: #ffffff;
  border: 1.5px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 68px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}

.status-card.highlight {
  border-color: #38bdf8;
  background: #f0f9ff;
}

.status-card .label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.status-card .value {
  font-weight: 800;
  font-size: 1.05rem;
  color: #0284c7;
  white-space: nowrap;
}

.status-card .value small {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.label-short {
  display: none;
}

/* Ruler Toolbar */
.ruler-toolbar {
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
}

.tool-btn {
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  color: #334155;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tool-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  transform: translateY(-1px);
}

.tool-btn.active {
  background: #e0f2fe;
  border-color: #0284c7;
  color: #0369a1;
}

.tool-lock-icon {
  font-size: 1.05rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
}

#btn-lock-all-rulers.active .tool-lock-icon {
  font-size: 1.15rem;
}

.tool-btn-short,
.btn-label-short {
  display: none;
}

.ruler-chip-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ruler-chip {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 3px;
  border-radius: 11px;
  border: 2px solid #cbd5e1;
  background: linear-gradient(145deg, #ffffff 0%, #f1f5f9 100%);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.ruler-chip-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.12));
}

.ruler-chip .chip-body {
  fill: rgba(255, 255, 255, 0.15);
  stroke-width: 2;
  stroke-linejoin: round;
}

.ruler-chip .chip-inner {
  fill: rgba(255, 255, 255, 0.72);
  stroke-width: 1.2;
  stroke-linejoin: round;
}

.ruler-chip .chip-corner {
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.ruler-chip-lock {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  background: rgba(15, 23, 42, 0.42);
  border-radius: 9px;
  pointer-events: none;
  z-index: 2;
}

.ruler-chip-blue {
  border-color: #0284c7;
  background: linear-gradient(145deg, #e0f2fe 0%, #bae6fd 100%);
}

.ruler-chip-blue .chip-body {
  fill: rgba(56, 189, 248, 0.45);
  stroke: #0284c7;
}

.ruler-chip-blue .chip-inner {
  fill: rgba(224, 242, 254, 0.95);
  stroke: rgba(2, 132, 199, 0.55);
}

.ruler-chip-blue .chip-corner {
  stroke: #0369a1;
}

.ruler-chip-green {
  border-color: #059669;
  background: linear-gradient(145deg, #d1fae5 0%, #a7f3d0 100%);
}

.ruler-chip-green .chip-body {
  fill: rgba(52, 211, 153, 0.45);
  stroke: #059669;
}

.ruler-chip-green .chip-inner {
  fill: rgba(209, 250, 229, 0.95);
  stroke: rgba(5, 150, 105, 0.55);
}

.ruler-chip-green .chip-corner {
  stroke: #047857;
}

.ruler-chip-orange {
  border-color: #ea580c;
  background: linear-gradient(145deg, #ffedd5 0%, #fed7aa 100%);
}

.ruler-chip-orange .chip-body {
  fill: rgba(251, 146, 60, 0.45);
  stroke: #ea580c;
}

.ruler-chip-orange .chip-inner {
  fill: rgba(255, 237, 213, 0.95);
  stroke: rgba(234, 88, 12, 0.55);
}

.ruler-chip-orange .chip-corner {
  stroke: #c2410c;
}

.ruler-chip.is-selected {
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.28), 0 4px 10px rgba(2, 132, 199, 0.18);
  transform: translateY(-1px);
}

.ruler-chip.is-locked .ruler-chip-lock {
  display: flex;
}

.ruler-chip.is-locked {
  opacity: 0.92;
}

.ruler-chip.is-hidden {
  opacity: 0.38;
  filter: grayscale(0.45);
}

.ruler-chip.is-hidden .ruler-chip-svg {
  opacity: 0.5;
}

.ruler-chip.is-hidden::after {
  content: '';
  position: absolute;
  inset: 6px;
  background: linear-gradient(
    to top right,
    transparent calc(50% - 1px),
    #64748b calc(50% - 1px),
    #64748b calc(50% + 1px),
    transparent calc(50% + 1px)
  );
  pointer-events: none;
  z-index: 1;
}

.toolbar-right {
  font-size: 0.78rem;
  color: #64748b;
}

.guide-tip strong {
  color: #0284c7;
}

/* Game Board */
.game-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.board-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-board {
  position: relative;
  width: 100%;
  height: 520px;
  background: radial-gradient(circle at center, #ffffff 0%, #f8fafc 100%);
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-md);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.04);
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}

@media (min-width: 768px) and (min-height: 720px) {
  .game-board {
    height: 560px;
  }
}

@media (min-width: 1024px) and (min-height: 820px) {
  .game-board {
    height: 580px;
  }
}

.board-grid-pattern {
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(to right, rgba(203, 213, 225, 0.3) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(203, 213, 225, 0.3) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
}

/* SVG Geometry Layer */
.geometry-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* Canvas Layer */
.line-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* HTML Elements Layer */
.elements-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* Rulers Layer */
.rulers-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

/* Student Pins */
.student-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 12;
}

.student-emoji-box {
  background: #ffffff;
  border: 3.5px solid #0284c7;
  border-radius: 50%;
  width: 54px;
  height: 54px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.9rem;
  box-shadow: 0 6px 14px rgba(0,0,0,0.18);
  transition: all 0.2s ease;
}

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

.student-pin.mood-happy .student-emoji-box {
  border-color: #10b981 !important;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.7);
  transform: scale(1.15);
}

.student-pin.mood-neutral .student-emoji-box {
  border-color: #0284c7 !important;
}

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

/* User Bingsoo Pin */
.placed-bingsoo-pin {
  position: absolute;
  transform: translate(-50%, -24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
  cursor: grab;
  z-index: 30;
  transition: transform 0.1s ease;
}

.placed-bingsoo-pin:active,
.placed-bingsoo-pin.is-dragging {
  cursor: grabbing;
  transform: translate(-50%, -24px) scale(1.15);
  filter: drop-shadow(0 8px 16px rgba(2, 132, 199, 0.4));
}

/* Center Crosshair Indicator for exact alignment */
.bingsoo-center-crosshair {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  pointer-events: none;
  z-index: 35;
}

.bingsoo-center-crosshair .crosshair-h {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: #ef4444;
  transform: translateY(-50%);
  box-shadow: 0 0 3px #ffffff, 0 0 6px rgba(239, 68, 68, 0.8);
}

.bingsoo-center-crosshair .crosshair-v {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ef4444;
  transform: translateX(-50%);
  box-shadow: 0 0 3px #ffffff, 0 0 6px rgba(239, 68, 68, 0.8);
}

.bingsoo-center-crosshair .crosshair-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border: 2px solid #ffffff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px rgba(239, 68, 68, 1);
}

.bingsoo-center-crosshair.target-crosshair {
  top: 20px;
  width: 24px;
  height: 24px;
}

.bingsoo-center-crosshair.target-crosshair .crosshair-h,
.bingsoo-center-crosshair.target-crosshair .crosshair-v {
  background: #10b981;
  box-shadow: 0 0 3px #ffffff, 0 0 6px rgba(16, 185, 129, 0.8);
}

.bingsoo-center-crosshair.target-crosshair .crosshair-dot {
  background: #10b981;
  border-color: #ffffff;
  box-shadow: 0 0 8px rgba(16, 185, 129, 1);
}

.bingsoo-icon-wrapper {
  width: 48px;
  height: 48px;
  background: #ffffff;
  border: 3px solid #f59e0b;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.8rem;
  box-shadow: 0 6px 14px rgba(245, 158, 11, 0.35);
  animation: pulseBingsoo 1.5s infinite;
  position: relative;
}

.bingsoo-label {
  font-size: 0.72rem;
  font-weight: 800;
  background: #f59e0b;
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 3px;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

@keyframes pulseBingsoo {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); }
  70% { box-shadow: 0 0 0 12px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

/* Original Submitted Ghost Pin */
.original-submitted-pin {
  position: absolute;
  transform: translate(-50%, -20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 24;
  animation: popIn 0.35s ease;
}

.original-ghost-box {
  width: 42px;
  height: 42px;
  background: rgba(254, 243, 199, 0.75);
  border: 2px dashed #f59e0b;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  opacity: 0.85;
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.2);
}

.original-ghost-label {
  font-size: 0.7rem;
  font-weight: 800;
  background: rgba(180, 83, 9, 0.9);
  color: #ffffff;
  padding: 2px 6px;
  border-radius: 8px;
  margin-top: 2px;
  white-space: nowrap;
}

/* True Target Pin */
.target-circumcenter-pin {
  position: absolute;
  transform: translate(-50%, -20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 25;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.target-icon-box {
  width: 40px;
  height: 40px;
  background: #ecfdf5;
  border: 2.5px solid #10b981;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.target-label {
  font-size: 0.72rem;
  font-weight: 800;
  background: #10b981;
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 2px;
  white-space: nowrap;
}

@keyframes popIn {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Distance Badge */
.distance-badge {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, 0.85);
  color: #38bdf8;
  font-weight: 700;
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  z-index: 14;
}

/* ----------------------------------------------------
   SET SQUARE (직각자) UI & INTERACTIVE CONTROLS
   ---------------------------------------------------- */
.set-square-container {
  position: absolute;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  transform-origin: 0px 0px; /* Pivots at right-angle corner */
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.15));
  transition: filter 0.2s ease, opacity 0.2s ease;
  opacity: 0.82;
}

.set-square-container:hover {
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.22));
  opacity: 1;
}

.set-square-container.is-dragging {
  cursor: grabbing;
  filter: drop-shadow(0 12px 24px rgba(2, 132, 199, 0.35));
  z-index: 100 !important;
  opacity: 1;
}

.set-square-container.is-locked {
  cursor: default;
  pointer-events: none;
  opacity: 0.88;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
}

.set-square-container.is-selected:not(.is-dragging) {
  opacity: 1;
  filter: drop-shadow(0 10px 20px rgba(2, 132, 199, 0.28));
  z-index: 24;
}

.set-square-container.is-locked .ruler-rotate-handle {
  display: none;
}

.set-square-svg {
  display: block;
  overflow: visible;
}

/* Ruler Theme Variants */
.ruler-theme-blue .ruler-body {
  fill: rgba(14, 165, 233, 0.22);
  stroke: #0284c7;
  stroke-width: 2.5;
}
.ruler-theme-blue .ruler-inner-cutout {
  fill: rgba(255, 255, 255, 0.35);
  stroke: rgba(2, 132, 199, 0.6);
  stroke-width: 1.5;
}
.ruler-theme-blue .ruler-ticks {
  stroke: #0369a1;
  stroke-width: 1.2;
}
.ruler-theme-blue .ruler-right-angle-mark {
  stroke: #0284c7;
  stroke-width: 2;
  fill: none;
}

.ruler-theme-blue .ruler-angle-label {
  fill: #0369a1;
}

.ruler-theme-green .ruler-body {
  fill: rgba(16, 185, 129, 0.22);
  stroke: #059669;
  stroke-width: 2.5;
}
.ruler-theme-green .ruler-inner-cutout {
  fill: rgba(255, 255, 255, 0.35);
  stroke: rgba(5, 150, 105, 0.6);
  stroke-width: 1.5;
}
.ruler-theme-green .ruler-ticks {
  stroke: #047857;
  stroke-width: 1.2;
}
.ruler-theme-green .ruler-right-angle-mark {
  stroke: #059669;
  stroke-width: 2;
  fill: none;
}

.ruler-theme-green .ruler-angle-label {
  fill: #047857;
}

.ruler-theme-orange .ruler-body {
  fill: rgba(249, 115, 22, 0.22);
  stroke: #ea580c;
  stroke-width: 2.5;
}
.ruler-theme-orange .ruler-inner-cutout {
  fill: rgba(255, 255, 255, 0.35);
  stroke: rgba(234, 88, 12, 0.6);
  stroke-width: 1.5;
}
.ruler-theme-orange .ruler-ticks {
  stroke: #c2410c;
  stroke-width: 1.2;
}
.ruler-theme-orange .ruler-right-angle-mark {
  stroke: #ea580c;
  stroke-width: 2;
  fill: none;
}

.ruler-theme-orange .ruler-angle-label {
  fill: #c2410c;
}

.ruler-lock-badge {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  color: #fbbf24;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  z-index: 106;
  border: 2px solid rgba(251, 191, 36, 0.65);
}

/* Rotation Knob Handle */
.ruler-rotate-handle {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ffffff;
  border: 2.5px solid #10b981;
  color: #059669;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  z-index: 105;
  transform: translate(-50%, -50%);
  transition: transform 0.15s ease, background 0.15s ease;
}

.ruler-rotate-handle:hover {
  transform: translate(-50%, -50%) scale(1.2);
  background: #ecfdf5;
}

.ruler-rotate-handle:active,
.ruler-rotate-handle.is-rotating {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.25);
  background: #10b981;
  color: #ffffff;
}


/* Floating Touch D-Pad Controller (Draggable) */
.dpad-controller {
  position: absolute;
  right: 14px;
  bottom: 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(2, 132, 199, 0.45);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  z-index: 45;
  pointer-events: auto;
  user-select: none;
  touch-action: none;
  cursor: grab;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.dpad-controller:hover {
  border-color: #0284c7;
}

.dpad-controller.is-dragging {
  cursor: grabbing;
  box-shadow: 0 12px 28px rgba(2, 132, 199, 0.35);
  z-index: 70 !important;
}

.dpad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 6px;
  cursor: grab;
}

.dpad-controller.is-dragging .dpad-header {
  cursor: grabbing;
}

.dpad-drag-handle {
  font-size: 0.9rem;
  color: #94a3b8;
  letter-spacing: -1px;
  cursor: grab;
}

.dpad-title {
  font-size: 0.74rem;
  font-weight: 800;
  color: #0369a1;
}

.dpad-step-btn {
  background: #e0f2fe;
  border: 1px solid #0284c7;
  color: #0369a1;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dpad-step-btn:hover {
  background: #0284c7;
  color: #ffffff;
}

.dpad-cross {
  display: grid;
  grid-template-columns: 32px 32px 32px;
  grid-template-rows: 32px 32px 32px;
  gap: 3px;
  justify-items: center;
  align-items: center;
}

.dpad-btn {
  width: 32px;
  height: 32px;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  color: #0369a1;
  font-size: 0.82rem;
  font-weight: 900;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  touch-action: none;
  transition: all 0.1s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.dpad-btn:hover {
  background: #e0f2fe;
  border-color: #0284c7;
  transform: translateY(-1px);
}

.dpad-btn:active,
.dpad-btn.is-pressed {
  background: #0284c7;
  border-color: #0369a1;
  color: #ffffff;
  transform: scale(0.92);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-center-dot {
  grid-column: 2;
  grid-row: 2;
  font-size: 0.85rem;
  font-weight: 800;
  color: #ef4444;
  display: flex;
  justify-content: center;
  align-items: center;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 3;
}

/* Instruction Banner */
.instruction-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.3s ease;
  max-width: min(92%, 560px);
  text-align: center;
  white-space: normal;
  word-break: keep-all;
  line-height: 1.35;
}

.instruction-banner.is-faded {
  opacity: 0.18;
}

/* Score Popup Card */
.score-popup {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  cursor: pointer;
  animation: popupSlideDown 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.score-card-inner {
  background: #ffffff;
  border: 3px solid #38bdf8;
  border-radius: var(--radius-md);
  padding: 12px 24px;
  box-shadow: 0 10px 25px rgba(2, 132, 199, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.rating-badge {
  background: #0284c7;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 12px;
  margin-bottom: 4px;
}

.score-number {
  font-family: 'Jua', sans-serif;
  font-size: 2rem;
  color: #0369a1;
  line-height: 1.1;
}

.distance-info {
  font-size: 0.78rem;
  color: #64748b;
  font-weight: 600;
}

@keyframes popupSlideDown {
  0% { transform: translate(-50%, -20px); opacity: 0; }
  100% { transform: translate(-50%, 0); opacity: 1; }
}

/* Controls Bar */
.controls-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
}

.btn {
  font-family: 'Pretendard', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  padding: 12px 28px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #ffffff;
}

.btn-accent {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
}

.btn-secondary {
  background: #f1f5f9;
  border: 1.5px solid #cbd5e1;
  color: #334155;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-outline {
  background: transparent;
  border: 1.5px solid #cbd5e1;
  color: #0369a1;
}

.btn-outline:hover {
  background: #f0f9ff;
  border-color: #0284c7;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1.1rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  text-align: center;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-opening {
  max-width: 520px;
}

.modal-header {
  text-align: center;
  position: relative;
}

.modal-header h2 {
  font-family: 'Jua', sans-serif;
  font-size: 1.8rem;
  color: #0284c7;
}

.modal-trophy {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 4px;
}

.opening-banner h2 {
  font-family: 'Jua', sans-serif;
  font-size: 1.4rem;
  color: #0f172a;
  margin-bottom: 8px;
}

.opening-subtitle {
  font-size: 0.8rem;
  font-weight: 800;
  color: #0284c7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Champion Gold Box */
.champ-card {
  position: relative;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 2px solid #f59e0b;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.2);
}

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

.champ-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 1;
  margin-left: 12px;
}

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

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

.champ-score {
  font-family: 'Jua', sans-serif;
  font-size: 1.8rem;
  color: #b45309;
}

.game-guide-box {
  background: #f0f9ff;
  border: 1.5px solid #bae6fd;
  border-radius: var(--radius-md);
  padding: 12px;
  margin: 12px 0;
  text-align: left;
}

.guide-title {
  font-weight: 800;
  font-size: 0.92rem;
  color: #0369a1;
  margin-bottom: 4px;
}

.guide-desc {
  font-size: 0.82rem;
  color: #334155;
  line-height: 1.45;
}

.game-guide-box.short-banner {
  background: linear-gradient(135deg, #e0f2fe, #f0f9ff);
  border: 1.5px solid #7dd3fc;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  text-align: center;
  margin-top: 2px;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.08);
}

.game-guide-box.short-banner .guide-title {
  font-family: 'Jua', sans-serif;
  font-size: 1.12rem;
  color: #0369a1;
  margin-bottom: 1px;
}

.game-guide-box.short-banner .guide-desc {
  font-size: 0.82rem;
  font-weight: 700;
  color: #0f172a;
}

/* Form Styles */
.form-group {
  text-align: left;
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  color: #334155;
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  border-color: #0284c7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.profile-lead {
  margin: 0 0 12px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #475569;
  text-align: center;
}

.profile-err {
  color: #ef4444;
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 6px;
  min-height: 1.2em;
}

/* Leaderboard Tables */
.leaderboard-table-wrapper {
  max-height: 220px;
  overflow-y: auto;
  margin: 8px 0;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

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

.leaderboard-table th,
.leaderboard-table td {
  padding: 6px 10px;
  text-align: center;
  border-bottom: 1px solid #f1f5f9;
}

.leaderboard-table th {
  background: #f8fafc;
  font-weight: 700;
  color: #475569;
  position: sticky;
  top: 0;
}

.leaderboard-table tr:hover {
  background: #f0f9ff;
}

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

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

.final-score-box {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.final-label {
  font-size: 0.85rem;
  opacity: 0.9;
}

.final-score {
  font-family: 'Jua', sans-serif;
  font-size: 3rem;
  line-height: 1;
}

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

.new-record-badge {
  background: #f59e0b;
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 800;
  animation: pulse-bounce 1.5s infinite;
}

.send-action-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.result-locked-player-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #ffffff;
  border: 1px solid #a7f3d0;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #166534;
}

.locked-icon {
  font-size: 1rem;
}

.locked-text strong {
  color: #0284c7;
  font-size: 0.95rem;
}

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

.api-status-msg.success { color: #16a34a; }
.api-status-msg.error { color: #dc2626; }

.leaderboard-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.leaderboard-header h3 {
  font-size: 0.98rem;
  color: #0f172a;
}

.round-breakdown h3 {
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: var(--text-main);
  text-align: left;
  margin-top: 12px;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.history-item .round-tag {
  font-weight: 800;
  color: #64748b;
}

.history-item .score-tag {
  font-weight: 800;
  color: #0284c7;
}

@keyframes pulse-bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Footer */
.app-footer {
  text-align: center;
  margin-top: 4px;
}

.privacy-link-btn {
  font-size: 0.78rem;
  color: #64748b;
  text-decoration: none;
}

.privacy-link-btn:hover {
  color: #0284c7;
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* Responsive adjustments — keep the play board, shrink chrome */
@media (max-width: 640px), (max-height: 700px) {
  html, body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
  }

  body.mobile-play-active {
    top: var(--app-offset-top, 0px);
    height: var(--app-vh, 100svh);
  }

  body {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .game-app {
    max-width: none;
    width: 100%;
    min-height: var(--app-vh, 100svh);
    height: var(--app-vh, 100svh);
    max-height: var(--app-vh, 100svh);
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 8px;
    gap: 6px;
    overflow: hidden;
    touch-action: none;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-bottom: 8px;
  }

  .brand {
    min-width: 0;
  }

  .logo-emoji {
    font-size: 1.6rem;
  }

  .brand h1 {
    font-size: 1.05rem;
    line-height: 1.15;
  }

  .brand .subtitle,
  .toolbar-label,
  .toolbar-right,
  .tool-btn-full,
  .btn-label-full,
  .label-full {
    display: none;
  }

  .label-short {
    display: inline;
  }

  .tool-btn-short,
  .btn-label-short {
    display: inline;
  }

  .status-bar {
    width: 100%;
    flex: none;
    justify-content: stretch;
    align-items: stretch;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .player-info-card {
    display: none;
  }

  .status-card {
    min-width: 0;
    flex: 1;
    padding: 5px 6px;
    min-height: 44px;
    justify-content: center;
    gap: 1px;
  }

  .status-card .label {
    font-size: 0.62rem;
    white-space: nowrap;
    line-height: 1.1;
  }

  .status-card .value {
    font-size: 0.9rem;
    white-space: nowrap;
    line-height: 1.15;
  }

  .status-card .value small {
    font-size: 0.62rem;
  }

  .player-info-card {
    padding: 3px 8px;
  }

  .ruler-toolbar {
    padding: 4px 8px;
    gap: 4px;
  }

  .toolbar-left {
    width: 100%;
    justify-content: stretch;
    gap: 4px;
  }

  .ruler-chip-group {
    flex: 1;
    gap: 4px;
  }

  .ruler-chip {
    flex: 1;
    min-width: 0;
    height: 38px;
    width: auto;
    padding: 2px;
  }

  .ruler-chip-lock {
    font-size: 1rem;
  }

  .ruler-lock-badge {
    width: 32px;
    height: 32px;
    font-size: 1.05rem;
  }

  .tool-btn {
    flex: 0 0 auto;
    justify-content: center;
    padding: 6px 8px;
    font-size: 0.72rem;
  }

  #btn-lock-all-rulers {
    min-width: 54px;
  }

  .game-container,
  .board-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .game-board {
    flex: 1;
    height: auto;
    min-height: 220px;
  }

  .instruction-banner {
    top: 8px;
    font-size: 0.72rem;
    padding: 5px 10px;
    max-width: 94%;
  }

  .score-popup {
    top: 44px;
  }

  .score-card-inner {
    padding: 8px 14px;
  }

  .score-number {
    font-size: 1.5rem;
  }

  .dpad-controller {
    right: 8px;
    bottom: 8px;
    padding: 5px 6px;
    gap: 4px;
  }

  .dpad-cross {
    grid-template-columns: 28px 28px 28px;
    grid-template-rows: 28px 28px 28px;
    gap: 2px;
  }

  .dpad-btn {
    width: 28px;
    height: 28px;
    font-size: 0.72rem;
  }

  .ruler-rotate-handle {
    width: 36px;
    height: 36px;
  }

  .student-emoji-box {
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
  }

  .bingsoo-icon-wrapper {
    width: 42px;
    height: 42px;
    font-size: 1.5rem;
  }

  .controls-bar {
    gap: 6px;
    margin-top: 0;
  }

  .btn {
    padding: 8px 10px;
    font-size: 0.82rem;
    flex: 1;
  }

  .app-footer {
    margin-top: 0;
  }

  .privacy-link-btn {
    font-size: 0.68rem;
  }

  .set-square-container {
    opacity: 0.72;
  }

  .set-square-container.is-dragging,
  .set-square-container:hover {
    opacity: 1;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .game-app {
    padding: 4px 8px;
    gap: 4px;
  }

  .app-header {
    padding-bottom: 4px;
  }

  .status-card .label {
    display: none;
  }

  .player-details {
    flex-direction: row;
    gap: 6px;
    align-items: center;
  }

  .ruler-toolbar {
    padding: 2px 6px;
  }

  .tool-btn {
    padding: 4px 6px;
  }

  .app-footer {
    display: none;
  }

  .instruction-banner {
    font-size: 0.68rem;
    padding: 4px 8px;
  }
}
