:root {
  --bg: #f4f5f8; --card: #ffffff; --text: #1b1d22; --sub: #6b7080; --line: #e3e5ea;
  --primary: #2f6fed; --primary-soft: #e6eefe; --danger: #e5484d; --ok: #1f9d55; --warn: #e88a00;
  --radius: 14px; --tabh: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --card: #1b1e24; --text: #eceef2; --sub: #9aa0ad; --line: #2b2f37;
    --primary: #5b8cff; --primary-soft: #1d2a45; --danger: #ff6b6f; --ok: #3ecf7a; --warn: #ffb02e;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 16px); }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 17px; margin: 22px 0 8px; }
.muted { color: var(--sub); font-size: 14px; }
.empty { color: var(--sub); text-align: center; padding: 28px 0; font-size: 14px; }

#topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--bg); }
#topbar h1 { font-size: 21px; margin: 0; }
#top-actions { display: flex; gap: 6px; }
#view { padding: 0 16px; }

#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs a { flex: 1; max-width: 112px; height: var(--tabh); display: flex; flex-direction: column; align-items: center;
  justify-content: center; font-size: 12px; color: var(--sub); }
#tabs a .ic { font-size: 21px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
#tabs a.on { color: var(--primary); font-weight: 600; }
#tabs a.on .ic { filter: none; opacity: 1; }

#fab { position: fixed; z-index: 11; right: max(16px, calc(50% - 264px)); bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; font-size: 30px;
  box-shadow: 0 6px 18px rgba(47,111,237,.4); }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; border: 1px solid var(--line); }
.card.tap { cursor: pointer; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }

.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--primary); color: #fff; font-weight: 600; cursor: pointer; }
.btn.sub { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--primary); padding: 8px 10px; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; padding: 14px; }
.icon-btn { border: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-width: 38px; height: 38px; font-size: 16px; cursor: pointer; }

