:root {
  --sea: #e2dccb; --land: #f6f2e7; --ink: #1c1915; --accent: #c32a12; --paper: #fbf9f3;
  --sans: "Pretendard Variable", Pretendard, -apple-system, "Malgun Gothic", sans-serif;
  --serif: "Noto Serif KR", "Batang", serif;
  --side: 236px; --rail: 58px;
  --ease: cubic-bezier(.05, .7, .1, 1);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); color: var(--ink); font-family: var(--sans); -webkit-tap-highlight-color: transparent; transition: background-color .7s ease; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

#app { position: fixed; inset: 0; display: grid; grid-template-columns: var(--side) minmax(0, 1fr) minmax(280px, 31%); }
#grain { position: absolute; inset: 0; pointer-events: none; opacity: .32; mix-blend-mode: multiply; z-index: 3;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .22 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E"); }

/* 왼쪽 패널 */
#side { background: #24211b; color: #f1ecdf; padding: 26px 22px 18px; display: flex; flex-direction: column; min-height: 0; z-index: 4; }
#brand { font: 900 21px var(--serif); letter-spacing: .08em; }
#title { font: 900 42px/1.12 var(--serif); margin: 26px 0 8px; word-break: keep-all; min-height: 96px; }
#span { font: 500 15.5px var(--serif); opacity: .75; font-variant-numeric: tabular-nums; padding-bottom: 14px; border-bottom: 1px solid rgba(241, 236, 223, .22); }
#cats { list-style: none; margin: 6px 0 0; padding: 0; flex: 1 1 auto; overflow-y: auto; min-height: 0; scrollbar-width: none; }
#cats::-webkit-scrollbar { display: none; }
#cats button { width: 100%; display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0; border-bottom: 1px solid rgba(241, 236, 223, .14); font-weight: 700; font-size: 15px; transition: opacity .2s; min-height: 42px; }
#cats button span { font-weight: 400; opacity: .7; font-variant-numeric: tabular-nums; }
#cats button.off { opacity: .32; }
#cats .nm { font-style: normal; display: inline-flex; align-items: center; gap: 8px; }
#cats .sw { flex: 0 0 10px; width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1.5px rgba(241, 236, 223, .7); }
#side-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding-top: 10px; font-size: 14px; }
#side-foot button { padding: 6px 0; opacity: .82; min-height: 34px; }
#side-foot button:hover { opacity: 1; }

