:root {
  --ink: #182c2e;
  --ink-soft: #3c5457;
  --muted: #6f8486;
  --line: #dfe4e1;
  --paper: #f4f3ee;
  --white: #ffffff;
  --accent: #2f5d57;
  --accent-soft: #e4eeea;
  --gold: #a9854a;
  --danger: #a33d33;
  --danger-soft: #f8e9e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(24, 44, 46, .06), 0 8px 24px rgba(24, 44, 46, .06);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ------------------------------------------------------------------ boot -- */
.boot {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 14px; background: var(--paper); color: var(--muted); z-index: 50;
}
.boot p { margin: 0; }
.boot.error { color: var(--danger); text-align: center; padding: 24px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------- top -- */
#app { display: flex; flex-direction: column; height: 100%; }

.top {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 18px;
  background: var(--ink); color: var(--paper);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 1px solid rgba(244, 243, 238, .35); border-radius: 10px;
  font: 600 13px/1 Georgia, serif; letter-spacing: .02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 600; letter-spacing: .01em; }
.brand-text small { font-size: 12px; color: rgba(244, 243, 238, .62); overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tabs button {
  position: relative;
  border: 0; background: transparent; color: rgba(244, 243, 238, .72);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}
.tabs button:hover { background: rgba(244, 243, 238, .08); color: var(--paper); }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--ink); font-weight: 600; }
.tabs .dot {
  position: absolute; top: 6px; right: 7px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--gold);
}
.tabs button[aria-selected="true"] .dot { background: var(--gold); }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ghost {
  border: 1px solid rgba(244, 243, 238, .25); background: transparent; color: inherit;
  padding: 7px 12px; border-radius: 9px; font-size: 13.5px; text-decoration: none;
}
.ghost:hover { background: rgba(244, 243, 238, .1); }
.primary {
  border: 0; background: var(--paper); color: var(--ink);
  padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 14px;
}
.primary:disabled { opacity: .45; cursor: default; }
.primary.busy { position: relative; color: transparent; }
.primary.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px;
  border-radius: 50%; border: 2px solid rgba(24, 44, 46, .25); border-top-color: var(--ink);
  animation: spin .8s linear infinite;
}

/* ---------------------------------------------------------------- banner -- */
.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; font-size: 13.5px;
  background: #fdf6e6; color: #6b4f16; border-bottom: 1px solid #efe0bd;
}
.banner.danger { background: var(--danger-soft); color: var(--danger); border-bottom-color: #eccfc9; }
.banner button {
  border: 1px solid currentColor; background: transparent; color: inherit;
  padding: 4px 10px; border-radius: 7px; font-size: 12.5px;
}
.banner .spacer { flex: 1; }

.progress {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 18px; font-size: 13px;
  background: var(--accent-soft); color: var(--accent); border-bottom: 1px solid #cfe0da;
}
.progress.step::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(47, 93, 87, .3); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.progress a { color: inherit; text-decoration: underline; }

/* ----------------------------------------------------------------- main -- */
main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 330px minmax(0, 1fr);
}

