: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: 960px;
  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: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 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);
  font-weight: 600;
}

.status-card {
  background: #f1f5f9;
  border-radius: var(--radius-md);
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 74px;
  border: 1px solid #e2e8f0;
}

.status-card.highlight {
  background: #e0f2fe;
  border-color: #7dd3fc;
}

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

.status-card .value {
  font-family: 'Jua', sans-serif;
  font-size: 1.2rem;
  color: var(--primary-color);
}

.status-card.highlight .value {
  color: #0284c7;
  font-weight: 800;
}

/* Game Container & Board */
.game-container {
  width: 100%;
}

.board-wrapper {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.game-board {
  position: relative;
  width: 100%;
  height: clamp(340px, 58vh, 520px);
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 2px dashed #93c5fd;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.04);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

.board-grid-pattern {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(#e2e8f0 1.5px, transparent 1.5px);
  background-size: 24px 24px;
  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;
}

/* Responsive Guidance Banner */
.instruction-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: clamp(0.72rem, 3vw, 0.82rem);
  font-weight: 700;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 20;
  max-width: 92%;
  text-align: center;
  white-space: normal;
  word-break: keep-all;
  animation: pulse-bounce 2s infinite ease-in-out;
}

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

/* Student Pin Styles */
.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);
}

.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;
}

/* Individual Student Expressions */
.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); }
}

/* Draggable Placed Bingsoo Pin */
.placed-bingsoo-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
  cursor: grab;
  z-index: 20;
  transition: opacity 0.3s ease, transform 0.05s ease-out;
}

.placed-bingsoo-pin.transparent-mode {
  opacity: 0.65;
  filter: drop-shadow(0 0 12px rgba(2, 132, 199, 0.6));
}

.placed-bingsoo-pin.is-dragging {
  cursor: grabbing !important;
  transform: translate(-50%, -50%) scale(1.2) !important;
  z-index: 30;
}

.bingsoo-icon {
  font-size: 2.6rem;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.3));
}

.bingsoo-label {
  background: #ef4444;
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
}

/* Distance Badges */
.distance-badge {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, 0.92);
  color: #7dd3fc;
  border: 1.5px solid #38bdf8;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  pointer-events: none;
  z-index: 12;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

/* Non-blocking Score Popup */
.score-popup {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  pointer-events: none;
  animation: fadeIn 0.2s ease-out;
}

.score-card-inner {
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid #38bdf8;
  border-radius: 16px;
  padding: 12px 28px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  animation: zoomIn 0.25s 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: #e0f2fe;
  color: #0284c7;
  padding: 2px 12px;
  border-radius: 16px;
  font-size: 0.85rem;
  font-weight: 800;
}

.score-number {
  font-family: 'Jua', sans-serif;
  font-size: 3.2rem;
  color: #0284c7;
  line-height: 1;
}

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

/* Opening Champion Card & Leaderboard */
.modal-opening {
  max-width: 500px;
  text-align: center;
}

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

.opening-banner h2 {
  font-family: 'Jua', sans-serif;
  font-size: 1.6rem;
  color: #0284c7;
  margin-top: 2px;
}

.opening-subtitle {
  font-size: 0.82rem;
  font-weight: 800;
  color: #d97706;
  background: #fef3c7;
  padding: 3px 12px;
  border-radius: 12px;
}

.champ-card {
  position: relative;
  width: 100%;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 2px solid #f59e0b;
  border-radius: 16px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.25);
  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.4) 50%,
    transparent 100%
  );
  transform: rotate(30deg);
  animation: gold-sweep 3.5s infinite;
}

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

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

.champ-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  z-index: 2;
}

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

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

.champ-score {
  font-family: 'Jua', sans-serif;
  font-size: 2.2rem;
  color: #d97706;
  z-index: 2;
}

/* Simplified Short Game Purpose Banner */
.game-guide-box.short-banner {
  background: linear-gradient(135deg, #e0f2fe, #f0f9ff);
  border: 1.5px solid #7dd3fc;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  text-align: center;
  margin-top: 4px;
  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.25rem;
  color: #0369a1;
  margin-bottom: 2px;
  justify-content: center;
}

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

.style-toggle-btn {
  margin-top: 4px;
  font-size: 0.82rem;
  padding: 6px 14px;
  border-color: #f59e0b;
  color: #b45309;
}

.opening-leaderboard-box {
  width: 100%;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 8px;
  margin-top: 6px;
  overflow: visible;
}

.style-sparkle-btn {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  box-shadow: 0 6px 18px rgba(2, 132, 199, 0.4);
}

/* Result Modal Header */
.modal-header {
  text-align: center;
  position: relative;
}

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

/* Controls & Buttons */
.controls-bar {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-2px);
}

.btn-accent {
  background: var(--accent-color);
  color: white;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-accent:hover:not(:disabled) {
  background: #d97706;
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

.btn-secondary:hover:not(:disabled) {
  background: #0f766e;
  transform: translateY(-2px);
}

.btn-outline {
  background: transparent;
  border: 2px solid #cbd5e1;
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f1f5f9;
}

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

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

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

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 16px;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.modal-sm {
  max-width: 420px;
}

.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;
}

/* Locked Player Info Badge */
.send-action-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.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 */
.leaderboard-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.leaderboard-table-wrapper {
  max-height: none;
  overflow: visible;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
}

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

.leaderboard-table th {
  background: #0284c7;
  color: white;
  padding: 7px;
  font-weight: 700;
}

.leaderboard-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
}

.leaderboard-table tr:nth-child(even) td {
  background: #f1f5f9;
}

.leaderboard-table tr.current-player-row td {
  background: #e0f2fe !important;
  font-weight: 800;
  color: #0369a1;
}

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

/* History List */
.round-breakdown h3 {
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: var(--text-main);
}

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

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

.history-item .round-tag {
  font-weight: 700;
  color: var(--primary-color);
}

.history-item .score-tag {
  font-family: 'Jua', sans-serif;
  font-size: 1rem;
  color: #0369a1;
}

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

.form-group label {
  font-size: 0.82rem;
  font-weight: 700;
}

.form-input {
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.88rem;
}

.hidden {
  display: none !important;
}

/* Mobile Optimization */
@media (max-width: 640px) {
  body {
    padding: 6px;
  }

  .game-app {
    padding: 12px;
    border-radius: 16px;
    gap: 12px;
  }

  .brand h1 {
    font-size: 1.3rem;
  }

  .brand .subtitle {
    display: none;
  }

  .status-bar {
    width: 100%;
    justify-content: space-between;
  }

  .status-card {
    min-width: 62px;
    padding: 4px 8px;
  }

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

  .game-board {
    height: clamp(300px, 54vh, 460px);
  }

  .student-emoji-box {
    width: 42px;
    height: 42px;
    font-size: 1.4rem;
  }

  .bingsoo-icon {
    font-size: 2.1rem;
  }

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

  .btn {
    padding: 10px 16px;
    font-size: 0.9rem;
  }
}
