:root {
  --ink: oklch(0.96 0.005 250);
  --muted: oklch(0.82 0.01 250);
  --glass: oklch(0.18 0.012 250 / 0.62);
  --edge: oklch(1 0 0 / 0.12);
  --accent: oklch(0.82 0.13 75);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: oklch(0.16 0.01 250); color: var(--ink); font: 14px/1.4 "Libre Franklin", system-ui, sans-serif; }
canvas { display: block; width: 100vw; height: 100dvh; touch-action: none; }
button { font: inherit; color: var(--ink); background: transparent; border: 1px solid var(--edge); border-radius: 999px; padding: 6px 12px; cursor: pointer; transition: background .25s cubic-bezier(.16,1,.3,1); }
button:hover { background: oklch(1 0 0 / 0.1); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[aria-pressed="true"] { background: var(--accent); color: oklch(0.2 0.02 75); border-color: var(--accent); }

#title { position: fixed; top: 22px; left: 26px; pointer-events: none; text-shadow: 0 1px 18px oklch(0 0 0 / .45); }
#title h1 { margin: 0; font: 300 clamp(34px, 5vw, 58px)/1 "Libre Franklin", sans-serif; letter-spacing: -0.03em; }
#stats { margin: 6px 0 0; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

#places { position: fixed; top: 22px; right: 22px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 520px; }
#places button { background: var(--glass); backdrop-filter: blur(10px); font-size: 13px; }

#time { position: fixed; left: 26px; bottom: 24px; width: min(360px, calc(100vw - 52px)); background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--edge); border-radius: 16px; padding: 12px 16px 14px; }
#time .row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
#clock { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
#hour { width: 100%; accent-color: var(--accent); }
#liveTag { margin-left: 10px; margin-right: auto; font-size: 12px; color: oklch(0.85 0.12 150); }
#liveTag[hidden] { display: none; }
.row2 { display: flex; gap: 8px; margin-top: 10px; }
#date { flex: 1; font: inherit; color: var(--ink); background: oklch(1 0 0 / .06); border: 1px solid var(--edge); border-radius: 999px; padding: 5px 12px; color-scheme: dark; }

#hint { position: fixed; right: 24px; bottom: 22px; margin: 0; font-size: 12px; color: var(--muted); text-shadow: 0 1px 8px oklch(0 0 0 / .6); }

#attrib { position: fixed; left: 50%; transform: translateX(-50%); bottom: 4px; margin: 0; font-size: 10px; color: oklch(0.9 0.005 250 / .85); text-shadow: 0 1px 4px oklch(0 0 0 / .8); pointer-events: none; z-index: 1; max-width: 70vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#attrib[hidden], body:not(.photo) #attrib { display: none; }
#credits { position: fixed; right: 24px; bottom: 6px; margin: 0; font-size: 10px; color: oklch(0.8 0.01 250 / .75); text-shadow: 0 1px 6px oklch(0 0 0 / .7); pointer-events: none; }
body.tm #credits, body.henge #credits, body.xray #credits, body.reading #credits { display: none; }
@media (max-width: 1280px) { #credits { display: none; } }
#labels { position: fixed; inset: 0; pointer-events: none; }
.lbl { position: absolute; transform: translate(-50%, -100%); font-size: 12px; font-weight: 500; white-space: nowrap; padding: 3px 9px; border-radius: 999px; background: oklch(0.15 0.01 250 / .7); border: 1px solid var(--edge); transition: opacity .3s; }
.lbl::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: 18px; background: oklch(1 0 0 / .5); }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: oklch(0.16 0.01 250); transition: opacity 1.2s cubic-bezier(.16,1,.3,1); z-index: 2; }
#loading.done { opacity: 0; pointer-events: none; }
#loadText { font: 300 26px "Libre Franklin", sans-serif; color: var(--muted); }

