:root {
  color-scheme: light;
  font-family:
    Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR",
    "Segoe UI", sans-serif;
  font-synthesis: none;
  --bg: #eef2f3;
  --surface: #ffffff;
  --text: #172124;
  --muted: #5e6b6f;
  --line: #ccd7d9;
  --primary: #176c68;
  --primary-soft: #e1f1ef;
  --accent: #9a5b22;
  --complete: #287449;
  --focus: #0b67c2;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
select,
input {
  font: inherit;
}

button,
select {
  min-height: 44px;
}

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 8px max(18px, calc((100vw - 980px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 97%);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
}

.app-switch {
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 750;
  text-decoration: none;
}

.app-switch:hover {
  text-decoration: underline;
}

.selector-band {
  border-bottom: 1px solid var(--line);
  background: #f8fafb;
}

.selector-inner {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto minmax(130px, 180px);
  gap: 10px 12px;
  align-items: center;
  width: min(980px, calc(100% - 36px));
  margin: 0 auto;
  padding: 14px 0;
}

.selector-inner label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.selector-inner select {
  width: 100%;
  padding: 0 36px 0 12px;
  border: 1px solid #aebbbe;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.course-summary {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.summary-inner {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  width: min(980px, calc(100% - 36px));
  margin: 0 auto;
  padding: 22px 0;
}

#course-cover {
  width: 116px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  object-position: top;
}

#course-code {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 850;
}

#course-title {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.35;
  letter-spacing: 0;
}

#week-summary {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.complete-control {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  font-size: 0.86rem;
  font-weight: 750;
}

.complete-control input {
  width: 19px;
  height: 19px;
  accent-color: var(--complete);
}

.completion-summary {
  grid-column: 3;
  margin: -12px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

.reading-shell {
  width: min(860px, calc(100% - 36px));
  margin: 24px auto 56px;
}

.outline {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.outline summary {
  padding: 13px 16px;
  color: var(--primary);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
}

#toc {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
}

#toc a {
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.45;
  text-decoration: none;
}

#toc a[data-level="3"] {
  padding-left: 14px;
  color: var(--muted);
}

#toc a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.note-content {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.note-document {
  padding: clamp(22px, 5vw, 48px);
}

.note-document + .note-document {
  border-top: 10px solid var(--bg);
}

.source-file {
  display: inline-block;
  margin: 0 0 18px;
  padding: 5px 8px;
  border-radius: 5px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 750;
}

.note-body {
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.78;
}

.note-body h1,
.note-body h2,
.note-body h3 {
  scroll-margin-top: 76px;
  letter-spacing: 0;
}

.note-body h1 {
  margin: 0 0 28px;
  font-size: 1.65rem;
  line-height: 1.38;
}

.note-body h2 {
  margin: 42px 0 15px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-soft);
  font-size: 1.25rem;
  line-height: 1.45;
}

.note-body h3 {
  margin: 28px 0 10px;
  font-size: 1.05rem;
  line-height: 1.5;
}

.note-body p,
.note-body ul,
.note-body ol {
  margin: 0 0 16px;
}

.note-body li + li {
  margin-top: 6px;
}

.note-body blockquote {
  margin: 18px 0;
  padding: 14px 16px;
  border-left: 4px solid var(--accent);
  background: #fff7ed;
  color: #50351f;
}

.note-body blockquote p:last-child {
  margin-bottom: 0;
}

.note-body code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #edf1f2;
  font-size: 0.9em;
}

.table-layout {
  margin: 20px 0;
  border: 1px solid var(--line);
}

.note-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.55;
}

.note-body th,
.note-body td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.note-body th {
  background: #f0f6f5;
  color: var(--primary);
}

.week-nav {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.week-nav button {
  flex: 1;
  border: 1px solid var(--primary);
  border-radius: 7px;
  background: var(--surface);
  color: var(--primary);
  font-weight: 800;
}

.week-nav button:last-child {
  background: var(--primary);
  color: #fff;
}

.week-nav button:disabled {
  border-color: var(--line);
  background: #f4f6f6;
  color: #9aa5a8;
}

.loading,
.error-message {
  margin: 0;
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

noscript {
  display: block;
  padding: 24px;
  text-align: center;
}

@media (max-width: 640px) {
  .topbar {
    min-height: 52px;
    padding: 7px 12px;
  }

  .brand {
    font-size: 0.88rem;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  .app-switch {
    font-size: 0.76rem;
  }

  .selector-inner {
    grid-template-columns: 54px minmax(0, 1fr);
    width: calc(100% - 20px);
    padding: 10px 0;
  }

  .summary-inner {
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 12px;
    width: calc(100% - 20px);
    padding: 14px 0;
  }

  #course-cover {
    width: 78px;
    height: 104px;
    aspect-ratio: auto;
  }

  #course-title {
    font-size: 1.05rem;
  }

  #week-summary {
    font-size: 0.8rem;
  }

  .complete-control {
    grid-column: 1 / -1;
    min-height: 38px;
    padding-top: 2px;
  }

  .completion-summary {
    grid-column: 1 / -1;
    margin: -10px 0 0;
    text-align: left;
  }

  .reading-shell {
    width: calc(100% - 20px);
    margin-top: 14px;
  }

  .note-document {
    padding: 22px 16px 30px;
  }

  .note-body {
    font-size: 0.96rem;
    line-height: 1.74;
  }

  .note-body h1 {
    font-size: 1.35rem;
  }

  .note-body h2 {
    margin-top: 34px;
    font-size: 1.14rem;
  }

  .note-body h3 {
    font-size: 1rem;
  }

  .table-layout {
    border: 0;
  }

  .note-body table,
  .note-body tbody,
  .note-body tr,
  .note-body td,
  .note-body th {
    display: block;
    width: 100%;
  }

  .note-body thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .note-body tbody tr {
    padding: 6px 0;
    border-top: 2px solid var(--primary);
    border-bottom: 1px solid var(--line);
  }

  .note-body tbody tr + tr {
    margin-top: 16px;
  }

  .note-body tbody td,
  .note-body tbody th {
    display: grid;
    grid-template-columns: minmax(76px, 30%) minmax(0, 1fr);
    gap: 10px;
    padding: 9px 4px;
    border-right: 0;
    border-bottom: 1px solid #e6ecec;
  }

  .note-body tbody tr > :last-child {
    border-bottom: 0;
  }

  .note-body tbody td::before,
  .note-body tbody th::before {
    content: attr(data-label);
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
