/* ===== Lore: underlined words, hover cards, encyclopedia ===== */
.lk { cursor: help; padding-bottom: 2px; border-radius: 3px 3px 0 0; text-decoration: none; transition: background-color .15s;
  background-color: var(--lkbg, rgba(255, 200, 87, .17));
  background-image: repeating-linear-gradient(90deg, var(--lk, #ffc857) 0 11px, transparent 11px 16px);
  background-size: 100% 3.5px; background-position: 0 100%; background-repeat: no-repeat; }
.lk:hover, .lk:focus-visible { background-color: var(--lkhover, rgba(255, 200, 87, .38)); background-image: linear-gradient(var(--lk, #ffc857), var(--lk, #ffc857)); outline: none; }
.th-erin, .th-narrator, .th-goblin, .th-pisces, .th-magnolia, .pagein, .lp, .enc { --lk: #8f4a0a; --lkbg: rgba(150, 85, 15, .14); --lkhover: rgba(200, 120, 20, .3); }
.th-ryoka { --lk: #ffc857; }
body.no-lore .lk { background: none !important; cursor: inherit; pointer-events: none; }

/* ---------- hover cards ---------- */
#lore-layer { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
.lp { position: fixed; pointer-events: auto; width: min(24.8em, 92vw); color: #2b1a0d; font: 500 clamp(16.5px, 1.2vw, 27px)/1.45 'EB Garamond', serif;
  border: 1.33em solid transparent; border-image: url(../img/ui/lore/card.webp) 27% 12% fill / 2.3em 2.67em stretch; padding: .12em .85em .36em;
  filter: drop-shadow(0 14px 30px rgba(0, 0, 0, .65)); opacity: 0; transform: translateY(6px) scale(.98); transition: opacity .16s, transform .16s; user-select: text; -webkit-user-select: text; }
.lp.in { opacity: 1; transform: none; }
.lp-head { display: flex; align-items: center; gap: .6em; padding: 0 3.9em .25em 0; position: relative; min-height: 2.8em; }
.lp-ico { width: 2.67em; height: 2.67em; flex: none; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5)); }
.lp-title h3 { margin: 0; font: 700 1.27em 'Caudex', serif; letter-spacing: .08em; text-transform: uppercase; color: #3b2210; line-height: 1.1; }
.lp-tag { margin-top: .12em; font: 700 .64em 'Cormorant UC', serif; letter-spacing: .16em; text-transform: uppercase; color: #7a4a17; }
.lp-body { border-top: 1px solid rgba(90, 60, 28, .45); padding-top: 7px; }
.lp-sum { margin: 0 0 6px; }
.lp ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lp li { display: flex; align-items: flex-start; gap: .5em; padding-left: .9em; position: relative; font-size: .92em; }
.lp li::before { content: '◆'; position: absolute; left: 0; top: .25em; font-size: 8px; color: #8a5a20; }
.lp li .tx { flex: 1; }
.chtab { flex: none; align-self: flex-start; margin-left: .3em; display: inline-block; background: url(../img/ui/lore/tab.webp) center / 100% 100% no-repeat; color: #f6e3b0 !important; font: 700 .72em/1 'EB Garamond', serif; letter-spacing: .04em; padding: .45em 1em; text-decoration: none; border: 0; border-radius: 3px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .4)); vertical-align: 2px; transition: filter .15s; text-shadow: 0 1px 1px rgba(0, 0, 0, .5); }
.chtab:hover { filter: drop-shadow(0 0 5px rgba(255, 190, 80, .9)) brightness(1.15); }
.chtab.flat { background: none; color: #7a4a17 !important; padding: 0; text-decoration: underline; filter: none; font-size: inherit; text-shadow: none; }
.lp-foot { display: flex; align-items: center; justify-content: space-between; gap: .6em; margin-top: .5em; padding-top: .35em; border-top: 1px solid rgba(90, 60, 28, .45); font-size: .86em; }
.lp-foot button, .lp-foot a { background: none; border: 0; padding: 2px 4px; color: #6b3d0d; font: 500 1em 'EB Garamond', serif; text-decoration: underline dotted; cursor: pointer; }
.lp-foot button:hover, .lp-foot a:hover { color: #b25d00; text-decoration-style: solid; }
.lp-pin, .lp-x, .lp-back { display: none; position: absolute; top: -.35em; width: 1.85em; height: 1.85em; padding: 0; border-radius: 50%; border: 0; place-items: center; cursor: pointer; }
.lp-pin { right: 1.95em; background: radial-gradient(circle at 35% 30%, #d9a856, #7a4a17 70%); color: #2a1808; box-shadow: 0 0 0 2px #3b2210, 0 2px 4px rgba(0, 0, 0, .5); }
.lp-pin svg { width: 60%; height: 60%; fill: currentColor; transform: rotate(35deg); transition: transform .2s; }
.lp-pin.on { background: radial-gradient(circle at 35% 30%, #ffd27a, #b8791f 70%); box-shadow: 0 0 0 2px #3b2210, 0 0 12px rgba(255, 190, 80, .9); }
.lp-pin.on svg { transform: rotate(0); }
.lp-x { right: -2px; background: url(../img/ui/lore/close.webp) center / contain no-repeat; font-size: 0; }
.lp-back { left: -6px; top: 6px; width: 28px; height: 28px; background: rgba(60, 36, 14, .12); font: 700 22px/1 'Caudex', serif; color: #4a2f14; }
#lore-layer.alt .lp:not(.sheet) .lp-pin, .lp.pinned .lp-pin { display: grid; animation: pinpop .25s both; }
.lp.pinned .lp-x, .lp.sheet .lp-x { display: block; }
.lp.sheet .lp-back { display: grid; }
@keyframes pinpop { from { transform: scale(.4); opacity: 0; } }
.lp-notch { position: absolute; left: var(--notch, 50%); bottom: -15px; width: 16px; height: 16px; margin-left: -8px; background: #d3b06e; transform: rotate(45deg); border-right: 2px solid #4a2f14; border-bottom: 2px solid #4a2f14; z-index: -1; }
.lp.below .lp-notch { bottom: auto; top: -15px; transform: rotate(225deg); }
.lp.side .lp-notch, .lp.sheet .lp-notch, .lp.moved .lp-notch { display: none; }
/* touch: a bottom sheet */
.lp.sheet { left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; max-height: min(66vh, 560px); overflow: auto; transform: translateY(105%); transition: transform .24s cubic-bezier(.2, .8, .2, 1), opacity .2s; padding-bottom: env(safe-area-inset-bottom); font-size: 17.5px; scrollbar-width: none; }
.lp.sheet.in { transform: none; }
.lp.sheet li { font-size: 16.5px; }
.lp.sheet .lp-foot { flex-direction: column; align-items: stretch; gap: 8px; }
.lp.sheet .lp-foot button, .lp.sheet .lp-foot a { display: block; text-align: center; text-decoration: none; padding: 12px; background: var(--plaque) center / 100% 100% no-repeat; color: #2a190c; font-size: 17px; border-radius: 4px; }

/* ---------- encyclopedia ---------- */
.enc-overlay { position: fixed; inset: 0; z-index: 12; display: grid; place-items: center; background: rgba(4, 3, 2, .74); backdrop-filter: blur(7px); padding: clamp(6px, 3vh, 26px); animation: fade .2s; }
.enc { position: relative; zoom: var(--zoom, 1); width: min(1200px, calc(100vw / var(--zoom, 1) - 24px)); height: min(780px, calc(100dvh / var(--zoom, 1) - 90px)); margin-top: 40px; border: 20px solid transparent; border-image: var(--modal) 30% 8% / 64px 72px stretch; background: linear-gradient(#2c1c0f, #1b1109); background-clip: padding-box; box-shadow: 0 30px 80px rgba(0, 0, 0, .8); padding: 30px 12px 10px; color: #f3e3c3; }
.enc-title { position: absolute; top: -50px; left: 50%; transform: translateX(-50%); width: min(520px, 62%); aspect-ratio: 4 / 1; background: url(../img/ui/lore/header.webp) center / 100% 100% no-repeat; display: grid; place-items: center; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .6)); pointer-events: none; z-index: 3; }
.enc-title h2 { margin: 0; font: 700 clamp(20px, 3.4vw, 34px) 'Caudex', serif; color: #f6e0a6; letter-spacing: .06em; text-shadow: 0 2px 6px #000; }
.enc-x { position: absolute; top: -36px; right: -34px; width: 52px; height: 52px; border: 0; padding: 0; background: url(../img/ui/lore/close.webp) center / contain no-repeat; font-size: 0; cursor: pointer; filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .6)); transition: filter .15s, transform .15s; z-index: 2; }
.enc-x:hover { filter: drop-shadow(0 0 8px rgba(255, 190, 80, .9)); transform: scale(1.06); }
.enc-cols { display: grid; grid-template-columns: minmax(270px, 34%) 1fr; gap: 14px; height: 100%; min-height: 0; }
.enc-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; padding: 4px 2px; }
.enc-search { position: relative; display: block; height: 50px; background: url(../img/ui/lore/search.webp) center / 100% 100% no-repeat; flex: none; }
.enc-search .mag { position: absolute; left: 44px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: #6b4315; }
.enc-search input { position: absolute; inset: 8px 40px 8px 74px; width: calc(100% - 114px); background: transparent; border: 0; outline: 0; color: #2b1a0d; font: 500 18px 'EB Garamond', serif; }
.enc-search input::placeholder { color: rgba(60, 36, 14, .7); font-style: italic; }
.enc-tabs { display: flex; flex-wrap: wrap; gap: 5px; flex: none; }
.enc-tab { border: 0; background: url(../img/ui/lore/tab.webp) center / 100% 100% no-repeat; color: #f3dfae; font: 700 12.5px/1 'EB Garamond', serif; padding: 8px 12px; min-width: 52px; cursor: pointer; filter: brightness(.82) saturate(.9); transition: filter .15s; text-shadow: 0 1px 1px #000; }
.enc-tab:hover { filter: brightness(1.05); }
.enc-tab.on { filter: brightness(1.2) drop-shadow(0 0 6px rgba(255, 190, 80, .85)); }
.enc-list { flex: 1; overflow-y: auto; overflow-x: hidden; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 6px; padding: 2px 6px 6px 2px; scrollbar-width: thin; scrollbar-color: #7a4a17 #241509; }
.enc-row { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; min-height: 52px; min-width: 0; width: 100%; padding: 0 52px 0 26px; background: url(../img/ui/lore/row.webp) center / 100% 100% no-repeat; color: #2a190c; cursor: pointer; transition: filter .15s, transform .15s; flex: none; }
.enc-row:hover { filter: brightness(1.08); transform: translateX(2px); }
.enc-row.on { filter: brightness(1.12) drop-shadow(0 0 6px rgba(255, 176, 60, .95)); }
.enc-row .ico { width: 34px; height: 34px; flex: none; }
.enc-row .nm { flex: 1; min-width: 0; font: 500 18.5px 'EB Garamond', serif; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.enc-row .ty { flex: none; max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 9.5px 'Cormorant UC', serif; letter-spacing: .14em; text-transform: uppercase; color: #6d4514; }
.enc-empty { color: #d8c49c; font-style: italic; padding: 14px; }
.enc-right { position: relative; min-height: 0; display: flex; flex-direction: column; }
.enc-back { display: none; }
.enc-page { flex: 1; overflow: auto; color: #2c1a0b; padding: 24px 34px 12px; border-radius: 6px; scrollbar-width: thin; scrollbar-color: #8a5a20 transparent;
  background: radial-gradient(ellipse at 50% 0, rgba(255, 240, 200, .5), transparent 60%), linear-gradient(#e6cd98, #d6b678); box-shadow: inset 0 0 40px rgba(110, 70, 20, .45), inset 0 0 0 2px rgba(80, 50, 18, .5); user-select: text; -webkit-user-select: text; }
.enc-head { display: flex; gap: 22px; align-items: center; margin-bottom: 8px; }
.enc-portrait { flex: none; width: 128px; height: 128px; background: url(../img/ui/lore/portrait.webp) center / 100% 100% no-repeat; display: grid; place-items: center; }
.enc-portrait img { width: 56%; opacity: .9; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .4)); }
.enc-name { flex: 1; text-align: center; }
.enc-head.only .enc-name { text-align: left; }
.enc-name h3 { margin: 0; font: 700 clamp(28px, 4.4vw, 48px)/1.05 'Caudex', serif; letter-spacing: .04em; background: linear-gradient(#e9b64d, #8a5514); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 2px 0 rgba(255, 240, 200, .5)); }
.enc-tag { margin-top: 8px; font: 700 12.5px 'Cormorant UC', serif; letter-spacing: .3em; text-transform: uppercase; color: #6b4210; display: flex; justify-content: center; gap: .4em; align-items: center; }
.enc-head.only .enc-tag { justify-content: flex-start; }
.enc-lead { font: italic 500 19px/1.5 'EB Garamond', serif; margin: 12px 0 6px; }
.enc-sec { margin-top: 14px; }
.enc-sec h4 { display: flex; align-items: center; gap: 12px; margin: 0 0 6px; font: 700 15px 'Cormorant UC', serif; letter-spacing: .2em; text-transform: uppercase; color: #5b3510; }
.enc-sec h4::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(90, 55, 15, .7), transparent); }
.enc-sec ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.enc-sec li { display: flex; gap: 12px; align-items: flex-start; padding-left: 16px; position: relative; font: 500 18px/1.45 'EB Garamond', serif; }
.enc-sec li::before { content: '•'; position: absolute; left: 2px; color: #7a4a17; }
.enc-sec li .tx { flex: 1; }
.enc-prev { border: 0; background: none; color: #6b3d0d; font: 600 15px 'EB Garamond', serif; padding: 2px 0; cursor: pointer; text-decoration: underline dotted; }
.enc-note { margin: 22px 0 4px; padding-top: 8px; text-align: right; font: italic 500 14px 'EB Garamond', serif; color: #6b4a26; border-top: 1px solid rgba(90, 55, 15, .35); }

@media (max-width: 860px), (max-aspect-ratio: 1/1) {
  .enc-overlay { padding: 0; place-items: stretch; grid-template-columns: minmax(0, 1fr); }
  .enc { zoom: 1; width: 100%; min-width: 0; max-width: 100vw; height: 100dvh; margin-top: 0; border-width: 12px; border-image-width: 40px 46px; padding: 46px 6px 6px; }
  .enc-title { top: -6px; width: min(300px, 62%); }
  .enc-x { top: -2px; right: 2px; width: 44px; height: 44px; }
  .enc-cols { grid-template-columns: minmax(0, 1fr); }
  .enc-right { display: none; }
  .enc-side { display: flex; }
  .enc-overlay.view-entry .enc-side { display: none; }
  .enc-overlay.view-entry .enc-right { display: flex; }
  .enc-back { display: block; align-self: flex-start; border: 0; background: rgba(0, 0, 0, .25); color: #f3dfae; font: 600 16px 'EB Garamond', serif; padding: 8px 14px; border-radius: 4px; margin: 0 0 6px 2px; }
  .enc-page { padding: 16px 16px 10px; }
  .enc-head { flex-direction: column; gap: 8px; }
  .enc-portrait { width: 104px; height: 104px; }
  .enc-name { text-align: center !important; }
  .enc-head.only .enc-tag, .enc-tag { justify-content: center; }
  .enc-sec li { font-size: 17px; }
  .enc-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .enc-tab { flex: none; padding: 9px 14px; }
  .enc-row { min-height: 58px; }
}

/* the first time a word with an entry shows up: a gold flash + glow, then a diamond marker that stays until you hover the word */
.lk.new { animation: lkNew 4.6s ease-out both; background-image: linear-gradient(var(--lk, #ffc857), var(--lk, #ffc857)); }
.lk.new::after { content: ''; display: inline-block; width: .34em; height: .34em; margin-left: .18em; vertical-align: .62em; background: #ffc857; transform: rotate(45deg); box-shadow: 0 0 8px 2px rgba(255, 200, 87, .9); animation: lkTwinkle 1.3s ease-in-out infinite; }
@keyframes lkNew { 0% { background-color: rgba(255, 210, 110, 0); box-shadow: 0 0 0 0 rgba(255, 200, 90, 0); }
  10% { background-color: rgba(255, 214, 120, .95); box-shadow: 0 0 26px 8px rgba(255, 200, 90, .9); color: #4a2604; }
  30% { background-color: rgba(255, 210, 110, .6); box-shadow: 0 0 18px 5px rgba(255, 200, 90, .6); }
  55% { background-color: rgba(255, 210, 110, .8); box-shadow: 0 0 22px 6px rgba(255, 200, 90, .8); }
  100% { background-color: rgba(255, 210, 110, .3); box-shadow: 0 0 0 0 rgba(255, 200, 90, 0); } }
@keyframes lkTwinkle { 50% { opacity: .35; transform: rotate(45deg) scale(.7); } }
.mark.lorenew { position: fixed; top: calc(env(safe-area-inset-top) + 14px); left: 50%; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 12px; padding: 8px 20px 8px 10px; border-radius: 999px;
  background: linear-gradient(#3a2412, #1f130a); border: 1px solid #e2a94f; box-shadow: 0 8px 26px rgba(0, 0, 0, .6), 0 0 22px rgba(226, 169, 79, .35); color: #f6e3b0; animation: loreIn 3.8s both; pointer-events: none; }
.mark.lorenew img { width: 34px; height: 34px; }
.mark.lorenew b { display: block; font: 700 14px 'Cormorant UC', serif; letter-spacing: .18em; text-transform: uppercase; color: #ffd98a; }
.mark.lorenew small { display: block; font: 500 15px 'EB Garamond', serif; color: #f3e3c0; }
@keyframes loreIn { 0% { opacity: 0; transform: translate(-50%, -12px); } 8%, 86% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -8px); } }

/* pictures instead of icons once an entry has one */
.lp-ico.pic { border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px #7a4a17, 0 0 0 4px #d9a856, 0 3px 6px rgba(0, 0, 0, .5); }
.enc-row .ico.pic { border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px #7a4a17; }
.enc-portrait.has-pic img.pic { width: 74%; height: 74%; object-fit: cover; opacity: 1; filter: none; border-radius: 3px; }

/* big screens: the encyclopedia scales up instead of sitting small in the middle */
@media (min-width: 1700px) and (min-height: 900px) { .enc-overlay { --zoom: 1.3; } }
@media (min-width: 2300px) and (min-height: 1250px) { .enc-overlay { --zoom: 1.75; } }
