/* ==========================================================================
   큰수차례킹 학급대항전 - 1인용 20칸 오름차순 + 콤보/보너스 점수 디자인 시스템
   로비/게임종료 화면은 '10 만들킹'(10/index.php)의 화면 구성을 그대로 계승한다.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Outfit:wght@500;700;900&display=swap');

:root {
  /* 게임 화면(HUD/슬롯) 전용 - 기존 골드 테마 */
  --bg-main: #090c14;
  --bg-card: rgba(18, 24, 38, 0.92);
  --border-color: rgba(255, 255, 255, 0.18);
  --gold-accent: #ffd700;
  --text-primary: #ffffff;
  --text-secondary: #94a3b8;
  --glass-border: 1px solid rgba(255, 255, 255, 0.18);
  --radius-lg: 16px;
  --radius-md: 10px;
  --font-main: 'Outfit', 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', 'Inter', -apple-system, sans-serif;

  /* 로비/게임종료 화면 전용 - '10 만들킹'과 동일한 네온 시안/마젠타 테마 */
  --panel-bg: rgba(15, 18, 36, 0.7);
  --panel-border: rgba(0, 243, 255, 0.25);
  --primary-color: #00f3ff;
  --primary-glow: rgba(0, 243, 255, 0.4);
  --accent-color: #ff00ff;
  --accent-glow: rgba(255, 0, 255, 0.4);
  --neon-yellow: #fdf200;
}

/* ==========================================================================
   [전자칠판/태블릿 최적화 제약 조건 - 전역 필수 적용]
   ========================================================================== */
html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden !important;
  background: var(--bg-main);
  background-image:
    radial-gradient(at 0% 0%, rgba(0, 243, 255, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(255, 0, 255, 0.15) 0px, transparent 50%),
    linear-gradient(rgba(0, 243, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 243, 255, 0.03) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px;
  color: var(--text-primary);
  font-family: 'Pretendard', 'Noto Sans KR', 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;
}

*, *::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;
}

input, .autocomplete-list, .autocomplete-list *, .scroll-container {
  touch-action: manipulation !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; }

/* --- SCREEN SWITCHER (lobby-screen ↔ game-screen, '10'과 동일) --- */
.screen {
  display: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.screen.active { display: flex; opacity: 1; }

/* --- Glass Panel (로비/게임종료 화면 공용) --- */
.glass-panel {
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 243, 255, 0.08);
}

.neon-border {
  border: 3px solid rgba(0, 243, 255, 0.3);
  border-radius: 20px;
  box-shadow: 0 0 25px rgba(0, 243, 255, 0.15), inset 0 0 25px rgba(0, 243, 255, 0.05);
}

.game-title {
  font-family: 'Outfit', 'Jua', sans-serif;
  font-weight: 900;
  font-size: clamp(30px, 5vh, 52px);
  letter-spacing: -1.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.1);
  line-height: 1.15;
}

.game-title span {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-left: 5px;
  text-shadow: 0 0 30px var(--accent-glow);
}

/* --- 학교 검색 & 자동완성 ('10'과 동일) --- */
.search-container { position: relative; width: 100%; }

#school-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1.5px solid rgba(0, 243, 255, 0.25);
  border-radius: 12px;
  padding: 14px 20px;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  outline: none;
  font-family: inherit;
  transition: all 0.3s ease;
}

#school-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 20px var(--primary-glow);
  background: rgba(0, 0, 0, 0.6);
}

#btn-clear-school {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  pointer-events: auto;
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  background: rgba(10, 12, 28, 0.98);
  border: 1px solid var(--primary-color);
  border-radius: 12px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 99;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
}

.autocomplete-item {
  padding: 12px 20px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  color: #e2e8f0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  pointer-events: auto;
  transition: background 0.2s;
}

.autocomplete-item:hover { background: rgba(0, 243, 255, 0.2); color: #fff; }

.school-badge {
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, rgba(0, 243, 255, 0.15), rgba(0, 243, 255, 0.05));
  border: 1px solid rgba(0, 243, 255, 0.4);
  border-radius: 12px;
  padding: 10px 16px;
  justify-content: space-between;
}

