:root {
  color-scheme: dark;
  --rose-200:#fecdd3; --rose-300:#fda4af; --rose-400:#fb7185;
  --rose-500:#f43f5e; --rose-600:#e11d48; --rose-700:#be123c;
  --rose-800:#9f1239; --rose-900:#881337;
  --wine:#4a0e1f; --wine-2:#2a0a14;
  --gold:#d4af7a; --gold-2:#b8916a; --champagne:#f5e6d3;
}
html, body { margin:0; padding:0; }
body {
  font-family: 'Inter', 'Noto Serif TC', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 600px at 12% 8%, rgba(225, 29, 72, 0.28), transparent 60%),
    radial-gradient(800px 600px at 88% 92%, rgba(159, 18, 57, 0.32), transparent 55%),
    radial-gradient(600px 400px at 50% 50%, rgba(212, 175, 122, 0.06), transparent 60%),
    linear-gradient(135deg, #1a0509 0%, #2a0a14 40%, #1a0509 100%);
  min-height:100vh;
  min-height:100dvh;
  color:#f5e6d3;
  /* iOS safe areas for installed PWA */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.serif { font-family: 'Cormorant Garamond', 'Noto Serif TC', serif; letter-spacing: .01em; }
.glass {
  background: linear-gradient(135deg, rgba(42, 10, 20, 0.78), rgba(74, 14, 31, 0.55));
  border: 1px solid rgba(212, 175, 122, 0.18);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.45), inset 0 1px 0 rgba(245, 230, 211, 0.05);
}
.glass-soft {
  background: linear-gradient(135deg, rgba(74, 14, 31, 0.55), rgba(42, 10, 20, 0.4));
  border: 1px solid rgba(212, 175, 122, 0.12);
}
.divider {
  display:flex; align-items:center; gap:14px; margin: 8px 0 14px;
  color: var(--gold);
}
.divider::before, .divider::after {
  content:""; flex:1; height:1px;
  background: linear-gradient(90deg, transparent, rgba(212,175,122,.4), transparent);
}
.divider span { font-family:'Cormorant Garamond',serif; font-style:italic; font-size:13px; letter-spacing:.15em; }
.field {
  background: rgba(20, 4, 9, 0.55);
  border: 1px solid rgba(212, 175, 122, 0.22);
  color: #f5e6d3;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.field::placeholder { color: rgba(245, 230, 211, 0.35); }
.field:focus {
  outline: none;
  border-color: rgba(244, 63, 94, 0.65);
  box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.18);
  background: rgba(20, 4, 9, 0.7);
}
select.field option { background:#2a0a14; color:#f5e6d3; }
.btn-primary {
  background: linear-gradient(135deg, #be123c 0%, #881337 50%, #4a0e1f 100%);
  border: 1px solid rgba(212, 175, 122, 0.35);
  color: #fff5ee;
  box-shadow: 0 6px 20px rgba(190, 18, 60, 0.35), inset 0 1px 0 rgba(255,255,255,.08);
  transition: transform .08s, filter .15s, box-shadow .2s;
  letter-spacing: .04em;
}
.btn-primary:hover { filter: brightness(1.12); box-shadow: 0 8px 24px rgba(190, 18, 60, 0.5); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity:.5; cursor:not-allowed; filter:none; }
.btn-ghost {
  background: rgba(20, 4, 9, 0.45);
  border: 1px solid rgba(212, 175, 122, 0.25);
  color: #f5e6d3;
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: rgba(244, 63, 94, 0.12); border-color: rgba(212, 175, 122, 0.45); }
.chip {
  display:inline-flex; align-items:center; gap:6px;
  padding: 3px 10px; border-radius:999px;
  background: rgba(212, 175, 122, 0.1);
  border:1px solid rgba(212, 175, 122, 0.3);
  color:var(--gold);
  font-size:11px; letter-spacing:.06em;
}
.chip.rose { background: rgba(244, 63, 94, 0.12); border-color: rgba(244, 63, 94, 0.4); color:#fda4af; }
.chip.green { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.4); color:#86efac; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader {
  display:inline-block; width:14px; height:14px;
  border:2px solid #fff5ee; border-top-color:transparent;
  border-radius:50%; animation: spin .8s linear infinite;
  vertical-align:-2px; margin-right:8px;
}
.output { font-family:'Inter','Noto Serif TC',serif; }
.output h1, .output h2, .output h3 { font-family:'Cormorant Garamond','Noto Serif TC',serif; color:#fecdd3; letter-spacing:.01em; }
.output h1 { font-size:1.55rem; font-weight:600; margin:.7em 0 .35em; }
.output h2 { font-size:1.3rem; font-weight:600; margin:.65em 0 .3em; }
.output h3 { font-size:1.1rem; font-weight:600; margin:.55em 0 .25em; color:#fda4af; }
.output p { margin:.5em 0; color:#f5e6d3; }
.output ul, .output ol { margin:.3em 0 .6em; padding-left:22px; }
.output ul li { list-style: '❀ '; padding-left:4px; }
.output ol li { list-style: decimal; }
.output li { margin:.18em 0; }
.output code { background: rgba(212,175,122,.12); padding:1px 5px; border-radius:4px; font-size:.92em; color:#f5e6d3; }
.output pre { background: rgba(0,0,0,.45); border:1px solid rgba(212,175,122,.15); padding:10px 12px; border-radius:8px; overflow:auto; }
.output a { color:#fda4af; text-decoration: underline; text-decoration-color: rgba(253,164,175,.4); }
.output blockquote { border-left:3px solid var(--rose-500); margin:.4em 0; padding:.1em 14px; color:#fecdd3; font-style:italic; }
.output strong { color:#fff1f2; }
.output hr { border:0; height:1px; background: linear-gradient(90deg, transparent, rgba(212,175,122,.4), transparent); margin: 1em 0; }
.scrollbar-thin::-webkit-scrollbar { width:8px; height:8px; }
.scrollbar-thin::-webkit-scrollbar-thumb { background: linear-gradient(180deg, rgba(244,63,94,.55), rgba(159,18,57,.7)); border-radius:999px; }
.scrollbar-thin::-webkit-scrollbar-track { background: rgba(255,255,255,.04); border-radius:999px; }
.petal-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.petal {
  position: absolute; top: -8vh;
  width: var(--s, 14px); height: calc(var(--s, 14px) * .68);
  border-radius: 60% 40% 58% 42% / 62% 38% 62% 38%;
  background: linear-gradient(135deg, rgba(253,164,175,.95), rgba(190,18,60,.85));
  opacity: 0;
  animation: petalFall var(--d, 9s) ease-in infinite;
  animation-delay: var(--del, 0s);
  filter: drop-shadow(0 0 6px rgba(244,63,94,.35));
  left: var(--x, 10vw);
}
@keyframes petalFall {
  0%   { opacity:0; transform: translate3d(0,-4vh,0) rotate(0deg); }
  10%  { opacity:.85; }
  100% { opacity:0; transform: translate3d(var(--drift,40px), 110vh, 0) rotate(var(--rot,540deg)); }
}
@keyframes twinkle { 0%,100% { opacity:.15; transform:scale(.8);} 50% {opacity:.9; transform:scale(1.1);} }
.sparkle { position:fixed; pointer-events:none; color: var(--gold); animation: twinkle 3s ease-in-out infinite; z-index:1; }
.ornament {
  color:var(--gold);
  font-family:'Cormorant Garamond',serif;
  font-style: italic;
  letter-spacing:.18em;
  font-size: 12px;
}
.toast {
  position: fixed; bottom: calc(22px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(42,10,20,.96);
  border:1px solid rgba(212,175,122,.4);
  color: var(--champagne);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toast.show { opacity:1; transform: translateX(-50%) translateY(0); }
.history-item {
  background: rgba(20,4,9,.5);
  border: 1px solid rgba(212,175,122,.15);
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.history-item:hover { border-color: rgba(244,63,94,.45); background: rgba(74,14,31,.5); }
.titlebar {
  display:flex; align-items:center; justify-content:center; gap:14px;
  color: var(--gold);
}
.titlebar .line { flex:0 0 36px; height:1px; background:linear-gradient(90deg, transparent, var(--gold)); }
.titlebar .line.r { background:linear-gradient(90deg, var(--gold), transparent); }
.lang-btn {
  padding:4px 10px; border-radius:999px;
  border:1px solid rgba(212,175,122,.25);
  background: rgba(20,4,9,.5); color:#f5e6d3; font-size:12px;
  cursor:pointer; transition: all .15s;
}
.lang-btn.active { background: linear-gradient(135deg,#be123c,#881337); border-color:rgba(212,175,122,.5); color:#fff5ee; }
.badge-cost {
  background: rgba(212,175,122,.1);
  border:1px solid rgba(212,175,122,.3);
  color: var(--gold);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.4;
}
.truncate-2 {
  display:-webkit-box; -webkit-line-clamp:2; line-clamp:2; -webkit-box-orient:vertical;
  overflow:hidden;
}
input[type=range].mix-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px;
  background: linear-gradient(90deg, rgba(212,175,122,.35), rgba(244,63,94,.7));
  border-radius: 999px; outline: none;
  border: 1px solid rgba(212,175,122,.25);
}
input[type=range].mix-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(135deg, #fecdd3, #be123c);
  border: 1px solid rgba(245,230,211,.6);
  box-shadow: 0 2px 8px rgba(190,18,60,.5);
  cursor: pointer;
}
input[type=range].mix-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(135deg, #fecdd3, #be123c);
  border: 1px solid rgba(245,230,211,.6);
  cursor: pointer;
}
.preset-chip {
  cursor:pointer; user-select:none;
  padding:3px 10px; border-radius:999px;
  background: rgba(212,175,122,.08);
  border:1px solid rgba(212,175,122,.25);
  color: var(--champagne);
  font-size:11px; transition: all .15s;
}
.preset-chip:hover { background: rgba(244,63,94,.15); border-color: rgba(244,63,94,.5); color:#fecdd3; }
.file-chip {
  display:inline-flex; align-items:center; gap:8px;
  padding:5px 10px; border-radius:10px;
  background: rgba(212,175,122,.1);
  border:1px solid rgba(212,175,122,.35);
  color: var(--champagne); font-size:12px;
}
.file-chip button {
  color:#fda4af; background:none; border:0; cursor:pointer;
  font-size:14px; line-height:1;
}
.tts-box {
  background: rgba(20,4,9,.45);
  border: 1px dashed rgba(212,175,122,.3);
  border-radius: 14px;
  padding: 12px 14px;
}
.tts-box.disabled { opacity:.5; pointer-events:none; }
.audio-block {
  background: rgba(20,4,9,.55);
  border: 1px solid rgba(212,175,122,.22);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 10px;
}
.audio-block .label-row {
  display:flex; align-items:center; justify-content:space-between;
  font-size:12px; color: var(--gold); margin-bottom:6px;
}
audio { width:100%; filter: hue-rotate(-15deg) saturate(.85); }

/* ============ Login overlay ============ */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display:flex; align-items:center; justify-content:center;
  background: radial-gradient(800px 600px at 50% 30%, rgba(159,18,57,.35), transparent 60%),
              linear-gradient(135deg, #1a0509, #2a0a14);
  padding: 20px;
}
.overlay.hidden { display:none; }
.login-card { width: 100%; max-width: 380px; }

/* ============ Install button ============ */
#installBtn { display:none; }
#installBtn.show { display:inline-flex; }

/* ============ Device-specific optimizations ============ */
/* Larger, finger-friendly hit targets on touch devices */
.touch .btn-primary,
.touch .btn-ghost,
.touch .lang-btn,
.touch .preset-chip { min-height: 40px; }
.touch input[type=range].mix-slider { height: 10px; }
.touch input[type=range].mix-slider::-webkit-slider-thumb { width: 26px; height: 26px; }
.touch .field { font-size: 16px; } /* prevents iOS zoom-on-focus */

/* Phone layout */
@media (max-width: 640px) {
  .device-mobile-stack { flex-direction: column; align-items: stretch; }
  .device-mobile-stack > * { width: 100%; }
  header h1 { font-size: 2rem !important; }
  .glass, .glass-soft { border-radius: 18px !important; }
  #historyList { max-height: 52vh; }
  .petal-layer { opacity: .5; } /* lighter motion on small screens */
}

/* Tablet layout */
@media (min-width: 641px) and (max-width: 1024px) {
  .app-shell { max-width: 720px; }
}

/* Desktop layout — wider canvas + sticky result column comfort */
@media (min-width: 1025px) {
  .app-shell { max-width: 860px; }
}

/* Honor reduced motion */
@media (prefers-reduced-motion: reduce) {
  .petal, .sparkle { animation: none !important; opacity: 0 !important; }
  * { scroll-behavior: auto !important; }
}

.usage-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
@media (max-width: 640px){ .usage-grid { grid-template-columns:1fr; } }
.usage-bar-track { height:6px; border-radius:999px; background:rgba(212,175,122,.12); overflow:hidden; }
.usage-bar-fill { height:100%; width:0%; background:linear-gradient(90deg, var(--gold), var(--rose-500)); transition:width .25s; }
