/* The main app (index.html). Mobile first: the base rules are the design for a phone. A wide
   screen (the end of this file) only gives it more room: larger text and buttons, and the
   sheets at the right of the screen. */
:root {
  --fog: #c9c7c0;
  --panel: #e9e4d5;
  --panel-dither: #d8d2c1;
  --panel-edge: #2a2722;
  --ink: #26231f;
  --ink-2: #6b6457;
  --ink-3: #a39b8b;
  --accent: #e39a30;
  --tag: #ef6f52;
  --tag-ink: #2b130c;
  --label-bg: #1c1b19;
  --label-ink: #ede6d3;
  --hover: #f3efe3;
  /* The one font of the app (John, 2026-11-07): Silkscreen, the blocky pixel font, and no other.
     sans-serif only gives the glyphs that Silkscreen does not have, such as the Chinese. */
  --pixel: 'Silkscreen', sans-serif;
  /* the space from the edges of the screen, the size of an icon button, and the corners */
  --edge: 10px;
  --btn: 46px;
  --top: calc(env(safe-area-inset-top) + var(--edge));
  --left: max(var(--edge), env(safe-area-inset-left));
  --right: max(var(--edge), env(safe-area-inset-right));
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--fog); color: var(--ink); font-family: var(--pixel); font-size: 10px; line-height: 1.6; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.panel {
  position: fixed;
  background-color: var(--panel);
  background-image: repeating-conic-gradient(var(--panel-dither) 0% 25%, transparent 0% 50%);
  background-size: 3px 3px;
  border: 2px solid var(--panel-edge);
}

/* ---- the title box at the top left: the name of the City, the date and the time ----------
   It is never wider than the space to the left of the menu button, thus the two never meet. */
#title {
  top: var(--top); left: var(--left); z-index: 5; padding: 7px 11px 8px;
  max-width: calc(100vw - var(--left) - var(--right) - var(--btn) - 10px);
}
#title .t-name { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; }
#title .t-cn { font-weight: 700; font-size: 16px; letter-spacing: 0.16em; }
#title .t-en { font-size: 10px; letter-spacing: 0.06em; }
#title .t-time { margin-top: 2px; font-size: 10px; letter-spacing: 0.04em; }
/* the colon blinks while the clock runs, thus real time does not look stopped */
#title.run #t-colon { animation: clk-blink 1s steps(1, end) infinite; }
@keyframes clk-blink { 50% { opacity: 0; } }

/* ---- the menu button at the top right, and the column of the tools under it ----------------
   The menu button and the tools are icons only. Closed, each tool sits under the menu button;
   open, the tools come down from it one after the other. */
#menu-btn {
  top: var(--top); right: var(--right); width: var(--btn); height: var(--btn); padding: 0; z-index: 41; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--ink);
}
#menu-btn svg, .ti svg { display: block; }
#tools {
  position: fixed; top: calc(var(--top) + var(--btn) + 8px); right: var(--right); z-index: 40;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.ti {
  position: relative; width: var(--btn); height: var(--btn); padding: 0; cursor: pointer; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(calc((var(--i) + 1) * (var(--btn) + 8px) * -1)) scale(0.6);
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.16s, visibility 0s 0.22s;
}
body.tools-open .ti {
  opacity: 1; visibility: visible; pointer-events: auto; transform: none;
  transition-delay: calc(var(--i) * 30ms), calc(var(--i) * 30ms), 0s;
}
#menu-btn[aria-expanded="true"], .ti[aria-expanded="true"] { background: var(--label-bg); color: var(--label-ink); }

/* ---- the sheets: one for each tool, and the selected building or person. On a phone each one
   comes up from the foot of the screen. ---- */