.list {
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--line); background: var(--white);
}
.list-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.list-head input {
  flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--white);
}
.list-head input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.add {
  border: 0; background: var(--ink); color: var(--paper); padding: 0 12px;
  border-radius: 8px; font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.add:hover { background: #243e41; }

.list-body { overflow: auto; padding: 6px 8px 40px; }

.group-title {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 6px 6px; font-size: 12px; font-weight: 600;
  letter-spacing: .04em; color: var(--muted); text-transform: uppercase;
}
.group-title .count {
  font-weight: 500; color: var(--muted); background: var(--paper);
  border-radius: 999px; padding: 0 7px; font-size: 11px;
}
.group-title .mini {
  margin-left: auto; border: 0; background: transparent; color: var(--muted);
  font-size: 11.5px; padding: 2px 4px; border-radius: 6px;
}
.group-title .mini:hover { background: var(--paper); color: var(--ink); }

.row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px; border-radius: 10px; color: inherit;
}
.row:hover { background: var(--paper); }
.row[aria-current="true"] { background: var(--accent-soft); }
.row img, .row .ph {
  width: 38px; height: 38px; flex: none; border-radius: 8px; object-fit: cover;
  background: var(--paper); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 12px; color: var(--muted);
}
.row .txt { min-width: 0; flex: 1; }
.row .txt b { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .txt span { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tag {
  font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--paper);
  color: var(--muted); white-space: nowrap;
}
.row .tag.hidden-tag { background: #f1ece2; color: #7a6742; }
.row.muted { opacity: .55; }
.empty-list { color: var(--muted); font-size: 13.5px; padding: 24px 12px; text-align: center; }

/* --------------------------------------------------------------- editor -- */
.editor { overflow: auto; padding: 22px 26px 80px; }
.editor-inner { max-width: 820px; margin: 0 auto; }
.editor h1 { font-size: 20px; margin: 0 0 4px; }
.editor .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 {
  font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 14px; font-weight: 600;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; font-weight: 600; }
.field .hint { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.field input[type=text], .field input[type=search], .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--white); transition: border-color .12s, box-shadow .12s;
}
.field textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair .field { margin-bottom: 0; }
.pair + .pair, .pair + .field, .field + .pair { margin-top: 14px; }
.lang { font-size: 10.5px; color: var(--muted); font-weight: 500; margin-left: 6px; letter-spacing: .03em; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button {
  border: 0; background: var(--white); padding: 7px 14px; font-size: 13.5px; color: var(--muted);
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

/* image control */
.image-field { display: flex; gap: 14px; align-items: flex-start; }
.image-field .preview {
  width: 132px; height: 99px; flex: none; border-radius: 10px; overflow: hidden;
  background: var(--paper); border: 1px solid var(--line); display: grid; place-items: center;
  color: var(--muted); font-size: 12px; text-align: center; padding: 6px;
}
.image-field .preview img { width: 100%; height: 100%; object-fit: cover; }
.image-field .meta { display: flex; flex-direction: column; gap: 6px; }
.image-field .meta small { color: var(--muted); font-size: 11.5px; }
.btn {
  border: 1px solid var(--line); background: var(--white); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; font-size: 13px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #edd3ce; }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.solid { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.solid:hover { background: #243e41; color: var(--paper); }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumbs figure { margin: 0; position: relative; }
.thumbs img {
  width: 96px; height: 72px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); display: block;
}
.thumbs .x {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: var(--ink); color: var(--paper); font-size: 12px; line-height: 1;
}
.thumbs .missing {
  width: 96px; height: 72px; border-radius: 8px; border: 1px dashed var(--danger);
  color: var(--danger); font-size: 11px; display: grid; place-items: center; text-align: center; padding: 4px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 18px; }
.actions .spacer { flex: 1; }
.actions .status-note { font-size: 12px; color: var(--muted); }

.editor-empty {
  max-width: 520px; margin: 12vh auto 0; text-align: center; color: var(--muted);
}
.editor-empty h1 { color: var(--ink); font-size: 18px; }
.editor-empty p { font-size: 13.5px; line-height: 1.7; }
.editor-empty .btn { margin-top: 10px; }

/* ----------------------------------------------------------------- modal -- */
.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(24, 44, 46, .42); padding: 18px;
}
.modal-card {
  width: min(560px, 100%); max-height: 86vh; overflow: auto;
  background: var(--white); border-radius: 16px; padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .22);
}
.modal-card h2 { margin: 0 0 4px; font-size: 17px; }
.modal-card .modal-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.changes { margin: 0; padding: 0; list-style: none; }
.changes li {
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px;
  display: flex; gap: 8px; align-items: baseline;
}
.changes li:last-child { border-bottom: 0; }
.changes .kind {
  flex: none; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--paper); color: var(--muted);
}
.changes .kind.add { background: var(--accent-soft); color: var(--accent); }
.changes .kind.del { background: var(--danger-soft); color: var(--danger); }
.commit-field { margin-top: 16px; }

/* ---------------------------------------------------------------- toasts -- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px;
  font-size: 13.5px; box-shadow: var(--shadow); max-width: 340px;
  animation: rise .18s ease-out;
}
.toast.bad { background: var(--danger); }
.toast a { color: var(--paper); }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }

/* -------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .brand-text small { display: none; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; padding-bottom: 2px; }
  .tabs button { flex: 1; padding: 8px 10px; }
  .top-actions { gap: 6px; }
  .ghost.link { display: none; }
  main { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 42vh; }
  .editor { padding: 16px 14px 80px; }
  .pair { grid-template-columns: 1fr; }
  .pair .field + .field { margin-top: 12px; }
  .image-field { flex-direction: column; }
  .image-field .preview { width: 100%; height: 150px; }
}

/* ------------------------------------------------------------------ map -- */
.map-mode main { grid-template-columns: minmax(0, 1fr); }
.map-mode .list { display: none; }

.map-inner { max-width: 1080px; margin: 0 auto; }
.map-head h1 { font-size: 21px; margin: 0 0 6px; }
.map-head p { margin: 0; color: var(--muted); font-size: 13.5px; }
.map-legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.legend-note { font-size: 12px; color: var(--muted); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .01em;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--paper); border: 1px solid var(--line); color: var(--muted);
}
.badge.b-open { background: #e7f1e9; border-color: #c9e2d0; color: #2f6b47; }
.badge.b-access { background: #f3eddf; border-color: #e2d5b9; color: #7a5f27; }
.badge.b-pin { background: #f3eddf; border-color: #e2d5b9; color: #7a5f27; }
.badge.b-soon { background: transparent; border-style: dashed; color: var(--muted); }

.map-zone { margin-top: 26px; }
.zone-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.zone-head h2 {
  margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}

.map-hub {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 18px; border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); background: var(--white); box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
}
.map-hub:hover { border-color: var(--accent); }
.hub-mark {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px;
  border: 1px solid var(--line); border-radius: 10px;
  font: 600 13px/1 Georgia, serif; color: var(--ink);
}
.hub-text { min-width: 0; }
.hub-text b { display: block; font-size: 15.5px; }
.hub-text span { font-size: 12.5px; color: var(--muted); }
.hub-open { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--accent); white-space: nowrap; }

.hub-source { margin: 8px 2px 14px; font-size: 12px; color: var(--muted); }

.map-nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: 12px; }
.map-nodes.pages {
  margin-left: 22px; padding-left: 18px;
  border-left: 2px solid var(--line);
}

