:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --primary-dark: #3730a3;
  --secondary: #06b6d4;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f97316;
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f2b48 100%);
  --card-bg: rgba(255, 255, 255, 0.96);
  --card-shadow: 0 20px 45px -15px rgba(0, 0, 0, 0.35);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-color: #e2e8f0;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-gradient);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  overflow-x: hidden;
  position: relative;
}

/* 배경 장식 요소 */
.bg-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.45;
  animation: float 12s ease-in-out infinite alternate;
}

.shape-1 {
  width: 380px;
  height: 380px;
  background: #6366f1;
  top: -100px;
  left: -100px;
}

.shape-2 {
  width: 400px;
  height: 400px;
  background: #06b6d4;
  bottom: -120px;
  right: -120px;
  animation-delay: -6s;
}

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(35px, 35px) scale(1.12); }
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}

/* 메인 앱 컨테이너 */
.app-container {
  width: 100%;
  max-width: 520px;
  position: relative;
  z-index: 1;
}

/* 상단 네비게이션 바 */
.top-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.nav-sub-link {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: all 0.2s;
}

.nav-sub-link:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.top-nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn-small {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn-small:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.06);
}

/* 화면 전환 애니메이션 */
.screen {
  display: none;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 공통 카드 */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.9);
}

/* ================= 1. 시작 화면 스타일 ================= */
.header-card {
  text-align: center;
  padding: 26px 20px;
}

.badge {
  display: inline-block;
  background: #ede9fe;
  color: #5b21b6;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 50px;
  margin-bottom: 12px;
}

.title {
  font-size: 1.75rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: #1e1b4b;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.setting-group {
  margin-bottom: 18px;
}

.setting-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 800;
  color: #334155;
  margin-bottom: 8px;
}

/* 모드 & 난이도 셀렉터 */
.mode-selector, .range-selector {
  display: grid;
  gap: 8px;
}

.mode-selector {
  grid-template-columns: repeat(2, 1fr);
}

.range-selector {
  grid-template-columns: repeat(3, 1fr);
}

.mode-btn, .range-btn {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.mode-btn .mode-title, .range-btn .range-title {
  font-size: 0.85rem;
  font-weight: 800;
  color: #334155;
}

.mode-btn .mode-desc, .range-btn .range-desc {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 3px;
}

.mode-btn:hover, .range-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.mode-btn.active, .range-btn.active {
  background: #eef2ff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.mode-btn.active .mode-title, .range-btn.active .range-title {
  color: var(--primary-dark);
}

.mode-btn.active .mode-desc, .range-btn.active .range-desc {
  color: #6366f1;
  font-weight: 600;
}

/* 토글 스위치 옵션 */
.toggle-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.switch-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  position: relative;
}

.toggle-checkbox {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background-color: #cbd5e1;
  border-radius: 24px;
  transition: .25s;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .25s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-checkbox:checked + .toggle-slider {
  background-color: var(--primary);
}

.toggle-checkbox:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* 최고 기록 박스 */
.best-score-box {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.best-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #475569;
}

.best-val {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--accent);
}

/* 버튼 스타일 */
.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 15px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 20px -4px rgba(79, 70, 229, 0.45);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -4px rgba(79, 70, 229, 0.55);
}

.primary-btn:active {
  transform: translateY(1px);
}

.info-footer {
  text-align: center;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1.4;
  padding: 0 4px;
}

/* ================= 2. 게임 화면 스타일 ================= */
.game-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.stat-pill {
  flex: 1;
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.stat-pill .stat-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}

.stat-pill .stat-value {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--text-main);
}

.avg-error-pill .stat-value {
  color: var(--primary);
}

.streak-pill .stat-value {
  color: var(--accent);
}

/* 캔버스 카드 */
.angle-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.canvas-header-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.canvas-hint-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: #475569;
  background: #f1f5f9;
  padding: 4px 10px;
  border-radius: 20px;
}

