/* =====================================================================
   GiftChemistry · styles.css
   ---------------------------------------------------------------------
   视觉与交互样式，改编自"7月17日版"原型（配色、深浅色主题、卡片式结果、
   可点击填空句），仅做品牌名替换和少量适配，未改动整体设计语言。
   ===================================================================== */

:root{
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Karla', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow-soft: 0 18px 40px -20px rgba(20,6,16,.55);
}

/* ---------- 烛光暮色主题（默认） Candlelight Dusk (default) ---------- */
html[data-theme="dusk"]{
  --bg: #241019;
  --bg-alt: #2E1524;
  --bg-card: #33192A;
  --ink: #F3E4D0;
  --ink-soft: #D9C3B4;
  --ink-faint: #B79C9E;
  --plum: #6E2F5C;
  --plum-soft: #8A3F71;
  --amber: #E8A94A;
  --rose: #E58AA0;
  --gold: #E3BD72;
  --border: rgba(243,228,208,.14);
  --border-strong: rgba(243,228,208,.26);
}

/* ---------- 暖白日光主题 Warm Ivory (light) ---------- */
html[data-theme="ivory"]{
  --bg: #FBF3E7;
  --bg-alt: #F4E6D4;
  --bg-card: #FFFCF6;
  --ink: #2E1B26;
  --ink-soft: #5A3F4C;
  --ink-faint: #8A6E77;
  --plum: #5B2649;
  --plum-soft: #79345F;
  --amber: #C97F2A;
  --rose: #C96A83;
  --gold: #B4863E;
  --border: rgba(46,27,38,.12);
  --border-strong: rgba(46,27,38,.22);
}

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

/* 视觉上隐藏但保留给屏幕阅读器和搜索引擎的内容，例如页面唯一的h1。
   标准的"sr-only"写法：不用display:none，避免部分屏幕阅读器直接跳过。 */
.sr-only{
  position:absolute; width:1px; height:1px;
  padding:0; margin:-1px; overflow:hidden;
  clip:rect(0,0,0,0); white-space:nowrap; border:0;
}
body{
  position:relative;
  background: radial-gradient(120% 140% at 50% -10%, var(--bg-alt), var(--bg) 60%);
  color: var(--ink);
  font-family: var(--font-body);
  line-height:1.55;
  min-height:100vh;
  overflow-x:hidden;
  transition: background .4s ease, color .4s ease;
}

/* ---------- 氛围光晕：呼应"烛光"主题的背景装饰 ---------- */
.ambient{
  position:fixed; inset:0; z-index:0; pointer-events:none;
  overflow:hidden;
}
.ambient span{
  position:absolute; border-radius:50%; filter: blur(60px);
  opacity:.5; animation: drift 14s ease-in-out infinite;
}
.ambient .g1{
  width:340px; height:340px; top:-80px; left:8%;
  background: radial-gradient(circle, var(--amber), transparent 70%);
  animation-duration: 16s;
}
.ambient .g2{
  width:300px; height:300px; top:10%; right:6%;
  background: radial-gradient(circle, var(--rose), transparent 70%);
  animation-duration: 19s; animation-delay: -4s;
}
.ambient .g3{
  width:260px; height:260px; bottom:-60px; left:38%;
  background: radial-gradient(circle, var(--plum-soft), transparent 70%);
  animation-duration: 22s; animation-delay: -9s;
}
@keyframes drift{
  0%,100%{ transform: translate(0,0) scale(1); }
  50%{ transform: translate(2%,3%) scale(1.08); }
}
@media (prefers-reduced-motion: reduce){
  .ambient span{ animation:none; }
}

.topbar, .hero, .results, footer{ position:relative; z-index:1; }
/* The listbox is rendered inside the hero. Keep that stacking context above
   the results so an open mobile listbox cannot be painted underneath cards. */
.hero{ z-index:2; }

a{color:inherit;}

/* ---------- 顶部：logo + 主题切换 ---------- */
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  max-width:920px; margin:0 auto; padding: 28px 24px 0;
}
.brand{ display:flex; align-items:center; gap:12px; }
.spark{
  width:34px; height:34px; flex:0 0 auto;
  filter: drop-shadow(0 0 6px rgba(232,169,74,.55));
  animation: breathe 3.2s ease-in-out infinite;
}
@keyframes breathe{
  0%,100%{ transform: scale(1); opacity:.88; }
  50%{ transform: scale(1.14); opacity:1; }
}
@media (prefers-reduced-motion: reduce){
  .spark{ animation:none; }
}
.brand-word{
  font-family: var(--font-display);
  font-weight:600;
  font-size: 26px;
  letter-spacing: .2px;
}
.brand-word .spark-text{ color: var(--gold); font-style: italic; font-weight:600; }

