:root {
  --bg: #07080a;
  --tile: #14161b;
  --tile2: #1b1e25;
  --line: #262a33;
  --text: #f2f4f7;
  --dim: #8b93a1;
  --faint: #5a616d;
  --up: #34d399;
  --down: #f87171;
  --accent: #60a5fa;
  --warn: #fbbf24;
  --r: 18px;
  --gap: 8px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
  overscroll-behavior: none;
}
body.night { filter: brightness(0.55); }
.num { font-variant-numeric: tabular-nums; }

#pages {
  display: flex;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#pages::-webkit-scrollbar { display: none; }
.page {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 10px) 10px calc(var(--safe-b) + 30px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.page::-webkit-scrollbar { display: none; }
h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 6px 4px 0;
}
.tile {
  background: var(--tile);
  border-radius: var(--r);
  padding: 12px 14px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }

/* clock */
.clock-tile { padding: 8px 14px 10px; background: linear-gradient(160deg, #182033, #12151b 60%); }
.clock { font-size: 64px; font-weight: 200; letter-spacing: -2px; line-height: 1; font-variant-numeric: tabular-nums; }
.clock small { font-size: 22px; color: var(--dim); font-weight: 300; letter-spacing: 0; margin-left: 4px; }
.date { color: var(--dim); font-size: 15px; margin-top: 2px; }
.date::first-letter { text-transform: uppercase; }

/* weather */
.weather-tile { display: flex; flex-direction: column; gap: 10px; }
.w-top { display: flex; align-items: center; gap: 12px; }
.w-icon { font-size: 42px; line-height: 1; }
.w-temp { font-size: 40px; font-weight: 300; line-height: 1; }
.w-meta { color: var(--dim); font-size: 13px; line-height: 1.35; margin-left: auto; text-align: right; }
.w-meta b { color: var(--text); font-weight: 500; }
.hours { display: flex; justify-content: space-between; }
.hour { text-align: center; font-size: 12px; color: var(--dim); width: 16.6%; }
.hour .hi { font-size: 18px; margin: 3px 0 1px; }
.hour .ht { color: var(--text); font-size: 14px; }
.hour .hp { color: var(--accent); font-size: 11px; min-height: 13px; }

/* rain */
.rain-tile { padding: 10px 14px; }
.rain-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--dim); }
.rain-head b { color: var(--text); font-weight: 500; }
.rain-bars { display: flex; align-items: flex-end; gap: 4px; height: 34px; margin-top: 8px; }
.rain-bars i { flex: 1; background: var(--accent); border-radius: 3px 3px 1px 1px; min-height: 2px; opacity: .9; }
.rain-bars i.zero { background: var(--line); }
.rain-tile.dry .rain-bars { height: 6px; }
.rain-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); margin-top: 3px; }

/* mini market tiles */
.mini { padding: 10px 12px; }
.mini .ml { font-size: 12px; color: var(--dim); display: flex; justify-content: space-between; }
.mini .mp { font-size: 20px; font-weight: 500; margin: 2px 0; font-variant-numeric: tabular-nums; }
.mini svg { display: block; width: 100%; height: 26px; }

/* headline */
.headline { font-size: 15px; line-height: 1.35; }
.headline .src { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }

/* market lists */
.list { display: flex; flex-direction: column; gap: 6px; }
.q {
  background: var(--tile);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 70px auto;
  align-items: center;
  gap: 8px;
}
.q .ql { min-width: 0; }
.q .ql b { display: block; font-size: 16px; font-weight: 600; white-space: nowrap; }
.q .ql span { font-size: 12px; color: var(--dim); }
.q svg { width: 70px; height: 28px; display: block; }
.q .qr { text-align: right; min-width: 92px; }
.q .qp { font-size: 16px; font-variant-numeric: tabular-nums; }
.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 7px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.pill.up { background: rgba(52, 211, 153, .15); color: var(--up); }
.pill.down { background: rgba(248, 113, 113, .15); color: var(--down); }
.pill.flat { background: var(--tile2); color: var(--dim); }
.closed { font-size: 10px; color: var(--faint); margin-left: 4px; text-transform: uppercase; }
.up { color: var(--up); }
.down { color: var(--down); }
.err { color: var(--faint); font-size: 13px; }

