/* ==========================================================================
   큰수차례킹 - ELECTRONIC WHITEBOARD GAME DESIGN SYSTEM (WITH GAME THUMBNAIL)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Outfit:wght@500;700;900&display=swap');

:root {
  --bg-main: #090c14;
  --bg-card: rgba(18, 24, 38, 0.92);
  --border-color: rgba(255, 255, 255, 0.18);
  --red-team: #ff4b5c;
  --red-team-glow: rgba(255, 75, 92, 0.45);
  --blue-team: #00d2ff;
  --blue-team-glow: rgba(0, 210, 255, 0.45);
  --gold-accent: #ffd700;
  --text-primary: #ffffff;
  --text-secondary: #94a3b8;
  --glass-border: 1px solid rgba(255, 255, 255, 0.18);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  --radius-lg: 16px;
  --radius-md: 10px;
  --font-main: 'Outfit', 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', 'Inter', -apple-system, sans-serif;
}

/* ==========================================================================
   [전자칠판 최적화 제약 조건 - 전역 필수 적용]
   ========================================================================== */
html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden !important;
  background: var(--bg-main);
  background-image: 
    radial-gradient(circle at 15% 20%, rgba(255, 75, 92, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 85% 20%, rgba(0, 210, 255, 0.2) 0%, transparent 50%);
  color: var(--text-primary);
  font-family: var(--font-main);
  
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;

  touch-action: none !important;
  overscroll-behavior: none !important;
  -webkit-tap-highlight-color: transparent !important;
  
  display: flex;
  flex-direction: column;
  position: relative;
}

*, *::before, *::after {
  box-sizing: border-box;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
  touch-action: none !important;
  -webkit-tap-highlight-color: transparent !important;
}

.emoji {
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif !important;
  display: inline-block;
}

/* Fraction UI Styling */
.tb-mixed {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tb-whole {
  font-size: 1.1em;
  font-weight: 900;
}

.tb-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  line-height: 1;
  font-size: 0.8em;
  padding: 0 2px;
}

.tb-num {
  border-bottom: 2px solid #ffffff;
  padding-bottom: 2px;
  width: 100%;
  text-align: center;
  font-weight: 900;
}

.tb-den {
  padding-top: 2px;
  width: 100%;
  text-align: center;
  font-weight: 900;
}

/* --- FULLSCREEN CANVAS LAYER (Z-INDEX TOPMOST 500) --- */
.canvas-wrapper {
  position: fixed;
  inset: 0;
  z-index: 500;
  pointer-events: none;
}

#physics-canvas {
  width: 100vw;
  height: 100vh;
  display: block;
}

/* --- SIDE FIXED BUTTONS --- */
/* z-index 720: 시작 인트로 모달(700)보다도 위에 있어야, 첫 화면(옵션 선택 전)
   에서도 홈/전체화면 버튼이 보이고 눌린다. */
.side-btn {
  position: fixed;
  top: 20%;
  transform: translateY(-50%);
  z-index: 720;
  background: rgba(18, 24, 38, 0.97);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: 50%;
  width: clamp(48px, 6vh, 60px);
  height: clamp(48px, 6vh, 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  transition: transform 0.15s ease, background-color 0.15s;
}

.side-btn:active {
  transform: translateY(-50%) scale(0.9);
  border-color: var(--gold-accent);
  background: rgba(255, 215, 0, 0.2);
}

.side-btn-left { left: clamp(10px, 1.5vw, 20px); }
.side-btn-right { right: clamp(10px, 1.5vw, 20px); }

.side-icon { font-size: clamp(1.4rem, 2.4vh, 2rem); }

/* --- Header Section --- */
header {
  height: clamp(48px, 7vh, 60px);
  position: relative;
  z-index: 160;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(16px, 2.5vw, 32px);
  background: rgba(15, 22, 36, 0.97);
  border-bottom: var(--glass-border);
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-badge {
  background: linear-gradient(135deg, var(--red-team), var(--blue-team));
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-weight: 900;
  font-size: clamp(0.9rem, 1.5vh, 1.2rem);
  letter-spacing: 1px;
}

h1 {
  font-size: clamp(1.1rem, 1.8vh, 1.4rem);
  font-weight: 900;
  font-family: var(--font-main);
  background: linear-gradient(to right, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.select-large {
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  background: #1e293b;
  color: var(--gold-accent);
  border-radius: var(--radius-md);
  border: var(--glass-border);
  outline: none;
}

.option-select-box {
  text-align: left;
  margin-bottom: 14px;
}

.option-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 4px;
}

/* --- START MODAL HEADER (TEXT-ONLY GAME TITLE) --- */
.start-modal-header {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 215, 0, 0.35);
  box-shadow: inset 0 0 15px rgba(255, 215, 0, 0.08), 0 4px 20px rgba(0, 0, 0, 0.4);
  margin-bottom: 16px;
  text-align: center;
}

.start-modal-title {
  font-size: clamp(1.6rem, 3.5vh, 2.3rem);
  font-weight: 900;
  margin: 0;
  padding: 0;
  letter-spacing: 0.5px;
  color: #ffd700;
  line-height: 1.2;
}

@supports (background-clip: text) or (-webkit-background-clip: text) {
  .start-modal-title {
    background: linear-gradient(180deg, #fff6c8 0%, #ffd700 35%, #ff9d2e 70%, #ff4b5c 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    filter: drop-shadow(0 2px 8px rgba(255, 215, 0, 0.4));
  }
}

.start-modal-subtitle {
  font-size: clamp(0.85rem, 1.3vh, 0.98rem);
  color: var(--text-secondary);
  margin: 6px 0 0 0;
  font-weight: 600;
}

/* Timer Display */
.timer-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.6);
  border: var(--glass-border);
  padding: 4px 22px;
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.6);
}

