:root {
  color-scheme: light;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #fff4fb, #ffe9f5 55%, #ffe3f0);
  color: #2e1c26;
  min-height: 100dvh;
  overflow: hidden;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  height: 100dvh;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.2vw, 1.9rem);
}

.header p {
  margin: 4px 0 0;
  font-size: 0.95rem;
}

.tabs-panel {
  background: #ffffffcc;
  border: 1px solid #f4cadf;
  border-radius: 14px;
  padding: 10px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  height: 230px;
}

.tabs-header {
  display: flex;
  gap: 8px;
}

.tab-btn {
  border: 1px solid #e9b8d2;
  background: #fff;
  color: #5a2b43;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-weight: 700;
}

.tab-btn.active {
  background: #ffd8eb;
  border-color: #d97eb0;
}

.tab-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tab-content {
  display: none;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  align-content: start;
}

.tab-content.active {
  display: grid;
}

.control {
  display: grid;
  gap: 6px;
}

.control span {
  font-weight: 600;
}

.btn {
  border: 1px solid #e9b8d2;
  background: white;
  color: #442234;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 600;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn.primary {
  background: #ff5fa4;
  border-color: #ff5fa4;
  color: white;
}

.preview {
  background: #ffffffcc;
  border: 1px solid #f4cadf;
  border-radius: 14px;
  padding: 10px;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
}

.preview-stage {
  width: min(100%, 900px);
  height: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.canvas-wrap {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

.control-dock {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dock-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.dock-control {
  padding: 5px 7px;
  border: 1px solid #f1c7de;
  border-radius: 10px;
  background: #ffffff;
  width: 100%;
}

.dock-control span {
  font-size: 0.78rem;
  font-weight: 700;
  color: #5a2b43;
  text-align: left;
}

#scale-control,
#rotation-control {
  gap: 4px;
}

.scale-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#scaleValue,
#rotationValue {
  min-width: 54px;
  text-align: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #e9b8d2;
  background: #fff7fc;
  color: #7a3458;
  font-weight: 700;
  font-size: 0.76rem;
}

.scale-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 5px;
}

.scale-btn,
.scale-reset {
  border: 1px solid #e9b8d2;
  background: #fff;
  color: #5a2b43;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
}

.scale-btn {
  width: 24px;
  height: 24px;
  font-size: 1rem;
}

.scale-reset {
  height: 24px;
  padding: 0 8px;
  font-size: 0.72rem;
}

.scale-btn:hover,
.scale-reset:hover {
  background: #ffe8f4;
}

.control-dock input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.control-dock input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffc6e1, #ff89ba);
}

.control-dock input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background: #ff5fa4;
  box-shadow: 0 1px 4px #d97eb0aa;
}

.control-dock input[type="range"]::-moz-range-track {
  height: 6px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffc6e1, #ff89ba);
}

.control-dock input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #ff5fa4;
  box-shadow: 0 1px 4px #d97eb0aa;
}

.control-dock.is-hidden {
  display: none;
}

.bg-palette {
  display: grid;
  grid-template-columns: repeat(6, 35px);
  gap: 20px;
  justify-content: start;
}

.bg-color-btn {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  border: 1px solid #e9b8d2;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px #ffffff80;
}

.bg-color-btn[data-color="#ffd9eb"] { background: linear-gradient(180deg, #ffeef7, #ffcde3); }
.bg-color-btn[data-color="#ffe7c1"] { background: linear-gradient(180deg, #fff4de, #ffdca3); }
.bg-color-btn[data-color="#d7f1ff"] { background: linear-gradient(180deg, #ecf9ff, #bfe8ff); }
.bg-color-btn[data-color="#dff7e1"] { background: linear-gradient(180deg, #effcf0, #c7efcb); }
.bg-color-btn[data-color="#e7ddff"] { background: linear-gradient(180deg, #f2edff, #d7c7ff); }
.bg-color-btn[data-color="#f5f5f5"] { background: linear-gradient(180deg, #ffffff, #ebebeb); }

.bg-color-btn.active {
  border-color: #d97eb0;
  box-shadow: 0 0 0 2px #ffd8eb;
}

.bg-color-btn:hover {
  filter: brightness(0.98);
}

.nav-arrow {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid #e9b8d2;
  background: #fff;
  color: #442234;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.nav-arrow:hover {
  background: #ffd2e7;
}

canvas {
  width: min(100%, 66vh);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  justify-self: center;
  align-self: center;
  display: block;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 35%, #fff5fb, #ffd9eb 70%);
}

.footer {
  opacity: 0.75;
  font-size: 0.78rem;
}

@media (max-width: 980px) {
  .app {
    padding: 10px;
    gap: 8px;
  }

  .tabs-panel {
    height: 250px;
  }

  .preview-stage {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
  }

  .nav-arrow {
    width: 40px;
    height: 40px;
  }

  .dock-row {
    grid-template-columns: 1fr;
  }

  .control-dock {
    height: auto;
  }

  canvas {
    max-height: 100%;
  }

  .bg-color-btn {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 640px) {
  .header p,
  .footer {
    display: none;
  }

  .header h1 {
    font-size: 1.3rem;
  }

  .tabs-panel {
    height: 260px;
  }

  .tab-btn {
    flex: 1;
  }

  .preview {
    padding: 8px;
  }

  .preview-stage {
    grid-template-columns: 36px minmax(0, 1fr) 36px;
    gap: 6px;
  }

  .nav-arrow {
     width: 2.25em;
     height: 2.25em;
     font-size: 1rem;
  }

  .scale-row {
    grid-template-columns: auto 1fr auto;
  }

  .scale-reset {
     grid-column: 1 / -1;
     justify-self: end;
     margin-top: 0.125em;
  }

  .control-dock {
     padding: 0.375rem;
  }

  .bg-palette {
     grid-template-columns: repeat(6, 1.375em);
  }

  canvas {
    max-height: 100%;
  }
}
