:root {
  --primary: #4F6BED;
  --primary-hover: #3D57D8;
  --primary-light: rgba(79, 107, 237, 0.10);
  --primary-border: rgba(79, 107, 237, 0.25);
  --success: #22C55E;
  --success-light: rgba(34, 197, 94, 0.10);
  --success-border: rgba(34, 197, 94, 0.30);
  --warning: #F59E0B;
  --warning-light: rgba(245, 158, 11, 0.10);
  --danger: #EF4444;
  --danger-light: rgba(239, 68, 68, 0.10);
  --danger-border: rgba(239, 68, 68, 0.30);
  --bg: #F0F2F8;
  --card: #FFFFFF;
  --text: #1E293B;
  --text-secondary: #64748B;
  --text-light: #94A3B8;
  --border: #E2E8F0;
  --input-bg: #F8FAFC;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow: 0 4px 16px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 28px rgba(0,0,0,0.10);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --font-heading: 'Jua', sans-serif;
  --font-body: 'Noto Sans KR', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: var(--font-body);
  background: linear-gradient(160deg, #e8ecf8 0%, #f0f2f8 30%, #f5f0f0 100%);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body.noscroll {
  overflow: hidden !important;
  touch-action: none !important;
}

/* ── Splash ── */
.splash {
  position: fixed;
  inset: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}
.splash-logo { width: 180px; margin-bottom: 16px; animation: pulse 1.5s ease-in-out infinite; }
.splash-text { font-family: var(--font-heading); color: var(--text-secondary); font-size: 15px; }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.04); opacity: 0.85; }
}

/* ── Views ── */
.view { max-width: 680px; margin: 0 auto; padding: 16px; }
.view-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

/* ── Login ── */
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 44px 32px 36px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-logo { width: 160px; margin-bottom: 12px; }
.login-title {
  font-family: var(--font-heading);
  font-size: 26px;
  color: var(--primary);
  margin-bottom: 28px;
}
.login-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; }
.choice-card .login-title { margin-bottom: 8px; }
.choice-btn { margin-bottom: 10px; }
.choice-btn-secondary {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: #fff;
}
.choice-btn-secondary:hover { background: linear-gradient(135deg, #38bdf8, #0ea5e9); }

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { width: 100px; height: auto; border-radius: 8px; object-fit: contain; }
.header-info { line-height: 1.3; }
.header-name { font-family: var(--font-heading); font-size: 17px; margin: 0; }
.header-grade { font-size: 12px; color: var(--text-secondary); }
.btn-pw-small {
  background: none;
  border: none;
  font-size: 12px;
  cursor: pointer;
  padding: 0 0 0 4px;
  min-width: 28px;
  min-height: 28px;
  opacity: 0.5;
  transition: opacity 0.2s;
  vertical-align: middle;
}
.btn-pw-small:hover { opacity: 1; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.mileage-badge {
  font-family: var(--font-heading);
  font-size: 13px;
  padding: 5px 10px;
  background: var(--warning-light);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: 20px;
  color: #92400E;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.mileage-badge:hover { background: rgba(245,158,11,0.18); }

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
}
.card-title {
  font-family: var(--font-heading);
  font-size: 17px;
  color: var(--text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex-shrink: 0;
}

/* ── Forms ── */
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}
.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2364748B' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group input::placeholder { color: var(--text-light); }

/* ── Buttons ── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font-heading);
  cursor: pointer;
  transition: background 0.2s, transform 0.08s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-lg { padding: 15px; font-size: 17px; }

.btn-outline {
  padding: 7px 12px;
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-outline:hover { background: var(--input-bg); border-color: var(--text-light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-success {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font-heading);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-success:hover { background: #1aab50; }

.btn-secondary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--input-bg);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font-heading);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: #edf0f7; }

/* ── Chart ── */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}

/* ── Unit Grid ── */
.unit-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.unit-item {
  padding: 12px 14px;
  background: var(--input-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: box-shadow 0.2s;
}
.unit-item:hover { box-shadow: var(--shadow-xs); }
.unit-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
}
.unit-item-name {
  font-family: var(--font-heading);
  font-size: 15px;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 8px;
}
.unit-item-level {
  font-family: var(--font-heading);
  font-size: 12px;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 9px;
  border-radius: 14px;
  white-space: nowrap;
  flex-shrink: 0;
}

.xp-bar {
  width: 100%;
  height: 6px;
  background: #E2E8F0;
  border-radius: 3px;
  overflow: hidden;
}
.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #7C8FFF);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.xp-text {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 3px;
  text-align: right;
}

/* ── Selected Unit Info ── */
.unit-info-box {
  padding: 14px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary-border);
  margin-bottom: 12px;
}
.unit-info-box .xp-bar { height: 8px; border-radius: 4px; }
.unit-info-box .xp-bar-fill { border-radius: 4px; }

/* ── XP Info Row ── */
.xp-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--success-light);
  border-radius: var(--radius-sm);
  border: 1px solid var(--success-border);
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--text);
}
.xp-preview {
  font-family: var(--font-heading);
  font-size: 17px;
  color: var(--success);
}

