:root {
  --ink: #1a1714;
  --muted: #5c564e;
  --paper: #f3efe8;
  --panel: rgba(247, 244, 239, 0.92);
  --line: #d4cdc3;
  --accent: #9a3f22;
  --accent-2: #2b4f5c;
  --shadow: 0 8px 28px rgba(26, 23, 20, 0.16);
  --radius: 14px;
  --sans: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
}
a { color: var(--accent-2); }
.top {
  display: flex;
  gap: 1.25rem;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0.9rem 1.2rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: #efebe3;
}
.top-text h1 {
  margin: 0 0 0.2rem;
  font-size: clamp(1.15rem, 2.4vw, 1.65rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}
.top-text p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  max-width: 52rem;
}
.top-nav { display: flex; flex-wrap: wrap; gap: 0.7rem 1rem; padding-bottom: 0.15rem; }
.top-nav a { font-size: 0.92rem; font-weight: 600; text-decoration: none; border-bottom: 1px solid currentColor; }

.viewer-wrap {
  position: relative;
  height: min(78vh, 920px);
  min-height: 420px;
  background: #d8d2c8;
  overflow: hidden;
}
#c {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  position: relative;
  z-index: 0;
}
.loader {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(216, 210, 200, 0.8);
  font-weight: 600;
  letter-spacing: 0.02em;
  z-index: 40;
}
.loader.done { display: none; }

.panel {
  position: absolute;
  z-index: 30;
  max-width: min(280px, calc(100vw - 1.4rem));
  pointer-events: none;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}
.layers { top: 0.8rem; left: 0.8rem; }
.legend { top: 0.8rem; right: 0.8rem; }
.panel-pill,
.panel-card,
.panel-close,
.panel-body,
.views button {
  pointer-events: auto;
}
.panel-pill,
.panel-close,
.views button,
.panel-body label,
.panel-body input {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.panel-pill {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
  padding: 0.42rem 0.9rem;
  cursor: pointer;
  position: relative;
  z-index: 31;
}
.panel-card {
  display: none;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel.open .panel-pill { display: none; }
.panel.open .panel-card { display: block; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.4rem 0 0.85rem;
}
.panel-title { font-weight: 700; font-size: 0.95rem; }
.panel-close {
  border: 0;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}
.panel-close:hover { color: var(--ink); }
.panel-body { padding: 0.4rem 0.85rem 0.8rem; }
.panel-body label {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.86rem;
  margin: 0.22rem 0;
  cursor: pointer;
}
.panel-body input { margin-top: 0.18rem; accent-color: var(--accent); }
.hint { margin: 0.55rem 0 0; font-size: 0.72rem; color: var(--muted); }
.views { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.65rem; }
.views button, .btn {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #f6f3ee;
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.views button { background: #fff; color: var(--ink); }
.views button:hover, .btn:hover { opacity: 0.88; }
.btn-ghost { background: transparent; color: var(--ink); }

.legend-row { display: flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; margin: 0.18rem 0; }
.swatch { width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); flex: none; }

.info {
  position: absolute;
  z-index: 32;
  left: 0.8rem;
  right: 0.8rem;
  bottom: 0.8rem;
  margin: 0 auto;
  max-width: 420px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem 2.1rem 0.9rem 1rem;
}
.info.hidden { display: none; }
.info-close {
  position: absolute; top: 0.35rem; right: 0.4rem;
  border: 0; background: transparent; font-size: 1.3rem; cursor: pointer; color: var(--muted);
}
.info h3 { margin: 0 0 0.2rem; font-size: 1.02rem; }
.info .type { font-weight: 700; color: var(--accent); }
.info dl { margin: 0.4rem 0 0; display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.7rem; font-size: 0.88rem; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.info .note { margin: 0.5rem 0 0; font-size: 0.82rem; color: var(--muted); }

.drawings { padding: 1.6rem 1.2rem 2rem; max-width: 1200px; margin: 0 auto; }
.drawings-head { display: flex; flex-wrap: wrap; gap: 0.8rem 1.2rem; justify-content: space-between; align-items: flex-end; margin-bottom: 1rem; }
.drawings h2, .drawings h3 { margin: 0 0 0.7rem; letter-spacing: -0.02em; }
.drawings h3 { margin-top: 1.6rem; font-size: 1.05rem; }
.drawings-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.85rem; }
.grid-sm { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.card {
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 2px 8px rgba(26,23,20,.06);
}
.card img { width: 100%; height: 160px; object-fit: cover; object-position: top; background: #eee; display: block; }
.card span { display: block; padding: 0.5rem 0.7rem 0.65rem; font-size: 0.84rem; font-weight: 600; }
.card:hover { border-color: var(--accent-2); }

.foot { padding: 0.9rem 1.2rem 1.4rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.82rem; }
.foot p { margin: 0; max-width: 70rem; }

@media (max-width: 768px) {
  .top { flex-direction: column; align-items: flex-start; }
  .viewer-wrap { height: min(70vh, 640px); min-height: 360px; }
  .legend { top: auto; bottom: 0.8rem; right: 0.8rem; left: auto; }
  .layers { max-width: min(250px, calc(100vw - 5.5rem)); }
  .info { bottom: 3.4rem; }
}
