:root {
  --gap: 10px;
  --outer-gap: 10px;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: darkgray;
  font-family: Arial, Helvetica, sans-serif;
}

.wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.grid-container {
  width: 90vw;
  height: calc(100dvh - 96px);
  margin: 48px auto 48px auto;
  position: relative;
  overflow: hidden;
  background-color: #000;
  box-sizing: border-box;
  transform: translateZ(0);
  isolation: isolate;
  transition: background-color 300ms ease;
}

.mode-vintage .grid-container {
  background-color: rgb(22, 19, 16);
}

.base-layer,
.overlay-layer,
.vintage-overlay {
  position: absolute;
  inset: 0;
}

.base-layer,
.overlay-layer {
  pointer-events: none;
}

.overlay-layer {
  isolation: isolate;
}

#base-normal {
  z-index: 1;
  opacity: 1;
  transition: opacity 300ms ease;
}

#base-vintage {
  z-index: 2;
  opacity: 0;
  transition: opacity 300ms ease;
}

.mode-vintage #base-normal {
  opacity: 0;
}

.mode-vintage #base-vintage {
  opacity: 1;
}


.tile,
.color-tile {
  position: absolute;
  box-sizing: border-box;
  transform-origin: center center;
  transition: background-color 350ms ease, opacity 300ms ease;
}

.tile {
  background: #f2f2f2;
}

.color-tile {
  mix-blend-mode: multiply;
}

.top-bar {
  position: fixed;
  left: 50%;
  top: max(10px, env(safe-area-inset-top));
  transform: translateX(-50%);
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 80;
  padding-inline: 16px;
}

.clock-readout {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.55);
  line-height: 1;
}

.controls-wrap {
  position: fixed;
  top: 1.55vh;
  right: 5vw;
  width: min(760px, calc(100vw - 32px));
  z-index: 100;
  pointer-events: none;
}

.controls-toggle {
  position: absolute;
  top: 0;
  right: 0;
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  width: 28px;
  height: 28px;
  padding: 0;
  cursor: pointer;
  opacity: .5;
  transition:
    opacity 180ms ease,
    background-color 180ms ease,
    transform 180ms ease;
  pointer-events: auto;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 102;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.controls-toggle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid rgba(0, 0, 0, 0.62);
  border-bottom: 2px solid rgba(0, 0, 0, 0.62);
  transform: translateY(-1px) rotate(-45deg);
  transform-origin: center center;
  transition:
    transform 180ms ease,
    border-color 180ms ease;
}

.controls-toggle[aria-expanded="true"] {
  opacity: 1;
  background: rgba(255, 255, 255, 0.36);
}

.controls-toggle[aria-expanded="true"]::before {
  transform: translateY(-2px) rotate(45deg);
  border-color: rgba(0, 0, 0, 0.82);
}

@media (hover: hover) and (pointer: fine) {
  .controls-toggle:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.28);
  }
}

.controls-panel {
  position: absolute;
  top: 40px;
  right: 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.34);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  padding: 10px 10px 12px;
  box-sizing: border-box;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-6px);
  transition:
    max-height 260ms ease,
    opacity 180ms ease,
    transform 180ms ease;
  pointer-events: none;
  z-index: 101;
}

.controls-panel.open {
  max-height: 80vh;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.field-head label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .72;
  line-height: 1.1;
}

.field-head output {
  font-size: 11px;
  opacity: .74;
  text-align: right;
  white-space: nowrap;
  min-width: 3ch;
  line-height: 1.1;
}

.field input,
.field select {
  width: 100%;
  box-sizing: border-box;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  padding: 6px 8px;
  font-size: 12px;
  color: #000;
}

.field input[type="range"] {
  margin-top: -1px;
}

.field-interval {
  justify-content: flex-start;
}

.field-interval-compact {
  width: 150px;
  max-width: 150px;
}

.interval-clock-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: nowrap;
  min-width: 0;
  align-self: start;
}

.controls-bottom-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding-top: 4px;
  flex-wrap: nowrap;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: 10px;
  flex: 0 0 auto;
}

.ui-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  line-height: 1;
  color: rgba(0, 0, 0, .72);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  margin: 0;
}

.ui-toggle input {
  margin: 0;
}

.actions-inline {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
}

.actions-inline button {
  white-space: nowrap;
}

.actions button {
  appearance: none;
  border: none;
  background: #000;
  color: #fff;
  padding: 8px 11px;
  font-size: 12px;
  cursor: pointer;
}

.actions .secondary {
  background: rgba(0, 0, 0, 0.15);
  color: #000;
}

.footer {
  position: fixed;
  left: 50%;
  bottom: max(6px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: .7em;
  z-index: 80;
}

a {
  text-decoration: none;
  color: black;
  opacity: .2;
  transition: opacity .3s;
}

a:hover {
  opacity: .9;
}

.vintage-overlay {
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  background-repeat: no-repeat;
  background-size: cover;
  mix-blend-mode: multiply;
  transition: opacity 300ms ease;
}

.mode-vintage .vintage-overlay {
  opacity: 0.18;
}

#overlay-normal {
  z-index: 3;
  opacity: 1;
  transition: opacity 300ms ease;
}

#overlay-vintage {
  z-index: 4;
  opacity: 0;
  transition: opacity 300ms ease;
}

.mode-vintage #overlay-normal { opacity: 0; }
.mode-vintage #overlay-vintage { opacity: 1; }

@media (max-width: 700px) {
  .grid-container {
    width: calc(100vw - 20px);
    height: calc(100dvh - 112px);
    margin: 68px auto 44px auto;
  }

  .controls-wrap {
    top: max(8px, env(safe-area-inset-top));
    right: 3vw;
    width: min(92vw, 400px);
  }

  .controls-panel {
    top: 34px;
    padding: 8px 8px 9px;
  }

  .controls-panel.open {
    max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 110px);
    overflow: hidden;
  }

  .controls-grid-clean {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .field {
    gap: 1px;
  }

  .field-head {
    gap: 6px;
  }

  .field-head label {
    font-size: 9px;
    letter-spacing: .04em;
    line-height: 1.05;
  }

  .field-head output {
    font-size: 10px;
    line-height: 1.05;
  }

  .field input,
  .field select {
    padding: 4px 7px;
    font-size: 11px;
  }

  .field input[type="range"] {
    margin-top: -2px;
  }

  .interval-clock-row {
    gap: 8px;
    align-items: center;
  }

  .field-interval-compact {
    width: 138px;
    max-width: 138px;
  }

  .ui-toggle {
    gap: 6px;
    font-size: 11px;
    margin-top: 15px;
  }

  .controls-bottom-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .toggle-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }

  .actions-inline {
    gap: 6px;
  }

  .actions button {
    padding: 7px 8px;
    font-size: 11px;
  }
}

@media (max-height: 820px) {
  .controls-panel.open {
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .controls-toggle,
  .controls-panel,
  a,
  #base-normal,
  #base-vintage,
  .vintage-overlay,
  .tile,
  .color-tile,
  .grid-container {
    transition: none !important;
  }
}