:root {
  --bg: #faf6f2;
  --bg-tint: #f3ede5;
  --card: #ffffff;
  --card-hover: #fdf9f4;
  --text: #3d3530;
  --muted: #8c857e;
  --border: #ede4d9;
  --border-strong: #ddd2c2;
  --accent: #e8a598;
  --accent-hover: #dc9084;
  --accent-soft: #fbeeea;
  --sage: #a8c09f;
  --sage-soft: #eaf0e5;
  --cream: #f5e9d7;
  --shadow-sm: 0 1px 2px rgba(120, 100, 80, 0.04);
  --shadow: 0 2px 12px rgba(145, 120, 95, 0.06);
  --shadow-lg: 0 10px 30px rgba(145, 120, 95, 0.08);
  --radius: 18px;
  --radius-lg: 24px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(232, 165, 152, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 88% 82%, rgba(168, 192, 159, 0.07) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(245, 233, 215, 0.5) 0%, transparent 70%);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Noto Sans TC', 'Zen Kaku Gothic New', -apple-system,
    BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei',
    sans-serif;
  font-weight: 400;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header {
  text-align: center;
  padding: 3rem 1.25rem 1.5rem;
  position: relative;
}

header::before,
header::after {
  content: '✿';
  position: absolute;
  color: var(--accent);
  opacity: 0.4;
  font-size: 1.4rem;
  top: 3.2rem;
}
header::before { left: max(1.5rem, calc(50% - 220px)); }
header::after { right: max(1.5rem, calc(50% - 220px)); }

header h1 {
  margin: 0;
  font-family: 'Zen Kaku Gothic New', 'Noto Sans TC', sans-serif;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

header h1 .ja {
  display: block;
  font-family: 'Caveat', cursive;
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: 0.15em;
  margin-bottom: 0.25rem;
  opacity: 0.85;
}

.tagline {
  color: var(--muted);
  margin: 0.5rem auto 0;
  max-width: 32rem;
  font-size: 0.95rem;
}

.howto {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0.75rem;
  margin: 1.5rem auto 0;
  max-width: 640px;
  flex-wrap: wrap;
}

.howto-step {
  flex: 1 1 240px;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.9rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.howto-step strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.howto-step span {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.55;
}

.howto-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0;
}

.howto-or {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 0.5rem;
  font-family: 'Caveat', cursive;
  font-size: 1.3rem;
}

@media (max-width: 560px) {
  .howto-or { display: none; }
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.25s ease;
}

.card:hover { box-shadow: var(--shadow-lg); }

.card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.card-header h2 { margin: 0; }

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0.4rem 0 1rem;
  line-height: 1.65;
}

.upload-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  text-align: center;
  gap: 0.5rem;
  color: var(--muted);
  background: linear-gradient(180deg, #fbf7f2 0%, #fdfbf8 100%);
}

.upload-box:hover,
.upload-box.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
  transform: translateY(-1px);
}

.upload-box.compact { padding: 1.75rem 1rem; }

.upload-icon {
  width: 44px;
  height: 44px;
  color: var(--muted);
  transition: color 0.2s ease, transform 0.2s ease;
}
.upload-box:hover .upload-icon,
.upload-box.dragover .upload-icon {
  color: var(--accent);
  transform: translateY(-2px);
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.icon-btn .btn-icon {
  width: 20px;
  height: 20px;
}

.inline-icon {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  color: var(--accent-hover);
  margin-right: 4px;
}

#source-preview,
#selfie-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

#source-img {
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

#selfie-img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 50%;
  border: 3px solid var(--card);
  box-shadow: 0 4px 16px rgba(145, 120, 95, 0.12);
  object-fit: cover;
}

.tiles-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 0.25rem;
}

.tiles-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tint);
  box-shadow: var(--shadow-sm);
}

.video-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.video-controls label {
  display: flex;
  flex-direction: column;
  font-size: 0.82rem;
  color: var(--muted);
  gap: 4px;
  letter-spacing: 0.02em;
}

.video-controls input,
.video-controls select,
.field input,
.field select {
  background: #fffaf5;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.92rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.video-controls input { width: 90px; }
.video-controls select { min-width: 130px; }

.video-controls input:focus,
.video-controls select:focus,
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button, .primary, .ghost {
  font: inherit;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.4rem;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.18s ease;
  letter-spacing: 0.03em;
}

.primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(232, 165, 152, 0.35);
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(232, 165, 152, 0.4);
}