.theme-toggle{
  display:flex; align-items:center; gap:8px;
  background: transparent;
  border:1px solid var(--border);
  color: var(--ink-soft);
  padding:8px 14px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 13px;
  cursor:pointer;
  transition: border-color .2s ease, color .2s ease, background .2s ease;
}
.theme-toggle:hover{ border-color: var(--border-strong); color: var(--ink); }
.theme-toggle svg{ width:15px; height:15px; }

/* ---------- Hero ---------- */
.hero{
  max-width: 780px; margin: 0 auto; padding: 56px 24px 12px;
  text-align:center;
}
.eyebrow{
  font-size:13px; letter-spacing:.14em; text-transform:uppercase;
  color: var(--rose); font-weight:600; margin-bottom:18px;
}
.sentence{
  font-family: var(--font-display);
  font-weight:500;
  font-size: clamp(22px, 4.2vw, 34px);
  line-height:1.5;
  color: var(--ink);
}
.sentence .static-word{ color: var(--ink-soft); }

/* 可点击的"金色词" */
.blank{
  position:relative;
  display:inline-flex; align-items:center; gap:5px;
  color: var(--gold);
  font-style: italic;
  font-weight:600;
  border-bottom: 1.5px dashed var(--gold);
  cursor:pointer;
  padding: 0 2px;
  background:none; border-top:none; border-left:none; border-right:none;
  font-family: inherit; font-size: inherit; line-height:inherit;
}
.blank:hover, .blank[aria-expanded="true"]{ color: var(--amber); border-color: var(--amber); }
.blank:focus-visible, .theme-toggle:focus-visible{
  outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 4px;
}
.blank .caret{
  display:inline-block; font-style:normal; font-size:.6em; transform: translateY(-2px);
  opacity:.85;
}

.dropdown{
  position:absolute; z-index:20; top: calc(100% + 8px); left:50%;
  transform: translateX(-50%) translateY(-4px) scale(.96);
  background: var(--bg-card);
  border:1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  padding:6px;
  min-width: 190px;
  opacity:0; visibility:hidden;
  transition: opacity .14s ease, transform .14s ease, visibility .14s;
}
.dropdown.open{
  opacity:1; visibility:visible;
  transform: translateX(-50%) translateY(0) scale(1);
}
@media (prefers-reduced-motion: reduce){
  .dropdown{ transition:none; }
}
/* dropdown 本身是 role=listbox 并接收DOM焦点（tabindex=-1），
   用可见的outline代替浏览器默认焦点框，覆盖:focus和:focus-visible两种情况，
   保证键盘用户始终能看到当前焦点在哪个列表上。 */
.dropdown:focus,
.dropdown:focus-visible{
  outline: 2px solid var(--amber); outline-offset: 2px;
}
.dropdown .option{
  display:block; width:100%; text-align:left;
  background:none; border:none; color: var(--ink);
  font-family: var(--font-body); font-size:14.5px;
  padding:9px 12px; border-radius: 8px; cursor:pointer;
}
.dropdown .option:hover{ background: var(--bg-alt); color: var(--amber); }
.dropdown .option[aria-selected="true"]{ color: var(--gold); font-weight:700; }
/* .active 是键盘高亮的当前项，与aria-activedescendant同步，
   和鼠标hover共用同一套视觉，但即使不用鼠标也能看到高亮位置 */
.dropdown .option.active{ background: var(--bg-alt); color: var(--amber); }

/* ---------- 结果区 ---------- */
.results{ max-width: 780px; margin: 44px auto 0; padding: 0 24px 80px; }

.tier-label{
  font-family: var(--font-display); font-style: italic; font-weight:600;
  font-size: 15px; color: var(--rose);
  display:flex; align-items:center; gap:10px;
  margin: 34px 0 16px;
}
.tier-label::after{
  content:""; flex:1; height:1px; background: var(--border);
}
.tier-label.backup{ color: var(--ink-faint); }