.sheet, #bld {
  position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; border-width: 2px 0 0;
  box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.18); overscroll-behavior: contain; animation: sheet-in 0.18s ease-out;
}
.sheet[hidden], #bld[hidden] { display: none; }
@keyframes sheet-in { from { transform: translateY(28px); opacity: 0; } }
.sheet {
  z-index: 20; max-height: 84vh; max-height: 84dvh; overflow-y: auto; scrollbar-width: thin;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
}
.x-btn, #bld-close {
  flex: none; width: 42px; height: 34px; padding: 0; border: 2px solid var(--panel-edge); background: var(--panel); cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--ink);
}
.x-btn svg, #bld-close svg { width: 12px; height: 12px; display: block; }
.x-btn:active, #bld-close:active { background: var(--label-bg); color: var(--label-ink); }
/* the head of a sheet: its name and its x, at the top while the sheet scrolls */
.m-head {
  display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1;
  margin: 0 -14px 12px; padding: 6px 8px 6px 14px; background: var(--panel); border-bottom: 2px solid var(--panel-edge);
  font-size: 11px; letter-spacing: 0.04em;
}
.m-h { margin-bottom: 7px; font-size: 9px; letter-spacing: 0.04em; color: var(--ink-2); }

/* the time: the title box gives the date and the time */
#wx { margin: 0 0 12px; font-size: 10px; line-height: 1.6; color: var(--ink-2); }
#wx b { color: var(--ink); font-weight: 700; }
#spark { position: relative; height: 44px; margin: 0 0 10px; cursor: pointer; border-bottom: 2px solid var(--panel-edge); }
#spark canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
#playhead { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--tag); left: 0; }
.speeds { display: flex; gap: 6px; }
.speeds button {
  flex: 1; height: 42px; border: 2px solid var(--panel-edge); background: var(--panel); cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center; color: var(--ink);
}
.speeds button svg { display: block; }
.speeds button.on { background: var(--label-bg); color: var(--label-ink); }

/* the floors: pull them apart, and the storeys in one row that scrolls */
.tool {
  width: 100%; height: 46px; margin: 0 0 14px; border: 2px solid var(--panel-edge); background: var(--panel); cursor: pointer; color: var(--ink);
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
}
.tool svg { width: 20px; height: 20px; flex: none; }
.tool-l { font-size: 10px; letter-spacing: 0.04em; }
.tool.on { background: var(--label-bg); color: var(--label-ink); }
#levels { list-style: none; margin: 0; display: flex; gap: 5px; overflow-x: auto; padding: 0 0 6px; scrollbar-width: thin; }
#levels li { flex: none; position: relative; }
#levels button {
  height: 40px; min-width: 52px; padding: 0 8px; border: 2px solid var(--panel-edge); background: var(--panel); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--ink);
}
#levels button.above { color: var(--ink-3); }
#levels button.sel { background: var(--accent); color: var(--ink); }
#levels .sep { border-left: 2px dashed var(--ink-3); margin: 6px 3px; }