/* ── Quiz ── */
.quiz-header { gap: 8px; flex-wrap: wrap; }
.quiz-info { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.quiz-timer {
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.quiz-badge {
  font-family: var(--font-heading);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 14px;
  white-space: nowrap;
}
.quiz-badge-subject {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}
.quiz-badge-diff {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.quiz-card { padding-bottom: 20px; }
.problem-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
  padding-bottom: 300px;
}
.problem-img {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  background: #fff;
}
#drawCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  touch-action: none;
}

.answer-area { margin: 14px 0; }
.answer-area input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font-body);
  outline: none;
  margin-bottom: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.answer-area input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.answer-area input::placeholder { color: var(--text-light); }

/* ── Feedback ── */
.feedback { margin-top: 16px; }
.feedback-result {
  padding: 20px;
  border-radius: var(--radius-sm);
  text-align: center;
  margin-bottom: 12px;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.feedback-correct {
  background: var(--success-light);
  border: 1px solid var(--success-border);
}
.feedback-wrong {
  background: var(--danger-light);
  border: 1px solid var(--danger-border);
}
.feedback-result h4 {
  font-family: var(--font-heading);
  font-size: 22px;
  margin-bottom: 6px;
}
.feedback-correct h4 { color: var(--success); }
.feedback-wrong h4 { color: var(--danger); }
.feedback-xp {
  font-family: var(--font-heading);
  font-size: 16px;
  color: var(--success);
  margin-top: 4px;
}
.feedback-mileage {
  font-family: var(--font-heading);
  font-size: 14px;
  color: #92400E;
  margin-top: 2px;
}
.feedback-level-box {
  padding: 14px;
  background: var(--input-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 12px 0;
}
.feedback-level-label {
  font-family: var(--font-heading);
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text);
}
.feedback-explanation { margin-top: 12px; }
.feedback-explanation img {
  width: 100%;
  border-radius: var(--radius-sm);
  background: #fff;
}
.feedback-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.feedback-actions button { flex: 1; }

/* ── Floating Draw Buttons ── */
.float-btn {
  position: fixed;
  right: 14px;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 10000;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.float-btn:hover { background: #fff; box-shadow: var(--shadow-lg); }
#toggleDraw { top: 40%; }
.float-btn-clear { top: calc(40% + 56px); }
.float-icon { font-size: 20px; opacity: 0.65; transition: opacity 0.2s; }
.float-btn.active {
  background: var(--primary);
  border-color: var(--primary);
}
.float-btn.active .float-icon { opacity: 1; }

/* ── Footer ── */
.footer-link { text-align: center; margin: 20px 0 30px; }
.home-link-img {
  width: 120px;
  transition: transform 0.2s;
}
.home-link-img:hover { transform: scale(1.05); }

/* ── Utility ── */
.text-muted { color: var(--text-secondary); }
.text-center { text-align: center; }

/* ── Resume Card ── */
.resume-card {
  background: linear-gradient(135deg, #FFF7ED, #FFFBEB);
  border: 1.5px solid rgba(245, 158, 11, 0.30);
}

/* ── Saved Problems ── */
.saved-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--input-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.saved-item:hover { box-shadow: var(--shadow-xs); }
.saved-thumb {
  width: 80px;
  height: 60px;
  object-fit: cover;
  background: #fff;
  flex-shrink: 0;
}
.saved-info { flex: 1; min-width: 0; }
.saved-info-title {
  font-family: var(--font-heading);
  font-size: 13px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.saved-info-meta { font-size: 11px; color: var(--text-secondary); }
.saved-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.saved-detail-box {
  background: #fff;
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}
.saved-detail-box img {
  width: 100%;
  margin-bottom: 12px;
}
.btn-delete-saved {
  padding: 6px 14px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-xs);
  font-size: 13px;
  cursor: pointer;
}
.btn-delete-saved:hover { opacity: 0.85; }

/* ── Teacher View ── */
.teacher-presence-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.teacher-presence-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.teacher-presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.teacher-presence-dot.online { background: var(--success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.5); }
.teacher-presence-dot.offline { background: var(--danger); }
.teacher-presence-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.teacher-student-card {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.teacher-student-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.2s;
}
.teacher-student-header:hover { background: rgba(79, 107, 237, 0.04); }
.teacher-student-name {
  font-family: var(--font-heading);
  font-size: 15px;
  color: var(--text);
}
.teacher-student-grade {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 8px;
}
.teacher-student-toggle {
  font-size: 12px;
  color: var(--text-light);
  transition: transform 0.2s;
}
.teacher-student-body {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}
.teacher-student-body.open {
  display: block;
}
.teacher-section-title {
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--primary);
  margin: 14px 0 8px;
}
.teacher-record-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: #fff;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 12px;
}
.teacher-record-ok { color: var(--success); font-weight: 600; }
.teacher-record-fail { color: var(--danger); font-weight: 600; }
.teacher-record-clickable { cursor: pointer; transition: background 0.15s; }
.teacher-record-clickable:hover { background: rgba(79, 107, 237, 0.06); }

/* ── Responsive ── */
@media (max-width: 480px) {
  .view { padding: 8px; }
  .login-card { padding: 32px 20px 28px; }
  .card { padding: 16px; }
  .header { padding: 10px 12px; }
  .header-name { font-size: 15px; }
  .mileage-badge { font-size: 12px; padding: 4px 8px; }
  .unit-item-name { font-size: 14px; }
  .quiz-badge { font-size: 11px; }
  .chart-wrap { height: 180px; }
}
