body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #f5f1ea;
  color: #241f19;
}

* {
  box-sizing: border-box;
}

img, canvas {
  display: block;
  max-width: 100%;
}

.app {
  max-width: 1360px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
}

.subtitle {
  margin: 6px 0 0;
  color: #6f675d;
}

.lang-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #fff;
  border: 1px solid #ebe4da;
  border-radius: 999px;
}

.lang-switch button {
  border: 0;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 999px;
  background: transparent;
  color: #6f675d;
  font-weight: 700;
  cursor: pointer;
}

.lang-switch button.active {
  background: #0f6b6f;
  color: #fff;
}

.layout {
  display: grid;
  grid-template-areas: "preview" "panel";
  gap: 16px;
  padding: 16px;
}

.panel {
  grid-area: panel;
  background: #fff;
  border: 1px solid #ddd4c8;
  border-radius: 24px;
  padding: 20px;
}

.preview-card {
  grid-area: preview;
  background: #fff;
  border: 1px solid #ddd4c8;
  border-radius: 24px;
  overflow: hidden;
}

.preview-head {
  padding: 16px;
  border-bottom: 1px solid #ebe4da;
  background: #fff;
  font-weight: 600;
  color: #0f6b6f;
}

.layers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  max-height: 240px;
  overflow-y: auto;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid #ebe4da;
  border-radius: 12px;
  background: #f8f5f0;
}

.layer-row.active {
  border-color: #0f6b6f;
  background: #eaf4f4;
}

.layer-name {
  flex: 1;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 6px 2px;
  font-size: 0.85rem;
  color: #241f19;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-remove {
  border: 0;
  background: transparent;
  color: #b23b3b;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.layer-remove:hover {
  background: rgba(178, 59, 59, 0.1);
}

input:disabled, select:disabled, button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* STAGE CONTAINER */
.stage {
  position: relative;
  width: 100%;
  height: min(58vh, 64dvh, 560px);
  min-height: 260px;
  background: radial-gradient(circle at center, #423d36 0%, #2d2924 100%);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

/* 1. LAYER STANZA CARICATA */
#roomImg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
}

/* 2. LAYER SCHERMATA VUOTA */
#empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(45, 41, 36, 0.75), rgba(45, 41, 36, 0.9));
  color: #fff;
  z-index: 2;
}

/* 3. LAYER CANVAS PROSPETTIVA */
#warpCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
}

/* 4. LAYER QUADRO FRONTALE (2D) */
#artWrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28%;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 4;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.frame {
  position: relative;
  background: #111;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3);
}

#artImg {
  width: 100%;
  height: auto;
}

.wm {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: none;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* 5. LAYER CONTROLLI MANIGLIE PROSPETTIVA */
#perspectiveLayer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.perspective-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #0f6b6f;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
  z-index: 6;
}

/* 6. FIRMA SVILUPPATORE (fuori dallo stage, non copre mai l'opera) */
.signature-footer {
  padding: 4px 14px;
  text-align: right;
  font-size: 10px;
  color: #a39a8c;
  background: #fff;
  border-top: 0.5px solid #ebe4da;
}

.signature-footer a {
  color: #0f6b6f;
  font-weight: 500;
  text-decoration: none;
}

.signature-footer a:hover,
.signature-footer a:focus-visible {
  text-decoration: underline;
}

/* ELEMENTI DEL PANNELLO */
.block {
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #ebe4da;
}

.block.last {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.block h2 {
  margin: 0 0 12px;
  color: #0f6b6f;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field > span {
  display: block;
  margin-bottom: 8px;
  color: #6f675d;
  font-size: 0.88rem;
  font-weight: 600;
}

.file-name, .help {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #ebe4da;
  border-radius: 14px;
  background: #f8f5f0;
  font-size: 0.85rem;
  color: #6f675d;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  background: #0f6b6f;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.button.secondary {
  background: #f1ece4;
  color: #241f19;
  border: 1px solid #ebe4da;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input[type=file] {
  display: none;
}

input[type=text], select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #ddd4c8;
  border-radius: 14px;
  background: #fff;
}

input[type=range] {
  width: 100%;
  accent-color: #0f6b6f;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #ebe4da;
  border-radius: 14px;
  background: #f8f5f0;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #0f6b6f;
}

/* RESPONSIVE DESKTOP */
@media (min-width: 960px) {
  .layout {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    grid-template-areas: "panel preview";
    gap: 20px;
    padding: 0 20px 20px;
  }
  .panel {
    position: sticky;
    top: 24px;
  }
  .stage {
    height: auto;
    aspect-ratio: 4/3;
    min-height: 520px;
  }
}

@media (max-width: 959px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .subtitle {
    display: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .layout {
    padding: 12px;
    gap: 12px;
  }
  .panel {
    padding: 16px;
  }
  .actions {
    grid-template-columns: 1fr;
  }
  .stage {
    min-height: 220px;
    height: min(50vh, 420px);
  }
}
