/* time-machine-ui v1 · base components: layout shell, glass surfaces, era card, icon buttons, settings sheet, city search,
   toggles, segmented controls, globe controls, time dock, timeline, shortcut chips, pins, event popover
   Shared by the time-machine products (junhyeopsong.github.io). Load tokens.css, then base.css,
   then the product's own styles. Breaking changes go to /v2/; /v1/ only gets compatible fixes. */
/* Layout: the globe fills the screen; three small glass surfaces float over it — era chip (top-left),
   settings button + popover (top-right), and a compact time dock (bottom). Radii follow Apple's concentric
   rule: inner radius = outer radius − padding. Single dark look on purpose (space). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body { background: var(--space); color: var(--ink); font-family: var(--f-body); overflow: hidden; -webkit-font-smoothing: antialiased; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }

.glass {
  background: var(--glass); border: 0.5px solid var(--hair);
  -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.22), inset 0 -1px 0 rgba(255,255,255,0.04), 0 10px 30px rgba(0,0,0,0.35);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .glass { background: var(--glass-solid); } }

.hud {
  position: fixed; inset: 0; pointer-events: none;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.hud > * { pointer-events: auto; }
button, select { font: inherit; color: var(--ink); background: none; border: 0; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible + .tr { outline: 2px solid var(--accent); outline-offset: 2px; }

/* era chip */
.era { position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); top: calc(env(safe-area-inset-top, 0px) + 12px);
  width: min(340px, calc(100vw - 92px)); border-radius: var(--r-panel); padding: 10px 14px; display: grid; gap: 3px; text-align: left; }
.era .eyebrow { font-size: 10.5px; letter-spacing: .1em; color: var(--ink-3); text-transform: uppercase; font-family: var(--f-data); display: flex; gap: 8px; align-items: center; }
.era .period { display: flex; align-items: center; gap: 7px; font-size: 16px; font-weight: 700; line-height: 1.3; text-wrap: balance; }
.era .chip { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.era .txt { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); display: block; }
.era.open .txt { -webkit-line-clamp: unset; display: block; }
.era .badge { font-size: 9.5px; padding: 1px 6px; border-radius: 999px; border: 0.5px solid var(--ink-3); color: var(--ink-2); letter-spacing: .02em; text-transform: none; }

/* round icon buttons */
.icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 17px; line-height: 1; }
.icon:hover { background: rgba(255,255,255,0.08); }
#gear { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); top: calc(env(safe-area-inset-top, 0px) + 12px); }
#gear[aria-expanded="true"] { background: rgba(255,255,255,0.18); }

/* settings popover */
.sheet { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); top: calc(env(safe-area-inset-top, 0px) + 60px);
  width: min(300px, calc(100vw - 32px)); max-height: calc(100% - 210px); overflow: hidden; border-radius: var(--r-panel);
  display: flex; flex-direction: column; background: var(--glass-solid); z-index: 4; }
