: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;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
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%);
  background-attachment: fixed;
  min-height:100vh;
  min-height:100dvh;
  color:#f5e6d3;
  -webkit-text-size-adjust: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.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; }

@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 + var(--safe-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: 300;
  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; }
.lang-btn:disabled { opacity:.4; cursor:not-allowed; }

.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; -webkit-box-orient:vertical; overflow:hidden; }

/* ---- Login overlay ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(10,3,6,.85);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.login-card { width: 100%; max-width: 380px; }

/* =====================================================================
   Device-specific optimization (mobile / tablet / desktop / pointer)
   ===================================================================== */

/* Phones: larger tap targets, comfortable inputs (>=16px stops iOS zoom). */
@media (max-width: 640px) {
  .field { font-size: 16px; }
  textarea.field { font-size: 16px; }
  .btn-primary, .btn-ghost { min-height: 44px; }
  .lang-btn { min-height: 34px; padding: 6px 12px; }
  input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; }
  .output { font-size: 15px; }
  /* Reduce decorative motion cost on small screens. */
  .petal:nth-child(n+8) { display: none; }
}

/* Tablets: two-column comfortable layout, bigger reading column. */
@media (min-width: 641px) and (max-width: 1024px) {
  #appRoot .max-w-3xl { max-width: 46rem; }
  .output { font-size: 15px; }
}

/* Desktop: wider reading column, hover affordances. */
@media (min-width: 1025px) {
  #appRoot .max-w-3xl { max-width: 52rem; }
}

/* Coarse pointers (touch): make all interactive rows easier to hit. */
@media (pointer: coarse) {
  .history-item { padding: 12px 14px; }
  button { touch-action: manipulation; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .petal, .sparkle, .loader { animation: none !important; }
  .petal { display: none; }
  * { scroll-behavior: auto !important; }
}
