:root {
  --bg: #e7e7e7;
  --panel: #ffffff;
  --surface: #f1f1f1;
  --border: #dee1e3;
  --slider-bg: #e3e3e3;
  --slider-fill: #cacaca;
  --text: #000000d9;
  --text-muted: rgba(0, 0, 0, 0.3);
  --text-soft: rgba(0, 0, 0, 0.2);
}

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

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  font-family: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: -0.025em;
  color: var(--text);
  background: var(--bg);
}

#main {
  position: relative;
  min-height: 100dvh;
  width: 100%;
  overflow: hidden;
}

#mobilePlaceholder {
  display: none;
  min-height: 100dvh;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.mobile-placeholder-content {
  width: min(430px, 100%);
  min-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.mobile-placeholder-icon {
  width: 30px;
  height: 30px;
  fill: #000;
}

.mobile-placeholder-text {
  margin: 0;
  width: 304px;
  max-width: 100%;
  text-align: center;
  font-family: "SF Pro Display", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 18px;
  font-weight: 500;
  color: #000;
}

#sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 348px;
  max-height: calc(100dvh - 32px);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow: auto;
  scrollbar-width: none;
  background: var(--panel);
}

#sidebar::-webkit-scrollbar {
  display: none;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.control-group-slider {
  gap: 6px;
}

.control-group label {
  display: block;
  margin: 0;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--text);
}

label[for="contrast"],
label[for="cellSize"] {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#contrastLabel,
#cellSizeLabel,
.shape-value {
  font-variant-numeric: tabular-nums;
}

button {
  width: auto;
  min-height: 48px;
  height: 48px;
  padding: 16px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 32px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

button svg {
  flex-shrink: 0;
}

.sf-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "SF Pro Display", "SF Pro Text", "SF Symbols", "Apple Symbols", sans-serif;
  font-size: 12px;
  line-height: 1;
  font-weight: 500;
  font-style: normal;
}

button:hover:not(:disabled) {
  background: #ececec;
}

button:disabled {
  cursor: default;
}

.control-group input[type="range"],
.shape-control input[type="range"] {
  --value: 0%;
  width: 100%;
  height: 3px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  appearance: none;
  background: linear-gradient(
    to right,
    var(--slider-fill) 0%,
    var(--slider-fill) var(--value),
    var(--slider-bg) var(--value),
    var(--slider-bg) 100%
  );
  cursor: pointer;
}

.control-group input[type="range"]::-webkit-slider-runnable-track,
.shape-control input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: transparent;
}

.control-group input[type="range"]::-webkit-slider-thumb,
.shape-control input[type="range"]::-webkit-slider-thumb {
  width: 1px;
  height: 1px;
  margin-top: 0;
  border: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
}

.control-group input[type="range"]::-moz-range-track,
.shape-control input[type="range"]::-moz-range-track {
  height: 3px;
  border: 0;
  border-radius: 999px;
  background: transparent;
}

.control-group input[type="range"]::-moz-range-thumb,
.shape-control input[type="range"]::-moz-range-thumb {
  width: 1px;
  height: 1px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.upload-btn-primary {
  width: 100%;
}

.media-block {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 0;
}

.media-thumb-wrap {
  position: relative;
  width: 80px;
  height: 48px;
  flex-shrink: 0;
  overflow: hidden;
}

.media-block-thumb {
  width: 80px;
  height: 48px;
  object-fit: cover;
  display: block;
  background: var(--surface);
}

.media-block-replace {
  min-width: 0;
  padding: 0 16px;
  justify-content: center;
  border-radius: 32px;
}

.media-block-delete {
  width: 48px;
  min-width: 48px;
  padding: 0;
  border-radius: 32px;
}

#videoControls {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.32);
}

#videoControls #playPauseBtn {
  position: relative;
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  color: #fff;
  background: rgba(0, 0, 0, 0.75);
}

#videoControls #playPauseBtn svg {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 14px;
  height: 14px;
  fill: currentColor;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

#videoControls #playPauseBtn .icon-play {
  transform: translate(-46%, -50%) scale(0.86);
}

#videoControls #playPauseBtn .icon-pause {
  transform: translate(-50%, -50%) scale(0.86);
}

#videoControls #playPauseBtn[data-state="paused"] .icon-play {
  opacity: 1;
  transform: translate(-46%, -50%) scale(1);
}

#videoControls #playPauseBtn[data-state="playing"] .icon-pause {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#shapeControls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shape-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.shape-control img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--surface);
}

