/* learn-modules base CSS — ② 공통 UX 패턴. 색·크기는 lm-tokens.css의 변수만 쓴다.
   모듈 개성은 --lm-accent(html[data-accent])와 모듈 자신의 static/ CSS로 표현한다. */

/* ── 기본 ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: calc(100% * var(--lm-font-scale)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font-family: var(--lm-font-family); font-size: var(--lm-text-md); line-height: var(--lm-leading-normal);
  color: var(--lm-fg); background: var(--lm-bg);
  word-break: keep-all; overflow-wrap: anywhere; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: var(--lm-leading-tight); margin: 0 0 var(--lm-space-3); font-weight: var(--lm-weight-bold); }
h1 { font-size: var(--lm-text-2xl); } h2 { font-size: var(--lm-text-xl); } h3 { font-size: var(--lm-text-lg); }
p { margin: 0 0 var(--lm-space-4); }
a { color: var(--lm-primary); text-underline-offset: 0.2em; }
a:hover { color: var(--lm-primary-hover); }
img, video, svg, iframe { max-width: 100%; }
img, video { height: auto; display: block; }
:focus-visible { outline: 3px solid var(--lm-focus); outline-offset: 2px; border-radius: var(--lm-radius-sm); }
::selection { background: var(--lm-primary-soft); color: var(--lm-primary-soft-fg); }
.lm-icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.25em; }
.lm-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.lm-skip { position: absolute; left: var(--lm-space-3); top: -4rem; z-index: 100; padding: var(--lm-space-2) var(--lm-space-4); background: var(--lm-surface); border-radius: var(--lm-radius-md); }
.lm-skip:focus { top: var(--lm-space-3); }
.lm-muted { color: var(--lm-muted); }
.lm-small { font-size: var(--lm-text-sm); }

/* ── 상단 바: 어느 모듈이든 같은 자리, 같은 모양 ─────────── */
.lm-topbar {
  position: sticky; top: 0; z-index: 20; height: var(--lm-size-topbar);
  display: flex; align-items: center; gap: var(--lm-space-3); padding: 0 var(--lm-space-4);
  background: var(--lm-surface); border-bottom: 1px solid var(--lm-border);
}
.lm-topbar__module { display: flex; align-items: center; gap: var(--lm-space-2); font-weight: var(--lm-weight-semibold); color: var(--lm-fg); text-decoration: none; min-height: var(--lm-size-touch); }
.lm-topbar__module::before { content: ""; width: 0.625rem; height: 0.625rem; border-radius: var(--lm-radius-pill); background: var(--lm-accent); }
.lm-topbar__spacer { flex: 1; }
.lm-topbar__nav { display: flex; align-items: center; gap: var(--lm-space-1); }
.lm-topbar__who { font-size: var(--lm-text-sm); color: var(--lm-muted); }

/* ── 본문 레이아웃 ─────────────────────────────── */
.lm-main { flex: 1; width: 100%; max-width: var(--lm-size-content); margin: 0 auto; padding: var(--lm-space-5) var(--lm-space-4) var(--lm-space-7); }
.lm-main--wide { max-width: var(--lm-size-wide); }
.lm-page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--lm-space-3); margin-bottom: var(--lm-space-5); }
.lm-page-header h1 { margin: 0; }
.lm-page-header p { margin: var(--lm-space-1) 0 0; color: var(--lm-muted); }
.lm-stack > * + * { margin-top: var(--lm-space-4); }
.lm-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--lm-space-3); }
.lm-grid { display: grid; gap: var(--lm-space-4); grid-template-columns: repeat(auto-fill, minmax(min(16rem, 100%), 1fr)); }
.lm-footer { padding: var(--lm-space-4); text-align: center; font-size: var(--lm-text-xs); color: var(--lm-muted); }

/* ── 카드·목록 ─────────────────────────────────── */
.lm-card { background: var(--lm-surface); border: 1px solid var(--lm-border); border-radius: var(--lm-radius-lg); padding: var(--lm-space-5); }
.lm-card--flat { background: var(--lm-surface-2); border-color: transparent; }
.lm-list { list-style: none; margin: 0; padding: 0; background: var(--lm-surface); border: 1px solid var(--lm-border); border-radius: var(--lm-radius-lg); }
.lm-list > li { display: flex; align-items: center; gap: var(--lm-space-3); min-height: 3.5rem; padding: var(--lm-space-3) var(--lm-space-4); }
.lm-list > li + li { border-top: 1px solid var(--lm-border); }
.lm-list a.lm-list__link { flex: 1; display: flex; align-items: center; gap: var(--lm-space-3); color: var(--lm-fg); text-decoration: none; min-height: var(--lm-size-touch); }
.lm-list a.lm-list__link:hover { color: var(--lm-primary); }