.timer-label {
  font-size: clamp(0.65rem, 1vh, 0.75rem);
  color: var(--text-secondary);
  font-weight: 700;
}

.timer-clock {
  font-size: clamp(1.4rem, 2.4vh, 1.9rem);
  font-weight: 900;
  color: var(--gold-accent);
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

.timer-clock.urgent {
  color: #ff4b5c;
  text-shadow: 0 0 10px #ff4b5c;
  animation: pulseTimer 0.6s infinite alternate;
}

@keyframes pulseTimer {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-secondary, .btn-primary {
  background: rgba(255, 255, 255, 0.1);
  border: var(--glass-border);
  color: #fff;
  padding: clamp(6px, 1vh, 8px) clamp(10px, 1.2vw, 16px);
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-weight: 600;
  font-size: clamp(0.75rem, 1.2vh, 0.9rem);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.1s ease;
}

.btn-secondary:active, .btn-primary:active {
  transform: scale(0.94);
}

/* --- TOP REGION RESULT BANNERS --- */
.top-results-container {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  width: 100vw;
  display: flex;
  justify-content: space-around;
  padding: 0 60px;
  z-index: 520;
  pointer-events: none;
}

.top-result-banner {
  padding: clamp(14px, 2vh, 20px) clamp(28px, 3vw, 44px);
  border-radius: var(--radius-lg);
  font-size: clamp(3rem, 5vh, 4.4rem);
  font-weight: 900;
  letter-spacing: 2px;
  background: rgba(15, 22, 36, 0.96);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transform: translateY(-20px) scale(0.9);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.top-result-banner.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.top-result-banner.win {
  color: #10b981;
  border: 3px solid #10b981;
  text-shadow: 0 0 15px rgba(16, 185, 129, 0.6);
}

.top-result-banner.lose {
  color: #ef4444;
  border: 3px solid #ef4444;
  text-shadow: 0 0 15px rgba(239, 68, 68, 0.6);
}

.top-result-banner.draw {
  color: var(--gold-accent);
  border: 3px solid var(--gold-accent);
  text-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
}

/* --- BOTTOM FIXING SLOTS ARENA --- */
.bottom-slots-arena {
  position: fixed;
  bottom: 0;
  left: 0;
  height: clamp(140px, 25vh, 220px);
  width: 100vw;
  background: rgba(12, 16, 26, 0.98);
  border-top: var(--glass-border);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.6);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 1.2vw, 16px);
  padding: clamp(6px, 1vh, 12px) clamp(50px, 4vw, 70px);
  z-index: 150;
}

.player-panel {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: var(--glass-border);
  padding: clamp(6px, 1vh, 10px) clamp(8px, 1vw, 14px);
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 0.8vh, 8px);
  justify-content: center;
  overflow: hidden;
}

.player-panel.red-side { border-top: 4px solid var(--red-team); }
.player-panel.blue-side { border-top: 4px solid var(--blue-team); }

.player-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 900;
  font-size: clamp(0.7rem, 1vh, 0.8rem);
}

.red-side .player-badge { background: var(--red-team); color: #fff; }
.blue-side .player-badge { background: var(--blue-team); color: #fff; }

.player-name {
  font-size: clamp(0.8rem, 1.2vh, 0.95rem);
  font-weight: 700;
}

.player-status {
  margin-left: auto;
  font-size: clamp(0.75rem, 1.1vh, 0.85rem);
  font-weight: 700;
  color: var(--text-secondary);
}

/* --- Single Horizontal Row Slots Layout --- */
.horizontal-slots-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  width: 100%;
}

.slot-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.slot-card {
  width: clamp(40px, 7.2vh, 60px);
  height: clamp(40px, 7.2vh, 60px);
  background: rgba(255, 255, 255, 0.05);
  border: 2px dashed rgba(148, 163, 184, 0.35);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  pointer-events: auto;
  margin: 0 auto;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.slot-card.empty:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.45);
}

