* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #1a1a2e;
  color: #fff;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* SCREENS */
.screen { display: none; flex-direction: column; height: 100dvh; }
.screen.active { display: flex; }

/* TOP BAR */
.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #16213e;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.top-bar h1 { font-size: 1.6rem; flex: 1; }
.top-bar h2 { font-size: 1.3rem; flex: 1; text-align: center; }
.top-bar.compact { padding: 8px 12px; gap: 8px; }
.top-buttons { display: flex; gap: 10px; }

/* BUTTONS */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s, opacity 0.1s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.95); opacity: 0.85; }
.btn-green  { background: #4caf50; color: #fff; }
.btn-red    { background: #f44336; color: #fff; }
.btn-yellow { background: #ffc107; color: #000; }
.btn-purple { background: #9c27b0; color: #fff; }
.btn-grey   { background: #555; color: #fff; }
.btn-back   { background: #333; color: #fff; font-size: 1.1rem; padding: 8px 14px; }

.size-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: #333;
  color: #fff;
  font-weight: bold;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.1s;
}
.size-btn.active { border-color: #ffc107; background: #555; }

/* GALLERY */
.gallery {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
  align-content: start;
}

.empty-msg {
  grid-column: 1 / -1;
  text-align: center;
  color: #888;
  font-size: 1.2rem;
  margin-top: 60px;
}

.gallery-item {
  background: #16213e;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  aspect-ratio: 1;
  border: 3px solid transparent;
  transition: border-color 0.2s, transform 0.1s;
}
.gallery-item:active { transform: scale(0.97); }
.gallery-item:hover { border-color: #9c27b0; }
.gallery-item img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-item .delete-x {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(244,67,54,0.85);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold;
}
.gallery-item .item-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55);
  font-size: 0.75rem;
  padding: 4px 6px;
  text-align: center;
}

/* CHOICE BUTTONS */
.choice-buttons {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  padding: 32px 24px;
}
.choice-btn {
  background: #16213e;
  border: 3px solid #333;
  border-radius: 20px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
}
.choice-btn:active { transform: scale(0.97); }
.choice-btn:hover { border-color: #9c27b0; }
.choice-icon { font-size: 3rem; }
.choice-label { font-size: 1.5rem; font-weight: bold; color: #fff; }
.choice-sub { font-size: 0.95rem; color: #aaa; text-align: center; }

/* CANVAS */
.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0f0f1a;
  touch-action: none;
}
canvas {
  background: #fff;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* PALETTE */
.palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  background: #16213e;
  flex-shrink: 0;
}
.color-swatch {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
  flex-shrink: 0;
}
.color-swatch:active { transform: scale(0.9); }
.color-swatch.selected { border-color: #fff; transform: scale(1.15); }
.color-swatch.eraser {
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Ctext y='28' font-size='22' x='6'%3E🧹%3C/text%3E%3C/svg%3E") center/28px no-repeat;
}

/* MODAL */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: #16213e;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 340px;
  width: 90%;
  text-align: center;
}
.modal-box p { font-size: 1.2rem; margin-bottom: 24px; line-height: 1.4; }
.modal-btns { display: flex; gap: 16px; justify-content: center; }
