:root {
  color-scheme: dark;
  --amber: #ffb526;
  --amber-soft: #ffd878;
  --ink: #171711;
  --panel: rgba(22, 22, 19, 0.92);
  --panel-border: rgba(255, 255, 255, 0.2);
  --text: #f8f5ec;
  --muted: #b8b5ad;
  --line: rgba(255, 255, 255, 0.13);
  --success: #54d675;
  --danger: #ff8278;
  --radius: 20px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #11120d;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="range"] {
  touch-action: manipulation;
}

.village-app {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 500px;
  isolation: isolate;
  overflow: hidden;
  background: #11120d;
}

.village-scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  user-select: none;
  pointer-events: none;
}

.app-header {
  position: absolute;
  z-index: 4;
  top: clamp(20px, 3vw, 38px);
  left: clamp(20px, 3vw, 42px);
  color: var(--text);
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.72));
}

.app-header h1,
.drawer-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.app-header h1 {
  font-size: clamp(1.8rem, 3vw, 2.65rem);
  line-height: 1;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 0;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.9);
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 12px rgba(84, 214, 117, 0.7);
}

.marker-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.light-marker {
  position: absolute;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 239, 195, 0.94);
  border-radius: 50%;
  color: #fff8e8;
  background: rgba(29, 23, 13, 0.72);
  box-shadow: 0 0 0 7px rgba(255, 181, 38, 0.1), 0 8px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.light-marker span {
  font-size: 1.08rem;
  font-weight: 650;
}

.light-marker svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.light-marker:hover,
.light-marker:focus-visible,
.light-marker.is-selected {
  outline: none;
  transform: translate(-50%, -50%) scale(1.1);
  background: rgba(90, 55, 8, 0.88);
  box-shadow: 0 0 0 8px rgba(255, 181, 38, 0.2), 0 0 28px rgba(255, 181, 38, 0.68);
}

.light-marker.is-off {
  opacity: 0.58;
  background: rgba(25, 25, 22, 0.78);
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.06), 0 8px 20px rgba(0, 0, 0, 0.35);
}

.settings-drawer {
  position: absolute;
  z-index: 8;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(380px, calc(100vw - 32px));
  padding: 28px 26px 24px;
  overflow: auto;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(18px) saturate(120%);
  transform: translateX(calc(100% + 30px));
  visibility: hidden;
  transition: transform 260ms cubic-bezier(.22, .75, .2, 1), visibility 260ms;
}

.settings-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 {
  font-size: 2rem;
  line-height: 1.1;
}

.drawer-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin: -8px -8px 0 0;
  padding: 0;
  color: var(--text);
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.1);
}

.icon-button svg,
.save-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.toggle-control {
  position: relative;
  flex: 0 0 auto;
  width: 54px;
  height: 30px;
}

.toggle-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-control span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #565650;
  transition: background 160ms ease;
}

.toggle-control span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35);
  transition: transform 160ms ease;
}

.toggle-control input:checked + span {
  background: var(--amber);
}

.toggle-control input:checked + span::after {
  transform: translateX(24px);
}

.toggle-control input:focus-visible + span {
  outline: 3px solid rgba(255, 216, 120, 0.45);
  outline-offset: 3px;
}

.field-block,
.mode-fields {
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

.field-block label,
.range-label label {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  color: #f1eee6;
}

.channel-field p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

select {
  width: 100%;
  height: 48px;
  margin-top: 10px;
  padding: 0 42px 0 14px;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 9px;
  background: #252521;
  cursor: pointer;
}

select:focus-visible {
  outline: 3px solid rgba(255, 181, 38, 0.32);
  border-color: var(--amber);
}

.range-field + .range-field {
  margin-top: 22px;
}

.range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 11px;
}

.range-label output {
  min-width: 52px;
  padding: 6px 9px;
  text-align: center;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 22px;
  margin: 0;
  accent-color: var(--amber);
  cursor: pointer;
}

.form-error {
  min-height: 21px;
  margin: 15px 0 0;
  color: var(--danger);
  font-size: 0.86rem;
}

.form-error.is-info {
  color: var(--muted);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
  margin-top: 10px;
}

.save-button,
.default-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 0 20px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.save-button {
  color: #1c160b;
  border: 0;
  background: var(--amber);
  box-shadow: 0 10px 26px rgba(255, 181, 38, 0.2);
}

.default-button {
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.055);
}

.save-button:hover,
.save-button:focus-visible,
.default-button:hover,
.default-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
}

.save-button:hover,
.save-button:focus-visible {
  background: var(--amber-soft);
}

.default-button:hover,
.default-button:focus-visible {
  border-color: rgba(255, 216, 120, 0.55);
  background: rgba(255, 255, 255, 0.1);
}

.save-button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

.drawer-scrim {
  position: absolute;
  z-index: 7;
  inset: 0;
  display: none;
  padding: 0;
  border: 0;
  background: rgba(7, 8, 5, 0.28);
}

.toast {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(24, 24, 20, 0.94);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error {
  border-color: rgba(255, 130, 120, 0.55);
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .village-app {
    min-height: 560px;
  }

  .village-scene {
    top: 82px;
    bottom: auto;
    height: 232px;
    object-fit: contain;
    object-position: center;
  }

  .app-header {
    top: 18px;
    left: 18px;
  }

  .app-header h1 {
    font-size: 1.7rem;
  }

  .light-marker {
    width: 44px;
    height: 44px;
  }

  .drawer-scrim.is-open {
    display: block;
  }

  .settings-drawer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: min(66dvh, 620px);
    padding: 24px 22px max(22px, env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 22px 22px 0 0;
    transform: translateY(105%);
  }

  .settings-drawer.is-open {
    transform: translateY(0);
  }

  .drawer-head h2 {
    font-size: 1.65rem;
  }

  .toast {
    bottom: max(16px, env(safe-area-inset-bottom));
  }
}

@media (min-width: 761px) and (max-height: 780px) {
  .settings-drawer {
    padding: 20px 24px 18px;
  }

  .drawer-head {
    padding-bottom: 15px;
  }

  .drawer-head h2 {
    font-size: 1.75rem;
  }

  .drawer-head p {
    margin-top: 4px;
  }

  .toggle-row {
    min-height: 60px;
  }

  .field-block,
  .mode-fields {
    padding: 15px 0;
  }

  .range-field + .range-field {
    margin-top: 13px;
  }

  .range-label {
    margin-bottom: 5px;
  }

  .range-label output {
    padding: 4px 8px;
  }

  .form-error {
    min-height: 17px;
    margin-top: 8px;
  }

  .save-button {
    min-height: 48px;
  }

  .form-actions {
    margin-top: 5px;
  }
}

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