.seg { display: flex; background: var(--line); border-radius: 11px; padding: 3px; gap: 2px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 0; border-radius: 9px; font-size: 14px; color: var(--sub); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag { display: inline-block; font-size: 12px; background: var(--primary-soft); color: var(--primary); border-radius: 6px; padding: 1px 7px; margin: 4px 4px 0 0; cursor: pointer; }
.badge { font-size: 12px; font-weight: 700; border-radius: 6px; padding: 2px 7px; background: var(--line); color: var(--sub); white-space: nowrap; }
.badge.red { background: var(--danger); color: #fff; }
.badge.orange { background: var(--warn); color: #fff; }
.badge.green { background: var(--ok); color: #fff; }

.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); margin-bottom: 12px; }

/* 일정 */
.calnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calnav strong { font-size: 17px; }
.ev { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.ev:last-child { border-bottom: 0; }
.ev .bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--primary); }
.ev .time { width: 74px; flex: none; font-size: 13px; color: var(--sub); padding-top: 1px; }
.ev .t { font-weight: 600; }
.rep { font-size: 11px; color: var(--sub); margin-left: 4px; }

.hours { border-top: 1px solid var(--line); max-height: calc(100vh - 300px); min-height: 300px; overflow-y: auto; background: var(--card); border-radius: 12px; padding: 0 8px; }
.hour { display: flex; min-height: 48px; border-bottom: 1px solid var(--line); cursor: pointer; }
.hour .hl { width: 48px; flex: none; font-size: 12px; color: var(--sub); padding-top: 4px; }
.hour .hc { flex: 1; padding: 4px 0; display: flex; flex-direction: column; gap: 3px; }
.hour.now .hl { color: var(--primary); font-weight: 700; }
.pill { border-radius: 8px; padding: 4px 8px; font-size: 14px; color: #fff; background: var(--primary); cursor: pointer; }

.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.month .dow { text-align: center; font-size: 12px; color: var(--sub); padding: 4px 0; }
.month .d { min-height: 64px; background: var(--card); border-radius: 8px; padding: 4px 3px; font-size: 13px; cursor: pointer; overflow: hidden; }
.month .d.out { opacity: .35; }
.month .d.today .n { background: var(--primary); color: #fff; border-radius: 50%; }
.month .n { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; }
.month .mini { font-size: 10px; line-height: 1.3; border-radius: 3px; padding: 0 3px; margin-top: 2px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sun { color: var(--danger); } .sat { color: var(--primary); }

.year { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ym { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; cursor: pointer; }
.ym b { font-size: 13px; display: block; margin-bottom: 4px; }
.ym .g { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.ym .g i { font-style: normal; font-size: 8.5px; text-align: center; line-height: 14px; border-radius: 3px; color: var(--sub); }
.ym .g i.has { background: var(--primary); color: #fff; }
.ym .g i.today { outline: 1.5px solid var(--danger); }

.weekday-pick { display: flex; gap: 4px; }
.weekday-pick label { flex: 1; }
.weekday-pick input { display: none; }
.weekday-pick span { display: block; text-align: center; padding: 8px 0; border-radius: 8px; border: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.weekday-pick input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.colors { display: flex; gap: 8px; }
.colors input { display: none; }
.colors span { display: block; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.colors input:checked + span { border-color: var(--text); }

/* 목표 */
.goal { display: flex; align-items: flex-start; gap: 10px; }
.goal input[type=checkbox] { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--primary); flex: none; }
.goal.done .gt { text-decoration: line-through; color: var(--sub); }
.progress { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--ok); }

/* 독서 */
.book { display: flex; gap: 12px; }
.cover { width: 54px; height: 76px; flex: none; border-radius: 6px; background: var(--primary-soft); object-fit: cover;
  display: flex; align-items: center; justify-content: center; font-size: 24px; }
.stars { color: #f5a623; letter-spacing: 1px; }
.quote { border-left: 3px solid var(--primary); padding: 2px 0 2px 10px; margin: 6px 0; font-style: italic; }

/* 파일 */
.file { display: flex; align-items: center; gap: 12px; }
.file .fi { width: 40px; height: 40px; border-radius: 10px; background: var(--primary-soft); display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.uploadbar { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.uploadbar i { display: block; height: 100%; background: var(--primary); width: 0; transition: width .2s; }

/* 메뉴 */
.menu a, .menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 15px 4px; border: 0; background: none;
  border-bottom: 1px solid var(--line); color: var(--text); font-size: 16px; text-align: left; cursor: pointer; }
.menu > :last-child { border-bottom: 0; }
.menu .ic { font-size: 20px; width: 28px; text-align: center; }

/* 바텀시트 */
#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
#sheet .grip { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 4px auto 10px; }
#sheet h3 { margin: 0 0 12px; font-size: 18px; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; }
.field textarea { min-height: 110px; resize: vertical; }
.two { display: flex; gap: 10px; } .two > * { flex: 1; min-width: 0; }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }
.sheet-actions .btn:not(.danger) { flex: 1; padding: 13px; }
.preview { width: 100%; max-height: 70vh; object-fit: contain; border-radius: 10px; background: var(--bg); }
iframe.preview { height: 70vh; border: 0; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabh) + 90px); z-index: 30;
  background: rgba(20,20,25,.9); color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 14px; max-width: 90vw; }

/* 로그인 */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login h1 { font-size: 26px; margin: 0 0 4px; }
.login .err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 6px 0; }
.notice { background: #fff4e0; color: #8a5300; border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; cursor: pointer; }
@media (prefers-color-scheme: dark) { .notice { background: #3a2a0c; color: #ffc46b; } }

/* 강의 */
#tabs a { max-width: 96px; }
.md { word-break: break-word; }
.md h3 { font-size: 18px; margin: 18px 0 6px; } .md h4 { font-size: 16px; margin: 16px 0 6px; color: var(--primary); }
.md h5 { font-size: 15px; margin: 12px 0 4px; }
.md h3:first-child, .md h4:first-child { margin-top: 0; }
.md p { margin: 6px 0; } .md ul, .md ol { margin: 6px 0; padding-left: 22px; } .md li { margin: 3px 0; }
.md blockquote { border-left: 3px solid var(--primary); margin: 8px 0; padding: 2px 0 2px 10px; color: var(--sub); }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 7px; text-align: left; }
.md th { background: var(--bg); } .md hr { border: 0; border-top: 1px dashed var(--line); margin: 16px 0; }
.md code { background: var(--bg); border-radius: 4px; padding: 0 4px; }
.pages img { width: 100%; display: block; border-radius: 8px; margin-bottom: 8px; background: var(--card); border: 1px solid var(--line); min-height: 120px; }
.filehead { display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; font-size: 14px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2.5px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