/* ── 버튼: 화면마다 주 행동(.lm-btn--primary)은 하나 ───────── */
.lm-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--lm-space-2);
  min-height: var(--lm-size-touch); padding: 0 var(--lm-space-5); border: 1px solid var(--lm-border-strong); border-radius: var(--lm-radius-md);
  font: inherit; font-weight: var(--lm-weight-semibold); line-height: 1; color: var(--lm-fg); background: var(--lm-surface);
  text-decoration: none; cursor: pointer; transition: background var(--lm-motion-fast) var(--lm-motion-ease), border-color var(--lm-motion-fast);
}
.lm-btn:hover { background: var(--lm-surface-2); color: var(--lm-fg); }
.lm-btn--primary { color: var(--lm-primary-fg); background: var(--lm-primary); border-color: var(--lm-primary); }
.lm-btn--primary:hover { color: var(--lm-primary-fg); background: var(--lm-primary-hover); border-color: var(--lm-primary-hover); }
.lm-btn--ghost { border-color: transparent; background: transparent; }
.lm-btn--danger { color: var(--lm-danger); border-color: currentColor; }
.lm-btn--lg { min-height: 3.5rem; font-size: var(--lm-text-lg); padding: 0 var(--lm-space-6); }
.lm-btn--block { display: flex; width: 100%; }
.lm-btn--icon { padding: 0; width: var(--lm-size-touch); }
.lm-btn[disabled], .lm-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.htmx-request.lm-btn, .htmx-request .lm-btn[type="submit"] { opacity: 0.7; pointer-events: none; }

/* ── 폼 ─────────────────────────────────────────── */
.lm-field { display: flex; flex-direction: column; gap: var(--lm-space-2); margin-bottom: var(--lm-space-4); }
.lm-field > label, .lm-label { font-weight: var(--lm-weight-semibold); }
.lm-hint { font-size: var(--lm-text-sm); color: var(--lm-muted); }
.lm-input, .lm-select, .lm-textarea {
  width: 100%; min-height: var(--lm-size-touch); padding: var(--lm-space-2) var(--lm-space-3);
  font: inherit; color: var(--lm-fg); background: var(--lm-surface);
  border: 1px solid var(--lm-border-strong); border-radius: var(--lm-radius-md);
}
.lm-textarea { min-height: 7rem; resize: vertical; }
.lm-input--code { font-size: var(--lm-text-2xl); letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }
.lm-field--error .lm-input, .lm-input[aria-invalid="true"] { border-color: var(--lm-danger); }
.lm-field__error { display: flex; gap: var(--lm-space-2); color: var(--lm-danger); font-size: var(--lm-text-sm); font-weight: var(--lm-weight-medium); }
.lm-choice { display: flex; align-items: center; gap: var(--lm-space-3); min-height: var(--lm-size-touch); padding: var(--lm-space-3) var(--lm-space-4); border: 1px solid var(--lm-border-strong); border-radius: var(--lm-radius-md); background: var(--lm-surface); cursor: pointer; }
.lm-choice:has(input:checked) { border-color: var(--lm-primary); background: var(--lm-primary-soft); color: var(--lm-primary-soft-fg); }
.lm-choice input { width: 1.25rem; height: 1.25rem; accent-color: var(--lm-primary); }
.lm-segment { display: flex; flex-wrap: wrap; gap: var(--lm-space-2); }
.lm-segment .lm-choice { flex: 1 1 8rem; justify-content: center; }

/* ── 상태 표시: point(바이올렛)는 한 화면에 1~2곳만 ──────── */
.lm-badge { display: inline-flex; align-items: center; gap: var(--lm-space-1); padding: 0.125rem var(--lm-space-2); border-radius: var(--lm-radius-pill); font-size: var(--lm-text-xs); font-weight: var(--lm-weight-semibold); background: var(--lm-surface-2); color: var(--lm-muted); }
.lm-badge--point { background: var(--lm-point-soft); color: var(--lm-point-soft-fg); }
.lm-badge--success { background: var(--lm-success-soft); color: var(--lm-success-soft-fg); }
.lm-badge--warning { background: var(--lm-warning-soft); color: var(--lm-warning-soft-fg); }
.lm-badge--danger { background: var(--lm-danger-soft); color: var(--lm-danger-soft-fg); }
.lm-progress { height: 0.5rem; border-radius: var(--lm-radius-pill); background: var(--lm-surface-2); overflow: hidden; }
.lm-progress > span { display: block; height: 100%; background: var(--lm-point); border-radius: inherit; transition: width var(--lm-motion-normal) var(--lm-motion-ease); }
.lm-steps { display: flex; gap: var(--lm-space-2); list-style: none; padding: 0; margin: 0 0 var(--lm-space-5); font-size: var(--lm-text-sm); color: var(--lm-muted); }
.lm-steps li { flex: 1; padding-top: var(--lm-space-2); border-top: 3px solid var(--lm-border); }
.lm-steps li[aria-current="step"] { color: var(--lm-point); border-color: var(--lm-point); font-weight: var(--lm-weight-semibold); }
.lm-steps li.is-done { color: var(--lm-fg); border-color: var(--lm-primary); }

