:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --panel-ink: rgba(0, 20, 72, 0.62);
  --panel-fill: rgba(255, 255, 255, 0.34);
  --control-fill: rgba(255, 255, 255, 0.51);
  --control-fill-soft: rgba(255, 255, 255, 0.31);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

#stage {
  display: block;
  width: 100vw;
  height: 100vh;
}

.author-link {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 11;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--panel-ink);
  background: var(--panel-fill);
  box-shadow: 0 8px 24px rgba(0, 20, 72, 0.1);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  backdrop-filter: blur(16px);
}

.author-label {
  color: rgba(0, 20, 72, 0.42);
}

.telegram-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  fill: currentColor;
}

.author-link:active {
  transform: translateY(1px);
}

.panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 22px;
  z-index: 10;
  display: flex;
  gap: 4px;
  align-items: center;
  width: auto;
  height: auto;
  padding: 8px;
  overflow-x: hidden;
  overflow-y: hidden;
  border-radius: 20px;
  background: var(--panel-fill);
  backdrop-filter: blur(16px);
}

.mode-toggle,
.source,
.icon-button,
.swatch,
.control {
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 12px;
  background: var(--control-fill);
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex-basis: 128px;
  width: 128px;
  padding: 4px;
}

.mode-toggle button {
  min-width: 0;
  border: 0;
  border-radius: 8px;
  color: var(--panel-ink);
  background: transparent;
  cursor: pointer;
}

.mode-toggle button.active {
  background: rgba(255, 255, 255, 0.72);
}

.source {
  flex: 1 1 188px;
  width: 188px;
  max-width: 260px;
  min-width: 0;
  padding: 0 14px;
  outline: none;
  color: var(--panel-ink);
}

.text-source {
  border: 0;
}

.upload-source {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.upload-source input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-source span {
  overflow: hidden;
  max-width: 100%;
  color: var(--panel-ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden {
  display: none;
}

.icon-button {
  width: 58px;
  flex-basis: 58px;
  min-width: 0;
  padding: 0;
  display: grid;
  place-items: center;
  color: #627394;
  font-size: 15px;
  cursor: pointer;
}

.icon-button:hover,
.mode-toggle button:hover {
  background: rgba(255, 255, 255, 0.82);
}

.icon-button.active {
  background: rgba(255, 255, 255, 0.78);
}

.color-toggle {
  width: 50px;
  flex-basis: 50px;
}

.swatch {
  display: block;
  position: relative;
  width: 42px;
  flex-basis: 42px;
  overflow: hidden;
  padding: 4px;
  cursor: pointer;
}

.swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.swatch-chip {
  display: block;
  width: 34px;
  height: 36px;
  border-radius: 8px;
  background: var(--swatch-color);
  pointer-events: none;
}

.control {
  position: relative;
  display: block;
  flex: 1 1 134px;
  width: 134px;
  max-width: 180px;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  color: var(--panel-ink);
  background: var(--control-fill-soft);
  font-size: 15px;
  line-height: 1;
  --p: 50%;
  cursor: pointer;
  user-select: none;
}

.control-fill {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 0;
  width: 100%;
  transform: translateX(calc(-100% + var(--p)));
  border-radius: inherit;
  background: var(--control-fill);
  pointer-events: none;
}

.control-label {
  display: grid;
  position: absolute;
  inset: 0;
  z-index: 2;
  place-items: center;
  white-space: nowrap;
  pointer-events: none;
}

.speed-group {
  display: flex;
  align-items: center;
  flex: 1.25 1 220px;
  width: 220px;
  max-width: 280px;
  min-width: 0;
  height: 44px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--control-fill-soft);
}

.speed-control {
  flex: 1 1 auto;
  width: auto;
  height: 44px;
  border-radius: 12px;
  background: transparent;
}

.pause-button {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  color: #627394;
  background: var(--control-fill);
  cursor: pointer;
}

.pause-button:hover {
  background: rgba(255, 255, 255, 0.82);
}

@media (max-width: 720px) {
  .author-link {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    height: 34px;
    padding: 0 10px;
    font-size: 13px;
  }

  .panel {
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    align-items: stretch;
    padding: 8px;
    overflow: hidden;
    border-radius: 18px;
  }

  .mode-toggle,
  .source,
  .icon-button,
  .swatch,
  .control,
  .speed-group {
    width: auto;
    max-width: none;
    min-width: 0;
    height: 48px;
    flex-basis: auto;
  }

  .mode-toggle {
    order: 1;
    grid-column: span 2;
    padding: 4px;
  }

  .source {
    order: 2;
    grid-column: span 4;
    padding: 0 12px;
  }

  .icon-button,
  .swatch,
  .color-toggle {
    grid-column: span 1;
  }

  #clearImage {
    order: 3;
  }

  .swatch {
    order: 4;
  }

  #imageColor {
    order: 5;
  }

  #exportSvg {
    order: 6;
  }

  #exportWebm {
    order: 7;
  }

  .swatch {
    padding: 4px;
  }

  .swatch-chip {
    width: 100%;
    height: 100%;
  }

  .speed-group {
    order: 8;
    grid-column: span 3;
    max-width: none;
    height: 48px;
  }

  .pause-button {
    flex-basis: 48px;
    height: 48px;
  }

  .speed-control {
    height: 48px;
  }

  #bigChance {
    order: 9;
    grid-column: span 3;
  }

  #cellSize,
  #bubbleScale,
  #stroke {
    grid-column: span 2;
  }

  #cellSize {
    order: 10;
  }

  #bubbleScale {
    order: 11;
  }

  #stroke {
    order: 12;
  }

  .control {
    font-size: 13px;
  }

  .icon-button {
    padding: 0 2px;
    font-size: 13px;
  }

  .mode-toggle button {
    font-size: 13px;
  }
}
