/* ===================================================================
   styles.css — ธีม Flip7 (teal-coral-gold) mobile-first
   =================================================================== */
:root {
  --teal: #0FB9B1;
  --teal-dark: #0E9D96;
  --coral: #FF6B6B;
  --gold: #FDCB6E;
  --cream: #FFF9F0;
  --ink: #2D3436;
  --muted: #8a8f91;
  --line: #efe7d9;
  --card-bg: #ffffff;
  --page-bg: #f3f5f4;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(14, 157, 150, 0.12);
  --shadow-coral: 0 8px 22px rgba(255, 107, 107, 0.28);
  --shadow-teal: 0 8px 22px rgba(15, 185, 177, 0.30);
  --shadow-gold: 0 8px 22px rgba(253, 203, 110, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans Thai', system-ui, -apple-system, sans-serif;
  background: var(--page-bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 40px;
}

/* ---- topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px calc(14px + env(safe-area-inset-top, 0));
  padding-top: max(14px, env(safe-area-inset-top, 0));
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar__title { font-weight: 800; font-size: 1.15rem; letter-spacing: .3px; }
.icon-btn {
  background: rgba(255,255,255,.2); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.1rem; cursor: pointer;
}
.icon-btn:active { transform: scale(.92); }

/* ---- layout ---- */
.wrap { max-width: 560px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0,0,0,.03);
}
.card__h { margin: 0 0 14px; font-size: 1.05rem; font-weight: 800; color: var(--teal-dark); }
.muted, .card__h .muted { color: var(--muted); font-weight: 500; font-size: .8rem; }

/* ---- fields ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: .85rem; font-weight: 600; color: #5a6163; }
input[type="text"], input[type="url"], input[type="number"], textarea {
  width: 100%;
  font-family: inherit; font-size: 1rem; color: var(--ink);
  background: var(--cream);
  border: 1.5px solid #f0e6d4;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,185,177,.15); }
textarea { resize: vertical; line-height: 1.6; }
.hint { font-size: .78rem; color: var(--muted); margin: 2px 0 12px; line-height: 1.5; }

/* ---- buttons (pill + glow) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; font-weight: 700; font-size: 1rem;
  border: none; border-radius: 999px; padding: 13px 20px; cursor: pointer;
  color: #fff; transition: transform .1s, box-shadow .15s, opacity .15s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--teal { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); box-shadow: var(--shadow-teal); }
.btn--coral { background: linear-gradient(135deg, #ff8585, var(--coral)); box-shadow: var(--shadow-coral); }
.btn--gold { background: linear-gradient(135deg, #ffd988, var(--gold)); color: #6b4f0a; box-shadow: var(--shadow-gold); }
.btn--ghost { background: #fff; color: var(--teal-dark); border: 1.5px solid var(--teal); box-shadow: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.row .btn { flex: 1; min-width: 130px; }

.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: #5a6163; margin-top: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }

/* ---- gallery ---- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; margin-top: 8px; }
.gallery .thumb {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  border: 2.5px solid transparent; cursor: pointer; background: var(--cream);
}
.gallery .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .thumb.selected { border-color: var(--teal); box-shadow: var(--shadow-teal); }
.gallery .thumb.selected::after {
  content: "✓ หลัก"; position: absolute; left: 0; bottom: 0; right: 0;
  background: var(--teal-dark); color: #fff; font-size: .65rem; text-align: center; padding: 2px;
}

/* ---- generated image ---- */
.genimg { margin-top: 14px; }
.genimg img { width: 100%; border-radius: 12px; box-shadow: var(--shadow); display: block; }

/* ---- notes / toast ---- */
.note { font-size: .85rem; margin-top: 10px; line-height: 1.6; word-break: break-word; }
.note a { color: var(--teal-dark); font-weight: 700; }
.note.ok { color: #0a8f5f; }
.note.err { color: var(--coral); }
.dashed { border-top: 1.5px dashed #e3dccb; margin: 12px 0; }

.steps { margin: 6px 0 12px; padding-left: 22px; font-size: .88rem; color: #5a6163; line-height: 1.7; }
.steps li { margin-bottom: 6px; }
#bmLink { word-break: break-all; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px;
  font-size: .9rem; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 90%;
}
.toast.err { background: var(--coral); }
.toast.ok { background: var(--teal-dark); }

.hidden { display: none !important; }

/* spinner บนปุ่มตอนโหลด */
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.5); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.btn--gold.loading::after { border-color: rgba(107,79,10,.4); border-top-color: #6b4f0a; }
.btn--ghost.loading::after { border-color: rgba(14,157,150,.4); border-top-color: var(--teal-dark); }
@keyframes spin { to { transform: rotate(360deg); } }