.sub-tool-btn {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.sub-tool-btn:hover {
  background: #f1f5f9;
}

.sub-tool-btn.active {
  background: #ede9fe;
  border-color: #8b5cf6;
  color: #6d28d9;
}

.canvas-wrapper {
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 280px;
  background: #0f172a;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#angle-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* 캔버스 범례 */
.canvas-legend {
  display: none;
  width: 100%;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #f1f5f9;
}

.canvas-legend.show {
  display: flex;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  color: #475569;
}

.legend-color-box {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.actual-color { background: #38bdf8; }
.guess-color { background: #f43f5e; }
.diff-color { background: rgba(244, 63, 94, 0.25); border: 1px dashed #f43f5e; }

/* 컨트롤 카드 (입력 / 피드백) */
.control-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--card-shadow);
}

.input-instruction {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 800;
  color: #334155;
  margin-bottom: 12px;
}

.angle-input-wrapper {
  position: relative;
  max-width: 220px;
  margin: 0 auto 14px;
}

.angle-input {
  width: 100%;
  font-size: 2.2rem;
  font-weight: 900;
  text-align: center;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 10px 36px 10px 10px;
  outline: none;
  color: #1e293b;
  background: #f8fafc;
  transition: all 0.2s;
  letter-spacing: -0.02em;
}

.angle-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px var(--primary-light);
}

.unit-deg {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.8rem;
  font-weight: 900;
  color: #94a3b8;
  pointer-events: none;
}

/* 빠른 조절 버튼 바 */
.quick-adjust-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.adjust-btn {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.adjust-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.adjust-btn:active {
  transform: scale(0.95);
}

/* 피드백 박스 */
.feedback-result-box {
  text-align: center;
  animation: fadeIn 0.25s ease-out;
}

.rating-badge {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 900;
  padding: 6px 18px;
  border-radius: 50px;
  margin-bottom: 14px;
}

.rating-badge.tier-perfect { background: #dcfce7; color: #15803d; }
.rating-badge.tier-great { background: #e0f2fe; color: #0369a1; }
.rating-badge.tier-good { background: #fef3c7; color: #b45309; }
.rating-badge.tier-fair { background: #ffedd5; color: #c2410c; }
.rating-badge.tier-poor { background: #fee2e2; color: #b91c1c; }

.feedback-comparison-grid {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 14px 10px;
  margin-bottom: 14px;
}

.comparison-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.comp-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.comp-val {
  font-size: 1.25rem;
  font-weight: 900;
}

.actual-text { color: #0284c7; }
.guess-text { color: #e11d48; }
.error-text { color: #ea580c; }

.comparison-item.highlight-error .comp-val {
  font-size: 1.45rem;
  color: var(--danger);
}

.comparison-divider {
  font-size: 0.8rem;
  font-weight: 800;
  color: #cbd5e1;
}

.feedback-comment {
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 16px;
  line-height: 1.4;
}

/* 모바일 가상 키패드 */
.keypad-container {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 10px;
  box-shadow: var(--card-shadow);
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.key-btn {
  background: #f1f5f9;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 0;
  font-size: 1.3rem;
  font-weight: 800;
  color: #1e293b;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: background 0.1s, transform 0.1s;
}

.key-btn:active {
  background: #e2e8f0;
  transform: scale(0.96);
}

.key-btn.action-key {
  background: #e2e8f0;
  color: #475569;
  font-size: 1.1rem;
}

.bottom-action-row {
  text-align: center;
  padding: 4px;
}

.text-link-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.15s;
}

.text-link-btn:hover {
  color: white;
  text-decoration: underline;
}

/* ================= 3. 결과 화면 스타일 ================= */
.result-card {
  text-align: center;
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
}

.new-record-badge {
  display: none;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 5px 16px;
  border-radius: 50px;
  margin: 0 auto 10px;
  width: fit-content;
  animation: bounce 0.6s infinite alternate;
}

.new-record-badge.show {
  display: block;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-4px); }
}

.result-rank-emoji {
  font-size: 3.6rem;
  line-height: 1;
  margin-bottom: 6px;
}

.result-title {
  font-size: 1.55rem;
  font-weight: 900;
  color: #1e1b4b;
  margin-bottom: 4px;
}

.result-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.main-score-display {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border: 2px solid #93c5fd;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
}

.main-score-number {
  font-size: 3rem;
  font-weight: 900;
  color: #1d4ed8;
  line-height: 1.1;
}

.main-score-label {
  font-size: 0.95rem;
  font-weight: 800;
  color: #1e40af;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}

.stat-card-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 3px;
}

.stat-card-val {
  font-size: 1.15rem;
  font-weight: 800;
  color: #1e293b;
}

/* 라운드별 오차 기록 리스트 */
.round-history-section {
  text-align: left;
  margin-bottom: 20px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.history-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: #334155;
  margin-bottom: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 140px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  border: 1px solid #f1f5f9;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.history-round-num {
  font-weight: 700;
  color: #64748b;
  width: 45px;
}

.history-comparison {
  color: #334155;
  font-weight: 600;
}

.history-error {
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 12px;
}

.history-error.good {
  background: #dcfce7;
  color: #15803d;
}

.history-error.bad {
  background: #fee2e2;
  color: #b91c1c;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.secondary-btn {
  width: 100%;
  background: #f1f5f9;
  color: #475569;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

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

/* 데스크탑 미디어 쿼리 */
@media (min-width: 600px) {
  .keypad-container {
    display: none;
  }
}
