*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
:root {
  /* Sunset Yellow (PRIMARY) */
  --sunset-10: #FFF9EC;
  --sunset-30: #FFECC6;
  --sunset-60: #FED98E;
  --sunset-80: #FECD68;
  --sunset-100: #FEC042;
  --sunset-plus40: #CB9A35;
  --sunset-plus80: #987328;

  /* Midnight Navy */
  --midnight-10: #EAEAEC;
  --midnight-30: #BFC0C6;
  --midnight-60: #80818E;
  --midnight-80: #555768;
  --midnight-100: #2B2D42;
  --midnight-plus40: #222435;
  --midnight-plus80: #1A1B28;

  /* Ocean Teal */
  --ocean-10: #EDF6F6;
  --ocean-30: #CAE4E4;
  --ocean-60: #95CAC8;
  --ocean-80: #72B8B6;
  --ocean-100: #4FA6A4;
  --ocean-plus40: #3F837F;
  --ocean-plus80: #2F615F;

  /* Coral Orange */
  --coral-10: #FEF2EB;
  --coral-30: #FBD8C4;
  --coral-60: #F7B188;
  --coral-80: #F59761;
  --coral-100: #F27D39;
  --coral-plus40: #C2612D;
  --coral-plus80: #8B421D;

  /* Cream */
  --cream-10: #FFFEFC;
  --cream-30: #FFFDF7;
  --cream-60: #FFFAEF;
  --cream-80: #FFF9E9;
  --cream-100: #FFF7E4;
  --cream-plus40: #CCC6B6;
  --cream-plus80: #999489;

  /* White */
  --white-10: #FFFFFF;
  --white-30: #FFFFFF;
  --white-60: #FFFFFF;
  --white-80: #FFFFFF;
  --white-100: #FFFFFF;
  --white-plus40: #CCCCCC;
  --white-plus80: #999999;

  /* Neutral Grey */
  --grey-10: #EDEDED;
  --grey-30: #C9C9C9;
  --grey-60: #929292;
  --grey-80: #6E6E6E;
  --grey-100: #4A4A4A;
  --grey-plus40: #3B3B3B;
  --grey-plus80: #2C2C2C;

  /* App semantics (map UI to palette) */
  --accent: var(--sunset-100);
  --accent-press: var(--sunset-plus40);
  --accent-ring: rgba(254, 192, 66, 0.22);
  --accent-muted: rgba(254, 192, 66, 0.12);
  --bg: var(--cream-100);
  --surface: var(--white-100);
  --border: var(--grey-30);
  --text: var(--midnight-100);
  --text-2: var(--midnight-60);
  --success: var(--ocean-100);
  --danger: var(--coral-100);
  --r: 14px;
  --r-sm: 10px;
}
html { height: 100%; }
body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 430px; margin: 0 auto; min-height: 100dvh; }

.header {
  position: sticky; top: 0; z-index: 10;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 14px;
  background: rgba(255, 247, 228, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid rgba(0,0,0,0.07);
}
.header-title { font-size: 28px; font-weight: 700; letter-spacing: -0.6px; }

.content {
  padding: 24px 16px calc(env(safe-area-inset-bottom, 0px) + 48px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.section { display: flex; flex-direction: column; gap: 8px; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 2px;
}
.section-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--text-2);
}
.section-count { font-size: 12px; font-weight: 600; color: var(--accent); }

.select-wrap { position: relative; }
select {
  width: 100%;
  padding: 15px 44px 15px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font: 500 17px/1 inherit;
  color: var(--text);
  appearance: none; -webkit-appearance: none;
  cursor: pointer; outline: none;
  transition: border-color .18s, box-shadow .18s;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--accent-ring); }
.chevron {
  pointer-events: none;
  position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
}

