:root {
  --bg: #fff9f2;
  --card: #ffffff;
  --ink: #2d2a32;
  --ink-soft: #6f6a78;
  --coral: #ff6b6b;
  --coral-deep: #ff8e53;
  --teal: #29c2b6;
  --yellow: #ffd93d;
  --purple: #8e7cff;
  --grad-main: linear-gradient(120deg, #ff6b6b, #ff8e53);
  --grad-teal: linear-gradient(120deg, #29c2b6, #4dd9a4);
  --grad-purple: linear-gradient(120deg, #8e7cff, #d59bff);
  --shadow: 0 10px 30px rgba(255, 107, 107, 0.12);
  --shadow-hover: 0 16px 40px rgba(255, 107, 107, 0.18);
  --radius: 22px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Nunito", -apple-system, "PingFang TC", "Microsoft JhengHei",
    sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

.blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.35;
  z-index: -1;
  animation: float 14s ease-in-out infinite;
}
.blob.b1 { width: 380px; height: 380px; background: #ffb3c1; top: -80px; left: -100px; }
.blob.b2 { width: 320px; height: 320px; background: #9be7d8; bottom: -60px; right: -80px; animation-delay: -5s; }
.blob.b3 { width: 260px; height: 260px; background: #ffe58f; top: 40%; left: 70%; animation-delay: -9s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -40px) scale(1.08); }
}

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

h1.logo {
  font-size: 34px;
  font-weight: 900;
  text-align: center;
  letter-spacing: -0.5px;
  background: var(--grad-main);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}

.subtitle {
  text-align: center;
  color: var(--ink-soft);
  font-weight: 600;
  margin-bottom: 28px;
}

label {
  display: block;
  font-weight: 800;
  margin: 18px 0 8px;
  font-size: 15px;
}

input, textarea, select {
  width: 100%;
  border: 2px solid #eee5da;
  border-radius: 14px;
  padding: 13px 16px;
  font: inherit;
  color: var(--ink);
  background: #fffdf9;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.15);
}
textarea { resize: vertical; min-height: 74px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 14px 30px;
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  background: var(--grad-main);
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(255, 107, 107, 0.35);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s;
}
.btn:hover { transform: translateY(-2px) scale(1.04); box-shadow: var(--shadow-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn.full { width: 100%; margin-top: 26px; }
.btn.teal { background: var(--grad-teal); box-shadow: 0 8px 20px rgba(41, 194, 182, 0.3); }
.btn.ghost {
  background: #fff;
  color: var(--coral);
  border: 2px solid var(--coral);
  box-shadow: none;
}
.btn.sm { padding: 8px 16px; font-size: 13px; }

.pin-input {
  text-align: center;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 10px;
  padding: 18px 16px;
  text-transform: uppercase;
}

.msg {
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
  margin-top: 16px;
  display: none;
}
.msg.error { background: #ffe3e3; color: #c0392b; }
.msg.show { display: block; animation: shake 0.4s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.q-card {
  background: #fff;
  border-radius: 18px;
  padding: 22px 24px;
  margin-top: 16px;
  box-shadow: 0 6px 18px rgba(141, 124, 255, 0.1);
  border: 1px solid #f1ecff;
  opacity: 0;
  animation: fadeUp 0.5s ease forwards;
}
.q-card .q-title { font-weight: 800; margin-bottom: 10px; font-size: 16px; }
.q-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--grad-purple);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  margin-right: 8px;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp 0.5s ease both; }

.chip {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
  background: #fff3d6;
  color: #b8860b;
}
.chip.teal { background: #ddf7f4; color: #148f85; }
.chip.purple { background: #efeaff; color: #6a51c9; }

.orb {
  width: 120px;
  height: 120px;
  margin: 30px auto;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #ff6b6b, #ffd93d, #29c2b6, #8e7cff, #ff6b6b);
  animation: spin 3s linear infinite, pulse 2s ease-in-out infinite;
  box-shadow: 0 0 60px rgba(255, 107, 107, 0.4);
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { scale: 1; }
  50% { scale: 1.1; }
}

.wait-text {
  text-align: center;
  font-size: 19px;
  font-weight: 800;
  margin-top: 10px;
  transition: opacity 0.4s;
}

.result-img {
  width: 100%;
  max-width: 420px;
  border-radius: 26px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.15);
  display: block;
  margin: 10px auto 20px;
  animation: popIn 0.65s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.6) rotate(-3deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.explanation {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 8px 0 24px;
  line-height: 1.6;
}

.confetti {
  position: fixed;
  top: -12px;
  width: 10px;
  height: 16px;
  z-index: 99;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: 0.4; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.topbar .title {
  font-size: 26px;
  font-weight: 900;
  background: var(--grad-main);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.pill-tabs {
  display: inline-flex;
  background: #fff;
  border-radius: 999px;
  padding: 5px;
  box-shadow: var(--shadow);
  gap: 4px;
}
.pill-tabs button {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 800;
  padding: 9px 22px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: all 0.2s;
}
.pill-tabs button.active {
  background: var(--grad-main);
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.35);
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
  margin: 18px 0;
}
.stat {
  background: #fff;
  border-radius: 18px;
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat .num {
  font-size: 34px;
  font-weight: 900;
  background: var(--grad-teal);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stat .lab { color: var(--ink-soft); font-weight: 700; font-size: 13px; }

.img-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}
.img-cell {
  background: #fff;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: fadeUp 0.4s ease both;
}
.img-cell.new { animation: popIn 0.55s cubic-bezier(0.34, 1.56, 0.64, 1); }
.img-cell img { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block; cursor: pointer; }
.img-cell .cap { padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.img-cell .cap b { font-size: 14px; }

table.data {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 14px;
}
table.data th {
  background: #fff3ec;
  text-align: left;
  padding: 12px 14px;
  font-weight: 900;
  white-space: nowrap;
}
table.data td {
  padding: 11px 14px;
  border-top: 1px solid #f7efe8;
  vertical-align: top;
}
table.data tr:hover td { background: #fffaf5; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.badge.done { background: #ddf7f4; color: #12857c; }
.badge.error { background: #ffe3e3; color: #c0392b; }
.badge.prog { background: #fff3d6; color: #b8860b; }

.empty {
  text-align: center;
  color: var(--ink-soft);
  font-weight: 700;
  padding: 50px 0;
}

.field-row { display: flex; gap: 10px; align-items: center; }
.field-row input { flex: 1; }

.loading { text-align: center; padding: 60px 0; font-weight: 800; color: var(--ink-soft); }

@media (max-width: 860px) {
  .card { padding: 26px 20px; }
}

@media (max-width: 720px) {
  .q-card { padding: 16px 14px; }
  .q-card textarea { min-height: 58px; }
  .result-img { max-width: 100%; }
}

@media (max-width: 520px) {
  .wrap { padding: 20px 12px 40px; }
  .card { padding: 20px 14px; }
  .img-wall { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .blob { filter: blur(45px); }
}
