:root {
  --bg: #b8d4ff;
  --text: #191919;
  --muted: rgba(25, 25, 25, 0.62);
  --line: rgba(55, 53, 47, 0.16);
  --card: #b8d4ff;
  --shadow: rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.08) 0 2px 4px;
  --active: #669dfd;
  --surface: rgba(255, 255, 255, 0.86);
  --radius: 12px;
  --nav-h: 48px;
  --content: 1040px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #191919;
  --text: #f4f4f4;
  --muted: rgba(255, 255, 255, 0.62);
  --line: rgba(255, 255, 255, 0.14);
  --card: #242424;
  --shadow: rgba(255, 255, 255, 0.08) 0 0 0 1px, rgba(0, 0, 0, 0.45) 0 2px 8px;
  --surface: rgba(36, 36, 36, 0.94);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Nanum Gothic", "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

.waves {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.wave {
  position: absolute;
  width: 90px;
  visibility: hidden;
  animation: wave-bob 8s ease-in-out infinite;
}

.wave svg { display: block; width: 100%; height: auto; }

.wave:nth-child(2) { animation-delay: -2.4s; }
.wave:nth-child(3) { animation-delay: -5s; }
.wave:nth-child(4) { animation-delay: -1.2s; }
.wave:nth-child(5) { animation-delay: -3.6s; }
.wave:nth-child(6) { animation-delay: -4.4s; }

main { position: relative; }

.page-logo,
h1,
.crumb,
.prose,
.card-body,
.card-excerpt,
.site-footer,
.db-title {
  position: relative;
  z-index: 3;
}

@keyframes wave-bob {
  0%, 100% { transform: rotate(var(--tilt)) translateY(0); }
  50% { transform: rotate(var(--tilt)) translateY(-7px); }
}

[data-theme="dark"] .waves { display: none; }

@media (prefers-reduced-motion: reduce) {
  .wave { animation: none; transform: rotate(var(--tilt)); }
}

a { color: inherit; }

img { max-width: 100%; }

button, input {
  font-family: inherit;
}

.nav {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 36px 0 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  min-width: 0;
  color: inherit;
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.nav-brand img {
  width: 32px;
  height: 32px;
  flex: none;
  object-fit: cover;
  border-radius: 6px;
}

.lang-switch {
  display: flex;
  align-items: center;
  margin-left: 18px;
}

.lang-switch select {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  padding: 0 8px;
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  height: 100%;
}

.nav-item { position: relative; height: 100%; display: flex; align-items: center; }

.nav-item > a {
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
  padding: 8px 10px;
}

.nav-item > a[aria-current="page"] {
  color: #1e4db7;
  box-shadow: inset 0 -2px 0 #1e4db7;
}

.nav-item > a:hover { color: #1e4db7; }

.dropdown {
  display: none;
  position: absolute;
  top: calc(100% - 4px);
  left: 0;
  min-width: 220px;
  max-width: min(320px, 70vw);
  padding: 8px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: rgba(15, 15, 15, 0.12) 0 0 0 1px, rgba(15, 15, 15, 0.16) 0 8px 24px;
}

.nav-item:last-child .dropdown {
  left: auto;
  right: 0;
}

.dropdown a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  line-height: 1.4;
}

.dropdown a:hover,
.dropdown a[aria-current="page"] { background: rgba(102, 157, 253, 0.18); }

@media (min-width: 801px) {
  .nav-item:hover .dropdown,
  .nav-item:focus-within .dropdown { display: block; }
}

.menu-btn {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.menu-btn:hover { background: rgba(0, 0, 0, 0.06); }

[data-theme="dark"] .menu-btn:hover { background: rgba(255, 255, 255, 0.08); }

[data-theme="dark"] .nav-item > a[aria-current="page"],
[data-theme="dark"] .nav-item > a:hover {
  color: #9ec0ff;
  box-shadow: inset 0 -2px 0 #9ec0ff;
}

.menu-btn { display: none; }

.shell {
  width: min(var(--content), calc(100% - 48px));
  margin: 0 auto;
  padding: 10px 0 88px;
}

.crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  margin: 2px 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.crumb a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  max-width: 240px;
}

.crumb a:hover { text-decoration: underline; }

.crumb .here {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumb img {
  width: 18px;
  height: 18px;
  object-fit: cover;
  border-radius: 3px;
}

.page-logo {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  background: #fff;
  margin: 28px 0 8px;
  box-shadow: rgba(15, 15, 15, 0.08) 0 0 0 1px;
}

h1 {
  font-size: 32px;
  line-height: 1.25;
  font-weight: 800;
  margin: 8px 0 18px;
  letter-spacing: -0.03em;
}

.prose p { margin: 1px 0; min-height: 1.6em; }

.prose .blank { min-height: 1.6em; }

.prose a { color: inherit; }

.prose p a, .caption a, .li-note a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose ul, .prose ol { margin: 2px 0 2px 1.2em; padding: 0; }

.prose li { margin: 1px 0; padding-left: 2px; }

.li-note {
  margin-left: 0;
  color: var(--text);
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.cols {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin: 6px 0;
}

.col { min-width: 0; }

figure { margin: 8px 0 14px; }

figure img, .frame img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
}

figure.icon-fig { margin: 4px 0; }

figure.icon-fig img, img.icon {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: contain;
}

img.contain {
  width: auto;
  max-width: 140px;
  height: auto;
  background: transparent;
}

.caption {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  word-break: break-all;
}

.missing {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 16px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.35);
  border: 1px dashed rgba(0, 0, 0, 0.25);
  text-align: center;
  font-size: 14px;
}

.missing code { font-size: 12px; }

video, .pdf, .embed {
  width: min(100%, 760px);
  border: 0;
  border-radius: 8px;
  background: #111;
  display: block;
  margin: 8px 0 14px;
}

.pdf { height: 80vh; background: #fff; }

.embed { height: 460px; background: #fff; }

.gallery-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  margin: 8px 0 14px;
}

.db-title {
  display: inline-block;
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}

.db-title:hover { background: rgba(102, 157, 253, 0.2); }

.gallery-tab {
  font-weight: 700;
  font-size: 14px;
  padding: 6px 2px 8px;
  border-bottom: 2px solid var(--text);
}

.gallery-search {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  padding: 6px 2px 8px;
  width: 140px;
  outline: none;
}

.gallery-search::placeholder { color: var(--muted); }

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  text-decoration: none;
  background: transparent;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  color: var(--text);
  transition: background 120ms ease;
}

.card:hover { background: rgba(255, 255, 255, 0.28); }

[data-theme="dark"] .card { background: var(--card); }

[data-theme="dark"] .card:hover { background: #2e2e2e; }

.card-cover {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.25);
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  border-radius: 0;
}

.card-cover img.contain {
  object-fit: contain;
  max-width: none;
  width: 100%;
  height: 100%;
  background: #d7e6ff;
}

.card-excerpt {
  padding: 14px 12px 4px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-line;
}

.card-body {
  margin-top: auto;
  padding: 10px 12px 12px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}

.card-body .emoji { margin-right: 4px; }

.site-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  padding-top: 8px;
}

.site-footer p { margin: 0; }

.site-footer a img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 4px;
}

@media (max-width: 900px) {
  .cards { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 800px) {
  .menu-btn { display: grid; }

  .nav { padding-right: 12px; }

  .nav-brand span { display: none; }

  .lang-switch { margin-left: 0; }

  .nav-links {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    width: auto;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding: 8px 12px 16px;
  }

  .nav.open .nav-links { display: flex; }

  .nav-item { height: auto; flex-direction: column; align-items: stretch; }

  .dropdown {
    position: static;
    transform: none;
    display: block;
    box-shadow: none;
    background: transparent;
    padding: 0 0 8px 12px;
    min-width: 0;
  }

  .shell { width: min(100% - 32px, var(--content)); }

  .cols { flex-direction: column; }

  .col { width: 100% !important; flex: none !important; }

  figure.narrow { width: min(100%, var(--img-w, 72px)); }

  h1 { font-size: 28px; }
}

@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; }
  .page-logo { width: 108px; height: 108px; }
}
