:root {
  --paper: #f7f4ee;
  --surface: #ffffff;
  --line: #ded8cc;
  --ink: #1c2430;
  --muted: #65717f;
  --kr: #b8324a;
  --cn: #216c7a;
  --gold: #b8862b;
  --shadow: 0 18px 50px rgba(28, 36, 48, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.8), rgba(225, 233, 232, 0.58)),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  min-height: 100vh;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto;
  min-width: 0;
  padding: 28px;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 4vw, 3.5rem);
  letter-spacing: 0;
}

.period-hud {
  max-width: 330px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: #334155;
  font-weight: 800;
  text-align: right;
  box-shadow: 0 8px 24px rgba(28, 36, 48, 0.08);
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.topbar-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lang-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.lang-switch button {
  padding: 3px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.lang-switch button[aria-pressed="true"] {
  background: var(--cn);
  color: #fff;
}

.lang-switch button:focus-visible {
  outline: 2px solid rgba(33, 108, 122, 0.32);
  outline-offset: 1px;
}

.about-link {
  flex: none;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--cn);
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(28, 36, 48, 0.08);
}

.about-link:hover {
  border-color: #97a6ad;
  color: var(--ink);
}

.about-link:focus-visible {
  outline: 2px solid rgba(33, 108, 122, 0.32);
  outline-offset: 2px;
}

.about-dialog {
  width: min(640px, calc(100% - 32px));
  max-height: min(84vh, 780px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.about-dialog::backdrop {
  background: rgba(28, 36, 48, 0.42);
  backdrop-filter: blur(3px);
}

.about-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.about-header h2 {
  margin-bottom: 0;
  word-break: keep-all;
  font-size: 1.45rem;
}

.about-tabs {
  display: flex;
  gap: 4px;
  margin-top: 12px;
}

.about-tab {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfa;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.about-tab[aria-selected="true"] {
  border-color: var(--cn);
  background: var(--cn);
  color: #fff;
}

.about-tab:focus-visible {
  outline: 2px solid rgba(33, 108, 122, 0.32);
  outline-offset: 2px;
}

.about-body {
  padding: 6px 24px 22px;
  line-height: 1.6;
}

.about-body:lang(ko) {
  word-break: keep-all;
}

.about-body ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: #334155;
}

.about-body a {
  color: var(--cn);
  font-weight: 700;
}

.about-body h3 {
  margin: 18px 0 4px;
  color: var(--gold);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.about-body p {
  margin-bottom: 0;
  color: #334155;
}

.globe-wrap {
  position: relative;
  z-index: 1;
  min-height: 0;
}

.globe {
  position: absolute;
  inset: 0;
  min-height: 380px;
}

.rotate-switch {
  position: absolute;
  left: 18px;
  top: 18px;
  z-index: 6;
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid rgba(222, 216, 204, 0.96);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(28, 36, 48, 0.12);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 800;
  backdrop-filter: blur(14px);
}

.rotate-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #c7cfd3;
  transition: background 160ms ease;
}

.switch-track span {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(28, 36, 48, 0.22);
  transition: transform 160ms ease;
}

.rotate-switch input:checked + .switch-track {
  background: var(--cn);
}

.rotate-switch input:checked + .switch-track span {
  transform: translateX(16px);
}

.rotate-switch:focus-within {
  outline: 2px solid rgba(33, 108, 122, 0.32);
  outline-offset: 2px;
}

.empty-state {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  box-shadow: var(--shadow);
}

.globe-popover {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 5;
  width: min(330px, calc(100% - 36px));
  overflow: hidden;
  border: 1px solid rgba(222, 216, 204, 0.96);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.popover-image {
  width: 100%;
  height: 158px;
  object-fit: cover;
  background: #e7e3da;
}

.popover-body {
  padding: 12px;
}

.popover-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: start;
}

.popover-header h2 {
  margin-bottom: 2px;
  font-size: 1.05rem;
  line-height: 1.25;
}

.popover-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfa;
  color: var(--muted);
  cursor: pointer;
}

.popover-close:hover {
  border-color: #97a6ad;
  color: var(--ink);
}

.popover-meta {
  display: grid;
  gap: 5px;
  margin: 10px 0 0;
  color: #364250;
  font-size: 0.82rem;
}

.popover-meta span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid #eee8dc;
  padding-top: 5px;
}

.popover-meta b {
  color: var(--muted);
  white-space: nowrap;
}

.popover-link {
  display: inline-block;
  margin-top: 10px;
  color: var(--cn);
  font-size: 0.84rem;
  font-weight: 800;
  text-decoration: none;
}

.popover-link:hover {
  text-decoration: underline;
}

.timeline-panel {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 34px rgba(28, 36, 48, 0.1);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover,
.seg-btn:hover,
.artifact-button:hover {
  border-color: #97a6ad;
  background: #f8fbfb;
}

.century-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.82rem;
}

.century-labels strong {
  color: var(--ink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cn);
}

.tick-row {
  position: relative;
  height: 10px;
}

.tick {
  position: absolute;
  top: 2px;
  width: 8px;
  height: 8px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: var(--gold);
}

.side-panel {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 100vh;
  overflow: auto;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(16px);
}

.controls-block,
.detail-card,
.compare-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(28, 36, 48, 0.08);
}