.slot-card .slot-idx {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(0.6rem, 0.9vh, 0.75rem);
  color: rgba(255, 255, 255, 0.3);
  font-weight: 700;
  pointer-events: none;
}

.slot-card.filled {
  width: 100%;
  height: clamp(48px, 9vh, 72px);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  animation: slotPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.slot-card.filled .slot-idx {
  top: 2px;
  left: 4px;
  transform: none;
  font-size: clamp(0.55rem, 0.8vh, 0.65rem);
  color: rgba(255, 255, 255, 0.4);
}

.red-side .slot-card.filled {
  border-color: var(--red-team);
  box-shadow: 0 0 12px var(--red-team-glow);
}

.blue-side .slot-card.filled {
  border-color: var(--blue-team);
  box-shadow: 0 0 12px var(--blue-team-glow);
}

.slot-card .slot-val {
  font-size: clamp(1.1rem, 2vh, 1.5rem);
  font-weight: 900;
  margin-top: 2px;
}

/* Less Than Sign (<) Display */
.less-than-sign {
  font-size: clamp(0.9rem, 1.5vh, 1.3rem);
  font-weight: 900;
  color: var(--gold-accent);
  opacity: 0.9;
  padding: 0 1px;
  margin-bottom: clamp(14px, 2vh, 22px);
  text-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
}

/* Remove (-) Button under Slot */
.remove-btn {
  width: 100%;
  padding: clamp(3px, 0.5vh, 5px) 0;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.25);
  font-family: var(--font-main);
  font-size: clamp(0.6rem, 0.9vh, 0.72rem);
  font-weight: 700;
  cursor: not-allowed;
  pointer-events: auto;
  position: relative;
  z-index: 200;
}

.remove-btn.active {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border: 1px solid #f87171;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.remove-btn.active:active {
  transform: scale(0.92);
  background: #b91c1c;
}

/* Drag hover status */
.slot-card.drag-valid {
  background: rgba(16, 185, 129, 0.28) !important;
  border: 2px solid #10b981 !important;
  transform: scale(1.04);
}

.slot-card.drag-invalid {
  background: rgba(239, 68, 68, 0.28) !important;
  border: 2px solid #ef4444 !important;
  transform: scale(0.96);
}

/* --- START INTRO MODAL & RULES MODAL --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 700;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #111827;
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.5vh, 28px);
  max-width: 500px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
  transform: scale(1);
}

.start-modal {
  border: 2px solid var(--gold-accent);
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.25);
}

.intro-rules-box {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  border: var(--glass-border);
  padding: 10px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: clamp(0.78rem, 1.1vh, 0.88rem);
  color: #e2e8f0;
  line-height: 1.3;
}

.rule-icon { font-size: 1.05rem; }

.btn-start {
  width: 100%;
  padding: clamp(10px, 1.5vh, 14px);
  font-size: clamp(1.05rem, 1.8vh, 1.2rem);
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, #10b981, #059669);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-start:active {
  transform: scale(0.95);
}

.btn-more-games {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 10px;
  padding: clamp(10px, 1.4vh, 13px);
  font-size: clamp(0.95rem, 1.5vh, 1.1rem);
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(29, 78, 216, 0.4);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn-more-games:hover {
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.6);
  color: #ffffff;
}

.btn-more-games:active {
  transform: scale(0.96);
  background: #1e40af;
}

.modal-title {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 12px;
}

.modal-body {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 24px;
  text-align: left;
}

@keyframes slotPop {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* --- COUNTDOWN OVERLAY STYLING --- */
.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 650;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(9, 12, 20, 0.82);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.countdown-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.countdown-text {
  font-size: clamp(6rem, 20vh, 12rem);
  font-weight: 900;
  font-family: var(--font-main);
  color: #ffd700;
  text-shadow: 0 0 35px rgba(255, 215, 0, 0.85), 0 0 70px rgba(255, 75, 92, 0.6);
  animation: countdownPop 0.85s cubic-bezier(0.175, 0.885, 0.32, 1.275) infinite;
  letter-spacing: 2px;
}

.countdown-text.start-text {
  color: #10b981;
  text-shadow: 0 0 35px rgba(16, 185, 129, 0.95), 0 0 70px rgba(0, 210, 255, 0.7);
  font-size: clamp(4.5rem, 16vh, 9rem);
}

@keyframes countdownPop {
  0% { transform: scale(0.3); opacity: 0; }
  35% { transform: scale(1.18); opacity: 1; }
  65% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.92); opacity: 0.7; }
}