.picker {
  position: relative;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 20px;
  cursor: pointer;
  transition: border-color .2s, background .15s, padding .22s ease, gap .22s ease;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
.picker.compact {
  flex-direction: row;
  padding: 14px 20px;
  gap: 10px;
  justify-content: center;
  border-style: solid;
  border-color: var(--border);
}
.picker input[type=file] {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
  width: 100%; height: 100%;
  z-index: 1;
}
.picker:active { background: #EBEBF0; }
.picker-icon { color: var(--accent); flex-shrink: 0; transition: transform .22s ease; }
.picker.compact .picker-icon { transform: scale(0.68); }
.picker-label-main {
  font-size: 17px; font-weight: 600; color: var(--text);
  transition: font-size .18s;
}
.picker.compact .picker-label-main { font-size: 15px; }
.picker-label-sub { font-size: 14px; color: var(--text-2); }
.picker.compact .picker-label-sub { display: none; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.thumb {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  overflow: hidden;
  position: relative;
  background: var(--border);
}
.thumb img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.thumb .overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.thumb.uploading .overlay { background: rgba(0,0,0,.48); }
.thumb.success   .overlay { background: rgba(79, 166, 164, 0.55); }
.thumb .del {
  position: absolute; top: 5px; right: 5px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,.58);
  border: none; border-radius: 50%;
  color: #fff; font-size: 16px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
  transition: background .12s;
}
.thumb .del:active { background: rgba(255,59,48,.8); }
.thumb.uploading .del, .thumb.success .del, .thumb.processing .del { display: none; }

.thumb.processing { animation: shimmer-pulse 1.4s ease-in-out infinite; }
@keyframes shimmer-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

.spin {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: rotate .65s linear infinite;
}
@keyframes rotate { to { transform: rotate(360deg); } }

.tick {
  width: 34px; height: 34px;
  background: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.tick::after {
  content: '';
  display: block;
  width: 14px; height: 8px;
  border-left: 3px solid var(--success);
  border-bottom: 3px solid var(--success);
  transform: rotate(-45deg) translate(1px, 1px);
}

textarea {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font: 400 17px/1.55 inherit;
  color: var(--text);
  resize: none;
  min-height: 110px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
textarea::placeholder { color: var(--text-2); }
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--accent-ring); }

.btn-upload {
  width: 100%;
  padding: 17px;
  background: var(--accent);
  color: #fff;
  border: none; border-radius: var(--r-sm);
  font: 600 17px/1 inherit;
  cursor: pointer; touch-action: manipulation;
  transition: opacity .15s, transform .1s, background .1s;
  position: relative; overflow: hidden;
}
.btn-upload:disabled { opacity: .38; cursor: default; }
.btn-upload:not(:disabled):active { transform: scale(.97); background: var(--accent-press); }
.btn-upload.busy { color: transparent; pointer-events: none; }
.btn-upload.busy::after {
  content: '';
  position: absolute; top: 50%; left: 50%;
  width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border: 3px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: rotate .65s linear infinite;
}

.success-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 20px 36px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
  animation: rise .38s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(18px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.success-circle {
  width: 72px; height: 72px;
  background: var(--success);
  border-radius: 50%;
  margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
}
.success-circle::after {
  content: '';
  display: block;
  width: 30px; height: 17px;
  border-left: 5px solid #fff;
  border-bottom: 5px solid #fff;
  transform: rotate(-45deg) translate(2px, 3px);
}
.success-card h2 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; margin-bottom: 8px; }
.success-card p  { font-size: 15px; color: var(--text-2); line-height: 1.5; margin-bottom: 26px; }
.btn-more {
  padding: 13px 28px;
  background: var(--accent-muted);
  border: none; border-radius: 10px;
  font: 600 16px/1 inherit;
  color: var(--accent);
  cursor: pointer; touch-action: manipulation;
}
.btn-more:active { opacity: .7; }

.upload-error {
  font-size: 12px; line-height: 1.45; color: var(--danger);
  text-align: left; padding: 10px 12px;
  background: rgba(242, 125, 57, 0.1);
  border: 1px solid rgba(242, 125, 57, 0.28);
  border-radius: var(--r-sm);
  white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.btn-generate {
  width: 100%;
  padding: 13px;
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font: 600 15px/1 inherit;
  cursor: pointer; touch-action: manipulation;
  transition: background .15s, opacity .15s;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.btn-generate:active { background: #EBEBF0; }
.btn-generate:disabled { opacity: .4; cursor: default; }

.admin-bar {
  text-align: center;
  padding: 12px 16px 24px;
}
.admin-toggle {
  background: none; border: none;
  font: 700 10px/1 inherit;
  letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--text-2); opacity: 0.45;
  cursor: pointer; padding: 6px 10px;
  transition: opacity .15s;
}
.admin-toggle:active { opacity: 1; }

.admin-content { padding-top: 8px; padding-bottom: 40px; }

.admin-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 500 15px/1.35 inherit;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 12px;
  user-select: none;
}
.admin-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.btn-admin-action {
  padding: 12px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font: 600 15px/1 inherit;
  color: var(--text);
  cursor: pointer; touch-action: manipulation;
  transition: background .15s;
  align-self: flex-start;
}
.btn-admin-action:active { background: #EBEBF0; }
.btn-admin-action:disabled { opacity: .4; cursor: default; }

#adminOutput {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5;
  resize: vertical;
}

[hidden] { display: none !important; }