.map-node {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--white); color: inherit; text-decoration: none;
  box-shadow: 0 1px 2px rgba(24, 44, 46, .04);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.map-node:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: var(--shadow); }
.map-node.small { padding: 10px 12px; }
.map-node.b-access, .map-node.b-pin { border-left: 3px solid var(--gold); }
.map-node.here { background: linear-gradient(0deg, var(--accent-soft), var(--white)); border-color: var(--accent); }

.node-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.node-top b { font-size: 14px; font-weight: 600; }
.node-host { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.node-note { font-size: 12px; color: var(--ink-soft); }
.node-open { margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--accent); }
.node-links { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.node-links .node-open { margin-top: 0; }
.ko-link { font-size: 12px; font-weight: 500; color: var(--muted); text-decoration: none; }
.ko-link:hover { color: var(--accent); text-decoration: underline; }

/* whole card opens the English page; the 국문 link sits above the stretched area */
.map-node.page { position: relative; }
.map-node.page:hover { border-color: var(--accent); }
.stretched::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.node-links .ko-link { position: relative; z-index: 1; }

@media (max-width: 900px) {
  .map-mode main { grid-template-rows: minmax(0, 1fr); }
  .map-nodes { grid-template-columns: 1fr; }
  .map-nodes.pages { margin-left: 10px; padding-left: 12px; }
  .map-hub { flex-wrap: wrap; }
  .hub-open { margin-left: 58px; }
}