.card-grid{ display:grid; gap:14px; }
.card{
  position:relative;
  background: var(--bg-card);
  border:1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px 18px 62px;
  opacity:0;
  animation: cardIn .5s ease forwards;
}
.card::before{
  content:"";
  position:absolute; left:0; top:0; bottom:0; width:4px;
  background: linear-gradient(180deg, var(--amber), var(--rose));
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}
@keyframes cardIn{
  from{ opacity:0; transform: translateY(8px); }
  to{ opacity:1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce){
  .card{ animation:none; opacity:1; }
}
.card .num{
  position:absolute; left:16px; top:18px;
  width:28px; height:28px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-family: var(--font-display); font-style:italic; color: var(--bg);
  background: linear-gradient(135deg, var(--gold), var(--amber));
  font-size: 13px; font-weight:700;
}
.card h3{
  margin:0 0 6px; font-family: var(--font-display); font-weight:600;
  font-size: 18px; color: var(--ink);
}
.card p{ margin:0; color: var(--ink-soft); font-size:14.5px; }

.card-grid.backup .card{
  background: transparent; border-style:dashed; padding-left:56px;
}
.card-grid.backup .card::before{ background: var(--border-strong); width:3px; }
.card-grid.backup .card .num{
  width:24px; height:24px; font-size:12px;
  background: var(--bg-alt); color: var(--ink-faint); border:1px solid var(--border-strong);
}
.card-grid.backup .card h3{ font-size:16px; }

.note-box{
  margin-top: 22px;
  display:flex; gap:10px; align-items:flex-start;
  background: linear-gradient(135deg, rgba(232,169,74,.10), rgba(229,138,160,.06));
  border:1px solid var(--border);
  border-radius: var(--radius-md);
  padding:14px 16px;
  font-size: 14px; color: var(--ink-soft);
}
.note-box .flame{ flex:0 0 auto; width:17px; height:17px; margin-top:1px; color: var(--gold); }
.note-box .flame svg{ width:100%; height:100%; display:block; }
.note-box b{ color: var(--rose); font-weight:700; }

.closing-line{
  text-align:center; margin-top: 40px;
  font-family: var(--font-display); font-style: italic;
  font-size: 16px; color: var(--ink-soft);
  max-width: 520px; margin-left:auto; margin-right:auto;
}

/* ---------- 空状态（防御性保留，正常不会触发——60格已全部有内容） ---------- */
.empty-room{
  text-align:center; padding: 46px 24px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--ink-soft);
}
.empty-room .flame-big{ display:flex; justify-content:center; margin-bottom:14px; color: var(--gold); }
.empty-room .flame-big svg{ width:30px; height:30px; }
.empty-room h3{
  font-family: var(--font-display); font-weight:600; font-size:19px;
  color: var(--ink); margin: 0 0 8px;
}
.empty-room p{ margin:0; font-size:14.5px; max-width:420px; margin:0 auto; }

footer{
  max-width:780px; margin: 0 auto; padding: 0 24px 50px;
  text-align:center; color: var(--ink-faint); font-size:12.5px;
}

@media (max-width:560px){
  /* Keep both the brand and theme control inside a narrow phone viewport. */
  .topbar{
    width:100%; min-width:0; gap:12px;
    padding:18px 16px 0;
  }
  .brand{ min-width:0; gap:8px; }
  .spark{ width:27px; height:27px; }
  .brand-word{ font-size:20px; white-space:nowrap; }
  .theme-toggle{
    flex:0 0 auto; gap:5px;
    padding:6px 9px;
    font-size:11.5px;
  }
  .theme-toggle svg{ width:13px; height:13px; }

  /* Every part of the fill-in sentence must be allowed to wrap on phones. */
  .hero{
    width:100%; min-width:0;
    padding:34px 16px 8px;
  }
  .eyebrow{
    margin-bottom:16px;
    font-size:11px;
    line-height:1.45;
    letter-spacing:.1em;
  }
  .sentence{
    max-width:100%;
    font-size:22px;
    line-height:1.45;
    overflow-wrap:break-word;
  }
  .blank{
    max-width:100%; min-width:0;
    white-space:normal;
    flex-wrap:wrap;
    justify-content:center;
  }

  /* Centre the listbox in the viewport so edge options cannot clip it. */
  .dropdown{
    position:fixed;
    top:50%; left:16px; right:16px;
    width:auto; min-width:0; max-width:none;
    transform:translateY(-50%) scale(.96);
  }
  .dropdown.open{
    transform:translateY(-50%) scale(1);
  }

  .results{
    width:100%; min-width:0;
    margin-top:34px;
    padding:0 16px 64px;
  }
  .card-grid,
  .card,
  .note-box,
  .closing-line{
    min-width:0;
    max-width:100%;
  }
  .card{
    padding:16px 14px 16px 52px;
    overflow-wrap:break-word;
  }
  .card .num{ left:14px; top:16px; }
  .card h3{ font-size:16.5px; }
  .card p{ font-size:14px; }
  .card-grid.backup .card{ padding-left:48px; }
  .note-box{
    gap:8px;
    padding:12px;
    font-size:13.5px;
    overflow-wrap:break-word;
  }
  .closing-line{
    margin-top:34px;
    font-size:15px;
    overflow-wrap:break-word;
  }
  footer{
    width:100%; min-width:0; max-width:100%;
    padding:0 16px 36px;
    font-size:11.5px;
    overflow-wrap:break-word;
  }
}
