/* Nam Quốc Sơn Hà — giấy dó, mực nho, son đỏ. */
:root {
  --paper: #f1e7d0;
  --paper-2: #e9dcbf;
  --paper-3: #dccba6;
  --ink: #2a2018;
  --ink-2: #5b4c3c;
  --ink-3: #8a7a64;
  --son: #b3261e;
  --son-2: #7d1711;
  --gold: #a47a1f;
  --indigo: #33508f;
  --line: rgba(42, 32, 24, .28);
  --serif: "Noto Serif", "Source Serif 4", "Palatino Linotype", "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tlh: 88px;
  --pw: 400px;
  --shadow: 0 1px 0 rgba(255, 250, 235, .7) inset, 0 6px 22px rgba(60, 40, 15, .22);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--paper); color: var(--ink); font: 15px/1.55 var(--serif); -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; text-align: inherit; }
button:focus-visible, input:focus-visible, #tl-track:focus-visible { outline: 2px solid var(--son); outline-offset: 2px; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#map.dragging { cursor: grabbing; }
#grain { position: fixed; inset: 0; pointer-events: none; mix-blend-mode: multiply; opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55  0 0 0 0 .45  0 0 0 0 .3  0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E"); }

/* khung giấy dùng chung: viền đôi kiểu tranh khắc gỗ */
.sheet, #panel, #timeline, #legend, #results, #layers, #brand, #tools, #zoom, #q {
  background: linear-gradient(180deg, rgba(246, 238, 219, .96), rgba(238, 227, 200, .96));
  border: 1px solid var(--ink-2);
  box-shadow: var(--shadow);
  border-radius: 3px;
}

