:root {
  color-scheme: dark;
  --bg: #0e161c;
  --device: #18232b;
  --line: rgba(207, 220, 228, 0.22);
  --text: #d9e0e4;
  --muted: #98a5ad;
  --green: #18ee6f;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  background:
    radial-gradient(circle at 50% 2%, rgba(105, 130, 144, 0.15), transparent 34%),
    linear-gradient(180deg, #17222a 0%, #0d1419 100%);
}

button {
  color: inherit;
  font: inherit;
}

.device {
  width: min(100%, 540px);
  height: 100vh;
  height: 100svh;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding:
    max(24px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none;
  touch-action: none;
  scrollbar-width: none;
  gap: clamp(18px, 2.7svh, 28px);
  background:
    repeating-linear-gradient(118deg, rgba(255, 255, 255, 0.007) 0 1px, transparent 1px 4px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018), transparent 13%, transparent 87%, rgba(255, 255, 255, 0.014)),
    var(--device);
  box-shadow: 0 0 110px rgba(0, 0, 0, 0.42);
}

.device::-webkit-scrollbar { display: none; }

.console {
  min-height: 112px;
  padding: 7px 10px 0;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) 34px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
}

.status-readout {
  margin: 0;
  display: grid;
  gap: 7px;
  color: #c8d1d6;
  font-size: clamp(9px, 2.55vw, 12px);
  letter-spacing: 0.14em;
  line-height: 1.2;
}

.status-readout div {
  display: grid;
  grid-template-columns: 46px 8px minmax(0, 1fr);
  align-items: baseline;
}

.status-readout div::before {
  content: ":";
  grid-column: 2;
  grid-row: 1;
  color: var(--muted);
}

.status-readout dt,
.status-readout dd {
  margin: 0;
  font-weight: 400;
}

.status-readout dt { grid-column: 1; }

.status-readout dd {
  grid-column: 3;
  min-width: 0;
  color: var(--muted);
  white-space: nowrap;
}

.status-light {
  width: 12px;
  height: 12px;
  margin: 13px auto 0;
  border-radius: 50%;
  background: var(--green);
  box-shadow:
    0 0 7px rgba(24, 238, 111, 0.95),
    0 0 22px rgba(24, 238, 111, 0.5);
}

.brand-block {
  padding-top: 2px;
  text-align: right;
}

.brand-block h1 {
  margin: 0;
  color: #eef2f4;
  font-size: clamp(22px, 7vw, 34px);
  font-weight: 400;
  letter-spacing: 0.22em;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 0 12px rgba(230, 238, 242, 0.08);
}

.brand-block p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: clamp(8px, 2.2vw, 11px);
  letter-spacing: 0.14em;
}

.notification-toggle {
  min-height: 44px;
  margin: 7px 0 0 auto;
  padding: 5px 0 5px 7px;
  display: grid;
  grid-template-columns: auto auto 34px;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.notification-label,
.notification-state {
  font-size: 8px;
  letter-spacing: 0.09em;
  line-height: 1;
}

.notification-state {
  min-width: 17px;
  color: #738087;
  text-align: right;
}

.switch-track {
  position: relative;
  width: 34px;
  height: 18px;
  border: 1px solid rgba(204, 217, 226, 0.3);
  border-radius: 999px;
  background: #11171b;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #7d898f;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.notification-toggle[aria-checked="true"] { color: #cbd4d8; }
.notification-toggle[aria-checked="true"] .notification-state { color: var(--green); }

.notification-toggle[aria-checked="true"] .switch-track {
  border-color: rgba(24, 238, 111, 0.55);
  background: rgba(24, 238, 111, 0.14);
  box-shadow: inset 0 0 8px rgba(24, 238, 111, 0.08);
}

.notification-toggle[aria-checked="true"] .switch-thumb {
  transform: translateX(16px);
  background: var(--green);
  box-shadow: 0 0 8px rgba(24, 238, 111, 0.72);
}

.chamber {
  position: relative;
  isolation: isolate;
  width: 100%;
  min-height: 0;
  aspect-ratio: 1.064 / 1;
  overflow: hidden;
  border: 1px solid rgba(4, 7, 9, 0.96);
  background-color: #222d34;
  background-image: url("./assets/chamber-bg-v1.webp");
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-shadow:
    inset 0 0 0 1px rgba(218, 228, 233, 0.08),
    0 20px 42px rgba(0, 0, 0, 0.3);
  transition: filter 1100ms ease;
  touch-action: manipulation;
}

.chamber::before,
.chamber::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.chamber::before {
  z-index: 7;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.045), transparent 18%),
    linear-gradient(90deg, rgba(173, 194, 205, 0.025), transparent 9%, transparent 91%, rgba(173, 194, 205, 0.02));
  mix-blend-mode: screen;
}

.chamber::after {
  z-index: 6;
  opacity: 0;
  background:
    radial-gradient(ellipse at 50% 9%, rgba(8, 12, 15, 0.76), transparent 24%),
    rgba(4, 8, 10, 0.32);
  transition: opacity 1100ms ease;
}

.chamber-ceiling,
.light-cone,
.vent { display: none; }

.chamber > .lamp {
  position: absolute;
  z-index: 10;
  top: 9.3%;
  left: 50%;
  width: 21%;
  min-width: 72px;
  height: 48px;
  min-height: 44px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  background: transparent;
  cursor: pointer;
}

