:root {
  --bg: #f6f4f0; --panel: #ffffff; --panel2: #faf8f5; --line: #e6e1d8; --ink: #1d1b18; --mute: #6f6a62;
  --accent: #b8322a; --accent-ink: #fff; --accent-soft: #f6e3e0; --ok: #2f7d4f; --ok-soft: #e1f1e6;
  --warn: #a8620a; --warn-soft: #fbeedb; --info: #2d5f8a; --info-soft: #e2ecf5;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412; --panel: #1f1d1a; --panel2: #262420; --line: #35322d; --ink: #ece8e1; --mute: #a39d93;
    --accent: #e0574c; --accent-soft: #3a2220; --ok: #5fbf85; --ok-soft: #1e3326; --warn: #e3a24a; --warn-soft: #3a2d18;
    --info: #7fb2de; --info-soft: #1d2b38; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151412; --panel: #1f1d1a; --panel2: #262420; --line: #35322d; --ink: #ece8e1; --mute: #a39d93;
  --accent: #e0574c; --accent-soft: #3a2220; --ok: #5fbf85; --ok-soft: #1e3326; --warn: #e3a24a; --warn-soft: #3a2d18;
  --info: #7fb2de; --info-soft: #1d2b38; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 24px 0 10px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.mute { color: var(--mute); } .small { font-size: 13px; }
.zh { font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", var(--font); }

/* 레이아웃: 넓으면 왼쪽 메뉴, 좁으면 아래 탭 */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; display: flex; gap: 8px; align-items: center; }
.brand .seal { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--ink); margin-bottom: 2px; }
.nav a:hover { background: var(--panel2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; }
.nav .sep { height: 1px; background: var(--line); margin: 10px 4px; }
.main { padding: 24px 28px 90px; max-width: 1100px; width: 100%; }
.topbar { display: none; }
.tabbar { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 14px 16px 96px; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
    background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
  .tabbar a { flex: 1; text-align: center; padding: 8px 0 6px; font-size: 11px; color: var(--mute); }
  .tabbar a .ico { display: block; font-size: 20px; line-height: 1.2; }
  .tabbar a.on { color: var(--accent); }
}

/* 공통 부품 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--accent); }
.btn[disabled] { opacity: .5; pointer-events: none; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; min-height: 40px; }
textarea { min-height: 100px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label.f { display: block; font-size: 13px; color: var(--mute); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=checkbox] { width: auto; min-height: 0; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel2); color: var(--mute); border: 1px solid var(--line); }
.chip.red { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.empty { text-align: center; color: var(--mute); padding: 28px 10px; }
.stat { font-size: 26px; font-weight: 700; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 12px; color: var(--mute); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--accent); font-weight: 600; }
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: 12px; color: var(--mute); font-weight: 600; }
.scroll-x { overflow-x: auto; }
.lesson { display: flex; gap: 12px; align-items: center; }
.lesson .time { min-width: 64px; font-weight: 700; font-variant-numeric: tabular-nums; }
.lesson .grow { flex: 1; min-width: 0; }
.day-h { font-weight: 700; margin: 18px 0 6px; font-size: 14px; }
.day-h.today { color: var(--accent); }
.slots { display: flex; flex-wrap: wrap; gap: 6px; }
.slots .btn { min-width: 76px; }

/* 문서(자료) */
.doc { line-height: 1.8; font-size: 16px; }
.doc table { border-collapse: collapse; width: 100%; margin: 10px 0; display: block; overflow-x: auto; }
.doc th, .doc td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.doc th { background: var(--panel2); }
.doc td:first-child { white-space: nowrap; }  /* 중국어 단어가 병음과 함께 잘리지 않게 */
.doc blockquote { margin: 10px 0; padding: 6px 14px; border-left: 3px solid var(--accent); background: var(--panel2); border-radius: 0 8px 8px 0; }
.doc ruby rt { font-size: .58em; color: var(--accent); letter-spacing: 0; }
.doc.nopy ruby rt { visibility: hidden; }
.doc ruby { ruby-position: over; }
.doc details { background: var(--panel2); padding: 8px 12px; border-radius: 8px; }
.doc img { max-width: 100%; }
.doc pre { background: var(--panel2); padding: 10px; border-radius: 8px; overflow-x: auto; }

/* 모달·토스트 */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 16px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h2 { margin-top: 0; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 200; max-width: 90vw; font-size: 14px; }
.toast.err { background: var(--accent); color: #fff; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
.badge { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; margin-left: auto; font-weight: 700; }

/* 로그인 */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(400px, 100%); padding: 28px; }

/* AI 연습 채팅 */
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 85%; padding: 10px 13px; border-radius: 14px; line-height: 1.7; }
.bubble.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.bot ruby rt { font-size: .58em; color: var(--accent); }
.composer { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; display: flex; gap: 8px; }
@media (max-width: 820px) { .composer { bottom: calc(58px + env(safe-area-inset-bottom)); } }

/* 수업방 */
.room { position: fixed; inset: 0; display: grid; grid-template-columns: 1fr 320px; grid-template-rows: auto 1fr; background: var(--bg); }
.room-top { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.room-top .title { font-weight: 700; margin-right: auto; white-space: nowrap; }
.stage-wrap { position: relative; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.toolbar { display: flex; gap: 6px; padding: 8px; align-items: center; flex-wrap: wrap; background: var(--panel); border-bottom: 1px solid var(--line); }
.toolbar .sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; min-height: 0; }
.toolbar .sw.on { outline: 2px solid var(--ink); outline-offset: 1px; }
.stage { flex: 1; position: relative; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 12px; min-height: 0; }
.board { position: relative; background: #fff; box-shadow: var(--shadow); border-radius: 6px; touch-action: none; }
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.board .base { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage .doc { background: var(--panel); padding: 20px 24px; border-radius: 10px; width: min(860px, 100%); box-shadow: var(--shadow); }
.room-side { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.videos { position: relative; background: #000; aspect-ratio: 4 / 3; }
.videos video { width: 100%; height: 100%; object-fit: cover; background: #111; }
.videos video.local { position: absolute; right: 8px; bottom: 8px; width: 32%; height: auto; aspect-ratio: 4/3; border-radius: 8px; border: 2px solid rgba(255,255,255,.6); }
.videos .vstat { position: absolute; left: 8px; top: 8px; color: #fff; font-size: 12px; background: rgba(0,0,0,.5); padding: 2px 8px; border-radius: 99px; }
.room-chat { flex: 1; overflow: auto; padding: 10px; font-size: 14px; min-height: 80px; }
.room-chat .m { margin-bottom: 6px; }
.room-chat .m b { font-weight: 600; margin-right: 6px; }
.room-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.hz-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px; background: var(--panel); border-radius: 12px; }
.hz-target { width: 260px; height: 260px; background: #fff; border-radius: 10px; border: 1px solid var(--line); }
@media (max-width: 900px) {
  .room { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .room-side { border-left: 0; border-bottom: 1px solid var(--line); flex-direction: row; grid-row: 2; }
  .videos { width: 100%; max-height: 32vh; aspect-ratio: auto; height: 32vh; }
  .room-chat, .room-input { display: none; }
  .room-side.chat-open { flex-direction: column; }
  .room-side.chat-open .room-chat { display: block; max-height: 22vh; }
  .room-side.chat-open .room-input { display: flex; }
}