.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.ghost {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.ghost:hover { background: var(--card-hover); border-color: var(--border-strong); }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 1.2rem;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  border-radius: 50%;
  line-height: 1;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--card-hover);
  border-color: var(--border);
  color: var(--text);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.field input, .field select { width: 100%; }

#progress, #ai-progress {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar {
  height: 6px;
  background: var(--bg-tint);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent) 0%, var(--sage) 100%);
  transition: width 0.3s ease;
  border-radius: 999px;
}

#progress-text, #ai-progress-text {
  color: var(--muted);
  font-size: 0.85rem;
}

.coffee-hint {
  margin-top: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: var(--cream);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
}

.coffee-hint a {
  color: var(--accent-hover);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.coffee-hint a:hover { border-bottom-style: solid; }

.rpm-hint {
  margin-top: 0.4rem;
  padding: 0.65rem 0.85rem;
  background: #fff7e8;
  border: 1px dashed #e4bf7a;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--text);
}
.rpm-hint strong { color: #a3731b; }
.rpm-hint a {
  color: #a3731b;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dotted #d4a24a;
}
.rpm-hint a:hover { border-bottom-style: solid; }

.tip-box {
  background: var(--sage-soft);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.95rem;
  margin: 0.6rem 0 0.5rem;
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text);
}

.tip-box summary {
  cursor: pointer;
  list-style: none;
  padding: 0.1rem 0;
  color: #5f7857;
  font-weight: 500;
}
.tip-box summary::-webkit-details-marker { display: none; }
.tip-box summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.2s ease;
  color: var(--sage);
}
.tip-box[open] summary::before { transform: rotate(90deg); }

.tip-box strong {
  color: #6a8760;
  margin-right: 2px;
}

.tip-body {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed rgba(168, 192, 159, 0.5);
}
.tip-body p {
  margin: 0 0 0.6rem;
  color: var(--text);
}

.tip-box a {
  color: #6a8760;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px dotted var(--sage);
}
.tip-box a:hover { border-bottom-style: solid; }

.prompt-box {
  position: relative;
  background: #fffdf9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem 0.85rem;
  margin-top: 0.4rem;
}

#copy-prompt-text {
  margin: 0;
  padding-right: 0;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 14rem;
  overflow-y: auto;
}

.copy-btn {
  position: sticky;
  top: 0.1rem;
  float: right;
  margin-left: 0.5rem;
  margin-bottom: 0.25rem;
  padding: 0.4rem 0.85rem;
  background: var(--card);
  color: #5f7857;
  border: 1px solid var(--sage);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.copy-btn:hover {
  background: var(--sage-soft);
}
.copy-btn.copied {
  background: var(--sage);
  color: #fff;
  border-color: var(--sage);
}
.copy-btn .btn-icon {
  width: 14px;
  height: 14px;
}

#video-output {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#preview-video {
  width: 100%;
  border-radius: var(--radius);
  background: var(--bg-tint);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.coffee-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.3rem;
  background: #ffe9a6;
  color: #5a4a1f;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  align-self: flex-start;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 6px rgba(200, 170, 80, 0.2);
}
.coffee-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(200, 170, 80, 0.28);
}

dialog {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 640px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(61, 53, 48, 0.35); }
dialog h3 { margin-top: 0; font-weight: 600; }

dialog menu {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  margin: 1rem 0 0;
  padding: 0;
  flex-wrap: wrap;
}
dialog menu button {
  padding: 0.55rem 0.95rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 1rem 0 0.25rem;
}

.slot-cell {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0.5rem;
  background: #fbf7f2;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.slot-head {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: center;
}

.slot-select {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.72rem;
  color: var(--text);
  font-family: inherit;
  width: 100%;
  cursor: pointer;
}

.slot-select:focus {
  outline: none;
  border-color: var(--accent);
}

.slot-custom {
  background: #ffffff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.72rem;
  color: var(--text);
  font-family: inherit;
  width: 100%;
}

@media (max-width: 560px) {
  .slot-grid { gap: 6px; }
  .slot-cell { padding: 0.4rem; }
  .slot-select { font-size: 0.68rem; }
}

.link-btn {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--accent-hover);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.link-btn:hover { border-bottom-style: solid; }

.slot-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  margin: 0.75rem 0 0.5rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text);
  flex-wrap: wrap;
}
.slot-status-text {
  color: var(--text);
}

footer {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1.25rem;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
footer a {
  color: var(--accent-hover);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  padding-bottom: 1px;
}
footer a:hover { border-bottom-style: solid; }

@media (max-width: 480px) {
  header { padding: 2rem 1rem 1rem; }
  header::before, header::after { display: none; }
  .card { padding: 1.25rem; }
}
