/* 틴커랩 공통 스타일 — 학생/학부모 페이지와 교사 페이지가 함께 쓴다. */
:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f8cff;
  --primary-dark: #2f6fe0;
  --danger: #e5484d;
  --c0: #e74c3c;
  --c1: #3498db;
  --c2: #f1c40f;
  --c3: #2ecc71;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(17, 24, 39, 0.06);
  --gutter: 16px;
  --font: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
  overflow-x: hidden;
}
body.modal-open { overflow: hidden; }
h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.25; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.75em; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.center { text-align: center; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
code.url { word-break: break-all; font-size: 0.95em; }

/* ---------- 입장 ---------- */
.gate {
  max-width: 420px;
  margin: 0 auto;
  padding: 48px var(--gutter) 40px;
  text-align: center;
}
.gate h1 { font-size: 2.2rem; color: var(--primary-dark); }
.gate form { display: grid; gap: 14px; text-align: left; margin-top: 20px; }
.gate label { display: grid; gap: 6px; font-weight: 600; }
.gate input[type="text"], .gate input:not([type]) {
  padding: 14px 16px; border: 2px solid var(--line); border-radius: 12px; font-size: 1.1rem; background: #fff;
}
.role-row { display: flex; gap: 12px; }
.role-row label {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font-weight: 600;
}
.role-row label:has(input:checked) { border-color: var(--primary); background: #eef4ff; color: var(--primary-dark); }
.role-row input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- 헤더 / 탭 ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px var(--gutter);
  background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.app-header strong { font-size: 1.15rem; color: var(--primary-dark); }
.header-actions { display: flex; gap: 8px; }
.tabs {
  display: flex; gap: 6px; padding: 10px var(--gutter) 0; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.app-header .tabs { padding: 0; }
.tab {
  position: relative; flex: 1 0 auto; min-height: 44px; padding: 8px 14px;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer;
  white-space: nowrap;
}
.tab[aria-selected="true"] { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow); }
.badge-dot {
  position: absolute; top: 8px; right: 8px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 0 2px #fff;
}
.panel { padding: 14px var(--gutter) 40px; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ---------- 카드 / 버튼 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card.danger { border: 1px solid #fecaca; }
.card.done { text-align: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 2px solid transparent;
  background: #eef2f7; color: var(--text); font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-lg { min-height: 56px; font-size: 1.15rem; width: 100%; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 0.9rem; }
.btn.chip { background: #eef4ff; color: var(--primary-dark); border-radius: 999px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row input { flex: 1 1 160px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.field { display: grid; gap: 6px; font-weight: 600; margin: 12px 0; }
.field.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field input, .field textarea, .row input, .gate input, .q-editor input {
  padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; width: 100%;
}
.field textarea { resize: vertical; min-height: 96px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--primary); }
.steps { padding-left: 1.2em; margin: 0; }
.steps li { margin: 6px 0; }
.mission-body { font-size: 1.1rem; white-space: pre-wrap; }

/* ---------- 퀴즈 ---------- */
.q-text { font-size: 1.35rem; margin: 6px 0 12px; }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.clock { font-weight: 800; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.timer-bar { height: 12px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin: 10px 0 14px; }
.timer-bar .fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--primary), #8ab4ff); transition: width 0.1s linear; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-btn {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px;
  min-height: 96px; padding: 12px 14px; border-radius: 14px; border: 0; color: #fff; text-align: left;
  font-weight: 700; font-size: 1.05rem; cursor: pointer; box-shadow: var(--shadow); word-break: keep-all;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.choice-btn b { font-size: 1.6rem; line-height: 1; }
.choice-btn:active { transform: scale(0.97); }
.choice-btn:disabled { opacity: 0.45; cursor: default; }
.choice-btn.picked { opacity: 1; outline: 4px solid #111827; outline-offset: -4px; }
.choice-0 { background: var(--c0); }
.choice-1 { background: var(--c1); }
.choice-2 { background: var(--c2); color: #3b2f00; }
.choice-3 { background: var(--c3); }
.done-line { margin-top: 12px; font-weight: 700; color: var(--primary-dark); text-align: center; }
.points { font-size: 2rem; font-weight: 900; color: var(--primary-dark); margin: 6px 0; }
.answer-line { font-size: 1.3rem; }
.bar-chart { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: end; height: 220px; margin: 14px 0; }
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bar-col .bar { width: 70%; min-height: 6px; border-radius: 10px 10px 4px 4px; transition: height 0.5s ease; }
.bar-col.correct b { color: var(--primary-dark); }
.bar-col.correct .bar { outline: 4px solid #111827; outline-offset: 2px; }
.bar-col b { font-size: 1.1rem; }
.bubbles { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.bubble {
  padding: 10px 16px; border-radius: 999px; background: #eef4ff; color: var(--primary-dark); font-weight: 700;
  animation: pop-in 0.35s ease;
}
.bubble.parent { background: #fdf2f8; color: #9d174d; }
.rank-list, .podium { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.rank-list li, .podium li {
  display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px;
  padding: 12px 16px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); font-size: 1.1rem;
}
.rank-no { font-weight: 900; font-size: 1.3rem; color: var(--muted); text-align: center; }
.rank-1 .rank-no { color: #d97706; }
.rank-2 .rank-no { color: #6b7280; }
.rank-3 .rank-no { color: #b45309; }
.rank-name { font-weight: 700; }
.rank-score { font-weight: 800; color: var(--primary-dark); }
.podium li.rank-1 { font-size: 1.4rem; background: #fff7e6; }
.rank-rest { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); margin-top: 8px; }
.stage { min-height: 320px; }
.big-msg { text-align: center; padding: 60px 0; }
.control-bar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.control-bar .btn-lg { width: auto; min-width: 200px; }

/* ---------- 제출 / 뷰어 ---------- */
.viewer { width: 100%; aspect-ratio: 1 / 1; min-height: 260px; max-height: 70vh; background: #eef2f7; border-radius: 14px; overflow: hidden; margin: 12px 0; }
.viewer canvas { width: 100% !important; height: 100% !important; display: block; }
.viewer.big { aspect-ratio: 4 / 3; }
.progress { height: 12px; border-radius: 999px; background: #e5e7eb; overflow: hidden; margin: 10px 0; }
.progress .fill { height: 100%; width: 0; background: var(--c3); transition: width 0.2s ease; }

/* ---------- 갤러리 ---------- */
.gallery-list { display: grid; gap: 12px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.work-card { margin: 0; cursor: default; position: relative; }
.gallery-grid .work-card { cursor: pointer; padding: 12px; }
.work-card.new { animation: glow 2s ease; }
.work-card.hidden-work { opacity: 0.45; }
.work-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.work-head strong { font-size: 1.1rem; }
.work-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; background: #eef2f7; border-radius: 12px; margin-bottom: 8px; }
.thumb.loading { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.hearts { font-weight: 700; }
.heart-btn {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 2px solid #fecdd3; background: #fff1f2; color: #be123c;
  font-weight: 800; cursor: pointer; transition: transform 0.1s ease;
}
.heart-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.heart-btn.pop { animation: pop 0.35s ease; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.heart-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.float-heart {
  position: absolute; bottom: -40px; font-size: 2.2rem; animation: float-up 2.6s ease-out forwards; opacity: 0;
}
.cheer-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 240px; overflow: auto; }
.cheer-list li { padding: 8px 12px; background: #f3f4f6; border-radius: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.big-work h2 { display: flex; gap: 10px; align-items: baseline; }

/* ---------- 미션·QR / 설정 ---------- */
.mission-tv { text-align: center; padding: 20px 0 10px; }
.mission-title { font-size: 2rem; color: var(--primary-dark); }
.qr-row { display: flex; gap: 24px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.qr-box { width: 220px; height: 220px; background: #fff; padding: 10px; border-radius: 14px; box-shadow: var(--shadow); }
.qr-box svg { width: 100%; height: 100%; display: block; }
/* 입장 관리 카드 */
.entry-hub { display: block; font-size: 1.5rem; font-weight: 800; margin: 8px 0 14px; color: var(--primary-dark); }
.entry-row { border-top: 1px solid var(--line); padding: 12px 0; }
.entry-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.entry-name { font-size: 1.15rem; }
.entry-badge { padding: 2px 10px; border-radius: 999px; background: #eef4ff; font-weight: 700; font-size: 0.9rem; }
.entry-badge.mode-open { background: #dcfce7; }
.entry-badge.mode-closed { background: #f3f4f6; }
.entry-mode.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.q-editor { display: grid; gap: 12px; }
.q-item { border: 2px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 8px; }
.q-item legend { font-weight: 800; padding: 0 6px; }
.choice-row { display: grid; grid-template-columns: 24px 1fr; gap: 8px; align-items: center; }
.choice-row input[type="radio"] { width: 20px; height: 20px; accent-color: var(--primary); }

/* ---------- 모달 / 토스트 / 띠 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: flex; align-items: center; justify-content: center;
  padding: var(--gutter); z-index: 50;
}
.modal-panel {
  position: relative; background: #fff; color: var(--text); border-radius: 18px; padding: 22px; width: min(100%, 480px);
  max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal-panel.wide { width: min(100%, 900px); }
.modal-close {
  position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: #f3f4f6; cursor: pointer; font-size: 1.1rem;
}
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 32px);
  transition: opacity 0.2s ease, transform 0.2s ease; z-index: 60; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.banner-offline {
  position: sticky; top: 0; z-index: 40; background: var(--danger); color: #fff; text-align: center; padding: 8px; font-weight: 700;
}

/* ---------- TV 모드 (교사) ---------- */
.tv-only { display: none; }
body.tv { background: #0f172a; color: #f8fafc; font-size: 1.35rem; }
body.tv .tv-hide { display: none !important; }
body.tv .tv-only { display: inline-flex; position: fixed; top: 12px; right: 12px; z-index: 45; opacity: 0.35; }
body.tv .tv-only:hover { opacity: 1; }
body.tv .panel { max-width: 1400px; padding-top: 28px; }
body.tv .card, body.tv .rank-list li, body.tv .podium li { background: #1e293b; color: #f8fafc; box-shadow: none; }
body.tv .muted { color: #cbd5e1; }
body.tv h1 { font-size: 2.6rem; }
body.tv .q-text { font-size: 2.2rem; }
body.tv .choice-btn { min-height: 130px; font-size: 1.5rem; }
body.tv .choice-btn b { font-size: 2.2rem; }
body.tv .clock { font-size: 2.2rem; }
body.tv .bar-chart { height: 340px; }
body.tv .bubble { font-size: 1.3rem; padding: 12px 20px; }
body.tv .control-bar { background: linear-gradient(to top, #0f172a 70%, transparent); }
body.tv .control-bar .btn { font-size: 1rem; }
body.tv .btn-ghost { border-color: #334155; color: #e2e8f0; }
body.tv .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
body.tv .thumb { background: #0b1220; }
body.tv .mission-title { color: #93c5fd; font-size: 3rem; }
body.tv .entry-hub { color: #93c5fd; }
body.tv .entry-badge, body.tv .entry-badge.mode-open, body.tv .entry-badge.mode-closed { background: #334155; color: #f8fafc; }
body.tv .entry-row { border-color: #334155; }
body.tv .mission-body { font-size: 1.6rem; }
body.tv .qr-box { width: 300px; height: 300px; }
body.tv .rank-score { color: #93c5fd; }
body.tv .podium li.rank-1 { background: #3b2f0b; }
body.tv .timer-bar { background: #334155; height: 16px; }
body.tv .bar-col.correct .bar, body.tv .choice-btn.picked { outline-color: #f8fafc; }

/* ---------- 애니메이션 ---------- */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes pop-in { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes glow { 0% { box-shadow: 0 0 0 0 rgba(79, 140, 255, 0.9); } 100% { box-shadow: 0 0 0 24px rgba(79, 140, 255, 0); } }
@keyframes float-up {
  0% { transform: translateY(0) scale(0.8); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-90vh) scale(1.3) rotate(15deg); opacity: 0; }
}

@media (max-width: 480px) {
  h1 { font-size: 1.5rem; }
  .choices { grid-template-columns: 1fr 1fr; }
  .choice-btn { min-height: 84px; font-size: 1rem; }
  .bar-chart { height: 180px; }
  .rank-list li, .podium li { grid-template-columns: 40px 1fr auto; font-size: 1rem; }
}

/* 생태 통로 수업 */
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn[hidden] { display: none; }
.card.done .row { justify-content: center; }
.sim-badge { display: inline-block; margin-top: 6px; padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: 0.9rem; }
.sim-badge.pass { background: #dcfce7; color: #166534; }
.sim-badge.fixing { background: #fef3c7; color: #92400e; }
.sim-badge .stale { font-weight: 600; color: #b42318; }
.spec-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.spec-table td { padding: 6px 0; border-bottom: 1px solid var(--line); }
.spec-table td:last-child { text-align: right; }
