:root {
  --bg: #f7f1ea;
  --card: #ffffff;
  --ink: #2b1d14;
  --muted: #8a7768;
  --line: #eadfd3;
  --brand: #6b4226;
  --brand-2: #a0673f;
  --accent: #e9d5c1;
  --ok: #2f8f5b;
  --danger: #c0392b;
  --hot: #e0663c;
  --ice: #3b8bd9;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(80, 50, 30, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1410;
    --card: #261c16;
    --ink: #f3e9df;
    --muted: #b09d8e;
    --line: #3a2c23;
    --brand: #d39b6a;
    --brand-2: #e3b48a;
    --accent: #3f2e22;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.logo { font-size: 1.3rem; }
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.who-name { font-weight: 500; max-width: 10em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.avatar.ph { display: grid; place-items: center; background: var(--accent); color: var(--brand); font-weight: 700; }

.banner {
  margin: 12px 16px 0; padding: 10px 14px; border-radius: 12px;
  background: #fff4d6; color: #7a5a00; font-size: .9rem;
}
@media (prefers-color-scheme: dark) { .banner { background: #3b3115; color: #f2d98a; } }

main { max-width: 560px; margin: 0 auto; padding: 16px 16px 48px; display: grid; gap: 14px; }
main.wide { max-width: 1040px; }
main.center { min-height: 75vh; place-items: center; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card h2, .card h3 { margin: 0 0 6px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
.title { margin: 8px 0 0; }
.muted { color: var(--muted); margin: 0; }
.sm { font-size: .85rem; }
.empty { text-align: center; color: var(--muted); padding: 32px 18px; }

.hero { text-align: center; padding: 36px 24px; max-width: 420px; width: 100%; }
.hero-icon { font-size: 3rem; }
.hero h1 { margin: 8px 0; font-size: 1.5rem; }
.hero p { margin-bottom: 24px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 500; transition: transform .05s, background .15s;
  min-height: 42px;
}
.btn:hover { background: var(--accent); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .88rem; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--accent); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #1b1410; } }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.google { width: 100%; padding: 12px; font-size: 1rem; border-width: 1.5px; }
.g {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #fff; background: conic-gradient(#ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0);
  font-size: .8rem;
}
:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }

.list { display: grid; gap: 10px; }
.session-pick { display: flex; align-items: center; justify-content: space-between; text-align: left; cursor: pointer; width: 100%; }
.session-pick:hover { border-color: var(--brand-2); }
.session-title { font-weight: 700; }
.chev { font-size: 1.6rem; color: var(--muted); }

.order { display: grid; gap: 18px; margin-top: 12px; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 10px; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  position: relative; padding: 9px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); cursor: pointer; user-select: none; transition: all .12s;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:hover { border-color: var(--brand-2); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }
@media (prefers-color-scheme: dark) { .chip.on { color: #1b1410; } }
.chip.off { opacity: .4; cursor: not-allowed; }
.chip:has(input:focus-visible) { outline: 3px solid var(--brand-2); outline-offset: 2px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--accent); padding: 4px; border-radius: 12px; }
.seg-item { position: relative; text-align: center; padding: 8px; border-radius: 9px; cursor: pointer; font-weight: 500; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item.on.hot { background: var(--hot); color: #fff; }
.seg-item.on.ice { background: var(--ice); color: #fff; }
.seg-item:has(input:focus-visible) { outline: 3px solid var(--brand-2); }

.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); min-height: 42px;
}
textarea.input { resize: vertical; }
.input.date { width: auto; }
.input.num { width: 80px; display: inline-block; }
select.input { width: auto; max-width: 100%; }

.done { text-align: center; }
.stamp {
  width: 64px; height: 64px; margin: 4px auto 10px; border-radius: 50%;
  display: grid; place-items: center; font-size: 2rem; color: #fff; background: var(--ok);
}
.summary { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; text-align: left; margin: 18px auto; max-width: 320px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 500; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tab {
  flex: none; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 500;
}
.tab.on { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .tab.on { color: #1b1410; } }

.row-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row-form .input:first-child { flex: 1 1 220px; }
.sess-list { list-style: none; margin: 0; padding: 0; }
.sess-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.sess-list li:first-child { border-top: 0; }
.sess-info { display: flex; align-items: center; gap: 10px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: .78rem; padding: 3px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.badge.open { background: #dcf3e5; color: var(--ok); }
.badge.closed { background: var(--accent); color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--accent); border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.6rem; color: var(--brand); }
.stat span { color: var(--muted); font-size: .85rem; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 680px) { .grid2 { grid-template-columns: 1fr; } }

.tally { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.tally li { display: grid; grid-template-columns: minmax(90px, 40%) 1fr 32px; align-items: center; gap: 10px; }
.tl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 10px; background: var(--accent); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--brand-2); border-radius: 99px; }
.tally b { text-align: right; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
.matrix td.o { color: var(--ok); font-weight: 700; }
.matrix td.x { color: var(--muted); }

.menu-form { display: grid; gap: 14px; margin-top: 10px; }
.lbl { display: block; font-weight: 700; margin-bottom: 6px; }
.inline { display: flex; align-items: center; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  padding: 12px 18px; border-radius: 12px; color: #fff; background: #2b1d14; box-shadow: 0 6px 20px rgba(0,0,0,.2);
  max-width: calc(100% - 32px); animation: pop .2s ease-out;
}
.toast.err { background: var(--danger); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }

.busy { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 30; background: linear-gradient(90deg, transparent, var(--brand-2), transparent); background-size: 50% 100%; animation: load 1s linear infinite; }
@keyframes load { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 넓은 표가 모바일 화면을 밀어내지 않도록 */
main > *, .grid2 > *, .stack > * { min-width: 0; }
.table-wrap td, .table-wrap th { white-space: nowrap; }

/* ===================== 강의 도우미 ===================== */
.stack { display: grid; gap: 14px; }
.sub-title { margin: 12px 0 0; font-size: 1rem; color: var(--muted); }
.hub-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.hub-head .title { margin: 0; }
.session-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.session-bar select { flex: 1 1 240px; }
.lbl { display: block; font-weight: 700; margin-bottom: 6px; }
.badge.quiz { background: #ece3fb; color: #6b3fc0; }
@media (prefers-color-scheme: dark) { .badge.quiz { background: #33264d; color: #c9b2f5; } .badge.open { background: #1f3b2c; } }

/* 질문 */
.qa-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.qa { padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }
.qa.answered { opacity: .6; }
.qa-text { margin: 0 0 10px; white-space: pre-wrap; word-break: break-word; font-size: 1.02rem; }
.qa-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.like {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px;
  cursor: pointer; font-weight: 700; color: var(--muted); min-height: 36px;
}
.like.on { border-color: #e0567a; color: #e0567a; background: color-mix(in srgb, #e0567a 10%, var(--card)); }
.like:disabled { cursor: default; opacity: .6; }
.like-count { font-weight: 700; color: #e0567a; }

/* 투표·퀴즈 */
.poll h3 { margin: 8px 0 12px; font-size: 1.15rem; }
.poll-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.options { display: grid; gap: 8px; }
.option {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card);
  cursor: pointer; font-size: 1rem; min-height: 48px;
}
.option:hover:not(:disabled) { border-color: var(--brand-2); }
.option.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, var(--card)); font-weight: 700; }
.option:disabled { cursor: default; }
.option .num {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); font-weight: 700; font-size: .85rem;
}
.option.on .num { background: var(--brand); color: #fff; }
.result { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.result-label { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.result .bar { display: block; height: 12px; }
.result li.correct .result-label span { color: var(--ok); font-weight: 700; }
.result li.correct .bar span { background: var(--ok); }
.result li.mine .result-label span { text-decoration: underline; text-underline-offset: 3px; }
.verdict { font-weight: 700; margin: 0; }
.verdict.ok { color: var(--ok); }
.verdict.no { color: var(--danger); }

/* 피드백 */
.stars { display: flex; gap: 4px; color: #f2b01e; font-size: 1.4rem; letter-spacing: 2px; }
.stars.big { justify-content: center; font-size: 2.2rem; }
.star { position: relative; cursor: pointer; font-size: 2.2rem; color: var(--line); transition: transform .1s; line-height: 1; }
.star input { position: absolute; opacity: 0; pointer-events: none; }
.star.on { color: #f2b01e; }
.star:hover { transform: scale(1.12); }
.star:has(input:focus-visible) { outline: 3px solid var(--brand-2); border-radius: 6px; }
.fb-summary { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; }
@media (max-width: 520px) { .fb-summary { grid-template-columns: 1fr; } }
.fb-avg { text-align: center; }
.fb-avg b { display: block; font-size: 2.6rem; color: var(--brand); line-height: 1.1; }
.fb-avg .stars { justify-content: center; }
.comments { margin: 0; padding-left: 18px; display: grid; gap: 8px; }
.comments li { white-space: pre-wrap; word-break: break-word; }

/* 조 편성 */
.team-name { font-size: 2rem; font-weight: 700; color: var(--brand); }
.members { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.members li { padding: 6px 14px; border-radius: 999px; background: var(--accent); }
.members li.me { background: var(--brand); color: #fff; font-weight: 700; }
.team-order { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.team-grid { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.team-card { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: var(--bg); }
.team-card ul { margin: 8px 0 0; padding-left: 18px; }
.team-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.team-head .order { font-size: .78rem; font-weight: 700; color: #fff; background: var(--brand-2); padding: 2px 8px; border-radius: 999px; }

/* 수료증 */
.cert-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; margin: 10px 0 14px; align-items: end; }
@media (max-width: 680px) { .cert-form { grid-template-columns: 1fr; } }
.cert-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 16px; }
.cert-list li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.cert-list li.no { opacity: .5; }

/* 크게 보기 (프로젝터) */
main.present { max-width: 1280px; font-size: 1.3rem; }
main.present .qa-text { font-size: 1.6rem; }
main.present .poll h3 { font-size: 2rem; }
main.present .result-label { font-size: 1.4rem; }
main.present .result .bar { height: 22px; }
main.present .team-card { font-size: 1.3rem; }

/* 인쇄: 수료증만 */
#print-area { display: none; }
@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  #app, .toast { display: none !important; }
  #print-area { display: block; }
  .cert { width: 210mm; height: 297mm; padding: 18mm; box-sizing: border-box; page-break-after: always; break-after: page; color: #222; }
  .cert:last-child { page-break-after: auto; break-after: auto; }
  .cert-inner {
    height: 100%; border: 3px double #8a6a3d; outline: 1px solid #8a6a3d; outline-offset: -8mm;
    padding: 26mm 22mm; display: flex; flex-direction: column; align-items: center; text-align: center;
    font-family: 'Noto Serif KR', 'Batang', serif;
  }
  .cert-no { align-self: flex-start; font-size: 11pt; margin: 0; }
  .cert h1 { font-size: 40pt; letter-spacing: 18pt; margin: 22mm 0 20mm; }
  .cert dl { display: grid; grid-template-columns: auto 1fr; gap: 6mm 10mm; font-size: 15pt; text-align: left; width: 80%; margin: 0; }
  .cert dt { font-weight: 700; }
  .cert dd { margin: 0; }
  .cert-body { font-size: 16pt; line-height: 2; margin: auto 0 0; }
  .cert-date { font-size: 14pt; margin: 14mm 0 6mm; }
  .cert-issuer { font-size: 18pt; font-weight: 700; margin: 0; }
}

/* ===================== 웹앱(PWA) ===================== */
.install-hint {
  margin: 12px 16px 0; padding: 14px 16px; border-radius: 14px; background: var(--card);
  border: 1.5px solid var(--brand-2); display: grid; gap: 6px; box-shadow: var(--shadow);
}
.install-hint ol { margin: 0; padding-left: 20px; }
.install-hint .btn { justify-self: end; }
/* 홈 화면 앱으로 실행할 때 노치·상태바 영역 피하기 */
@media (display-mode: standalone) {
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
  main { padding-bottom: max(48px, env(safe-area-inset-bottom)); }
}