#btn-change-school { background: none; border: none; color: #ff4a4a; font-size: 18px; cursor: pointer; pointer-events: auto; }

#grade-select, #grade-select option { background-color: #0d0e1b !important; color: #e2e8f0; }
#class-input { background: rgba(0, 0, 0, 0.25); }

/* --- 랭킹/명예의 전당 표 ('10'과 동일) --- */
.ranking-table { width: 100%; border-collapse: collapse; text-align: left; }

.ranking-table th {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-secondary);
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ranking-table td {
  font-size: 17px;
  font-weight: 700;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-table tbody tr:hover { background: rgba(0, 243, 255, 0.05); }

.no-rank-data { text-align: center; color: var(--text-secondary); padding: 30px !important; font-size: 14px; }

.rainbow-school {
  background: linear-gradient(to right, #00f3ff, #ff00ff, #fdf200, #00ff66);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
  animation: rainbow-anim 4s linear infinite;
}

@keyframes rainbow-anim { 0% { filter: hue-rotate(0deg); } 100% { filter: hue-rotate(360deg); } }

.scroll-container::-webkit-scrollbar { width: 6px; }
.scroll-container::-webkit-scrollbar-track { background: transparent; }
.scroll-container::-webkit-scrollbar-thumb { background: rgba(0, 243, 255, 0.3); border-radius: 4px; }
.scroll-container::-webkit-scrollbar-thumb:hover { background: rgba(0, 243, 255, 0.6); }

.lobby-left, .lobby-right { overflow-y: auto; scrollbar-width: thin; }
.lobby-left::-webkit-scrollbar, .lobby-right::-webkit-scrollbar { width: 6px; }
.lobby-left::-webkit-scrollbar-thumb, .lobby-right::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.25); border-radius: 4px; }

@media (max-height: 880px) {
  #lobby-screen { max-height: 96dvh !important; gap: 1.25rem !important; }
}

/* ==========================================================================
   게임 화면 (game-screen) - 오름차순 버블 드래그 아레나 (기존 골드 테마 유지)
   ========================================================================== */

#game-screen { position: relative; }

.canvas-wrapper { position: fixed; inset: 0; z-index: 500; pointer-events: none; }
#physics-canvas { width: 100vw; height: 100vh; display: block; }

.side-btn {
  position: fixed;
  top: 14%;
  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-right { right: clamp(10px, 1.5vw, 20px); }
.side-icon { font-size: clamp(1.4rem, 2.4vh, 2rem); }

header {
  height: clamp(48px, 7vh, 60px);
  position: relative;
  z-index: 160;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(8px, 1.2vw, 16px);
  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; min-width: 0; }

.logo-badge {
  background: linear-gradient(135deg, #ff4b5c, #00d2ff);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-weight: 900;
  font-size: clamp(0.9rem, 1.5vh, 1.2rem);
  letter-spacing: 1px;
  flex-shrink: 0;
}

h1 {
  font-size: clamp(0.95rem, 1.6vh, 1.25rem);
  font-weight: 900;
  font-family: var(--font-main);
  background: linear-gradient(to right, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.6);
  border: var(--glass-border);
  padding: 4px 18px;
  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.3rem, 2.2vh, 1.7rem); 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); } }

.score-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.6);
  border: var(--glass-border);
  padding: 4px 18px;
  border-radius: var(--radius-md);
}

.score-label { font-size: clamp(0.65rem, 1vh, 0.75rem); color: var(--text-secondary); font-weight: 700; }
#live-score { font-size: clamp(1.3rem, 2.2vh, 1.7rem); font-weight: 900; color: #fff; font-variant-numeric: tabular-nums; }

#ui-combo-container {
  display: none;
  align-items: baseline;
  gap: 4px;
  background: rgba(16, 185, 129, 0.18);
  border: 1px solid rgba(16, 185, 129, 0.6);
  padding: 4px 14px;
  border-radius: var(--radius-md);
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.35);
}