/* ---- the selected building or person (buildingPanel.js, life/personPanel.js) ---- */
#bld { z-index: 10; max-height: 52vh; max-height: 52dvh; padding-bottom: env(safe-area-inset-bottom); display: flex; flex-direction: column; font-size: 10px; line-height: 1.6; }
.bld-head { flex: none; display: flex; align-items: center; gap: 6px; border-bottom: 2px solid var(--panel-edge); background: var(--panel); padding: 5px 8px 5px 14px; }
#bld-head { flex: 1; font-family: var(--pixel); font-size: 10px; letter-spacing: 0.04em; }
#bld-body { overflow: auto; min-height: 0; padding: 10px 14px 16px; scrollbar-width: thin; scrollbar-color: var(--ink-2) transparent; }
#bld .nm { font-weight: 700; font-size: 12px; }
#bld .sub { color: var(--ink-2); margin-bottom: 2px; }
#bld .n { color: var(--ink-2); font-size: 9px; }
#bld i { color: var(--ink-2); font-style: normal; }
#bld b { font-weight: 700; }
#bld h3 { margin: 9px 0 3px; padding-top: 6px; border-top: 1px dashed var(--ink-3); font-family: var(--pixel); font-size: 9px; font-weight: 400; letter-spacing: 0.04em; }
#bld .r { display: flex; gap: 6px; }
#bld .r .k, #bld .st .k { flex: none; width: 34px; color: var(--ink-2); }
#bld .r.bl .k { width: 84px; }
#bld .r.w .k { width: 46px; }
#bld .st { display: flex; align-items: center; min-height: 28px; gap: 6px; width: calc(100% + 8px); margin: 0 -4px; padding: 0 4px; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; }
#bld .st.sel { background: rgba(227, 154, 48, 0.2); box-shadow: inset 0 0 0 2px var(--accent); }
#bld .st.above { color: var(--ink-3); }
#bld .st:focus-visible, #bld-close:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#bld .st .u { display: flex; flex-wrap: wrap; column-gap: 10px; }
#bld .p { display: inline-flex; align-items: center; gap: 5px; }
#bld .sq { flex: none; width: 10px; height: 10px; display: inline-block; border: 1px solid rgba(0, 0, 0, 0.35); }
#bld details summary { cursor: pointer; }
#bld .tag { display: inline-block; padding: 0 4px; font-family: var(--pixel); font-size: 8px; line-height: 13px; vertical-align: 1px; }
#bld .tag.verified { background: #184f95; color: #fff; }
#bld .tag.guess { border: 1px solid var(--ink-3); color: var(--ink-2); line-height: 10px; }
#bld .follow { margin: 6px 0 2px; padding: 7px 12px; border: 2px solid var(--panel-edge); background: var(--panel); font-family: var(--pixel); font-size: 9px; cursor: pointer; color: var(--ink); }
#bld .follow.on { background: var(--label-bg); color: var(--label-ink); }
#bld details[open] summary { margin-bottom: 2px; }
#bld .who { display: block; width: 100%; text-align: left; margin: 3px 0; padding: 7px 8px; border: 1px solid var(--panel-edge); background: var(--panel); cursor: pointer; font: inherit; font-size: 10px; color: var(--ink); }
#bld .who .tt-h { font-family: var(--pixel); font-size: 8px; }


/* ---- the tooltip, for a mouse ---- */
#tooltip {
  position: fixed; pointer-events: none; display: none; max-width: 300px;
  background: #f3efe2; border: 1px solid #3b372f; padding: 8px 11px; font-size: 10px; line-height: 1.6; color: var(--ink);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.18);
}
#tooltip .tt-h { font-weight: 700; font-size: 11px; }
#tooltip .tt-s { color: var(--ink-2); font-size: 9px; }
#tooltip .tt-k { color: var(--ink-2); }
#tooltip .tt-r { font-size: 9px; }
#tooltip .tt-r i { color: var(--ink-2); font-style: normal; }

/* ---- the sources (notes.js), and the hint of the controls ---- */
#sources, #cases { font-size: 10px; line-height: 1.7; background-image: none; }
#sources { max-height: 86vh; max-height: 86dvh; }
.m-hint { margin: 0 0 12px; font-size: 8px; line-height: 1.7; color: var(--ink-2); }
/* the hint for a mouse, or for a finger */
.m-hint .h-mouse { display: none; }
@media (hover: hover) and (pointer: fine) {
  .m-hint .h-mouse { display: inline; }
  .m-hint .h-touch { display: none; }
}
#sources h4 { margin: 16px 0 4px; font-size: 11px; }
#sources ul { margin: 0; padding-left: 18px; }
#sources a { color: #8a3d1a; }
#sources .st { font-family: var(--pixel); font-size: 8px; padding: 1px 4px; margin-right: 4px; vertical-align: 1px; }
#sources .st.ok { background: #cfe0c8; }
#sources .st.prov { background: #f0d29a; }
#src-stats { margin: 0 0 8px; color: var(--ink-2); font-size: 10px; }
#src-stats b { color: var(--ink); font-weight: 700; }

