@font-face {
  font-family: "Plex Condensed";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/plex-condensed-400.woff2") format("woff2");
}

@font-face {
  font-family: "Plex Condensed";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/plex-condensed-500.woff2") format("woff2");
}

@font-face {
  font-family: "Plex Condensed";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/plex-condensed-600.woff2") format("woff2");
}

@font-face {
  font-family: "Plex Condensed";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/plex-condensed-700.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --font: "Plex Condensed", "IBM Plex Sans Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --wall: #e5e2da;
  --ink: #25282a;
  --ink-soft: #6b6f6b;
  --plastic: #f6f4ef;
  --plastic-edge: #d6d1c6;
  --key: #ebe8e1;
  --key-edge: #cfcabf;
  --key-press: #dcd8ce;
  --key-ink: #2a2d2c;
  --power: #d0442a;
  --power-press: #b13820;
  --primary: #25282a;
  --primary-ink: #f6f4ef;
  --lcd: #c3ccb7;
  --lcd-lit: #c6ebc3;
  --lcd-glow: rgba(214, 255, 205, 0.7);
  --lcd-ink: #1a241d;
  --lcd-ghost: rgba(26, 36, 29, 0.075);
  --lcd-dim: rgba(26, 36, 29, 0.36);
  --led: #6b1f1a;
  --led-on: #ff4b36;
  --led-glow: rgba(255, 75, 54, 0.65);
  --ok: #2b8a55;
  --off: #b6b1a6;
  --danger: #b4291f;
  --focus: #1f6feb;
  --backdrop: rgba(20, 22, 21, 0.42);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --wall: #111312;
    --ink: #e6e8e4;
    --ink-soft: #8f948e;
    --plastic: #1c1f1e;
    --plastic-edge: #2c302e;
    --key: #262a28;
    --key-edge: #383d3a;
    --key-press: #1f2221;
    --key-ink: #ecefea;
    --primary: #e6e8e4;
    --primary-ink: #141615;
    --lcd: #0c2526;
    --lcd-lit: #113b3c;
    --lcd-glow: rgba(110, 240, 225, 0.22);
    --lcd-ink: #8eeee2;
    --lcd-ghost: rgba(142, 238, 226, 0.07);
    --lcd-dim: rgba(142, 238, 226, 0.4);
    --led: #3d1512;
    --off: #3d423f;
    --danger: #ff6b5e;
    --focus: #6ea8ff;
    --backdrop: rgba(0, 0, 0, 0.58);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--wall);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 1320px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  background: var(--wall);
}

.places-wrap {
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.places-wrap::-webkit-scrollbar {
  display: none;
}

.places {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--key-edge);
  border-radius: 999px;
  background: var(--key);
}

.places-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  border: 1px solid var(--plastic-edge);
  border-radius: 999px;
  background: var(--plastic);
  transition: transform 0.28s cubic-bezier(0.3, 0.7, 0.2, 1), width 0.28s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.place-tab {
  position: relative;
  z-index: 1;
  min-width: 44px;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.place-tab[aria-selected="true"] {
  color: var(--ink);
}

.topbar-gap {
  flex: 1;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink-soft);
}

.icon-btn:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.icon-btn.is-on {
  color: var(--ink);
  background: var(--key);
}

.status[data-health="ok"] {
  color: var(--ok);
}

.status[data-health="down"],
.status[data-health="partial"],
.status[data-health="none"] {
  color: var(--danger);
}

.place {
  max-width: 1320px;
  margin: 0 auto;
  padding: 6px max(12px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.remotes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  align-items: start;
  gap: 16px;
}

.remote {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  padding: 22px 14px 16px;
  border: 1px solid var(--plastic-edge);
  border-radius: 24px 24px 32px 32px;
  background: var(--plastic);
}

.ir-led {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 18px;
  height: 7px;
  margin-left: -9px;
  border-radius: 6px 6px 3px 3px;
  background: var(--led);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.22);
}

.ir-led.is-sending {
  animation: led 0.15s linear 5;
}

@keyframes led {
  0%,
  45% {
    background: var(--led-on);
    box-shadow: 0 0 9px 2px var(--led-glow);
  }

  55%,
  100% {
    background: var(--led);
    box-shadow: none;
  }
}

