* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1116;
  color: #e9edf1;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  overscroll-behavior: none;
}

.app {
  width: min(980px, 94vw);
  margin: 18px auto 36px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

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

.headerMeta {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-left: auto;
}

.dropzone {
  border: 2px dashed #6e7e96;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  background: #161a22;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.compactDropzone {
  padding: 10px 12px;
}

.compactDropzone p {
  margin: 2px 0 6px;
}

.dropzone.dragover {
  border-color: #4aa3ff;
  background: #1b2535;
}

.dropzone p {
  margin: 8px 0;
}

#fileInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #2f81f7;
  color: #fff;
  min-height: 44px;
  touch-action: manipulation;
}

.pickButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #2f81f7;
  color: #fff;
  min-height: 44px;
  touch-action: manipulation;
}

.smallPickButton {
  min-height: 36px;
  padding: 8px 12px;
  font-size: 13px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.controls {
  margin: 14px 0;
  display: grid;
  gap: 10px;
}

.controlsPanel {
  margin-top: 8px;
}

.controlsSummary {
  display: none;
}

.controlsPanelBody {
  display: block;
}

.compactControls {
  margin: 8px 0;
  gap: 8px;
}

.controlStack {
  display: grid;
  gap: 10px;
}

.control {
  display: flex;
  gap: 10px;
  align-items: center;
  background: #161a22;
  border: 1px solid #283042;
  border-radius: 8px;
  padding: 8px 10px;
}

.control input[type="range"] {
  width: 100%;
}

.control button {
  padding: 8px 12px;
  font-size: 12px;
  min-height: 36px;
}

.control-slider {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
}

.materialPanel {
  display: grid;
  gap: 6px;
  background: #161a22;
  border: 1px solid #283042;
  border-radius: 8px;
  padding: 8px 10px;
}

.materialPanelTitle {
  font-size: 12px;
  color: #aebad0;
}

.materialsList {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}

.materialButton {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid #3a4861;
  background: #1b2333;
  color: #e9edf1;
  cursor: pointer;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.materialButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.materialButton.is-selected {
  border-color: #4aa3ff;
  box-shadow: 0 0 0 1px #4aa3ff inset;
}

.materialButton img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.actionGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.actionGrid button {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  min-width: 0;
  white-space: normal;
  line-height: 1.2;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

#deleteEffectButton {
  grid-column: auto;
}

#processButton {
  background: linear-gradient(135deg, #ff4d9d, #ff2d8a);
}

#processButton:disabled {
  background: linear-gradient(135deg, #8f5674, #6f425a);
}

.saveBar {
  position: sticky;
  bottom: 0;
  z-index: 8;
  margin-top: 10px;
  padding-top: 8px;
  background: linear-gradient(to bottom, rgba(15, 17, 22, 0), rgba(15, 17, 22, 0.92) 28%);
}

.saveButton {
  width: 100%;
  min-height: 50px;
  font-size: 16px;
  font-weight: 700;
  background: #22a06b;
}

.saveButton:disabled {
  background: #1a6448;
}

.status {
  margin: 8px 0 10px;
  min-height: 1.25em;
  color: #c6d0dd;
}

.compactStatus {
  margin: 6px 0;
}

.editorHelp {
  margin: 0 0 10px;
  font-size: 12px;
  color: #aebad0;
}

.buildInfo {
  margin: 0;
  font-size: 11px;
  color: #7f8aa0;
  letter-spacing: 0.02em;
}

.modeInfo {
  margin: 0;
  font-size: 11px;
  color: #6f7b91;
  letter-spacing: 0.02em;
}

.preview {
  position: relative;
  width: 100%;
  min-height: 280px;
  height: min(66vh, 680px);
  border-radius: 10px;
  border: 1px solid #2b3448;
  background: #121722;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 10px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.blockedTextEditor {
  position: absolute;
  z-index: 12;
  transform: translate(-50%, -120%);
  pointer-events: auto;
}

.blockedTextEditor input {
  width: min(220px, 48vw);
  min-height: 30px;
  border-radius: 6px;
  border: 1px solid #31405a;
  background: rgba(15, 21, 33, 0.94);
  color: #e9edf1;
  padding: 5px 8px;
  font-size: 12px;
}

.blockedTextEditor input:focus {
  outline: 2px solid #4aa3ff;
  outline-offset: 1px;
}

.imagePickerCompact {
  margin: 8px 0 4px;
  display: flex;
  justify-content: center;
}

.is-hidden {
  display: none !important;
}

.processingMask {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(9, 12, 18, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.processingMaskInner {
  min-width: min(360px, 90vw);
  background: #171d29;
  border: 1px solid #2f3c56;
  border-radius: 12px;
  padding: 14px 16px;
  color: #e9edf1;
  text-align: center;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
}

.processingMaskInner p {
  margin: 0;
  font-size: 14px;
}

.processingSpinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 10px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: #4aa3ff;
  animation: processing-spin 0.8s linear infinite;
}

@keyframes processing-spin {
  to {
    transform: rotate(360deg);
  }
}

.canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: transparent;
  cursor: default;
  touch-action: none;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

@media (max-width: 768px) {
  html,
  body {
    height: 100svh;
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  .app {
    width: 100vw;
    margin: 0;
    padding: 6px 0 calc(72px + env(safe-area-inset-bottom, 0px));
    min-height: 100svh;
    height: 100svh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .header h1 {
    font-size: 17px;
    margin-bottom: 4px;
    white-space: nowrap;
    line-height: 1.1;
  }

  .header {
    align-items: center;
  }

  .dropzone {
    padding: 8px 10px;
  }

  .dropzone p {
    margin: 2px 0 5px;
    font-size: 12px;
  }

  .controls {
    gap: 8px;
    margin: 8px 0 0;
  }

  .control {
    padding: 7px 8px;
  }

  .control-slider {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .control button {
    width: 100%;
    min-height: 34px;
  }

  .actionGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .actionGrid button {
    font-size: 13px;
    padding: 8px 8px;
  }

  @media (max-width: 380px) {
    .actionGrid {
      grid-template-columns: 1fr;
    }
  }

  .saveBar {
    margin-top: 5px;
    padding-top: 4px;
  }

  .saveButton {
    min-height: 42px;
    font-size: 14px;
  }

  .status {
    font-size: 12px;
  }

  .editorHelp {
    margin: 0 0 6px;
    font-size: 11px;
    line-height: 1.3;
  }

  .preview {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    min-height: 0;
    height: auto;
    padding: 4px 6px;
    overflow: hidden;
    display: flex;
    flex: 1 1 auto;
  }

  .canvas {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    object-fit: contain;
    max-height: none;
  }

  .controlsPanel {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    margin-top: 0;
    border-top: 1px solid #283042;
    border-radius: 12px;
    background: #0f1116;
    box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.35);
  }

  .controlsSummary {
    display: block;
    list-style: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
    padding: 11px 14px;
    user-select: none;
    border-radius: 10px;
    border: 1px solid #3d8bfd;
    background: linear-gradient(135deg, #2f81f7, #1f6fe0);
    box-shadow: 0 6px 14px rgba(10, 43, 91, 0.35);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .controlsSummary::after {
    content: "▼";
    font-size: 11px;
    opacity: 0.95;
    transition: transform 0.15s ease;
  }

  .controlsSummary::-webkit-details-marker {
    display: none;
  }

  .controlsPanel[open] .controlsSummary {
    border-bottom: 1px solid #2d6fcb;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .controlsPanel[open] .controlsSummary::after {
    transform: rotate(180deg);
  }

  .controlsPanelBody {
    padding: 0 8px 8px;
    max-height: 38svh;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .imagePickerCompact {
    margin: 6px 0 2px;
  }
}