/* NS */
.ns { padding: 4px 0; }
.dep { display: grid; grid-template-columns: 52px 1fr 34px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line); }
.dep:first-child { border-top: 0; }
.dep .dt { font-size: 16px; font-variant-numeric: tabular-nums; }
.dep .dd { font-size: 11px; color: var(--down); }
.dep .to { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep .ty { font-size: 11px; color: var(--dim); }
.dep .tr { text-align: center; font-size: 15px; font-weight: 600; background: var(--tile2); border-radius: 8px; padding: 3px 0; }
.dep.cx .to, .dep.cx .dt { text-decoration: line-through; color: var(--faint); }
.note { padding: 12px 14px; color: var(--dim); font-size: 13px; line-height: 1.45; }

/* days */
.days { padding: 4px 0; }
.day { display: grid; grid-template-columns: 1fr 34px 40px 40px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 15px; }
.day:first-child { border-top: 0; }
.day .di { font-size: 20px; text-align: center; }
.day .dmin { color: var(--dim); text-align: right; }
.day .dmax { text-align: right; }

/* news */
.news { padding: 2px 0; }
.ni { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 15px; line-height: 1.35; }
.ni:first-child { border-top: 0; }
.ni span { display: block; font-size: 11px; color: var(--dim); margin-top: 3px; }

/* dots + status */
.dots {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--safe-b) + 8px);
  display: flex;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}
.dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--faint); transition: width .2s, background .2s; }
.dots i.on { width: 16px; background: var(--text); }
.status {
  position: fixed;
  top: calc(var(--safe-t) + 8px);
  right: 10px;
  z-index: 5;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(251, 191, 36, .15);
  color: var(--warn);
}
.hidden { display: none; }

/* landscape: two columns on the first page */
@media (orientation: landscape) {
  .clock { font-size: 52px; }
  #p-now { display: grid; grid-template-columns: 1fr 1fr; align-content: start; }
  #p-now .headline { grid-column: 1 / -1; }
}