.controls-block {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.control-row {
  display: grid;
  gap: 6px;
}

label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

input[type="search"],
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfbfa;
  color: var(--ink);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.seg-btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfa;
  color: var(--muted);
  cursor: pointer;
}

.seg-btn.active {
  color: #fff;
}

.seg-btn[data-culture="KR"].active {
  background: var(--kr);
  border-color: var(--kr);
}

.seg-btn[data-culture="CN"].active {
  background: var(--cn);
  border-color: var(--cn);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch,
.marker-sample {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.swatch.kr {
  background: var(--kr);
}

.swatch.cn {
  background: var(--cn);
}

.marker-sample.uncertain {
  border: 2px dashed var(--gold);
}

.map-marker {
  position: relative;
  width: 20px;
  height: 20px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(28, 36, 48, 0.18), 0 8px 18px rgba(28, 36, 48, 0.24);
  cursor: pointer;
}

.map-marker.kr {
  background: var(--kr);
}

.map-marker.cn {
  background: var(--cn);
}

.map-marker.estimated {
  border-style: dashed;
}

.map-marker.selected {
  box-shadow: 0 0 0 4px rgba(184, 134, 43, 0.45), 0 8px 18px rgba(28, 36, 48, 0.24);
}

.map-marker::after {
  position: absolute;
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  min-width: 72px;
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  content: attr(title);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.map-marker:hover::after {
  opacity: 1;
}

.detail-card {
  overflow: hidden;
}

.detail-placeholder {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.detail-image {
  width: 100%;
  height: 210px;
  object-fit: cover;
  background: #e7e3da;
}

.detail-body {
  padding: 14px;
}

.detail-body h2 {
  margin-bottom: 2px;
  font-size: 1.18rem;
}

.hanja {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 7px 10px;
  margin: 12px 0;
  font-size: 0.86rem;
}

.meta-grid dt {
  color: var(--muted);
  font-weight: 800;
}

.meta-grid dd {
  margin: 0;
}

.detail-body a {
  color: var(--cn);
  font-weight: 800;
  text-decoration: none;
}

.detail-body a:hover {
  text-decoration: underline;
}

.compare-panel {
  padding: 14px;
}

.panel-title,
.compare-grid {
  display: grid;
  gap: 12px;
}

.panel-title {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.panel-title h2,
.compare-grid h3,
.unknown-panel h3 {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.compare-grid {
  grid-template-columns: 1fr 1fr;
}

.artifact-list {
  display: grid;
  gap: 8px;
}

.artifact-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfbfa;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.artifact-button.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(184, 134, 43, 0.18);
}

.artifact-button small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.unknown-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.compact:empty::before,
.artifact-list:empty::before {
  color: var(--muted);
  content: "없음";
  font-size: 0.84rem;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .workspace {
    min-height: 72vh;
    padding: 18px;
  }

  .side-panel {
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .topbar,
  .timeline-panel,
  .compare-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .period-hud {
    max-width: none;
    text-align: left;
  }

  .topbar-actions {
    flex-direction: row;
    align-items: flex-start;
  }

  .about-link {
    padding: 10px 14px;
  }

  .about-header {
    padding: 16px 16px 12px;
  }

  .about-body {
    padding: 4px 16px 18px;
  }

  .globe-popover {
    left: 12px;
    right: 12px;
    top: 58px;
    width: auto;
  }

  .popover-image {
    height: 128px;
  }

  .timeline-panel {
    display: grid;
  }
}