/* 파형 */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#wavebox { position: relative; flex: 1 1 auto; min-height: 0; }
#wave { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.lane { position: absolute; left: 14px; font: 700 12.5px var(--sans); letter-spacing: .2em; opacity: .55; pointer-events: none; }
.lane.k { top: 14px; } .lane.w { bottom: 12px; }
#guide { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--accent); pointer-events: none; z-index: 2; }
#guide-y { position: absolute; top: 0; left: 0; transform: translateX(-50%); background: var(--accent); color: #fff; font: 700 12.5px var(--sans); padding: 2px 7px; white-space: nowrap; font-variant-numeric: tabular-nums; }
#bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.bub { position: absolute; width: 0; height: 0; pointer-events: auto; cursor: pointer; }
.bub .ph { position: absolute; left: -38px; top: -38px; width: 76px; height: 76px; border-radius: 50%; background: var(--ink); overflow: hidden; border: 2px solid var(--paper); transform: scale(.1); opacity: 0; transition: transform .34s var(--ease), opacity .15s; }
.bub.on .ph { transform: none; opacity: 1; }
.bub .ph img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .28s .24s; display: block; }
.bub.on .ph img { opacity: 1; }
.bub .cap { position: absolute; left: -62px; top: 42px; width: 124px; background: var(--paper); padding: 5px 7px; font: 700 12.5px/1.3 var(--sans); opacity: 0; transform: translateY(6px); transition: opacity .25s .28s, transform .25s .28s; word-break: keep-all; box-shadow: 0 3px 10px rgba(30, 22, 10, .16); }
.bub.on .cap { opacity: 1; transform: none; }
.bub .cap i { display: block; font: 500 11.5px var(--serif); opacity: .68; font-style: normal; }
.bub.up .cap { top: auto; bottom: 42px; }
#hover { position: absolute; width: 0; height: 0; pointer-events: none; z-index: 3; }
#hover .ph { position: absolute; left: -52px; top: -52px; width: 104px; height: 104px; border-radius: 50%; background: var(--ink); overflow: hidden; border: 3px solid var(--paper); animation: pop .24s var(--ease); box-shadow: 0 8px 22px rgba(30, 22, 10, .3); }
#hover .ph img { width: 100%; height: 100%; object-fit: cover; display: block; animation: fadein .2s .1s both; }
#hover .cap { position: absolute; left: -92px; top: 58px; width: 184px; background: var(--paper); padding: 7px 10px; font: 700 14px/1.32 var(--sans); box-shadow: 0 4px 14px rgba(30, 22, 10, .2); animation: fadein .18s .1s both; word-break: keep-all; }
#hover.up .cap { top: auto; bottom: 58px; }
#hover .cap i { display: block; font: 500 12.5px var(--serif); opacity: .7; font-style: normal; }
@keyframes pop { from { transform: scale(.2); } to { transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* 구간 막대 */
#rangebar { flex: 0 0 var(--rail); display: flex; align-items: center; gap: 10px; padding: 0 12px; background: rgba(28, 25, 21, .06); }
#play { flex: 0 0 38px; height: 38px; border-radius: 50%; background: var(--ink); position: relative; }
#play::after { content: ""; position: absolute; left: 15px; top: 11px; border-left: 12px solid var(--paper); border-top: 8px solid transparent; border-bottom: 8px solid transparent; }
#play.on::after { left: 13px; top: 12px; width: 12px; height: 14px; border: 0; border-left: 4px solid var(--paper); border-right: 4px solid var(--paper); }
#reset { flex: 0 0 auto; font: 700 14px var(--serif); padding: 8px 4px; min-height: 40px; }
#track { position: relative; flex: 1 1 auto; height: 40px; touch-action: none; cursor: grab; min-width: 0; }
#segs { position: absolute; inset: 0; display: flex; overflow: hidden; }
.seg { height: 100%; display: flex; align-items: center; justify-content: center; font: 700 13px var(--serif); overflow: hidden; white-space: nowrap; border-right: 1px solid rgba(28, 25, 21, .18); }
#sel { position: absolute; top: -3px; bottom: -3px; border: 2px solid var(--ink); background: rgba(255, 255, 255, .16); box-shadow: 0 0 0 100vmax rgba(28, 25, 21, .0); pointer-events: none; }
#sel .h { position: absolute; top: 0; bottom: 0; width: 5px; background: var(--ink); }
#sel .l { left: -2px; } #sel .r { right: -2px; }

/* 지도 */
#mapbox { position: relative; overflow: hidden; min-width: 0; }
#map, #mapc, #maplabels { position: absolute; inset: 0; width: 100%; height: 100%; }
#mapc, #maplabels { pointer-events: none; }
#map { touch-action: none; }
#land { fill: var(--land); transition: fill .7s ease; }
#rivers { fill: none; stroke: var(--sea); stroke-width: 1; vector-effect: non-scaling-stroke; transition: stroke .7s; }
.polity { font-family: var(--serif); font-weight: 900; fill: var(--ink); opacity: .22; text-anchor: middle; dominant-baseline: middle; letter-spacing: .1em; }
.place { fill: var(--ink); text-anchor: middle; }
.place.sea { font: 500 14px var(--serif); letter-spacing: .5em; opacity: .62; }
.place.river { font: 500 11px var(--serif); opacity: .4; }
.place.isle { font: 600 12px var(--sans); opacity: .68; }
.place-mark { fill: var(--ink); opacity: .75; }
#mini { position: absolute; right: 10px; bottom: 10px; width: 116px; pointer-events: none; }
#mini svg { display: block; width: 100%; background: rgba(251, 249, 243, .5); }
#mini-land { fill: rgba(28, 25, 21, .34); }
#mini-pin { fill: var(--accent); }
#mini span { position: absolute; left: 5px; top: 3px; font: 700 10.5px var(--sans); letter-spacing: .15em; opacity: .7; }
#link { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
#link-path { fill: none; stroke: var(--accent); stroke-width: 1.6; }

/* 카드 */
#disc { position: fixed; left: 0; top: 0; width: 100px; height: 100px; border-radius: 50%; background: var(--ink); z-index: 19; pointer-events: none; opacity: 0; background-size: cover; background-position: center; }
#scrim { position: fixed; inset: 0; background: rgba(28, 25, 21, .34); z-index: 18; animation: fadein .25s; }
#card { position: fixed; z-index: 20; left: 50%; top: 50%; width: min(1120px, calc(100vw - 48px)); height: min(720px, calc(100dvh - 40px)); margin-left: calc(min(1120px, calc(100vw - 48px)) / -2); margin-top: calc(min(720px, calc(100dvh - 40px)) / -2); background: var(--paper); box-shadow: 0 26px 70px rgba(25, 18, 8, .38); overflow: hidden; }
#card[hidden] { display: none; }
#card-x { position: absolute; right: 10px; top: 10px; z-index: 3; width: 44px; height: 44px; font-size: 26px; line-height: 1; color: #fff; background: rgba(28, 25, 21, .62); border-radius: 50%; }
#card-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: 100%; }
#c-left { overflow-y: auto; min-height: 0; border-right: 1px solid rgba(28, 25, 21, .12); }
#c-right { overflow-y: auto; min-height: 0; padding: 26px 28px 18px; background: #f3efe4; }
#c-fig { margin: 0; position: relative; height: 240px; overflow: hidden; background: var(--ink); }
#c-pic { position: absolute; inset: 0; }
#c-pic img { width: 100%; height: 100%; object-fit: cover; display: block; animation: ken 16s ease-out both; }
@keyframes ken { from { transform: scale(1.0); } to { transform: scale(1.09); } }
.poster { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font: 900 76px var(--serif); color: var(--ink); background: var(--sea); background-image: radial-gradient(rgba(28, 25, 21, .34) 2px, transparent 2.6px); background-size: 15px 15px; animation: drift 22s linear infinite; font-variant-numeric: tabular-nums; }
@keyframes drift { to { background-position: 150px 75px; } }
#c-credit { position: absolute; right: 0; bottom: 0; max-width: 100%; font-size: 11px; color: #fff; background: rgba(0, 0, 0, .55); padding: 2px 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#c-credit a { color: inherit; }
#c-credit:empty { display: none; }
#c-head { padding: 18px 26px 0; }
#c-date { font: 500 18px var(--serif); color: var(--accent); font-variant-numeric: tabular-nums; }
#c-name { margin: 4px 0 6px; font: 900 29px/1.24 var(--serif); word-break: keep-all; overflow-wrap: anywhere; }
#c-place { font-size: 14.5px; opacity: .72; }
#c-desc { font-size: 16.5px; line-height: 1.68; margin: 10px 26px 12px; word-break: keep-all; overflow-wrap: anywhere; min-height: 28px; }
#tabs { display: flex; gap: 2px; padding: 0 26px; }
#tabs button { flex: 1; min-height: 44px; font: 700 15.5px var(--serif); border-bottom: 2px solid rgba(28, 25, 21, .2); }
#tabs button[aria-selected="true"] { border-bottom: 3px solid var(--accent); font-weight: 900; }
#tab-panel { padding: 14px 26px 20px; }
.yt-main { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; text-decoration: none; }
.yt-main:hover { filter: brightness(.86); }
.yt-sub { display: flex; gap: 8px; margin-top: 8px; }
.yt-sub a { flex: 1; text-align: center; padding: 10px 0; border: 1px solid rgba(28, 25, 21, .25); color: inherit; text-decoration: none; font-size: 14.5px; font-weight: 600; min-height: 44px; }
.yt-note { font-size: 13px; opacity: .68; margin: 9px 0 0; line-height: 1.5; }
.dict a { display: flex; justify-content: space-between; align-items: center; min-height: 46px; border-bottom: 1px solid rgba(28, 25, 21, .14); color: inherit; text-decoration: none; font-weight: 700; font-size: 15.5px; }
.dict a span { font-weight: 400; font-size: 13.5px; opacity: .66; }
.ask { display: flex; flex-direction: column; gap: 8px; }
.ask button { text-align: left; border: 1px solid rgba(28, 25, 21, .22); padding: 10px 12px; min-height: 50px; }
.ask b { display: block; font-size: 15px; }
.ask span { font-size: 13.5px; opacity: .72; line-height: 1.45; display: block; margin-top: 2px; }
.ask button.done { border-color: var(--accent); }
.ask-note { font-size: 13px; opacity: .68; margin: 2px 0 0; line-height: 1.5; }
#c-right h3 { font: 900 19px var(--serif); margin: 0 0 10px; }
#mm { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr) minmax(0, 1fr); gap: 44px; align-items: center; min-height: 210px; }
#mm svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#mm path { fill: none; stroke: var(--accent); stroke-width: 1.8; opacity: .85; }
#mm path.dash { stroke: var(--ink); stroke-dasharray: 3 4; opacity: .55; }
#mm path.draw { animation: drawline .5s .25s var(--ease) both; }
@keyframes drawline { from { stroke-dashoffset: 300; stroke-dasharray: 300; } to { stroke-dashoffset: 0; stroke-dasharray: 300; } }
.mm-col { display: flex; flex-direction: column; gap: 10px; position: relative; z-index: 1; }
.mm-node { display: flex; align-items: center; gap: 7px; text-align: left; background: var(--paper); padding: 5px 7px 5px 5px; min-height: 44px; box-shadow: 0 2px 6px rgba(30, 22, 10, .1); animation: nodein .34s var(--ease) both; }
@keyframes nodein { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: none; } }
.mm-node .th { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%; background: var(--ink); overflow: hidden; }
.mm-node .th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mm-node b { display: block; font-size: 13.5px; line-height: 1.26; word-break: keep-all; }
.mm-node small { display: block; font-size: 12px; opacity: .68; line-height: 1.3; font-variant-numeric: tabular-nums; }
.mm-center { background: var(--ink); color: var(--paper); padding: 12px 10px; text-align: center; font: 900 15.5px/1.3 var(--serif); position: relative; z-index: 1; word-break: keep-all; }
.mm-center small { display: block; font: 500 12.5px var(--serif); opacity: .75; margin-top: 3px; }
.mm-label { font: 500 12.5px/1.4 var(--sans); opacity: .78; }
#mm-note { font-size: 13px; opacity: .68; margin: 10px 0 16px; line-height: 1.5; }
.same-row { display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left; padding: 9px 0; border-top: 1px solid rgba(28, 25, 21, .13); min-height: 42px; }
.same-row span { flex: 0 0 auto; font: 500 13.5px var(--serif); color: var(--accent); font-variant-numeric: tabular-nums; }
.same-row b { font-size: 14.5px; line-height: 1.35; word-break: keep-all; }
.same-row small { display: block; font-weight: 400; font-size: 13px; opacity: .7; margin-top: 2px; }
#same-h { margin-top: 2px !important; }
#c-nav { display: flex; justify-content: space-between; margin-top: 14px; font-size: 14px; }
#c-nav button { padding: 8px 0; opacity: .72; min-height: 40px; }
.rise { opacity: 0; transform: translateY(12px); }
#card.open .rise { opacity: 1; transform: none; transition: opacity .34s, transform .42s var(--ease); }
#card.open #c-date { transition-delay: .1s; } #card.open #c-name { transition-delay: .14s; letter-spacing: 0; }
#c-name { letter-spacing: .16em; transition: letter-spacing .55s var(--ease), opacity .34s, transform .42s var(--ease); }
#card.open #c-place { transition-delay: .18s; } #card.open #c-desc { transition-delay: .22s; }
#card.open #tabs { transition-delay: .26s; } #card.open #tab-panel { transition-delay: .3s; }
#card.open #c-right h3 { transition-delay: .2s; } #card.open #mm { transition-delay: .26s; }
#card.open #mm-note, #card.open #same, #card.open #c-nav { transition-delay: .32s; }

#intro { position: fixed; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#intro[hidden] { display: none; }
#intro p { font: 900 clamp(32px, 5vw, 64px)/1.3 var(--serif); text-align: center; margin: 0; animation: introfade 4.4s ease forwards; color: var(--ink); text-shadow: 0 0 16px var(--sea), 0 0 6px var(--sea), 0 0 2px var(--sea); }
#intro-skip { position: absolute; right: 24px; bottom: 74px; pointer-events: auto; font-size: 14px; font-weight: 700; padding: 10px 4px; border-bottom: 1px solid; }
@keyframes introfade { 0% { opacity: 0; } 14%, 76% { opacity: 1; } 100% { opacity: 0; } }

dialog#about { border: 0; padding: 34px 34px 28px; max-width: 540px; width: calc(100% - 32px); background: var(--paper); color: var(--ink); line-height: 1.7; font-size: 16px; }
dialog#about::backdrop { background: rgba(28, 25, 21, .5); }
#about h2 { font: 900 28px var(--serif); margin: 0 0 12px; }
#about h3 { font: 700 18px var(--serif); margin: 18px 0 4px; }
#about p { margin: 0 0 8px; word-break: keep-all; }
#about .foot { font-size: 13.5px; opacity: .7; margin-top: 16px; }
#about a { color: inherit; }
#about-x { position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; font-size: 26px; opacity: .6; }

@media (max-width: 860px), (max-height: 520px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 34fr) minmax(0, 40fr); }
  #side { flex-direction: row; flex-wrap: wrap; align-items: baseline; position: relative; padding: calc(10px + env(safe-area-inset-top)) 14px 8px; column-gap: 10px; row-gap: 4px; grid-row: 1; }
  #brand { display: none; }
  #title { font-size: 25px; margin: 0; min-height: 0; flex: 0 0 auto; }
  #span { font-size: 13.5px; border: 0; padding: 0 104px 0 0; flex: 1 1 0; min-width: 0; }
  #cats { flex: 1 0 100%; display: flex; gap: 14px; overflow-x: auto; margin: 0; }
  #cats button { width: auto; border: 0; gap: 4px; padding: 3px 0; font-size: 14px; white-space: nowrap; min-height: 34px; align-items: center; }
  #side-foot { position: absolute; right: 12px; top: calc(8px + env(safe-area-inset-top)); flex-direction: row; gap: 12px; padding: 0; font-size: 13px; }
  #lucky { display: none; }
  #mapbox { grid-row: 2; }
  #main { grid-row: 3; }
  #mini { width: 82px; right: 6px; bottom: 6px; }
  #rangebar { flex-basis: calc(52px + env(safe-area-inset-bottom)); padding: 0 8px env(safe-area-inset-bottom); gap: 6px; }
  .seg { font-size: 11.5px; }
  #reset { font-size: 13px; }
  .bub .ph { left: -28px; top: -28px; width: 56px; height: 56px; }
  .bub .cap { left: -46px; top: 31px; width: 92px; font-size: 12px; padding: 3px 5px; }
  .bub.up .cap { bottom: 31px; }
  #card { left: 0; top: 0; margin: 0; width: 100%; height: 100dvh; }
  #card-body { display: block; overflow-y: auto; height: 100%; }
  #c-left, #c-right { overflow: visible; border: 0; }
  #c-fig { height: 30dvh; min-height: 170px; }
  #c-head { padding: 14px 18px 0; }
  #c-name { font-size: 25px; }
  #c-desc { margin: 10px 18px 12px; font-size: 16px; }
  #tabs, #tab-panel { padding-left: 18px; padding-right: 18px; }
  #c-right { padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); }
  #mm { grid-template-columns: 1fr; gap: 24px; min-height: 0; }
  .mm-center { padding: 10px; }
}
@media (max-height: 520px) and (min-width: 561px) {
  #app { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #side { grid-column: 1 / 3; padding-top: 6px; padding-bottom: 4px; }
  #cats { flex: 0 1 auto; order: 3; }
  #cats { max-width: calc(100% - 330px); }
  #span { padding-right: 0; flex: 0 1 auto; }
  #mapbox { grid-row: 2; grid-column: 2; }
  #main { grid-row: 2; grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html, body, #land, #rivers { transition: none; }
  .bub .ph, .bub .ph img, .bub .cap, #hover .ph, #hover .ph img, #hover .cap, .poster, #c-pic img, #scrim, .mm-node, #mm path.draw, #intro p, .rise, #c-name { animation: none !important; transition: none !important; }
}
