* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.screen {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hidden {
  display: none !important;
}

#gallery-screen {
  background: #E8F4FD;
  justify-content: flex-start;
}

.gallery-scroll {
  width: 100%;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
  padding-bottom: max(32px, calc(32px + env(safe-area-inset-bottom)));
  gap: 16px;
}

.gallery-card {
  width: calc(100% - 32px);
  max-width: 400px;
  height: 160px;
  background: #FFFFFF;
  border: 2px solid #E5E7EB;
  border-radius: 20px;
  display: flex;
  align-items: center;
  padding: 16px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 100ms ease;
  flex-shrink: 0;
}

.gallery-card:active {
  transform: scale(0.97);
}

.gallery-emoji {
  font-size: 48px;
  flex-shrink: 0;
  margin-right: 16px;
}

.gallery-preview {
  flex: 1;
  max-height: 120px;
  object-fit: contain;
}

#canvas-screen {
  background: #FFFFFF;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#drawing-canvas {
  flex: 1;
  width: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#toolbar {
  flex-shrink: 0;
  background: #F3F4F6;
  padding: 8px 16px;
  padding-bottom: max(12px, calc(env(safe-area-inset-bottom) + 4px));
  border-top: 1px solid #E5E7EB;
  touch-action: manipulation;
}

.color-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 0 8px;
  gap: 6px;
}

.color-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.color-btn.selected {
  border-color: #1F2937;
  box-shadow: 0 0 0 2px #FFFFFF, 0 0 0 4px #1F2937;
}

.tool-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  padding: 0 2px;
}

.tool-row .tool-btn,
.tool-row .size-btn {
  flex-shrink: 0;
}

.size-btn {
  width: 52px;
  height: 52px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 2px solid #D1D5DB;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.size-btn.selected {
  border-color: #1F2937;
  background: #E5E7EB;
}

.size-dot {
  display: block;
  border-radius: 50%;
  background: #1F2937;
}

.tool-btn {
  width: 52px;
  height: 52px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 2px solid #D1D5DB;
  background: #FFFFFF;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.tool-btn.active {
  border-color: #EF4444;
  background: #FEE2E2;
}


.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.confirm-overlay.hidden {
  display: none !important;
}

.confirm-box {
  background: #FFFFFF;
  border-radius: 20px;
  padding: 30px;
  text-align: center;
  min-width: 280px;
}

.confirm-text {
  font-size: 24px;
  font-weight: bold;
  color: #1F2937;
  margin-bottom: 24px;
}

.confirm-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  font-size: 36px;
  cursor: pointer;
  touch-action: manipulation;
  margin: 0 16px;
  -webkit-tap-highlight-color: transparent;
}

.confirm-yes {
  background: #22C55E;
  color: white;
}

.confirm-no {
  background: #EF4444;
  color: white;
}


.tool-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

.tool-btn.save-success {
  background: #22C55E;
  border-color: #22C55E;
}

.tool-btn.save-success svg {
  display: none;
}

.tool-btn.save-failure {
  background: #EF4444;
  border-color: #EF4444;
}

.tool-btn.save-failure svg {
  display: none;
}

/* Save image overlay (fallback for non-HTTPS) */
.save-image-box {
  background: #FFFFFF;
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.save-preview-img {
  max-width: 80vw;
  max-height: 60vh;
  border-radius: 12px;
  object-fit: contain;
  -webkit-touch-callout: default;
}

.save-image-close {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

/* Responsive toolbar for small screens */
@media (max-width: 400px) {
  .tool-btn,
  .size-btn {
    width: 44px;
    height: 44px;
  }

  .color-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }

  .color-row {
    padding: 0 4px;
    gap: 4px;
  }
}