.remote-head {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: -8px -6px -6px 4px;
}

.remote-name {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remote-error {
  margin: -2px 2px 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}

.remote.is-offline .lcd-main,
.remote.is-offline .lcd-bottom {
  opacity: 0.45;
}

.lcd {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 4px;
  min-height: 132px;
  padding: 10px 12px 9px;
  border-radius: 12px;
  background: var(--lcd);
  color: var(--lcd-ink);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.22), inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: background-color 0.35s ease, box-shadow 0.35s ease;
}

.lcd.is-lit {
  background: var(--lcd-lit);
  box-shadow: inset 0 0 24px var(--lcd-glow), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.lcd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.lcd-mode,
.lcd-flag,
.lcd-power {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.lcd-mode .icon,
.lcd-flag .icon,
.lcd-power .icon {
  width: 16px;
  height: 16px;
  stroke-width: 2.2;
}

.lcd-power:not(.is-on) {
  opacity: 0.7;
}

.lcd-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.lcd-status .icon {
  width: 14px;
  height: 14px;
  stroke-width: 2.2;
}

.pop-line .icon {
  width: 16px;
  height: 16px;
  margin-left: -4px;
}

.lcd-top > :last-child {
  margin-left: auto;
}

.lcd-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
}

.lcd-left {
  justify-self: start;
}

.lcd-right {
  justify-self: end;
}

.lcd-center {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
}

.lcd-side {
  display: grid;
  justify-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.lcd-side-top {
  display: inline-flex;
  align-items: flex-end;
  gap: 4px;
  height: 20px;
}

.lcd-side .icon {
  width: 20px;
  height: 20px;
  stroke-width: 2.1;
}

.lcd.is-pending .lcd-center {
  animation: pending 0.7s steps(1, end) infinite;
}

@keyframes pending {
  50% {
    opacity: 0.3;
  }
}

.lcd-main {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 64px;
}

.segments .seg {
  fill: var(--lcd-ghost);
}

.segments .seg.on {
  fill: var(--lcd-ink);
}

.lcd-digits {
  width: auto;
  height: 60px;
  max-width: 100%;
}

.lcd-unit {
  width: auto;
  height: 22px;
  margin-bottom: 38px;
}

.lcd-word {
  width: auto;
  height: 34px;
  max-width: 100%;
  margin-bottom: 14px;
}

.lcd-small {
  width: auto;
  height: 14px;
}

.lcd-text {
  align-self: center;
  max-width: 100%;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.lcd-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}

.lcd-bars .bar {
  display: block;
  width: 4px;
  border-radius: 1px;
  background: var(--lcd-ghost);
}

.lcd-bars .bar:nth-child(1) {
  height: 6px;
}

.lcd-bars .bar:nth-child(2) {
  height: 11px;
}

.lcd-bars .bar:nth-child(3) {
  height: 16px;
}

.lcd-bars .bar.on {
  background: var(--lcd-ink);
}

.lcd-note,
.lcd-age {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.lcd-age {
  flex: none;
  opacity: 0.8;
}

.lcd-count {
  display: inline-flex;
}

.signal {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  height: 12px;
}

.signal-base {
  fill: var(--lcd-dim);
}

.signal-lit {
  fill: var(--lcd-ink);
  opacity: 0;
}

.lcd.is-scanning .signal-lit {
  animation: scan 0.8s linear;
}

@keyframes scan {
  0% {
    opacity: 1;
    clip-path: inset(0 100% 0 0);
  }

  85% {
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }

  100% {
    opacity: 0;
    clip-path: inset(0 0 0 0);
  }
}

.learn-lcd .lcd-word {
  animation: blink 1.1s steps(1, end) infinite;
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

.climate {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.key-temp {
  min-height: 58px;
}

.key-temp .icon {
  width: 26px;
  height: 26px;
}

.keys {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 9px;
}

.key {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--key-edge);
  border-radius: 15px;
  background: var(--key);
  color: var(--key-ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.07em;
  text-align: center;
  text-transform: uppercase;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.key:hover:not(:disabled) {
  background: color-mix(in srgb, var(--key) 92%, var(--ink));
}

.key:active:not(:disabled) {
  transform: scale(0.96);
  background: var(--key-press);
}

.key:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.key small {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  opacity: 0.72;
}

.key .icon {
  width: 18px;
  height: 18px;
}

.key-label {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.key.is-busy {
  pointer-events: none;
}

.key.is-busy .key-label {
  opacity: 0.5;
}

.key-power {
  border-color: var(--power-press);
  background: var(--power);
  color: #fff;
}

.key-power:hover:not(:disabled) {
  background: color-mix(in srgb, var(--power) 90%, black);
}

.key-power:active:not(:disabled) {
  background: var(--power-press);
}

.key-add {
  border-width: 1.5px;
  border-style: dashed;
  background: transparent;
  color: var(--ink-soft);
}

.key-ghost {
  background: transparent;
  color: var(--ink-soft);
}

.key-primary {
  flex-direction: row;
  gap: 8px;
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

.key-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--primary) 88%, var(--wall));
}

.key-danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--key-edge));
  background: transparent;
  color: var(--danger);
}

.key-edit {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 14px !important;
  height: 14px !important;
  opacity: 0.6;
}

.remote.is-editing .key:not(.key-ghost) {
  border-style: dashed;
}

.remote-slot {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: 120px;
  padding: 20px;
  border: 1.5px dashed var(--key-edge);
  border-radius: 24px 24px 32px 32px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.remote-slot .icon {
  width: 26px;
  height: 26px;
}

.remote-slot:hover {
  border-color: var(--ink-soft);
  color: var(--ink);
}

.popover {
  position: fixed;
  z-index: 30;
  width: max-content;
  max-width: min(300px, calc(100vw - 16px));
  padding: 12px 14px;
  border: 1px solid var(--key-edge);
  border-radius: 14px;
  background: var(--plastic);
  color: var(--ink);
  font-size: 14px;
}

.pop-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.pop-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 10px 16px;
  color: var(--ink-soft);
  font-size: 13px;
}

.pop-sub:last-child {
  margin-bottom: 0;
}

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--off);
}

