:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --secondary: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --perfect: #8b5cf6;

  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --canvas-bg: #ffffff;
  --canvas-ray: #1e293b;
  --canvas-arc: #6366f1;
  --canvas-grid: #f1f5f9;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-main: #0b0f19;
  --bg-card: #131b2e;
  --bg-subtle: #1e293b;
  --border-color: #27354f;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  --canvas-bg: #162035;
  --canvas-ray: #f1f5f9;
  --canvas-arc: #818cf8;
  --canvas-grid: #1e293b;

  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 헤더 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

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

.logo-icon {
  font-size: 2rem;
  background: var(--primary-light);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.logo h1 {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: flex;
  flex-direction: column;
}

.logo h1 span {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header-controls {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.icon-btn:hover {
  background: var(--bg-subtle);
  transform: translateY(-1px);
}

/* 모드 탭 & 설정 바 */
.top-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.mode-tabs {
  display: flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
  gap: 6px;
}

.mode-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.mode-tab.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.settings-drawer {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-top: 6px;
  border-top: 1px dashed var(--border-color);
  align-items: center;
  justify-content: space-between;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.setting-item select {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

.setting-item select:hover {
  border-color: var(--primary);
}

/* 대시보드 상태바 */
.status-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 12px 10px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
}

.stat-value.highlight {
  color: var(--primary);
}

/* 메인 캔버스 */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.canvas-wrapper {
  position: relative;
  background: var(--canvas-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  aspect-ratio: 1.2 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#angleCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-overlay-hint {
  position: absolute;
  top: 14px;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  color: #ffffff;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  pointer-events: none;
  animation: fadeIn 0.4s ease;
}

/* 인터랙션 카드 */
.interaction-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 입력 폼 */
.input-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-group {
  display: flex;
  align-items: center;
  position: relative;
  gap: 8px;
}

.input-group input {
  flex: 1;
  height: 52px;
  background: var(--bg-subtle);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0 45px 0 18px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
}

.input-group input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.unit-label {
  position: absolute;
  right: 120px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}

.btn {
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  padding: 0 24px;
  height: 52px;
  font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

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

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  padding: 12px 20px;
  font-size: 0.95rem;
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-large {
  width: 100%;
  height: 54px;
  font-size: 1.15rem;
  border-radius: var(--radius-md);
}

/* 빠른 각도 버튼 */
.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.quick-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.quick-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* 결과 패널 */
.result-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.result-panel.hidden {
  display: none;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  align-self: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: var(--radius-full);
  font-size: 1.1rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-badge.perfect {
  background: #ede9fe;
  color: var(--perfect);
}

.result-badge.excellent {
  background: #dcfce7;
  color: var(--success);
}

.result-badge.good {
  background: #e0f2fe;
  color: #0284c7;
}

.result-badge.fair {
  background: #fef3c7;
  color: #d97706;
}

.result-badge.poor {
  background: #fee2e2;
  color: var(--danger);
}

.result-details {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--bg-subtle);
  padding: 16px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.detail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.detail-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-val {
  font-size: 1.35rem;
  font-weight: 800;
}

.guess-val {
  color: #f97316;
}

.actual-val {
  color: var(--success);
}

.error-val {
  color: var(--danger);
}

.error-highlight .error-val {
  font-size: 1.5rem;
}

.detail-divider {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-muted);
}

.result-feedback {
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
}

.result-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.actual-dot { background-color: var(--success); }
.guess-dot { background-color: #f97316; }
.error-dot { background-color: rgba(239, 68, 68, 0.4); border: 1px solid var(--danger); }

/* 모달 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fadeIn 0.25s ease;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 28px;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: scaleUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-trophy {
  font-size: 3rem;
  display: inline-block;
  margin-bottom: 8px;
  animation: bounce 0.8s ease infinite alternate;
}

.modal-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
}

.modal-header p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.challenge-rank-box {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #ffffff;
  padding: 18px;
  border-radius: var(--radius-md);
  text-align: center;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.3);
}

.rank-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.9;
  font-weight: 600;
  display: block;
  margin-bottom: 2px;
}

.rank-letter {
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1;
}

.challenge-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.c-stat {
  background: var(--bg-subtle);
  padding: 12px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.c-stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.c-stat-val {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
}

.round-history-container h4 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.round-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
}

.history-item .h-round {
  color: var(--text-muted);
  width: 50px;
}

.history-item .h-angles {
  color: var(--text-main);
}

.history-item .h-diff {
  font-weight: 700;
}

.history-item .h-diff.good {
  color: var(--success);
}
.history-item .h-diff.warn {
  color: var(--warning);
}
.history-item .h-diff.bad {
  color: var(--danger);
}

.modal-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 푸터 */
.footer {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0;
}

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

.copyright {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* 애니메이션 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes scaleUp {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

/* 반응형 */
@media (max-width: 600px) {
  body {
    padding: 12px 8px;
  }
  
  .status-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .unit-label {
    right: 105px;
    font-size: 0.85rem;
  }

  .btn-primary {
    padding: 0 16px;
    font-size: 0.95rem;
  }

  .settings-drawer {
    flex-direction: column;
    align-items: flex-start;
  }
}
