* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #03060f; overflow: hidden; }
body {
  display: flex; align-items: center; justify-content: center;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
  color: #e8ecf4;
}

/* portrait 9:16 stage */
#stage {
  position: relative; overflow: hidden;
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  background: #050a18;
  box-shadow: 0 0 80px rgba(40,80,180,.15);
}
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- top HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  padding: max(14px, 3.2vh) 6% 0;
  text-align: center; pointer-events: none;
  background: linear-gradient(#04070fee, #04070f99 70%, transparent);
}
#dateLine { font-size: clamp(13px, 2.2vh, 18px); letter-spacing: .12em; color: #cdd6e6; }
#clockRow { margin-top: .4vh; display: flex; align-items: baseline; justify-content: center; gap: 12px; }
#tzLabel { font-size: clamp(15px, 2.8vh, 22px); color: #d8b45a; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46%; }
#clock {
  font-size: clamp(44px, 9vh, 84px); font-weight: 800; color: #f2c14e;
  font-variant-numeric: tabular-nums; letter-spacing: .02em; line-height: 1.05;
  text-shadow: 0 0 24px rgba(242,193,78,.35);
}
#timeline { margin-top: 1vh; pointer-events: auto; cursor: pointer; padding: 8px 0 2px; }
#tlTrack { position: relative; height: 4px; background: #2a3346; border-radius: 2px; margin: 0 2px 20px; }
#tlFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: #f2c14e; border-radius: 2px; }
#tlKnob {
  position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%;
  background: #ffd97a; transform: translate(-50%, -50%); left: 0;
  box-shadow: 0 0 10px rgba(255,217,122,.9);
}
.tlTick { position: absolute; top: 8px; transform: translateX(-50%); }
.tlTick::before { content: ""; position: absolute; left: 50%; top: -9px; width: 1px; height: 5px; background: #4a5568; }
.tlTick i { font-style: normal; font-size: clamp(9px, 1.5vh, 12px); color: #7d8aa0; }
.tlTick:first-child i { transform: translateX(0); }
.tlTick:last-child i { transform: translateX(-100%); }

/* ---------- title card ---------- */
#titleCard {
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 8%;
  background: radial-gradient(ellipse at 50% 42%, #04070fdd 0%, #04070f66 55%, transparent 75%);
  transition: opacity 1.1s ease; 
}
#titleCard.fading { opacity: 0; }
#tcDate { font-size: clamp(16px, 3vh, 24px); letter-spacing: .3em; color: #cdd6e6; }
#tcMain {
  margin-top: 1.6vh; font-size: clamp(30px, 6.4vh, 56px); font-weight: 800; color: #fff;
  text-shadow: 0 2px 30px rgba(0,0,0,.8);
}
#tcSub { margin-top: 1.8vh; font-size: clamp(14px, 2.6vh, 20px); color: #f2c14e; font-weight: 600; }
#tcHint { position: absolute; bottom: 14vh; font-size: 12px; color: #7d8aa0; letter-spacing: .2em; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- end card ---------- */
#endCard {
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  display: flex; align-items: flex-end; justify-content: center;
  background: linear-gradient(transparent 10%, #04070fcc 45%, #04070fee 100%);
  opacity: 0; transition: opacity .9s ease;
}
#endCard.shown { opacity: 1; }
#ecInner {
  pointer-events: auto;
  width: 92%; max-height: 78%; overflow-y: auto;
  padding: 2vh 2% calc(9vh + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}
#ecInner h2 { text-align: center; font-size: clamp(15px, 2.6vh, 20px); color: #f2c14e; letter-spacing: .08em; margin-bottom: 1.4vh; }
.ecRow { display: grid; grid-template-columns: minmax(72px, 24%) 1fr; gap: 8px; align-items: center; margin: .85vh 0; }
.ecName { font-size: clamp(11px, 1.9vh, 14px); color: #dfe6f2; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ecBarWrap { position: relative; height: clamp(16px, 2.6vh, 22px); }
.ecBar {
  position: absolute; inset: 0 auto 0 0; border-radius: 4px;
  background: linear-gradient(90deg, #f2c14ecc, #f2c14e55);
  transform-origin: left; animation: grow 1s ease both;
}
.ecBar.polar { background: linear-gradient(90deg, #a78bfaaa, #a78bfa44); }
@keyframes grow { from { transform: scaleX(0); } }
.ecTxt {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  font-size: clamp(10px, 1.7vh, 13px); color: #0b0f1a; font-weight: 700; white-space: nowrap;
}
.ecTxt.outside { color: #dfe6f2; font-weight: 500; }
#ecFooter { margin-top: 1.6vh; text-align: center; font-size: clamp(11px, 1.9vh, 14px); color: #f2c14e; }
#ecFine { margin-top: .8vh; text-align: center; font-size: 10px; color: #66738a; }

/* ---------- controls ---------- */
#controls {
  position: absolute; z-index: 7; right: 3.5%; bottom: max(14px, env(safe-area-inset-bottom, 0px));
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: 94%;
}
#speedGroup { display: flex; }
#speedGroup .spd {
  border-radius: 0; padding: 9px 9px; font-size: 12.5px; min-width: 34px;
  border-right-width: 0; font-variant-numeric: tabular-nums;
}
#speedGroup .spd:first-child { border-radius: 999px 0 0 999px; }
#speedGroup .spd:last-child { border-radius: 0 999px 999px 0; border-right-width: 1px; }
#speedGroup .spd.active {
  background: #f2c14e; color: #0b0f1a; border-color: #f2c14e; font-weight: 800;
  box-shadow: 0 0 12px rgba(242,193,78,.55);
}
#speedGroup .spd.active + .spd { border-left-color: #f2c14e; }
#controls button {
  border: 1px solid #39415a; background: #0d1526cc; color: #e8ecf4;
  border-radius: 999px; padding: 9px 14px; font-size: 14px; cursor: pointer;
  backdrop-filter: blur(6px);
}
#controls button:hover { background: #1a2540; }
#btnPlay { min-width: 52px; font-size: 16px; }

/* ---------- search ---------- */
#searchPanel {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: #04070fd9; backdrop-filter: blur(8px); transition: opacity .5s;
}
#searchPanel.gone { opacity: 0; pointer-events: none; }
#searchBox { width: 86%; max-width: 420px; }
#searchRow { display: flex; gap: 8px; }
#q {
  flex: 1; padding: 13px 16px; font-size: 16px; border-radius: 12px;
  border: 1px solid #39415a; background: #0b1220; color: #fff; outline: none;
}
#q:focus { border-color: #f2c14e; }
#btnGo {
  padding: 13px 18px; border-radius: 12px; border: none; cursor: pointer;
  background: #f2c14e; color: #0b0f1a; font-weight: 700; font-size: 15px;
}
#suggestList {
  margin-top: 6px; border: 1px solid #39415a; border-radius: 12px; overflow: hidden;
  background: #0b1220ee; max-height: 34vh; overflow-y: auto;
}
.sg { padding: 10px 16px; font-size: 15px; cursor: pointer; }
.sg:hover, .sg.active { background: #1c2740; }
.sg small { color: #7d8aa0; margin-left: 8px; }
#dateRow { margin-top: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: #9aa7bd; font-size: 13px; }
#dateIn {
  padding: 8px 10px; border-radius: 8px; border: 1px solid #39415a;
  background: #0b1220; color: #e8ecf4; color-scheme: dark; font-size: 13px;
}
#btnSolstice {
  padding: 8px 12px; border-radius: 8px; border: 1px solid #39415a; background: #0b1220;
  color: #f2c14e; cursor: pointer; font-size: 13px;
}
#dateNote { font-size: 12px; color: #7d8aa0; }
#err { margin-top: 10px; padding: 10px 14px; border-radius: 10px; background: #3a1220; color: #ff9aa8; font-size: 13px; }