/* ---- the mysteries (life/mysteries.js) ---- */
#cases { max-height: 78vh; max-height: 78dvh; line-height: 1.7; }
#cases .cb-head, #cases h3 { font-family: var(--pixel); font-size: 8px; font-weight: 400; letter-spacing: 0.04em; margin: 0 0 6px; }
#cases h3 { margin: 10px 0 4px; padding-top: 6px; border-top: 1px dashed var(--ink-3); }
#cases .sub, #cases .n { color: var(--ink-2); }
#cases .sub { margin-bottom: 4px; }
#cases .n { font-size: 9px; }
#cases .zh { color: var(--ink-2); font-weight: 400; }
#cases .nm { font-weight: 700; font-size: 11px; margin: 6px 0 4px; display: flex; align-items: center; gap: 7px; }
.cb-row { display: flex; align-items: flex-start; gap: 8px; width: 100%; text-align: left; padding: 9px 4px; margin: 0; border: 0; border-bottom: 1px dotted var(--ink-3); background: transparent; cursor: pointer; font: inherit; color: var(--ink); }
.cb-n { flex: none; width: 16px; text-align: right; color: var(--ink-2); font-family: var(--pixel); font-size: 9px; padding-top: 2px; }
.cb-dot { flex: none; position: relative; display: inline-block; width: 13px; height: 13px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--panel-edge); box-sizing: border-box; }
.cb-dot.big { width: 16px; height: 16px; margin-top: 0; }
.cb-dot.on { background: var(--accent); }
.cb-dot.on::after { content: '✓'; position: absolute; inset: -3px 0 0 0; text-align: center; font-size: 9px; font-weight: 700; color: #fff; }
.cb-dot.big.on::after { font-size: 11px; inset: -2px 0 0 0; }
.cb-back, .cb-more { border: 2px solid var(--panel-edge); background: var(--panel); font-family: var(--pixel); font-size: 9px; padding: 7px 12px; cursor: pointer; color: var(--ink); }
.cb-more { margin-top: 6px; }
.cb-brief { margin: 4px 0 2px; }
.cb-clue { display: flex; gap: 8px; margin: 5px 0; }
.cb-clue .k { flex: none; width: 14px; font-family: var(--pixel); font-size: 9px; color: var(--ink-2); padding-top: 2px; }
.cb-story { margin-bottom: 4px; }
#cases .follow { margin: 8px 0 2px; padding: 7px 12px; border: 2px solid var(--panel-edge); background: var(--panel); font-family: var(--pixel); font-size: 9px; cursor: pointer; color: var(--ink); }
/* the note of a found person, under the title box */
#found {
  position: fixed; top: calc(var(--top) + 84px); left: 50%; transform: translate(-50%, -12px); padding: 8px 16px; text-align: center; pointer-events: none;
  background: #f3efe2; border: 2px solid var(--panel-edge); box-shadow: 0 0 0 3px var(--accent); opacity: 0; transition: opacity 0.4s, transform 0.4s; z-index: 30;
}
#found.show { opacity: 1; transform: translate(-50%, 0); }
#found .f-h { font-family: var(--pixel); font-size: 9px; letter-spacing: 0.05em; margin-bottom: 2px; }


/* ---- the loading screen: the bauhinia of the Hong Kong flag on its red field (favicon.svg);
   its five petals light one after the other, clockwise, while the City is built ---- */