/* ---------------------------------------------------------------- đầu trang */
#top { position: fixed; top: 10px; left: 12px; right: calc(var(--pw) + 26px); display: flex; gap: 10px; align-items: flex-start; pointer-events: none; z-index: 5; transition: right .25s; }
.panel-closed #top { right: 12px; }
#top > * { pointer-events: auto; }
#brand { display: flex; align-items: center; gap: 10px; padding: 5px 14px 5px 8px; color: var(--son); flex: none; outline-offset: -4px; }
#brand svg { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 19px; letter-spacing: .04em; color: var(--son-2); font-weight: 700; }
.brand-text i { font-size: 11.5px; color: var(--ink-2); font-style: italic; }
#search { position: relative; flex: 1 1 260px; max-width: 380px; min-width: 0; }
#q { width: 100%; height: 52px; padding: 0 14px; font-size: 15px; -webkit-appearance: none; appearance: none; }
#q::placeholder { color: var(--ink-3); font-style: italic; }
#results { position: absolute; top: 58px; left: 0; right: 0; max-height: min(70vh, 520px); overflow: auto; padding: 6px; z-index: 9; }
.res { display: grid; grid-template-columns: 74px 1fr; column-gap: 8px; width: 100%; padding: 6px 8px; border-radius: 2px; align-items: baseline; }
.res em { grid-row: span 2; font: 600 10.5px/1.6 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--gold); font-style: normal; }
.res b { font-weight: 600; }
.res small { color: var(--ink-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res.on, .res:hover { background: rgba(179, 38, 30, .1); }
#results .none, .sg-title { margin: 6px 8px; color: var(--ink-2); font-size: 13px; }
.sg { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 8px 8px; }
.sg button, .chip { padding: 2px 10px; border: 1px solid var(--line); border-radius: 20px; font-size: 13px; background: rgba(255, 252, 240, .5); }
.sg button:hover, .chip:hover { border-color: var(--son); color: var(--son-2); }
.chip.on { background: var(--son); border-color: var(--son); color: #fff; }
#tools { display: flex; margin-left: auto; flex: none; padding: 0; overflow: hidden; }
#tools button { height: 50px; padding: 0 14px; font-size: 14px; border-left: 1px solid var(--line); }
#tools button:first-child { border-left: 0; }
#tools button:hover { background: rgba(179, 38, 30, .1); color: var(--son-2); }
#layers { position: fixed; top: 70px; right: calc(var(--pw) + 26px); z-index: 8; padding: 10px 14px; display: flex; flex-direction: column; gap: 5px; font-size: 14px; }
.panel-closed #layers { right: 12px; }
#layers label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
#layers input { accent-color: var(--son); }
#layers .sep { height: 1px; background: var(--line); margin: 4px 0; }
#zoom { position: fixed; left: 12px; top: 76px; display: flex; flex-direction: column; z-index: 4; overflow: hidden; }
#zoom button { width: 34px; height: 32px; text-align: center; font: 18px/1 var(--sans); border-top: 1px solid var(--line); }
#zoom button:first-child { border-top: 0; }
#zoom button:hover { background: rgba(179, 38, 30, .1); }

/* ---------------------------------------------------------------- bảng thông tin */
#panel { position: fixed; top: 10px; right: 12px; bottom: calc(var(--tlh) + 22px); width: var(--pw); z-index: 6; transition: transform .25s; outline: 1px solid var(--ink-2); outline-offset: -5px; }
.panel-closed #panel { transform: translateX(calc(100% + 14px)); }
#panel-toggle { position: absolute; left: -23px; top: 22px; width: 22px; height: 46px; background: var(--paper-2); border: 1px solid var(--ink-2); border-right: 0; border-radius: 3px 0 0 3px; }
#panel-toggle::before { content: "›"; display: block; text-align: center; font: 18px/1 var(--sans); color: var(--ink-2); }
.panel-closed #panel-toggle::before { content: "‹"; }
#panel-body { height: 100%; overflow-y: auto; padding: 18px 22px 26px; scrollbar-width: thin; scrollbar-color: var(--paper-3) transparent; overscroll-behavior: contain; }
#panel h2 { margin: 2px 0 6px; font-size: 25px; line-height: 1.2; color: var(--son-2); font-weight: 700; letter-spacing: .01em; }
#panel h2 .sw { display: inline-block; width: 18px; height: 18px; margin-right: 8px; border: 1px solid; vertical-align: -2px; }
#panel h3 { margin: 22px 0 8px; font: 700 11.5px/1.3 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); display: flex; align-items: center; gap: 10px; }
#panel h3::after { content: ""; flex: 1; height: 3px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#panel h4 { margin: 0 0 4px; font-size: 16.5px; line-height: 1.3; }
#panel h4 small { font-weight: 400; color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
#panel p { margin: 0 0 10px; }
.kicker { font: 600 11px/1.4 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--gold); margin: 0 0 2px !important; }
.lead { font-size: 15.5px; }
.aka { color: var(--ink-2); font-style: italic; font-size: 14px; margin-top: -2px !important; }
.hint, .coord { color: var(--ink-3); font-size: 12.5px; }
.coord { margin-top: 18px !important; }
.back { font: 13px var(--sans); color: var(--ink-2); margin: -6px 0 10px -4px; padding: 2px 4px; display: block; }
.back:hover, .lk:hover { color: var(--son); }
.lk { color: var(--son-2); text-decoration: underline; text-decoration-color: rgba(179, 38, 30, .35); text-underline-offset: 3px; font-size: 14px; }
.btn { display: inline-block; padding: 7px 16px; background: var(--son); color: #fff8ea; border-radius: 2px; font-weight: 600; letter-spacing: .02em; box-shadow: 0 2px 0 var(--son-2); }
.btn:hover { background: var(--son-2); }
.btn:disabled { background: var(--ink-3); box-shadow: none; cursor: not-allowed; opacity: .6; }
.yb { color: var(--son-2); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 2px; }
blockquote { margin: 10px 0; padding: 4px 0 4px 14px; border-left: 3px double var(--son); font-style: italic; color: #4a2a1a; }
.clue { font-size: 17px; }
.score b { font-size: 26px; color: var(--son); }

ol.events, ol.names, ol.land, ol.stops, ul.rulers, ul.help { list-style: none; margin: 0; padding: 0; }
.events li, .names li, .land li { border-bottom: 1px dotted var(--line); }
.events li > button, .names li > button, .land li > button { display: flex; gap: 10px; width: 100%; padding: 4px 4px; align-items: baseline; }
.events li > button:hover, .names li > button:hover, .land li > button:hover { background: rgba(179, 38, 30, .07); }
.events time, .names time, .land time { flex: none; width: 76px; font: 600 12.5px/1.6 var(--sans); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.land time { width: 118px; font-weight: 500; font-size: 12px; }
.events li.major > button span { font-weight: 600; }
.events li.on > button, .names li.on > button, .land li.on > button { background: rgba(179, 38, 30, .12); }
.events li.on time, .names li.on time, .land li.on time { color: var(--son); }
.events li > p { margin: 2px 4px 8px 90px !important; font-size: 14px; color: #3d2f22; }
.land i, .sym i, .lg i { flex: none; display: inline-block; width: 14px; height: 14px; border: 1px solid; align-self: center; }
.land small { color: var(--ink-2); }
.rulers li { padding: 5px 0 6px; border-bottom: 1px dotted var(--line); }
.rulers b { display: block; }
.rulers .meta { display: block; font: 12.5px var(--sans); color: var(--ink-2); }
.rulers .note { display: block; font-size: 14px; font-style: italic; color: #4a3a2a; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card { padding: 8px 10px; border: 1px solid var(--line); border-radius: 2px; background: rgba(255, 252, 240, .45); display: flex; flex-direction: column; line-height: 1.3; }
.card:hover { border-color: var(--son); background: rgba(179, 38, 30, .06); }
.card em { font: 600 10.5px/1.5 var(--sans); letter-spacing: .05em; text-transform: uppercase; color: var(--gold); font-style: normal; }
.card b { color: var(--son-2); font-size: 15px; }
.card small { color: var(--ink-2); font-size: 12.5px; }
.help li { margin: 0 0 7px; padding-left: 14px; position: relative; font-size: 14.5px; }
.help li::before { content: "❖"; position: absolute; left: -2px; top: 2px; font-size: 9px; color: var(--son); }
.help.sym li { display: flex; gap: 10px; align-items: center; padding-left: 0; }
.help.sym li::before { content: none; }
.ghost { width: 22px; border-top: 2px dashed var(--son); flex: none; }
kbd { font: 12px var(--sans); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; background: rgba(255, 252, 240, .7); }
.sides { display: flex; flex-wrap: wrap; gap: 4px 14px; font: 13px var(--sans); color: var(--ink-2); }
.sides i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.stepper { position: sticky; top: -18px; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 10px 22px 8px; margin: 8px -22px 4px; background: #f2e9d3; border-bottom: 1px solid var(--line); font: 14px var(--sans); }
.stepper button { min-width: 34px; height: 32px; text-align: center; border: 1px solid var(--ink-2); border-radius: 2px; background: rgba(255, 252, 240, .6); }
.stepper button:hover:not(:disabled) { background: var(--son); border-color: var(--son); color: #fff; }
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper .wide { margin-left: auto; padding: 0 12px; }
.stops li { position: relative; padding-left: 0; }
.stops li::before { content: ""; position: absolute; left: 12px; top: 26px; bottom: -6px; width: 0; border-left: 1px dashed var(--line); }
.stops li:last-child::before { content: none; }
.stops li > button { display: flex; gap: 10px; width: 100%; padding: 5px 2px; align-items: flex-start; }
.stops li > button:hover { background: rgba(179, 38, 30, .06); }
.stops i { flex: none; width: 25px; height: 25px; border-radius: 50%; border: 1.5px solid var(--c); color: var(--c); font: 700 12px/22px var(--sans); text-align: center; background: var(--paper); position: relative; z-index: 1; font-style: normal; opacity: .55; }
.stops li.done i { opacity: 1; }
.stops li.on i { opacity: 1; background: var(--c); color: #fff; }
.stops time { flex: none; width: 62px; font: 600 12.5px/25px var(--sans); color: var(--ink-2); }
.stops span { display: flex; flex-direction: column; line-height: 1.3; padding-top: 3px; }
.stops small { color: var(--ink-3); font-size: 12.5px; }
.stops li.on b { color: var(--son-2); }
.stop-body { margin: 2px 0 10px 35px; font-size: 14.5px; }

/* ---------------------------------------------------------------- chú giải */
#legend { position: fixed; left: 12px; bottom: calc(var(--tlh) + 22px); z-index: 4; max-width: 268px; padding: 4px 6px 6px; }
.lg-head { display: block; width: 100%; font: 700 10.5px/1.9 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); padding: 0 4px; }
.lg-head::after { content: " ▾"; }
#legend.collapsed .lg-head::after { content: " ▸"; }
#legend.collapsed .lg-items { display: none; }
.lg { display: flex; gap: 8px; align-items: center; width: 100%; padding: 2px 4px; font-size: 13px; line-height: 1.3; border-radius: 2px; }
.lg:hover { background: rgba(179, 38, 30, .1); }

/* ---------------------------------------------------------------- thanh thời gian */
#timeline { position: fixed; left: 12px; right: 12px; bottom: 10px; height: var(--tlh); z-index: 7; display: flex; align-items: flex-end; gap: 12px; padding: 0 14px 10px 10px; }
#tl-controls { display: flex; gap: 4px; flex: none; padding-bottom: 1px; }
#tl-controls button { width: 34px; height: 34px; text-align: center; border: 1px solid var(--ink-2); border-radius: 50%; font: 16px/1 var(--sans); background: rgba(255, 252, 240, .6); }
#tl-controls button:hover, #tl-controls button.on { background: var(--son); border-color: var(--son); color: #fff; }
#btn-speak svg { display: block; margin: auto; }
#tl-track { position: relative; flex: 1; height: 36px; cursor: ew-resize; touch-action: none; user-select: none; -webkit-user-select: none; }
#tl-eras { display: flex; height: 100%; border: 1px solid var(--ink-2); border-radius: 2px; overflow: hidden; }
.era { position: relative; height: 100%; border-left: 1px solid rgba(42, 32, 24, .35); background: color-mix(in srgb, var(--c) 30%, #f1e7d0); overflow: hidden; min-width: 0; }
.era:first-child { border-left: 0; }
.era span { position: absolute; left: 0; right: 0; bottom: 2px; padding: 0 3px; font: 10.5px/1.2 var(--sans); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: clip; color: rgba(42, 32, 24, .85); }
.era.on { background: color-mix(in srgb, var(--c) 62%, #f1e7d0); }
.era.on span { font-weight: 700; color: #1d140d; }
.era.tight span { visibility: hidden; }
#tl-ticks { position: absolute; inset: 0; pointer-events: none; }
#tl-ticks i { position: absolute; top: 1px; }
#tl-ticks .ph { width: 1px; height: 9px; background: rgba(42, 32, 24, .75); }
#tl-ticks .ev { width: 4px; height: 4px; margin-left: -2px; top: 12px; border-radius: 50%; background: var(--son); opacity: .7; }
#tl-cursor { position: absolute; top: -7px; bottom: -6px; width: 0; border-left: 2px solid var(--son); pointer-events: none; }
#tl-cursor::after { content: ""; position: absolute; left: -7px; bottom: -4px; width: 12px; height: 12px; background: var(--son); border-radius: 50%; border: 2px solid var(--paper); }
#tl-bubble { position: absolute; bottom: calc(100% + 3px); left: 0; transform: translateX(-50%); display: flex; gap: 10px; align-items: baseline; white-space: nowrap; padding: 1px 12px 2px; background: var(--paper); border: 1px solid var(--son); border-radius: 2px; font-size: 13.5px; box-shadow: 0 2px 8px rgba(60, 40, 15, .2); }
#tl-bubble b { font-size: 18px; color: var(--son-2); font-variant-numeric: tabular-nums; }
#tl-bubble span + span { padding-left: 10px; border-left: 1px solid var(--line); }
#tl-bubble em { color: var(--ink-2); }

/* ---------------------------------------------------------------- chú thích nổi */
#tooltip { position: fixed; z-index: 20; pointer-events: none; max-width: 280px; padding: 5px 10px; background: rgba(42, 32, 24, .93); color: #f6ecd6; border-radius: 3px; font-size: 13px; line-height: 1.35; }
#tooltip b { display: block; font-size: 14px; color: #fff; }
#tooltip span { display: block; color: #d9c9a8; }
#toast { position: fixed; z-index: 15; left: 50%; top: 78px; transform: translateX(-50%); max-width: min(560px, 86vw); padding: 7px 18px; background: var(--paper); border: 1px solid var(--son); border-top-width: 3px; box-shadow: var(--shadow); font-size: 16px; text-align: center; animation: drop .25s ease-out; }
#toast b { color: var(--son); margin-right: 6px; }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -8px); } }
#embed-link { position: fixed; top: 8px; right: 8px; z-index: 9; padding: 3px 10px; background: var(--paper); border: 1px solid var(--ink-2); border-radius: 2px; font: 12.5px var(--sans); color: var(--son-2); text-decoration: none; }

/* ---------------------------------------------------------------- chế độ nhúng */
.embed #top, .embed #panel, .embed #zoom, .embed #legend { display: none; }
.embed { --tlh: 70px; }

/* ---------------------------------------------------------------- màn hình hẹp */
@media (max-width: 1100px) { :root { --pw: 350px; } .brand-text i { display: none; } }
@media (max-width: 759px) {
  :root { --tlh: 78px; }
  html, body { font-size: 14.5px; }
  #top { left: 6px; right: 6px !important; top: 6px; flex-wrap: wrap; gap: 6px; }
  #brand { padding: 2px 7px 2px 4px; gap: 5px; height: 36px; }
  #brand svg { width: 24px; height: 24px; }
  .brand-text b { font-size: 13.5px; letter-spacing: 0; white-space: nowrap; }
  #tools { margin-left: auto; }
  #tools button { height: 34px; padding: 0 6px; font-size: 12px; white-space: nowrap; }
  #search { order: 3; flex-basis: 100%; max-width: none; }
  #q { height: 40px; }
  #results { top: 44px; }
  #layers { top: 52px; right: 6px !important; }
  #zoom { display: none; }
  #panel { top: auto; left: 6px; right: 6px; width: auto; height: 42vh; bottom: calc(var(--tlh) + 14px); transition: height .25s; }
  .panel-closed #panel { transform: none; height: 34px; overflow: hidden; }
  #panel-toggle { left: 50%; top: 0; margin-left: -40px; width: 80px; height: 20px; border: 0; background: none; z-index: 3; }
  #panel-toggle::before { content: ""; width: 44px; height: 4px; margin: 8px auto; border-radius: 3px; background: var(--ink-3); }
  .panel-closed #panel-toggle::before { content: ""; }
  #panel-body { padding: 22px 14px 18px; }
  #panel h2 { font-size: 21px; }
  .stepper { top: -22px; padding: 22px 14px 8px; margin: 0 -14px 4px; }
  #legend { left: 6px; top: 92px; bottom: auto; max-width: 62vw; max-height: 34vh; overflow: auto; }
  #timeline { left: 6px; right: 6px; bottom: 6px; padding: 0 8px 8px 6px; gap: 6px; }
  #tl-controls button { width: 30px; height: 30px; }
  #btn-speak { display: none; }
  .era span { display: none; }
  #tl-bubble { font-size: 12.5px; gap: 6px; padding: 0 8px 1px; }
  #tl-bubble b { font-size: 15px; }
  #tl-bubble span + span { padding-left: 6px; }
  #tl-bubble span:nth-of-type(2) em { display: none; }
  #toast { top: 100px; font-size: 14px; }
  .cards { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { #top, #panel, #timeline, #zoom, #legend, #grain { display: none !important; } }