.shape-control input[type="range"] {
  flex: 1;
  min-width: 0;
}

.shape-value {
  min-width: 3ch;
  text-align: right;
  color: var(--text);
}

.shape-control .shape-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.shape-control .remove-shape {
  width: 14px;
  min-width: 14px;
  height: 14px;
  min-height: 14px;
  padding: 0;
  border: 0;
  border-radius: 0;
  font-size: 12px;
  font-family: "SF Pro Display", "SF Pro Text", "SF Symbols", "Apple Symbols", sans-serif;
  line-height: 12px;
  color: var(--text-soft);
  background: transparent;
}

.shape-control .remove-shape:hover:not(:disabled) {
  color: rgba(0, 0, 0, 0.45);
  background: transparent;
}

.shape-control .remove-shape:disabled {
  opacity: 0.45;
}

.add-shapes-btn {
  display: none;
  min-height: 16px;
  height: auto;
  width: fit-content;
  align-self: flex-start;
  padding: 0;
  justify-content: flex-start;
  gap: 8px;
  line-height: 16px;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
}

.add-shapes-btn .sf-symbol {
  color: var(--text-soft);
}

.add-shapes-btn:hover:not(:disabled) {
  color: rgba(0, 0, 0, 0.5);
  background: transparent;
}

.add-shapes-btn:disabled {
  color: rgba(0, 0, 0, 0.2);
}

.picker-row {
  display: flex;
  align-items: center;
  width: 100%;
}

.color-circle {
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  border-radius: 32px;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.color-circle::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-circle::-webkit-color-swatch {
  border: 1px solid var(--border);
  border-radius: 32px;
}

.color-circle::-moz-color-swatch {
  border: 1px solid var(--border);
  border-radius: 32px;
}

.segmented-control {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 0;
  border-radius: 32px;
  overflow: hidden;
}

.segmented-btn {
  position: relative;
  flex: 1;
  min-width: 0;
  border-radius: 32px;
  padding: 16px 12px;
  color: var(--text);
  background: var(--surface);
  border: 0;
}

.segmented-btn.active {
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}

.segmented-btn:disabled {
  color: var(--text-muted);
}

.apply-control {
  display: none;
}

.download-btn {
  width: 100%;
  justify-content: center;
}

.download-btn .btn-label,
.download-btn .btn-icon {
  pointer-events: none;
}

.download-btn.outline {
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
}

.download-btn.outline:hover:not(:disabled) {
  color: rgba(0, 0, 0, 0.5);
  background: rgba(255, 255, 255, 0.35);
}

.download-btn.filled {
  border: 0;
  color: var(--text);
  background: var(--surface);
}

.download-btn.filled:hover:not(:disabled) {
  background: #ececec;
}

#previewContainer {
  position: absolute;
  left: 432px;
  right: 16px;
  top: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  scrollbar-width: none;
}

#previewContainer::-webkit-scrollbar {
  display: none;
}

#previewCanvas,
#webglCanvas,
#previewContainer video {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
}

#previewCanvas,
#webglCanvas {
  border: 0;
  background: transparent;
}

#previewContainer video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#progressOverlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
}

.progress-modal {
  width: min(320px, calc(100vw - 32px));
  padding: 16px 16px 20px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.progress-title {
  margin-bottom: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #eee;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #6aa6ff, #4778ff);
}

.progress-label {
  margin-top: 8px;
  text-align: center;
  opacity: 0.7;
}

@media (max-width: 980px) {
  #main {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 16px;
  }

  #sidebar {
    position: relative;
    top: auto;
    left: auto;
    width: calc(100% - 32px);
    max-height: none;
    margin: 16px auto 0;
  }

  #previewContainer {
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    margin: 0 16px;
    min-height: 280px;
    justify-content: center;
  }

  #previewCanvas,
  #webglCanvas,
  #previewContainer video {
    max-height: 100%;
  }
}

@media (max-width: 560px) {
  #sidebar {
    width: calc(100% - 16px);
    margin-top: 8px;
    padding: 20px;
    gap: 16px;
  }

  .media-block-thumb,
  .media-thumb-wrap {
    width: 64px;
  }

  #previewContainer {
    margin: 0 8px;
    min-height: 220px;
  }
}

@media (max-width: 699px) {
  #main {
    display: none !important;
  }

  #mobilePlaceholder {
    display: flex;
  }
}
