:root {
  color-scheme: light;
  --ink: #123146;
  --muted: #547083;
  --glass: rgba(247, 252, 255, .68);
  --line: rgba(31, 83, 112, .13);
  --control-bg: rgba(255,255,255,.76);
  --icon-bg: rgba(255,255,255,.62);
  --sky-background: linear-gradient(155deg, #dceef6 0%, #c8e0ed 45%, #f3e8cf 100%);
  --yard: #168e83;
  --floor: #ef8f4b;
  --shadow: 0 24px 70px rgba(41, 83, 108, .14);
  --celestial-x: 76vw;
  --celestial-y: 10vh;
  --sun-core: #fff8be;
  --sun-ring: #ffd36f;
  --sun-glow: rgba(255, 202, 92, .42);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #101d31; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--sky-background);
  transition: color 1.8s ease, background 2.5s ease;
}

body[data-theme="dawn"] {
  --sky-background: linear-gradient(155deg, #b9d4e5 0%, #e9c7ba 55%, #f4c88e 100%);
  --sun-glow: rgba(255, 145, 64, .5);
}

body[data-theme="sunset"] {
  --sky-background: linear-gradient(155deg, #9dbed3 0%, #e4a491 52%, #f29a55 100%);
  --glass: rgba(251, 241, 232, .7);
  --sun-glow: rgba(255, 104, 36, .58);
}

body[data-theme="night"] {
  color-scheme: dark;
  --ink: #edf6ff;
  --muted: #a9bdd0;
  --glass: rgba(14, 31, 53, .72);
  --line: rgba(177, 209, 233, .15);
  --control-bg: rgba(176, 209, 236, .13);
  --icon-bg: rgba(181, 214, 239, .1);
  --shadow: 0 24px 70px rgba(1, 8, 20, .34);
  --sky-background: radial-gradient(circle at 72% 18%, #243b60 0%, #111f36 43%, #080f1e 100%);
}

.sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.sky::after {
  content: "";
  position: absolute;
  inset: auto -10% -35% -10%;
  height: 62%;
  background: radial-gradient(ellipse at center, rgba(255,255,255,.6), rgba(255,255,255,0) 68%);
  opacity: 1;
  transition: opacity 2.5s ease;
}
.celestial {
  position: absolute;
  left: var(--celestial-x);
  top: var(--celestial-y);
  width: 1px;
  height: 1px;
  transition: left 60s linear, top 60s linear;
}
.sun, .moon {
  position: absolute;
  left: 0;
  top: 0;
  width: 230px;
  height: 230px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 2.2s ease, background 2.2s ease, box-shadow 2.2s ease;
}
.sun {
  background: radial-gradient(circle, var(--sun-core) 0 14%, var(--sun-ring) 31%, rgba(255,208,119,0) 70%);
  opacity: .92;
  filter: drop-shadow(0 0 34px var(--sun-glow));
  animation: sun-breathe 7s ease-in-out infinite;
}
.moon {
  width: 104px;
  height: 104px;
  opacity: 0;
  background: radial-gradient(circle at 38% 34%, #fffef0 0 18%, #e7ebdc 58%, #bbc8cf 100%);
  box-shadow: 0 0 30px rgba(208, 230, 255, .34), 0 0 90px rgba(151, 191, 229, .18);
}
.moon i { position: absolute; border-radius: 50%; background: rgba(127, 146, 153, .19); box-shadow: inset 2px 2px 5px rgba(93,112,120,.14); }
.moon i:nth-child(1) { width: 19px; height: 19px; left: 22px; top: 27px; }
.moon i:nth-child(2) { width: 11px; height: 11px; right: 23px; top: 20px; }
.moon i:nth-child(3) { width: 25px; height: 25px; right: 21px; bottom: 22px; }
.stars {
  position: absolute;
  inset: 0;
  opacity: 0;
  background-image:
    radial-gradient(circle at 12% 18%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 31% 11%, #ddebff 0 1.2px, transparent 1.8px),
    radial-gradient(circle at 52% 24%, #fff 0 .8px, transparent 1.5px),
    radial-gradient(circle at 72% 9%, #fff 0 1px, transparent 1.7px),
    radial-gradient(circle at 88% 31%, #d8eaff 0 1.2px, transparent 1.8px),
    radial-gradient(circle at 20% 48%, #fff 0 .9px, transparent 1.5px),
    radial-gradient(circle at 64% 55%, #fff 0 1px, transparent 1.7px);
  background-size: 310px 230px, 390px 280px, 270px 210px, 430px 320px, 350px 270px, 460px 350px, 290px 250px;
  transition: opacity 2.5s ease;
  animation: twinkle 5s ease-in-out infinite alternate;
}
.horizon-glow { position: absolute; inset: auto -10% -12% -10%; height: 38%; opacity: 0; background: radial-gradient(ellipse at center, rgba(255,116,48,.45), transparent 65%); transition: opacity 2s ease; }
body[data-theme="sunset"] .horizon-glow, body[data-theme="dawn"] .horizon-glow { opacity: 1; }
body[data-theme="night"] .sun { opacity: 0; }
body[data-theme="night"] .moon { opacity: .94; animation: moon-breathe 8s ease-in-out infinite; }
body[data-theme="night"] .stars { opacity: .72; }
body[data-theme="night"] .sky::after { opacity: .12; }
body[data-theme="night"] .cloud {
  --cloud-highlight: rgba(184, 205, 224, .58);
  --cloud-light: rgba(130, 158, 184, .5);
  --cloud-shade: rgba(58, 82, 112, .46);
  opacity: .24;
  filter: drop-shadow(0 13px 20px rgba(1, 8, 20, .28));
}
.cloud {
  --cloud-scale: 1;
  --cloud-highlight: rgba(255, 255, 255, .98);
  --cloud-light: rgba(239, 248, 252, .92);
  --cloud-shade: rgba(135, 169, 190, .32);
  position: absolute;
  width: 390px;
  height: 150px;
  opacity: .72;
  filter: drop-shadow(0 15px 24px rgba(57, 102, 128, .2));
  transform: translate3d(0, 0, 0) scale(var(--cloud-scale));
  transform-origin: center;
  will-change: transform;
  animation: drift 42s linear infinite;
}
.cloud::before {
  content: "";
  position: absolute;
  z-index: 2;
  left: 28px;
  right: 22px;
  bottom: 20px;
  height: 76px;
  border-radius: 55% 52% 48% 46% / 64% 62% 44% 42%;
  background:
    radial-gradient(ellipse at 52% 15%, var(--cloud-highlight), transparent 56%),
    linear-gradient(180deg, var(--cloud-light) 4%, var(--cloud-light) 58%, var(--cloud-shade) 100%);
  box-shadow:
    inset 0 17px 24px rgba(255, 255, 255, .28),
    inset 0 -15px 19px rgba(77, 120, 148, .13);
}
.cloud::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 58px;
  bottom: 9px;
  width: 282px;
  height: 39px;
  border-radius: 50%;
  background: radial-gradient(ellipse, var(--cloud-shade), transparent 70%);
  opacity: .62;
  filter: blur(8px);
}
.cloud-one { --cloud-scale: 1.06; top: 16%; left: -430px; animation-delay: -9s; }
.cloud-two { --cloud-scale: .68; top: 57%; left: -430px; animation-duration: 58s; animation-delay: -31s; opacity: .4; }
.cloud i {
  position: absolute;
  z-index: 3;
  display: block;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 23%, var(--cloud-highlight) 0 18%, var(--cloud-light) 58%, var(--cloud-shade) 100%);
  box-shadow:
    inset 7px 10px 18px rgba(255, 255, 255, .28),
    inset -8px -10px 18px rgba(73, 116, 144, .1);
}
.cloud i:nth-child(1) { width: 94px; height: 91px; left: 45px; bottom: 42px; }
.cloud i:nth-child(2) { width: 136px; height: 126px; left: 104px; bottom: 43px; }
.cloud i:nth-child(3) { width: 112px; height: 104px; left: 200px; bottom: 42px; }
.cloud i:nth-child(4) { width: 76px; height: 72px; left: 278px; bottom: 36px; z-index: 4; }
.cloud i:nth-child(5) { width: 65px; height: 59px; left: 22px; bottom: 31px; z-index: 4; }
.cloud i:nth-child(6) { width: 83px; height: 70px; left: 157px; bottom: 25px; z-index: 5; opacity: .82; }
.cloud i:nth-child(7) { width: 70px; height: 61px; left: 239px; bottom: 25px; z-index: 5; opacity: .76; }
.grain { position: absolute; inset: 0; opacity: .055; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E"); }

.shell { position: relative; width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 64px 0 32px; }
.hero { margin-bottom: 44px; animation: rise .8s cubic-bezier(.2,.8,.2,1) both; }
.eyebrow, .section-kicker { margin: 0 0 14px; color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .16em; text-transform: uppercase; }
.live-dot { display: inline-block; width: 8px; height: 8px; margin-right: 9px; border-radius: 50%; background: #3bbd84; box-shadow: 0 0 0 5px rgba(59,189,132,.13); animation: pulse 2s ease-out infinite; }
h1 { max-width: 1100px; margin: 0; font-size: clamp(36px, 5.25vw, 68px); font-weight: 650; letter-spacing: -.06em; line-height: .94; }
h1 span { display: inline-block; }
.hero-meta { display: flex; align-items: center; gap: 14px; margin-top: 28px; color: var(--muted); font-size: 14px; }
.divider { width: 34px; height: 1px; background: rgba(18,49,70,.35); }

.sensor-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.sensor-card, .chart-card {
  border: 1px solid color-mix(in srgb, var(--ink) 7%, transparent);
  border-radius: 25px;
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.1);
}
.sensor-card { position: relative; min-height: 224px; padding: 22px; overflow: hidden; animation: rise .75s cubic-bezier(.2,.8,.2,1) both; }
.sensor-card:nth-child(2) { animation-delay: .09s; }
.sensor-card:nth-child(3) { animation-delay: .18s; }
.sensor-card::before { content: ""; position: absolute; width: 190px; height: 190px; right: -70px; top: -70px; border-radius: 50%; background: var(--accent); opacity: .12; filter: blur(4px); }
.sensor-card-offline { border-style: dashed; }
.sensor-card-offline::before { opacity: .055; }
.sensor-card-offline .temperature { color: var(--muted); }
.sensor-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sensor-place { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 700; white-space: nowrap; }
.place-icon { display: grid; place-items: center; flex: 0 0 auto; width: 34px; height: 34px; border-radius: 11px; background: var(--icon-bg); color: var(--accent); }
.status { display: flex; align-items: center; justify-content: flex-end; gap: 6px; color: var(--muted); font-size: 10px; text-align: right; line-height: 1.2; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #39b982; }
.status.stale::before { background: #e09a50; }
.status.offline::before { background: #df6b61; box-shadow: 0 0 0 5px rgba(223,107,97,.1); }
.temperature { margin: 25px 0 18px; font-size: clamp(58px, 6vw, 76px); font-weight: 590; letter-spacing: -.075em; line-height: .8; }
.temperature sup { position: relative; top: -1.65em; margin-left: 6px; font-size: 15px; letter-spacing: 0; }
.sensor-details { display: grid; grid-template-columns: .9fr 1.25fr 1.05fr; gap: 12px; padding-top: 17px; border-top: 1px solid var(--line); }
.detail span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.detail strong { font-size: 14px; font-weight: 680; white-space: nowrap; }
.trend { display: inline-block; color: var(--accent); transform: translateY(-1px); }
.trend.up { color: #db7440; }
.trend.down { color: #347fae; }
.trend.stable { color: var(--muted); }

.chart-card { margin-top: 18px; padding: 30px; animation: rise .8s .16s cubic-bezier(.2,.8,.2,1) both; }
.chart-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.chart-head h2 { margin: 0; font-size: 31px; font-weight: 650; letter-spacing: -.04em; }
.section-kicker { margin-bottom: 7px; }
.periods { display: flex; gap: 5px; padding: 4px; border-radius: 13px; background: rgba(86,117,135,.1); }
.periods button { border: 0; border-radius: 10px; padding: 9px 12px; color: var(--muted); font: inherit; font-size: 12px; font-weight: 650; background: transparent; cursor: pointer; transition: .2s ease; }
.periods button:hover, .periods button.active { color: var(--ink); background: var(--control-bg); box-shadow: 0 3px 12px rgba(50,77,93,.08); }
.sensor-color-0 { --sensor-color: #168e83; --accent: #168e83; }
.sensor-color-1 { --sensor-color: #ef8f4b; --accent: #ef8f4b; }
.sensor-color-2 { --sensor-color: #7a6ee6; --accent: #7a6ee6; }
.sensor-color-3 { --sensor-color: #d45c86; --accent: #d45c86; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 8px; }
.legend-item { display: flex; align-items: center; gap: 10px; min-width: 172px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--control-bg); }
.legend-swatch { position: relative; display: block; flex: 0 0 34px; width: 34px; height: 4px; border-radius: 10px; background: var(--sensor-color); box-shadow: 0 3px 8px color-mix(in srgb, var(--sensor-color) 28%, transparent); }
.legend-swatch::after { content: ''; position: absolute; top: 50%; left: 50%; width: 8px; height: 8px; border: 2px solid var(--control-bg); border-radius: 50%; background: var(--sensor-color); transform: translate(-50%, -50%); }
.legend-text { display: grid; gap: 1px; }
.legend-text strong { color: var(--ink); font-size: 13px; font-weight: 700; line-height: 1.1; }
.legend-text small { color: var(--muted); font-size: 10px; line-height: 1.1; }
.chart-note { min-height: 17px; margin: 7px 0 4px; color: var(--muted); font-size: 12px; }
.chart-scroll { width: 100%; overflow: visible; }
.chart-wrap { position: relative; width: 100%; height: 320px; }
#temperatureChart { width: 100%; height: 100%; overflow: visible; }
.grid-line { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.axis-label { fill: var(--muted); font-size: 11px; }
.chart-line { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; filter: drop-shadow(0 5px 5px rgba(25,70,91,.1)); }
.chart-area { opacity: .1; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.chart-empty[hidden] { display: none; }
.tooltip { position: absolute; z-index: 3; transform: translate(-50%, -110%); padding: 8px 10px; border: 1px solid rgba(255,255,255,.8); border-radius: 10px; color: var(--ink); font-size: 12px; white-space: nowrap; background: rgba(255,255,255,.88); box-shadow: 0 8px 30px rgba(32,66,87,.14); pointer-events: none; }
.scroll-hint { display: none; color: var(--muted); font-size: 11px; }
footer { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; padding: 22px 4px 0; color: var(--muted); opacity: .72; font-size: 11px; letter-spacing: .04em; }
footer > :last-child { text-align: right; }
.visitor-count { color: var(--ink); font-weight: 700; text-align: center; }

.skeleton { background: linear-gradient(105deg, rgba(255,255,255,.42) 30%, rgba(255,255,255,.76) 45%, rgba(255,255,255,.42) 60%); background-size: 240% 100%; animation: shimmer 1.3s linear infinite; }

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(var(--cloud-scale)); }
  to { transform: translate3d(calc(100vw + 520px), 0, 0) scale(var(--cloud-scale)); }
}
@keyframes sun-breathe { 50% { transform: translate(-50%, -50%) scale(1.06); opacity: 1; } }
@keyframes moon-breathe { 50% { transform: translate(-50%, -50%) scale(1.035); } }
@keyframes twinkle { 50% { filter: brightness(1.25); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(59,189,132,.36); } 70%, 100% { box-shadow: 0 0 0 8px rgba(59,189,132,0); } }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { background-position-x: -240%; } }

@media (max-width: 940px) {
  .sensor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .shell { width: min(100% - 24px, 1120px); padding-top: 44px; }
  .hero { margin-bottom: 34px; }
  h1 { font-size: clamp(31px, 9.6vw, 49px); line-height: .98; }
  .hero-meta { align-items: flex-start; flex-direction: column; gap: 7px; }
  .divider { display: none; }
  .sensor-grid { grid-template-columns: 1fr; }
  .sensor-card { min-height: 220px; }
  .chart-card { padding: 22px 16px 14px; overflow: hidden; }
  .chart-head { align-items: flex-start; flex-direction: column; }
  .periods { width: 100%; }
  .periods button { flex: 1; }
  .scroll-hint { display: block; margin: 10px 0 0; }
  .chart-scroll { margin: 0 -16px; width: calc(100% + 32px); padding: 0 16px 10px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--muted) transparent; }
  .chart-scroll::-webkit-scrollbar { height: 4px; }
  .chart-scroll::-webkit-scrollbar-thumb { border-radius: 8px; background: var(--muted); }
  .chart-wrap { width: 760px; height: 290px; }
  .celestial .sun { width: 175px; height: 175px; }
  .celestial .moon { width: 82px; height: 82px; }
  footer { grid-template-columns: 1fr; gap: 7px; text-align: center; }
  footer > :last-child { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  .cloud-one { animation: drift 38s linear -7s infinite !important; }
  .cloud-two { animation: drift 52s linear -25s infinite !important; }
}