.dot.ok {
  background: var(--ok);
}

.dot.small {
  width: 6px;
  height: 6px;
}

.menu {
  display: grid;
  margin: -6px -8px;
}

.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
}

.menu button:hover {
  background: var(--key);
}

.menu .danger {
  color: var(--danger);
}

.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0;
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--plastic);
  color: var(--ink);
}

.sheet::backdrop {
  background: var(--backdrop);
}

.sheet[open] {
  animation: sheet-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes sheet-in {
  from {
    transform: translateY(32px);
    opacity: 0;
  }
}

.sheet-form {
  position: relative;
  display: grid;
  gap: 16px;
  padding: 24px 18px calc(18px + env(safe-area-inset-bottom));
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -8px -8px -4px 0;
}

.sheet-head h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.sheet-actions .key {
  flex: 1 1 96px;
}

.sheet-warning {
  margin: 0;
  color: var(--ink-soft);
  font-size: 16px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-label {
  padding: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--key-edge);
  border-radius: 13px;
  background: var(--key);
  color: var(--key-ink);
  font-size: 17px;
  font-weight: 500;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -6px;
}

.chip {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--key-edge);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
}

.chip:hover {
  background: var(--key);
}

.kind-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.kind {
  position: relative;
}

.kind input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.kind span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  border: 1px solid var(--key-edge);
  border-radius: 14px;
  background: var(--key);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.kind input:checked + span {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

.kind input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.form-error {
  margin: -6px 0 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}

.form-error:empty {
  display: none;
}

.login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.login-remote {
  width: min(100%, 340px);
  gap: 16px;
}

.login-remote .remote-name {
  text-align: center;
}

.login-remote .lcd {
  min-height: 96px;
}

@media (min-width: 700px) {
  .sheet {
    max-width: 440px;
    margin: auto;
    border-radius: 24px;
  }

  .sheet-form {
    padding-bottom: 20px;
  }
}

@media (min-width: 768px) {
  .topbar,
  .place {
    padding-right: 24px;
    padding-left: 24px;
  }

  .remotes {
    gap: 20px;
  }

  .remote-slot {
    min-height: 190px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  .learn-lcd .lcd-word {
    animation: none;
  }
}