/* ---------- interactivity */
[data-tap] { cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .12s ease, background .2s; }
[data-tap]:active { transform: scale(.97); }
body:not(.ready) .tile, body:not(.ready) .q { animation: fadein .35s ease both; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.flash-up { animation: flashUp 1.1s ease; }
.flash-down { animation: flashDown 1.1s ease; }
@keyframes flashUp { 0% { background: rgba(52, 211, 153, .32); } 100% { background: transparent; } }
@keyframes flashDown { 0% { background: rgba(248, 113, 113, .32); } 100% { background: transparent; } }
.qp, .mp { border-radius: 6px; padding: 0 3px; margin-right: -3px; }
.bell { font-size: 11px; margin-left: 4px; }
.livedot { display: inline-block; width: 6px; height: 6px; border-radius: 3px; background: var(--up); margin-left: 6px; vertical-align: middle; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* pull to refresh */
.ptr {
  position: fixed; top: calc(var(--safe-t) - 40px); left: 50%; z-index: 6;
  width: 34px; height: 34px; margin-left: -17px; border-radius: 17px;
  background: var(--tile2); color: var(--text); font-size: 18px;
  display: flex; align-items: center; justify-content: center; opacity: 0;
  transition: opacity .15s;
}
.ptr.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* bottom sheet */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 10; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-height: 92%; background: #111318; border-radius: 20px 20px 0 0;
  transform: translateY(105%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
}
.sheet.on { transform: none; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--faint); margin: 8px auto 4px; flex: 0 0 auto; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 14px 18px; }
.sh-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.sh-head h3 { font-size: 22px; font-weight: 600; }
.sh-head span { color: var(--dim); font-size: 13px; }
.sh-price { font-size: 32px; font-weight: 300; margin: 2px 0 2px; font-variant-numeric: tabular-nums; }
.sh-sub { font-size: 13px; color: var(--dim); min-height: 18px; font-variant-numeric: tabular-nums; }
.big-chart { position: relative; height: 150px; margin: 10px 0 6px; touch-action: none; }
.big-chart svg { width: 100%; height: 100%; display: block; }
.big-chart .cursor { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--dim); display: none; }
.big-chart .cdot { position: absolute; width: 9px; height: 9px; margin: -4px 0 0 -4px; border-radius: 5px; background: var(--text); display: none; }
.big-chart .loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 13px; }
.seg { display: flex; background: var(--tile); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; color: var(--dim); font: 600 13px -apple-system, sans-serif; padding: 7px 0; border-radius: 8px; }
.seg button.on { background: var(--tile2); color: var(--text); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.stats div { background: var(--tile); border-radius: 10px; padding: 8px 10px; font-size: 12px; color: var(--dim); }
.stats b { display: block; color: var(--text); font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; }
.sh-section { margin-top: 14px; }
.sh-section h4 { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; font-weight: 600; }
.alarm-row { display: flex; align-items: center; gap: 8px; background: var(--tile); border-radius: 10px; padding: 9px 10px; margin-bottom: 6px; font-size: 14px; }
.alarm-row .at { flex: 1; font-variant-numeric: tabular-nums; }
.alarm-row .at small { display: block; color: var(--dim); font-size: 11px; }
.alarm-row.hit { box-shadow: inset 3px 0 0 var(--warn); }
.btn { border: 0; border-radius: 9px; padding: 8px 12px; font: 600 13px -apple-system, sans-serif; background: var(--tile2); color: var(--text); }
.btn.primary { background: var(--accent); color: #06121f; }
.btn.danger { background: rgba(248, 113, 113, .15); color: var(--down); }
.alarm-add { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; }
.alarm-add select, .alarm-add input {
  font: 16px -apple-system, sans-serif; color: var(--text); background: var(--tile); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 8px; width: 100%; min-width: 0; -webkit-appearance: none; appearance: none;
}
.alarm-add select { width: auto; }
.hint { font-size: 12px; color: var(--faint); margin-top: 6px; }
.wx-chart { height: 120px; margin: 8px 0; }
.wx-chart svg { width: 100%; height: 100%; display: block; }
.wx-list { display: flex; flex-direction: column; }
.wx-row { display: grid; grid-template-columns: 44px 30px 1fr 44px 52px; align-items: center; padding: 7px 2px; border-top: 1px solid var(--line); font-size: 14px; font-variant-numeric: tabular-nums; }
.wx-row:first-child { border-top: 0; }
.wx-row .p { color: var(--accent); font-size: 12px; text-align: right; }
.wx-row .w { color: var(--dim); font-size: 12px; text-align: right; }
.news-full h3 { font-size: 19px; line-height: 1.3; font-weight: 600; margin: 4px 0 6px; }
.news-full p { font-size: 15px; line-height: 1.5; color: #d5d9e0; }
.news-full .meta { font-size: 12px; color: var(--dim); }
.news-full a.btn { display: inline-block; margin-top: 12px; text-decoration: none; }
.alarm-chip { display: flex; align-items: center; gap: 8px; background: rgba(251, 191, 36, .12); color: var(--warn); border-radius: 12px; padding: 9px 12px; font-size: 13px; }

/* login */
body.login { display: flex; align-items: center; justify-content: center; overflow: auto; }
.pinbox { text-align: center; padding: 20px; width: 100%; max-width: 300px; }
.pinbox img { border-radius: 13px; }
.pinbox h1 { font-size: 20px; font-weight: 600; margin: 8px 0 2px; }
.pinbox p { color: var(--dim); font-size: 14px; min-height: 20px; }
.pindots { display: flex; justify-content: center; gap: 10px; margin: 16px 0 20px; }
.pindots i { width: 12px; height: 12px; border-radius: 6px; border: 1.5px solid var(--dim); }
.pindots i.on { background: var(--text); border-color: var(--text); }
.pindots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pad button { height: 60px; border: 0; border-radius: 30px; background: var(--tile2); color: var(--text); font: 300 26px -apple-system, sans-serif; }
.pad button.fn { background: none; font-size: 18px; font-weight: 500; }
.pad button:active { background: var(--line); }