#loading {
  position: fixed; inset: 0; z-index: 100; display: grid; grid-template-rows: 1fr auto 1fr; justify-items: center;
  gap: 36px; padding: 24px; background: #ee1c25; color: #fff; text-align: center; transition: opacity 0.6s;
}
/* the flower in the middle row, thus in the middle of the screen; the name over it */
.ld-name { align-self: end; }
#loading[hidden] { display: none; }
#loading.done { opacity: 0; pointer-events: none; }
.ld-cn { font-family: var(--pixel); font-weight: 700; font-size: 34px; letter-spacing: 0.3em; margin-right: -0.3em; }
.ld-en { font-family: var(--pixel); font-size: 15px; letter-spacing: 0.08em; margin-top: 10px; }
.ld-flower { position: relative; width: clamp(128px, 19vmin, 176px); height: clamp(128px, 19vmin, 176px); flex: none; }
.ld-flower svg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.3; animation: ld-petal 1.5s linear infinite; will-change: opacity; }
.ld-flower svg:nth-child(1) { animation-delay: -1.5s; }
.ld-flower svg:nth-child(2) { animation-delay: -1.2s; }
.ld-flower svg:nth-child(3) { animation-delay: -0.9s; }
.ld-flower svg:nth-child(4) { animation-delay: -0.6s; }
.ld-flower svg:nth-child(5) { animation-delay: -0.3s; }
@keyframes ld-petal { 0%, 20% { opacity: 1; } 55%, 100% { opacity: 0.3; } }
.ld-msg { display: none; }
#loading.failed .ld-flower svg { animation: none; opacity: 1; }
#loading.failed .ld-msg { display: block; align-self: start; font-family: var(--pixel); font-size: 11px; letter-spacing: 0.04em; max-width: min(520px, 90vw); line-height: 1.6; }
@media (prefers-reduced-motion: reduce) {
  .ld-flower svg { animation: none; opacity: 1; }
}


/* ---- hover, for a mouse ---- */
@media (hover: hover) {
  #menu-btn:hover:not([aria-expanded="true"]), .ti:hover:not([aria-expanded="true"]), .tool:hover:not(.on),
  #levels button:hover:not(.sel), .speeds button:hover:not(.on), .cb-row:hover, #bld .who:hover { background: var(--hover); }
  #bld .st:hover { background: rgba(255, 255, 255, 0.6); }
  .x-btn:hover, #bld-close:hover, #bld .follow:hover, #cases .follow:hover,
  .cb-back:hover, .cb-more:hover { background: var(--label-bg); color: var(--label-ink); }
}

/* ---- a wide screen: a tablet, a computer or a phone on its side ----------------------------
   The same design with more room: larger text and buttons, and each sheet a card at the right
   of the screen, under the menu button. A card is as tall as what it holds, to the foot of
   the screen at most. */
@media (min-width: 721px), (min-width: 600px) and (max-height: 520px) {
  :root { --edge: 14px; --btn: 50px; }
  #title { padding: 9px 14px 10px; }
  #title .t-name { column-gap: 12px; }
  #title .t-cn { font-size: 19px; }
  #title .t-en { font-size: 12px; }
  #title .t-time { margin-top: 3px; font-size: 11px; }

  /* the ids, thus these rules win over the heights of the phone (#bld, #cases, #sources) */
  #time, #floors, #cases, #sources, #bld {
    --sheet-top: calc(var(--top) + var(--btn) + 10px);
    top: var(--sheet-top); right: var(--right); bottom: auto; left: auto; width: min(420px, 46vw);
    max-height: calc(100vh - var(--sheet-top) - max(var(--edge), env(safe-area-inset-bottom)));
    max-height: calc(100dvh - var(--sheet-top) - max(var(--edge), env(safe-area-inset-bottom)));
    border-width: 2px; box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.18); animation-name: sheet-in-side;
  }
  @keyframes sheet-in-side { from { transform: translateX(28px); opacity: 0; } }
  .sheet { padding-bottom: 14px; }
  #bld { padding-bottom: 0; }
  #levels { flex-wrap: wrap; overflow: visible; padding: 0; } /* room for all the storeys: no scroll */
  #found { top: calc(var(--top) + 86px); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, #bld, #title.run #t-colon { animation: none; }
  .ti { transition: none; }
}