.sheet[hidden] { display: none; }
.sheet-in { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--pad-panel); display: grid; gap: var(--pad-panel); }
/* more settings above / below: that edge fades out and the rows there soften (same idea as the shortcut chips) */
.sheet-in.more-b { -webkit-mask-image: linear-gradient(#000 calc(100% - 44px), rgba(0,0,0,.12)); mask-image: linear-gradient(#000 calc(100% - 44px), rgba(0,0,0,.12)); }
.sheet-in.more-t { -webkit-mask-image: linear-gradient(rgba(0,0,0,.12), #000 44px); mask-image: linear-gradient(rgba(0,0,0,.12), #000 44px); }
.sheet-in.more-t.more-b { -webkit-mask-image: linear-gradient(rgba(0,0,0,.12), #000 44px, #000 calc(100% - 44px), rgba(0,0,0,.12));
  mask-image: linear-gradient(rgba(0,0,0,.12), #000 44px, #000 calc(100% - 44px), rgba(0,0,0,.12)); }
.sheet-in .item, .sheet-in .legend, .sheet-in .foot { transition: filter .2s; }
.sheet-in .soft { filter: blur(1px); }
.sheet .group { background: var(--fill); border-radius: var(--r-inner); padding: 2px 12px; display: grid; }
.sheet .item { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; font-size: 13.5px; padding-block: 4px; }
.sheet .item > span:first-child { min-width: 0; }
.sheet .item + .item { border-top: 0.5px solid rgba(255,255,255,0.1); }
.sheet .item small { color: var(--ink-3); font-size: 11px; display: block; }
.sheet select { background: var(--fill-2); border-radius: 8px; padding: 5px 8px; font-size: 13px; }
.sheet select option { background: #1c1f2a; }
.sheet .foot { font-size: 10.5px; line-height: 1.5; color: var(--ink-3); padding: 4px 6px 2px; }
.sheet .foot a { color: var(--ink-2); }
.sheet .foot.fb { padding-top: 0; user-select: text; }
.sheet .foot .gh { display: inline-grid; place-items: center; width: 24px; height: 24px; margin: -6px 0 -6px 6px; vertical-align: middle; border-radius: 50%; color: var(--ink-2); }
.sheet .foot .gh:hover { color: var(--ink); background: rgba(255,255,255,0.12); }
.legend { padding: 8px 4px 2px; }
.legend .scale { display: grid; gap: 4px; }
.legend .bar { height: 6px; border-radius: 3px; }
.legend .lbl { display: flex; justify-content: space-between; font-family: var(--f-data); font-size: 10px; color: var(--ink-3); }
.combo { flex: 0 1 150px; display: flex; align-items: center; gap: 2px; background: var(--fill-2); border-radius: 8px; padding: 0 2px 0 8px; min-width: 0; }
.combo input { width: 100%; min-width: 0; background: none; border: 0; color: var(--ink); font: inherit; font-size: 13px; padding: 5px 0; outline: none; }
.combo input::-webkit-search-cancel-button { display: none; }
.combo button { width: 22px; height: 22px; border-radius: 50%; color: var(--ink-3); font-size: 14px; display: grid; place-items: center; flex: none; }
.combo button:hover { color: var(--ink); }
#cityLocate.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.locmsg { font-size: 11.5px; line-height: 1.45; color: #ffcf8a; padding: 2px 0 8px; }
/* dropdown floats over the settings sheet (lives at <body> level, positioned under the search field) */
#cityList { position: fixed; z-index: 20; list-style: none; margin: 0; padding: 4px; border-radius: var(--r-inner);
  background: rgba(30, 34, 48, 0.96); border: 0.5px solid var(--hair); box-shadow: 0 14px 40px rgba(0,0,0,.5);
  -webkit-backdrop-filter: blur(22px); backdrop-filter: blur(22px); max-height: 264px; overflow-y: auto; color: var(--ink); }
#cityList li { padding: 7px 10px; border-radius: 10px; font-size: 13px; cursor: pointer; display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); align-items: baseline; gap: 10px; }
#cityList li span, #cityList li small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cityList li small { color: var(--ink-3); font-size: 11px; text-align: right; }
#cityList li[aria-selected="true"], #cityList li:hover { background: rgba(255,255,255,0.14); }
#cityList .empty { color: var(--ink-3); cursor: default; }
.tchip { display: grid; line-height: 1.1; text-align: right; padding-right: 12px; margin-right: 2px; border-right: 0.5px solid rgba(255,255,255,0.18); flex: none; }
.tchip .tl { font-size: 10.5px; color: var(--ink-3); }   /* same size and slot as the Ma line beside it */
.tchip .tv { font-family: var(--f-data); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }   /* matches the year line */

/* toggle switch (iOS-style, compact) */
.sw { position: relative; display: inline-flex; flex: none; }
.sw input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.sw .tr { width: 40px; height: 24px; border-radius: 12px; background: var(--fill-2); transition: background .2s; position: relative; }
.sw .tr::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.3); transition: transform .2s; }
.sw input:checked + .tr { background: var(--on); }
.sw input:checked + .tr::after { transform: translateX(16px); }

/* segmented control (iOS) */
.seg { display: inline-flex; background: var(--fill); border-radius: var(--r-seg); padding: 2px; gap: 0; }
.seg button { border-radius: var(--r-seg-in); padding: 4px 9px; font-size: 12px; color: var(--ink-2); min-width: 40px; }
.seg button[aria-checked="true"] { background: rgba(255,255,255,0.24); color: var(--ink); font-weight: 600; box-shadow: 0 2px 6px rgba(0,0,0,.25); }

/* globe controls */
.nav { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); top: 50%; transform: translateY(-50%);
  display: grid; padding: 4px; gap: 0; border-radius: 24px; }
.nav button { width: 36px; height: 36px; border-radius: 50%; font-size: 17px; display: grid; place-items: center; }
.nav button:hover { background: rgba(255,255,255,0.1); }

/* time dock */
.dock { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  width: min(880px, calc(100vw - 32px)); border-radius: 30px; padding: 8px 16px 8px 8px; display: grid; gap: 4px; }
.row1 { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* one cluster for everything that drives playback: step back · play/pause · step forward | speed */
.transport { display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 22px; background: var(--fill); flex: none; }
.transport .divider { width: 0.5px; height: 22px; background: rgba(255,255,255,0.22); margin: 0 6px; }
.transport .seg { background: transparent; padding: 0; }
.transport .seg button { border-radius: 18px; padding: 6px 11px; }   /* concentric: 22px cluster − 4px inset */
.play { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.2); color: #fff; flex: none; display: grid; place-items: center;
  box-shadow: inset 0 0 0 0.5px rgba(255,255,255,0.35); }   /* glass, like the other controls */
.play:hover { background: rgba(255,255,255,0.28); }
.play svg { width: 16px; height: 16px; fill: currentColor; }
.play .pause { display: none; } .play.on .pause { display: block; } .play.on .tri { display: none; }
.when { display: grid; line-height: 1.1; min-width: 0; text-align: right; }
.when .big { font-family: var(--f-data); font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.when { flex: 0 1 auto; }
.when .big.long { font-size: 14px; line-height: 1.25; }
.fold { display: none; width: 28px; height: 28px; border-radius: 50%; place-items: center; color: var(--ink-2); background: var(--fill); flex: none; margin-left: 6px; }
.fold svg { transition: transform .2s; }
.when .ma { font-family: var(--f-data); font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.row1 .spacer { flex: 1; }
.step { width: 32px; height: 32px; border-radius: 50%; color: var(--ink-2); flex: none; display: grid; place-items: center; }
.step svg { width: 12px; height: 12px; fill: currentColor; }
.step:hover { background: rgba(255,255,255,0.1); }
.track { position: relative; height: 22px; margin: 0 2px 0 8px; }
.strata { position: absolute; left: 0; right: 0; top: 7px; height: 8px; display: flex; z-index: 0; pointer-events: none; } /* own stacking layer under the slider, so a raised (hovered) band never takes the click */
.strata div { height: 100%; position: relative; transition: transform .15s, opacity .15s, filter .15s; }
.strata div:first-child { border-radius: 4px 0 0 4px; } .strata div:last-child { border-radius: 0 4px 4px 0; }
.strata.hovering div:not(.hov) { opacity: .45; }
.strata div.hov { transform: scaleY(1.4); border-radius: 3px; filter: brightness(1.25); z-index: 1; }
.tltip { position: absolute; bottom: 27px; left: 0; z-index: 4; display: flex; align-items: center; gap: 6px; white-space: nowrap; pointer-events: none;
  padding: 5px 10px; border-radius: 10px; font-size: 12px; background: rgba(20,24,36,.97); border: .5px solid rgba(255,255,255,.22);
  box-shadow: 0 6px 18px rgba(0,0,0,.5); transform: translateX(-50%); }
.tltip[hidden] { display: none; }
.tltip i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.tltip b { font-weight: 600; color: var(--ink); }
.tltip span { font-family: var(--f-data); font-size: 10.5px; color: var(--ink-3); }
.tltip::after { content: ""; position: absolute; left: var(--ax, 50%); bottom: -5px; width: 8px; height: 8px; background: rgba(20,24,36,.97);
  transform: translateX(-50%) rotate(45deg); border-right: .5px solid rgba(255,255,255,.22); border-bottom: .5px solid rgba(255,255,255,.22); }
.strata .fut { background: repeating-linear-gradient(135deg, rgba(255,255,255,.28) 0 4px, rgba(255,255,255,.1) 4px 8px); }
input[type=range] { -webkit-appearance: none; appearance: none; position: absolute; inset: 0; width: 100%; height: 22px; margin: 0; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 22px; background: transparent; }
input[type=range]::-moz-range-track { height: 22px; background: transparent; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.45), 0 0 0 0.5px rgba(0,0,0,.2); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.45); }
.ticks { position: relative; height: 12px; margin: 0 2px 0 8px; font-family: var(--f-data); font-size: 9.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ticks span.now { color: var(--accent); font-weight: 600; }
.evrow { position: relative; height: 8px; margin: -2px 2px 0 8px; }
.evrow button { position: absolute; top: 0; width: 7px; height: 7px; padding: 0; border-radius: 50%; transform: translateX(-50%); background: var(--k); }
.evrow button:hover { transform: translateX(-50%) scale(1.6); }
.pwrap { position: relative; margin-left: 8px; min-width: 0; }
.presets { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-top: 2px; }
/* more chips off to a side: that edge fades out and softly blurs */
.pwrap.more-r .presets { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 56px), rgba(0,0,0,.12)); mask-image: linear-gradient(90deg, #000 calc(100% - 56px), rgba(0,0,0,.12)); }
.pwrap.more-l .presets { -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,.12), #000 56px); mask-image: linear-gradient(90deg, rgba(0,0,0,.12), #000 56px); }
.pwrap.more-l.more-r .presets { -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,.12), #000 56px, #000 calc(100% - 56px), rgba(0,0,0,.12));
  mask-image: linear-gradient(90deg, rgba(0,0,0,.12), #000 56px, #000 calc(100% - 56px), rgba(0,0,0,.12)); }
.presets button { transition: filter .2s; }
.presets button.soft { filter: blur(1px); }
.presets::-webkit-scrollbar { display: none; }
.presets button { font-size: 11.5px; padding: 3px 10px; border-radius: 999px; color: var(--ink-2); background: var(--fill); white-space: nowrap; flex: none; }
.presets button.on { background: rgba(255,181,71,0.22); color: var(--accent); }

.hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 150px);
  font-size: 11.5px; color: var(--ink-2); padding: 5px 12px; border-radius: 999px; width: max-content; max-width: calc(100vw - 32px); text-align: center; text-wrap: balance; transition: opacity .6s; pointer-events: none; }
.hint.gone { opacity: 0; }

#pins { position: fixed; inset: 0; pointer-events: none; }
.pin { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: 2px 9px 2px 3px; border-radius: 999px;
  background: rgba(10,14,24,.55); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border: 0.5px solid rgba(255,255,255,.2);
  color: var(--ink); font-size: 11.5px; font-weight: 500; white-space: nowrap; pointer-events: auto; cursor: pointer; transform: translate(-7px, -50%); }
.pin i { width: 10px; height: 10px; border-radius: 50%; background: var(--k); box-shadow: 0 0 0 2px rgba(0,0,0,.35), 0 0 10px var(--k); flex: none; }
.pin:hover, .pin.on { background: rgba(20,26,40,.85); border-color: var(--k); z-index: 2; }
.pin.dim span { display: none; } .pin.dim { padding-right: 3px; }
.pop { position: fixed; z-index: 5; width: min(290px, calc(100vw - 32px)); padding: 12px 14px; display: grid; gap: 5px; border-radius: var(--r-panel); background: var(--glass-solid); }
.pop .x { position: absolute; right: 6px; top: 6px; width: 28px; height: 28px; border-radius: 50%; font-size: 16px; color: var(--ink-2); background: var(--fill); }
.pop .pk { font-size: 10.5px; font-family: var(--f-data); letter-spacing: .08em; color: var(--k); }
.pop h2 { margin: 0; font-size: 15px; padding-right: 26px; text-wrap: balance; }
.pop .pa { font-family: var(--f-data); font-size: 11.5px; color: var(--ink-3); }
.pop p { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--ink-2); }
.pop .pf { font-size: 11.5px; line-height: 1.5; color: var(--ink-3); }
.pop .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.pop .go { justify-self: start; border-radius: 999px; font-size: 12px; padding: 4px 11px; background: var(--fill-2); }
#loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--ink-2); font-size: 14px; pointer-events: none; }
.cityTag { position: fixed; left: 0; top: 0; pointer-events: none; font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000, 0 0 6px #000; transform: translate(10px, -50%); white-space: nowrap; }

@media (max-width: 640px) {
  .tchip { padding-right: 8px; }
  .tchip .tv { font-size: 15px; }
  .step { width: 26px; height: 26px; }
  .transport .divider { margin: 0 3px; }
  .when .big { font-size: 15px; }
  .when .big.long { font-size: 13px; }
  .row1 { flex-wrap: wrap; row-gap: 6px; }
  .row1 .spacer { display: none; }
  .row1 { flex-wrap: wrap; }
  .row1 .tchip { margin-left: auto; border-right: 0; padding-right: 2px; }
  .row1 .tchip .tl { display: none; }   /* value only on phones; full label in its tooltip */
  .row1 .tchip { flex-direction: row; align-items: center; }
  .transport { gap: 0; padding: 3px; }
  .transport .seg button { padding: 4px 6px; font-size: 11.5px; }
  .play { width: 34px; height: 34px; }
  .row1 .when { order: 2; flex: 1 1 calc(100% - 80px); display: flex; align-items: center; gap: 8px; padding: 0 4px; }
  .row1 .when .big { flex: 1 1 auto; min-width: 0; text-align: left; }
  .dock > * { min-width: 0; }
  .transport .seg button { padding: 4px 7px; }
  .seg button { padding: 4px 7px; min-width: 0; }
  .hide-sm { display: none; }
  /* globe controls float just above the time dock (its height is measured into --dock-h) */
  .nav { top: auto; transform: none; bottom: calc(env(safe-area-inset-bottom, 0px) + var(--dock-h, 150px) + 22px);
    grid-auto-flow: column; padding: 3px; border-radius: 22px; }
  .nav #zIn, .nav #zOut { display: none; }           /* pinch to zoom on touch screens */
  .nav button { width: 38px; height: 38px; }
  .hint { bottom: calc(env(safe-area-inset-bottom, 0px) + var(--dock-h, 150px) + 76px); max-width: calc(100vw - 32px); }
  /* fold the less used rows: event dots and shortcut chips */
  .fold { display: grid; }
  .dock.folded .evrow, .dock.folded .pwrap { display: none; }
  .dock:not(.folded) .fold svg { transform: rotate(180deg); }
  /* era card: two lines, tap to read the rest */
  .era { cursor: pointer; padding: 9px 12px; }
  .era .txt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .era.open .txt { display: block; -webkit-line-clamp: unset; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