#modes { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); display: flex; gap: 10px; }
#subOpen { background: oklch(0.2 0.02 250 / .78); backdrop-filter: blur(10px); font-weight: 600; padding: 11px 20px; font-size: 15px; }
#tmOpen { background: var(--accent); color: oklch(0.2 0.02 75); border-color: var(--accent); font-weight: 600; padding: 11px 20px; font-size: 15px; box-shadow: 0 8px 30px oklch(0 0 0 / .35); }
#tmOpen:hover { background: oklch(0.87 0.12 75); }
body.henge #modes, body.henge #places, body.henge #labels, body.henge #hint, body.henge #time, body.henge #stats, body.tm #labels, body.tm #places, body.tm #time, body.tm #hint, body.tm #modes, body.xray #modes, body.xray #labels, body.xray #hint, body.xray #time, body.tm #stats { display: none; }
#tmHud[hidden] { display: none; }
#tmTop { padding: 10px 24px 14px; border-radius: 40px; background: radial-gradient(ellipse at center, oklch(0.15 0.01 250 / .38), transparent 72%); position: fixed; top: 18px; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; text-shadow: 0 2px 30px oklch(0 0 0 / .55); width: min(92vw, 760px); }
#tmYear { font: 300 clamp(64px, 11vw, 96px)/1 "Libre Franklin", sans-serif; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
#tmCap { margin: 8px 0 0; font-size: clamp(16px, 2vw, 21px); font-weight: 500; min-height: 1.4em; text-wrap: balance; }
#tmCount { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
#tmBar { position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%); width: min(720px, calc(100vw - 32px)); display: flex; gap: 12px; align-items: center; background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--edge); border-radius: 999px; padding: 8px 10px; }
#tmBar input { flex: 1; min-width: 0; accent-color: var(--accent); }
#tmBar button { flex: none; }
#tmPlay { min-width: 76px; }
#tmNote { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); margin: 0; width: min(720px, calc(100vw - 32px)); text-align: center; font-size: 11px; color: var(--muted); text-shadow: 0 1px 8px oklch(0 0 0 / .7); }
body.tm #title h1 { font-size: 22px; }