/* ── 알림(토스트/인라인): 위험한 작업은 확인창 대신 "실행 취소" ── */
.lm-alert { display: flex; align-items: flex-start; gap: var(--lm-space-3); padding: var(--lm-space-3) var(--lm-space-4); border-radius: var(--lm-radius-md); background: var(--lm-primary-soft); color: var(--lm-primary-soft-fg); }
.lm-alert--success { background: var(--lm-success-soft); color: var(--lm-success-soft-fg); }
.lm-alert--warning { background: var(--lm-warning-soft); color: var(--lm-warning-soft-fg); }
.lm-alert--danger { background: var(--lm-danger-soft); color: var(--lm-danger-soft-fg); }
.lm-alert__body { flex: 1; }
.lm-toasts { position: fixed; z-index: 50; left: 50%; bottom: var(--lm-space-5); transform: translateX(-50%); width: min(30rem, calc(100% - 2rem)); display: flex; flex-direction: column; gap: var(--lm-space-2); }
.lm-toast { box-shadow: var(--lm-shadow-md); animation: lm-rise var(--lm-motion-normal) var(--lm-motion-ease); }
.lm-toast .lm-btn { min-height: 2.25rem; padding: 0 var(--lm-space-3); color: inherit; border-color: currentColor; background: transparent; }
@keyframes lm-rise { from { opacity: 0; transform: translateY(0.5rem); } }

/* ── 빈 상태·오류 화면: 다음 행동을 안내 ─────────────── */
.lm-empty { text-align: center; padding: var(--lm-space-7) var(--lm-space-4); color: var(--lm-muted); }
.lm-empty > .lm-icon { width: 3rem; height: 3rem; color: var(--lm-border-strong); margin: 0 auto var(--lm-space-3); display: block; }
.lm-empty h2 { color: var(--lm-fg); font-size: var(--lm-text-lg); }

/* ── 표 ─────────────────────────────────────────── */
.lm-table-wrap { overflow-x: auto; border: 1px solid var(--lm-border); border-radius: var(--lm-radius-lg); background: var(--lm-surface); }
.lm-table { width: 100%; border-collapse: collapse; font-size: var(--lm-text-sm); }
.lm-table th, .lm-table td { padding: var(--lm-space-3) var(--lm-space-4); text-align: left; border-bottom: 1px solid var(--lm-border); white-space: nowrap; }
.lm-table th { font-weight: var(--lm-weight-semibold); color: var(--lm-muted); background: var(--lm-surface-2); }
.lm-table tr:last-child td { border-bottom: 0; }
.lm-num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── 큰 코드·QR (참여 안내) ─────────────────────────── */
.lm-code { display: inline-block; font-size: var(--lm-text-3xl); font-weight: var(--lm-weight-bold); letter-spacing: 0.15em; font-variant-numeric: tabular-nums; padding: var(--lm-space-2) var(--lm-space-5); border-radius: var(--lm-radius-lg); background: var(--lm-surface-2); }
.lm-qr { width: min(18rem, 70vw); aspect-ratio: 1; padding: var(--lm-space-3); background: #FFFFFF; border-radius: var(--lm-radius-lg); }

/* ── 미디어·임베드 ───────────────────────────────── */
.lm-media { border-radius: var(--lm-radius-lg); overflow: hidden; background: var(--lm-surface-2); }
.lm-embed { display: block; width: 100%; min-height: 24rem; border: 1px solid var(--lm-border); border-radius: var(--lm-radius-lg); background: var(--lm-surface); }
.lm-weight { font-size: var(--lm-text-xs); color: var(--lm-warning); }

/* ── 프로젝터 모드 (?projector=1): 교실 앞 화면용 ────────── */
.lm-projector { --lm-font-scale: 1.6; background: var(--lm-surface); }
.lm-projector .lm-topbar { display: none; }
.lm-projector .lm-main { max-width: var(--lm-size-wide); display: flex; flex-direction: column; justify-content: center; text-align: center; }
.lm-projector .lm-code { font-size: var(--lm-text-display); }
.lm-projector .lm-qr { width: min(26rem, 40vh); }

/* ── 연결 상태 ───────────────────────────────────── */
.lm-offline { display: none; position: fixed; z-index: 60; top: 0; left: 0; right: 0; padding: var(--lm-space-2) var(--lm-space-4); text-align: center; font-size: var(--lm-text-sm); background: var(--lm-warning-soft); color: var(--lm-warning-soft-fg); }
html.is-offline .lm-offline { display: block; }
.lm-spinner { width: 1.25em; height: 1.25em; animation: lm-spin 0.9s linear infinite; }
@keyframes lm-spin { to { transform: rotate(360deg); } }

/* ── 모션 줄이기: OS 설정 또는 사용자 설정 ──────────────── */
@media (prefers-reduced-motion: reduce) { :root:not([data-motion="full"]) *, :root:not([data-motion="full"]) *::before, :root:not([data-motion="full"]) *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; } }
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }

@media (min-width: 48rem) { .lm-main { padding-top: var(--lm-space-6); } }
@media print { .lm-topbar, .lm-toasts, .lm-offline, .lm-footer, .lm-skip { display: none; } }