.lamp span {
  position: absolute;
  inset: 13px 7px;
  border-radius: 50%;
  opacity: 0.2;
  background: #fffef5;
  box-shadow: 0 0 24px rgba(255, 255, 245, 0.6);
  transition: background 1100ms ease, box-shadow 1100ms ease, opacity 1100ms ease;
}

.device[data-lamp="off"] .chamber { filter: brightness(0.52) saturate(0.7); }
.device[data-lamp="off"] .chamber::after { opacity: 1; }

.device[data-lamp="off"] .lamp span {
  opacity: 0.95;
  border: 1px solid rgba(111, 126, 135, 0.22);
  background: #242e34;
  box-shadow: 0 0 2px rgba(126, 139, 146, 0.18);
}

.lamp:disabled { cursor: progress; }

.platform {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 3.5%;
  width: 34%;
  height: auto;
  aspect-ratio: 640 / 377;
  transform: translateX(-50%);
  border: 0;
  background: url("./assets/platform-v1.webp") center / contain no-repeat;
  filter: drop-shadow(0 12px 10px rgba(0, 0, 0, 0.42));
}

.platform-top { display: none; }

.fly {
  position: absolute;
  z-index: 5;
  width: var(--fly-size, 28px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(var(--rotation, 0deg)) scale(var(--fly-scale, 1));
  transform-origin: 50% 50%;
  background: url("./assets/fly-v1.webp") center / contain no-repeat;
  filter:
    drop-shadow(0 1px 1px rgba(0, 0, 0, 0.9))
    brightness(var(--brightness, 0.86));
  pointer-events: none;
  will-change: left, top, transform;
}

.fly::before,
.fly::after,
.fly i { display: none; }

.fly-one { --fly-size: 21px; --brightness: 0.95; }
.fly-two { --fly-size: 19px; --brightness: 0.82; }
.fly-three { --fly-size: 20px; --brightness: 0.9; }
.fly-four { --fly-size: 21px; --brightness: 0.86; }
.fly-five { --fly-size: 19px; --brightness: 0.8; }

.fly[data-surface="left"],
.fly[data-surface="right"] {
  filter:
    drop-shadow(1px 1px 1px rgba(0, 0, 0, 0.92))
    brightness(var(--brightness, 0.86))
    brightness(0.82);
}

.fly[data-surface="floor"],
.fly[data-surface="platform"] { z-index: 6; }

.fly.is-fidgeting,
.fly.is-walking {
  background-image: url("./assets/fly-walk-v2.webp");
  background-position: 0 0;
  background-size: 400% 100%;
  animation: leg-cycle 190ms steps(3, end) infinite;
}

.fly.is-fidgeting { animation-duration: 250ms; }

.fly.is-flying,
.fly.is-settling {
  z-index: 9;
  background-image: url("./assets/fly-flight-v2.webp");
  background-position: 0 0;
  background-size: 400% 100%;
  filter:
    drop-shadow(0 2px 2px rgba(0, 0, 0, 0.72))
    brightness(var(--brightness, 0.86))
    brightness(1.08);
  animation: wingbeat 64ms steps(3, end) infinite;
}

.fly.is-settling { animation-duration: 118ms; }

@keyframes wingbeat {
  from { background-position: 0 0; }
  to { background-position: 100% 0; }
}

@keyframes leg-cycle {
  from { background-position: 0 0; }
  to { background-position: 100% 0; }
}

.glass-pulse {
  position: absolute;
  z-index: 12;
  top: var(--tap-y, 50%);
  left: var(--tap-x, 50%);
  width: 12px;
  height: 12px;
  border: 1px solid rgba(220, 234, 240, 0.48);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.45);
}

.glass-pulse.is-active { animation: glass-response 420ms ease-out; }

@keyframes glass-response {
  0% { opacity: 0.7; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(4.8); }
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.control {
  min-width: 0;
  min-height: 136px;
  padding: 22px 5px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  border: 1px solid rgba(205, 218, 226, 0.23);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.022), transparent 42%),
    rgba(8, 14, 18, 0.08);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.035),
    0 8px 18px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}

.control svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: #e2e7e9;
  stroke-width: 2.35;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.24));
}

.control > span {
  max-width: 100%;
  color: #c9d1d5;
  font-size: clamp(8px, 2.25vw, 10px);
  letter-spacing: 0.12em;
  line-height: 1.3;
  white-space: nowrap;
}

.control strong {
  margin-top: -8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.12em;
}

.control:active { background-color: rgba(220, 232, 238, 0.025); }

.control:focus-visible,
.lamp:focus-visible,
.notification-toggle:focus-visible {
  outline: 2px solid rgba(24, 238, 111, 0.82);
  outline-offset: 3px;
}

@media (min-width: 560px) {
  body { padding: 20px 0; }

  .device {
    height: calc(100svh - 40px);
    min-height: calc(100svh - 40px);
    border: 1px solid rgba(212, 224, 230, 0.08);
  }
}

@media (max-width: 380px), (max-height: 760px) {
  .device {
    gap: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .console { min-height: 100px; }

  .control {
    min-height: 116px;
    padding-top: 16px;
    gap: 10px;
  }

  .control svg {
    width: 32px;
    height: 32px;
  }

}

@media (max-width: 340px) {
  .notification-toggle { grid-template-columns: auto 34px; }
  .notification-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { scroll-behavior: auto !important; }

  .switch-track,
  .switch-thumb,
  .chamber,
  .chamber::after,
  .lamp span { transition: none; }

  .fly.is-flying,
  .fly.is-settling,
  .fly.is-fidgeting,
  .fly.is-walking,
  .glass-pulse.is-active { animation: none; }
}