#subHud[hidden], #subTrain[hidden], #hengeHud[hidden] { display: none; }
#hengeOpen { background: oklch(0.2 0.02 250 / .78); backdrop-filter: blur(10px); font-weight: 600; padding: 11px 20px; font-size: 15px; }
#hengeTop { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); text-align: center; width: min(92vw, 640px); pointer-events: none; text-shadow: 0 2px 24px oklch(0 0 0 / .6); padding: 10px 24px 16px; border-radius: 40px; background: radial-gradient(ellipse at center, oklch(0.15 0.01 250 / .4), transparent 72%); }
#hengeTop h2 { margin: 0; font: 300 clamp(34px, 5vw, 56px)/1.05 "Libre Franklin", sans-serif; letter-spacing: -0.03em; }
#hengeWhen { margin: 8px 0 0; font-size: 17px; font-weight: 500; text-wrap: balance; }
#hengeAlso { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
#hengeClock { margin: 10px 0 0; font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
#hengeBar { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--edge); border-radius: 999px; padding: 6px; max-width: calc(100vw - 24px); overflow-x: auto; }
#hengeStreets { display: flex; gap: 6px; }
#hengeBar button { flex: none; }
#hengeNote { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0; width: min(760px, calc(100vw - 32px)); text-align: center; font-size: 11px; color: var(--muted); text-shadow: 0 1px 8px oklch(0 0 0 / .7); }
#subBar { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--edge); border-radius: 999px; padding: 7px 8px 7px 16px; white-space: nowrap; }
#subStat { margin: 0; font-variant-numeric: tabular-nums; }
.live { width: 9px; height: 9px; border-radius: 50%; background: oklch(0.72 0.2 25); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
#subTrain { position: fixed; right: 22px; top: 22px; display: flex; gap: 12px; align-items: center; background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--edge); border-radius: 16px; padding: 12px 16px; min-width: 240px; }
#subTrainLine { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 20px; color: #fff; }
#subTrain b { display: block; font-size: 15px; }
#subTrain p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
#subNote { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0; font-size: 11px; color: var(--muted); text-shadow: 0 1px 8px oklch(0 0 0 / .7); white-space: nowrap; }
body.xray #places { top: 22px; }
@media (prefers-reduced-motion: reduce) { .live { animation: none; } }

#search { position: fixed; top: 112px; left: 26px; width: min(340px, calc(100vw - 52px)); }
#q { width: 100%; font: inherit; color: var(--ink); background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--edge); border-radius: 999px; padding: 9px 16px; }
#q::placeholder { color: oklch(0.78 0.01 250); }
#qres { list-style: none; margin: 6px 0 0; padding: 0; background: oklch(0.18 0.012 250 / .94); border-radius: 14px; overflow: hidden; }
#qres:empty { display: none; }
#qres button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; padding: 9px 16px; }
#qres .none { padding: 9px 16px; color: var(--muted); }
body.tm #search, body.xray #search, body.henge #search { display: none; }

#wiki { position: fixed; top: 12px; right: 12px; bottom: 12px; width: min(440px, calc(100vw - 24px)); overflow-y: auto; background: oklch(0.17 0.012 250 / .96); backdrop-filter: blur(14px); border: 1px solid var(--edge); border-radius: 18px; padding: 0 22px 26px; z-index: 3; line-height: 1.55; }
#wiki[hidden] { display: none; }
body.reading #places, body.reading #hint, body.reading #modes { display: none; }
@media (min-width: 701px) and (max-width: 1280px) {
  #modes { left: auto; right: 22px; transform: none; flex-direction: column; align-items: flex-end; bottom: 22px; }
  #hint { display: none; }
}
.wk-head { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 12px 0 6px; background: linear-gradient(oklch(0.17 0.012 250), oklch(0.17 0.012 250 / 0)); z-index: 1; }
.wk-img { margin: 0 -22px 14px; }
.wk-img img { display: block; width: 100%; max-height: 300px; object-fit: cover; }
.wk-img figcaption { font-size: 11px; padding: 4px 22px 0; color: var(--muted); }
#wiki h2 { margin: 6px 0 2px; font: 400 30px/1.15 "Libre Franklin", sans-serif; letter-spacing: -0.02em; text-wrap: balance; }
.wk-sub { margin: 0 0 14px; color: var(--muted); }
.wk-facts { display: grid; grid-template-columns: 130px 1fr; gap: 7px 14px; margin: 0 0 20px; font-size: 14px; }
.wk-facts dt { color: var(--muted); }
.wk-facts dd { margin: 0; }
#wiki sup a { color: var(--accent); text-decoration: none; font-size: 10px; margin-left: 1px; }
#wiki a { color: oklch(0.82 0.08 240); }
#wiki h3 { margin: 22px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.wk-extract { margin: 0 0 12px; }
.wk-more { margin-bottom: 8px; }
.wk-full { font-size: 14px; }
.wk-full img { max-width: 100%; height: auto; }
.wk-full table { display: block; max-width: 100%; overflow-x: auto; font-size: 12px; border-collapse: collapse; }
.wk-full figure, .wk-full .thumb { margin: 12px 0; }
.wk-full figcaption, .wk-full .thumbcaption { font-size: 12px; color: var(--muted); }
.wk-full h2 { font-size: 20px; margin: 22px 0 6px; }
.wk-full h3 { color: var(--ink); }
.wk-full ol.references { font-size: 12px; padding-left: 22px; }
.wk-lic { font-size: 11px; color: var(--muted); }
.wk-refs ol { padding-left: 20px; font-size: 12px; color: var(--muted); }
.wk-refs li { margin-bottom: 6px; }

@media (max-width: 700px) {
  #search { top: auto; bottom: calc(160px + env(safe-area-inset-bottom)); left: 12px; width: calc(100vw - 24px); }
  #wiki { top: 30vh; left: 8px; right: 8px; width: auto; bottom: 8px; }
  #modes { bottom: auto; top: 116px; left: 16px; transform: none; flex-direction: column; align-items: flex-start; gap: 8px; }
  #tmOpen, #subOpen, #hengeOpen { font-size: 14px; padding: 9px 14px; }
  #subBar { bottom: calc(40px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); }
  #subTrain { left: 12px; right: 12px; top: auto; bottom: calc(96px + env(safe-area-inset-bottom)); }
  #subNote { white-space: normal; width: calc(100vw - 32px); text-align: center; }
  #tmTop { top: 64px; }
  #tmBar { bottom: calc(56px + env(safe-area-inset-bottom)); gap: 8px; padding: 6px; }
  #tmBar button { padding: 6px 10px; font-size: 13px; }
  #tmNote { bottom: calc(8px + env(safe-area-inset-bottom)); font-size: 10px; }
  #title { top: 14px; left: 16px; }
  #places { top: auto; bottom: calc(208px + env(safe-area-inset-bottom)); left: 12px; right: 12px; max-width: none; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  #places button { flex: none; }
  #time { left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); width: calc(100vw - 24px); }
  #hint { display: none; }
  body.xray #places { top: auto; }
  #subBar { bottom: calc(60px + env(safe-area-inset-bottom)); }
  #hengeBar { bottom: calc(92px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); overflow-x: auto; }
  #hengeNote { font-size: 10px; bottom: calc(8px + env(safe-area-inset-bottom)); }
  #attrib { left: 16px; right: 16px; bottom: auto; top: 78px; transform: none; max-width: none; text-align: left; white-space: normal; }
  body.tm #attrib, body.henge #attrib { top: auto; bottom: calc(2px + env(safe-area-inset-bottom)); font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