#ui-combo-container.active { display: flex; }

.combo-label { font-size: clamp(0.6rem, 0.9vh, 0.7rem); color: #10b981; font-weight: 900; letter-spacing: 1px; }
#ui-combo { font-size: clamp(1.1rem, 1.9vh, 1.4rem); font-weight: 900; color: #fde047; }

.controls-group { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn-secondary {
  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;
  white-space: nowrap;
}

.btn-secondary:active { transform: scale(0.94); }

.slots-arena {
  position: fixed;
  bottom: 0;
  left: 0;
  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);
  padding: clamp(8px, 1.4vh, 14px) clamp(20px, 3vw, 50px);
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 0.8vh, 8px);
}

.slots-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

#header-school-name { font-size: clamp(0.8rem, 1.2vh, 0.95rem); font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#slots-status { font-size: clamp(0.8rem, 1.2vh, 0.95rem); font-weight: 700; color: var(--text-secondary); }

/* 20칸 + 19개의 '<' 기호가 항상 "한 줄"에 들어가도록 flex-wrap을 절대 허용하지 않는다.
   슬롯 칸(.slot-box)은 flex:1로 남는 폭을 20등분해서 채우므로, 숫자가 채워져도
   전체 줄 폭이 늘어나지 않고(=칸 크기가 항상 고정) 화면 폭에 맞춰 자동으로 줄어들 뿐이다. */
.horizontal-slots-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  column-gap: clamp(1px, 0.3vw, 4px);
  flex: 1;
  min-height: 0;
}

.slot-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1 1 0;
  min-width: 0;
  max-width: 64px;
}

/* 빈 칸/채워진 칸의 크기를 완전히 동일하게 고정한다 (예전엔 채워지면 커져서
   한 줄에 다 안 들어가고 2줄로 밀려나는 문제가 있었다). */
.slot-card {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 56px;
  max-height: 56px;
  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: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 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.5rem, 0.8vh, 0.65rem);
  color: rgba(255, 255, 255, 0.3);
  font-weight: 700;
  pointer-events: none;
}

.slot-card.filled {
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid var(--gold-accent);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
  animation: slotPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: grab;
}

.slot-card.filled:active { cursor: grabbing; }

.slot-card.filled .slot-idx { top: 5px; left: 50%; transform: translateX(-50%); font-size: clamp(0.4rem, 0.6vh, 0.5rem); color: rgba(255, 255, 255, 0.4); }
.slot-card .slot-val { font-size: clamp(0.8rem, 1.5vh, 1.1rem); font-weight: 900; margin-top: 2px; }

/* 슬롯에 놓인 숫자를 옆 칸으로 드래그해서 옮길 때 손가락/펜을 따라다니는 원형 고스트 */
.slot-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 2px solid var(--gold-accent);
  box-shadow: 0 0 18px rgba(255, 215, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: clamp(0.8rem, 1.5vh, 1.1rem);
  font-weight: 900;
  pointer-events: none;
  z-index: 999;
  transform: translate(-50%, -50%) scale(1.08);
}

.less-than-sign {
  flex: 0 0 auto;
  font-size: clamp(0.75rem, 1.3vh, 1.05rem);
  font-weight: 900;
  color: var(--gold-accent);
  opacity: 0.9;
  padding: 0 1px;
  text-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
}

.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.5rem, 0.8vh, 0.62rem);
  font-weight: 700;
  cursor: not-allowed;
  pointer-events: auto;
  position: relative;
  z-index: 200;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

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

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

@keyframes slotPop { 0% { transform: scale(0.8); } 50% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* --- COUNTDOWN OVERLAY --- */
.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; }
}

@media (max-width: 640px) {
  header { flex-wrap: wrap; height: auto; padding: 6px clamp(10px, 3vw, 20px); gap: 6px; }
  .score-container, #ui-combo-container { padding: 3px 10px; }
}
