:root {
  /* Tell the browser the page supports both schemes so form controls,
     scrollbars and the default canvas follow the OS preference. */
  color-scheme: light dark;
  --bg: #0f1419;
  --bg-2: #161c24;
  --surface: #1b232d;
  --surface-2: #212b37;
  --line: #3a4757;
  --text: #eef2f7;
  --muted: #8d9cb0;
  --accent: #5b9dff;
  --accent-soft: rgba(91, 157, 255, 0.16);
  --win-bg: #0e151d;
  --shade: #2c3a4b;
  --shade-line: #46596e;
  --ok: #3fce7c;
  --err: #ff5d6c;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --motion: 2.4s cubic-bezier(0.22, 1, 0.36, 1);
  /* Open/close half overlays (top lighter, bottom darker). */
  --wash-open: rgba(255, 255, 255, 0.08);
  --wash-close: rgba(0, 0, 0, 0.26);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-2: #eef1f6;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --line: #d6dde7;
    --text: #1a2330;
    --muted: #6b7888;
    --accent: #2f7df6;
    --accent-soft: rgba(47, 125, 246, 0.12);
    --win-bg: #f0f4fa;
    --shade: #cdd8e6;
    --shade-line: #aab9cc;
    --shadow: 0 10px 28px rgba(31, 50, 79, 0.12);
    --wash-open: rgba(0, 0, 0, 0.015);
    --wash-close: rgba(0, 0, 0, 0.07);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: radial-gradient(
      1200px 600px at 50% -10%,
      var(--bg-2),
      var(--bg) 60%
    )
    fixed;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}
.svg-defs {
  position: absolute;
}

/* ===== Boot ===== */
.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.boot__spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Login ===== */
.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
}
.login__card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 26px 26px;
  display: flex;
  flex-direction: column;
  text-align: center;
}
.login__logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--accent-soft);
}
.login__logo-svg {
  width: 38px;
  height: 38px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.login__title {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.5px;
}
.login__subtitle {
  margin: 6px 0 22px;
  color: var(--muted);
  font-size: 14px;
}
.login__label {
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.login__input {
  width: 100%;
  font-size: 17px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login__btn {
  margin-top: 16px;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 16px;
  border-radius: 14px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s, opacity 0.15s;
}
.login__btn:active {
  transform: scale(0.98);
}
.login__btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.login__error {
  margin: 14px 0 0;
  color: var(--err);
  font-size: 14px;
}

/* ===== App ===== */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px
    calc(28px + env(safe-area-inset-bottom));
}
.app__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 2px 22px;
}
.app__title {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.5px;
}
.app__logout {
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.app__logout:active {
  background: var(--surface);
}

/* ===== Rooms ===== */
.room {
  margin-bottom: 28px;
}
.room__title {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin: 0 2px 12px;
}
.room__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 560px) {
  .room__grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===== Tile ===== */
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.25s, border-color 0.25s;
}
.tile.is-ok {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px var(--ok), var(--shadow);
}
.tile.is-err {
  border-color: var(--err);
  box-shadow: 0 0 0 1px var(--err), var(--shadow);
}

.tile__visual {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
}

.win {
  width: 78%;
  height: 78%;
  display: block;
  fill: none;
}
.frame {
  fill: var(--win-bg);
  stroke: var(--line);
  stroke-width: 2.4;
}
.shade,
.panel {
  fill: var(--shade);
}
.headbox {
  fill: var(--shade);
  stroke: var(--shade-line);
  stroke-width: 1.6;
}
.slat,
.fold {
  stroke: var(--shade-line);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}
.rail {
  stroke: var(--shade-line);
  stroke-width: 3;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.rod {
  stroke: var(--line);
  stroke-width: 2.6;
  stroke-linecap: round;
}

/* --- Motion --- */
.blind {
  transform-box: fill-box;
  transform-origin: top;
  transform: scaleY(0.5);
  transition: transform var(--motion);
}
.win--blind.is-open .blind {
  transform: scaleY(0.14);
}
.win--blind.is-closed .blind {
  transform: scaleY(1);
}
.curtain {
  transform-box: fill-box;
  transform: scaleX(0.62);
  transition: transform var(--motion);
}
.curtain--left {
  transform-origin: left;
}
.curtain--right {
  transform-origin: right;
}
.win--curtain.is-open .curtain {
  transform: scaleX(0.16);
}
.win--curtain.is-closed .curtain {
  transform: scaleX(1);
}
.no-anim .blind,
.no-anim .curtain {
  transition: none !important;
}

/* --- Zones (tap targets layered on the icon) --- */
.tile__zones {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: none;
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s ease;
}
/* Top half = Ava (open) — a faint light wash, echoing "valgeks". */
.zone--open {
  justify-content: flex-start;
  padding-top: 15px;
  background: linear-gradient(to bottom, var(--wash-open), transparent 58%);
}
/* Bottom half = Sule (close) — a faint dark wash, echoing "pimedaks". */
.zone--close {
  justify-content: flex-end;
  padding-bottom: 15px;
  background: linear-gradient(to top, var(--wash-close), transparent 58%);
  border-top: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
}
.zone:active {
  background: var(--accent-soft);
}
@media (hover: hover) {
  .zone:hover {
    background: var(--accent-soft);
  }
}
.zone__ico {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 5px rgba(0, 0, 0, 0.4));
}
.zone--close .zone__ico {
  stroke: var(--muted);
}
.zone__label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
  padding: 3px 11px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.28);
}

/* --- Feedback overlay --- */
.tile__feedback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
}
.tile.is-ok .tile__feedback,
.tile.is-err .tile__feedback {
  animation: pop 2.2s ease;
}
.fb {
  position: absolute;
  width: 64px;
  height: 64px;
  fill: none;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: none;
}
.fb--ok {
  stroke: var(--ok);
}
.fb--err {
  stroke: var(--err);
}
.tile.is-ok .fb--ok {
  display: block;
}
.tile.is-err .fb--err {
  display: block;
}
@keyframes pop {
  0% {
    opacity: 0;
    transform: scale(0.7);
  }
  12% {
    opacity: 1;
    transform: scale(1);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.tile.is-busy {
  opacity: 0.92;
}
.tile.is-busy .zone {
  cursor: progress;
}

/* --- Tile meta --- */
.tile__meta {
  padding: 11px 14px 13px;
  border-top: 1px solid var(--line);
}
.tile__name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.tile__status {
  margin: 3px 0 0;
  min-height: 16px;
  font-size: 12.5px;
  color: var(--muted);
}
.tile.is-ok .tile__status {
  color: var(--ok);
}
.tile.is-err .tile__status {
  color: var(--err);
}

@media (prefers-reduced-motion: reduce) {
  .blind,
  .curtain {
    transition-duration: 0.4s;
  }
}
