body {
  background: #ffe5d9;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.tools {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.2vh;
  padding-top: 64px;
}

.tools button,
.palette button {
  border: 3px solid #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

.tools button {
  width: min(9vh, 72px);
  height: min(9vh, 72px);
  border-radius: 18px;
  background: #fff;
  font-size: min(5vh, 40px);
  line-height: 1;
}

.tools .selected {
  background: #ffd166;
  border-color: #f78c6b;
  transform: scale(1.08);
}

.tools button:active,
.palette button:active {
  transform: scale(0.92);
}

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.paper {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  max-height: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}

@supports (width: 1cqw) {
  .stage {
    container-type: size;
  }
  .paper {
    width: min(100cqw, 133.33cqh);
    height: auto;
  }
}

.paper canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#lines {
  pointer-events: none;
}

.palette {
  display: grid;
  grid-template-columns: repeat(2, auto);
  grid-auto-rows: min-content;
  align-content: center;
  gap: 1vh;
}

.palette button {
  width: min(8vh, 60px);
  height: min(8vh, 60px);
  border-radius: 50%;
}

.palette .selected {
  box-shadow: 0 0 0 4px #333;
  transform: scale(1.12);
}

/* picker sheets */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.sheet[hidden] {
  display: none;
}

.sheet-grid {
  display: grid;
  gap: 14px;
  padding: 20px;
  border-radius: 28px;
  background: #fff;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
}

.stamps {
  grid-template-columns: repeat(6, 1fr);
}

.stamps button {
  width: 88px;
  height: 88px;
  border-radius: 20px;
  border: 3px solid #eee;
  background: #fff8f0;
  font-size: 56px;
  line-height: 1;
}

.pictures {
  grid-template-columns: repeat(4, 1fr);
}

.pictures button {
  width: 180px;
  height: 135px;
  border-radius: 18px;
  border: 4px solid #eee;
  background: #fff;
  overflow: hidden;
  font-size: 64px;
  position: relative;
}

.pictures canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.pictures .photo span {
  position: absolute;
  right: 8px;
  bottom: 4px;
  font-size: 36px;
}

/* iPad en vertical: herramientas arriba, colores abajo */
@media (orientation: portrait) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .tools {
    flex-direction: row;
    padding: 0 0 0 64px;
  }
  .tools button {
    width: min(9vw, 72px);
    height: min(9vw, 72px);
    font-size: min(5vw, 40px);
  }
  .palette {
    grid-template-columns: repeat(9, auto);
    justify-content: center;
  }
  .palette button {
    width: min(8vw, 60px);
    height: min(8vw, 60px);
  }
  .stamps {
    grid-template-columns: repeat(5, 1fr);
  }
  .pictures {
    grid-template-columns: repeat(3, 1fr);
  }
  .pictures button {
    width: 26vw;
    height: 19.5vw;
  }
}
