/* ===== Microsoft 中文語音實驗室｜樣式（RWD） ===== */
:root {
  --p: #2563eb;
  --s: #7c3aed;
  --bg: #f7fbff;
  --ink: #17324d;
  --line: #dbeafe;
  --muted: #64748b;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: linear-gradient(135deg, #effaff, #f8f2ff) fixed;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.5;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

img, svg, audio { max-width: 100%; }

.container { width: min(1180px, calc(100% - 28px)); margin: auto; }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 48px 20px 28px; }
.hero-icon { font-size: clamp(2.2rem, 8vw, 3rem); }
.hero h1 {
  font-size: clamp(1.8rem, 6vw, 3.6rem);
  line-height: 1.2;
  margin: .2em;
  text-wrap: balance;
  background: linear-gradient(90deg, var(--p), var(--s));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { margin: .4em auto 0; max-width: 46em; }

/* ---------- Panels & Cards ---------- */
.panel, .card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 12px 30px rgba(37, 99, 235, .1);
}
.panel { padding: 22px; margin-bottom: 20px; }
.panel h2 { margin-top: 0; font-size: clamp(1.25rem, 3.5vw, 1.5rem); }

.toolbar { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 14px; }
.full { grid-column: 1 / -1; }

label { display: block; font-weight: 800; margin-bottom: 7px; }
input, textarea, select {
  width: 100%;
  font: inherit;
  font-size: max(16px, 1em); /* 避免 iOS 聚焦時自動放大 */
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  background: #fff;
  color: inherit;
}
input[type="range"] { padding: 12px 0; border: 0; }
textarea { min-height: 120px; resize: vertical; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; align-items: center; }

.btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  min-height: 44px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}
.primary { background: linear-gradient(135deg, var(--p), var(--s)); color: #fff; }
.secondary { background: #e0f2fe; color: #075985; }
.ghost { background: #f8fafc; border: 1px solid #cbd5e1; color: var(--ink); }
.danger { background: #fee2e2; color: #991b1b; }
.btn:focus-visible, .mini:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }

.notice {
  margin-top: 14px;
  padding: 14px 16px;
  border-left: 5px solid #f59e0b;
  background: #fff7ed;
  border-radius: 12px;
  color: #7c2d12;
  line-height: 1.6;
}

.badge { padding: 7px 11px; border-radius: 999px; font-weight: 800; }
.ok { background: #dcfce7; color: #166534; }
.warn { background: #fef3c7; color: #92400e; }
.err { background: #fee2e2; color: #991b1b; }

/* 自動排欄：卡片寬度不足時自動減少欄數 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.card { padding: 18px; display: flex; flex-direction: column; }
.card-icon { font-size: 2.2rem; }
.card h3 { margin: .3em 0; }
.id {
  font-size: .86rem;
  background: #f5f3ff;
  color: #5b21b6;
  padding: 8px;
  border-radius: 10px;
  word-break: break-all;
}
.meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 9px 0; }
.tag { font-size: .86rem; background: #ecfeff; color: #155e75; padding: 5px 9px; border-radius: 999px; }
.scene { line-height: 1.55; color: #475569; flex: 1; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.mini {
  border: 0;
  border-radius: 10px;
  padding: 8px 11px;
  min-height: 40px;
  font: inherit;
  font-size: .95rem;
  font-weight: 800;
  cursor: pointer;
  background: #f1f5f9;
  color: var(--ink);
  touch-action: manipulation;
}
.play { background: #dcfce7; color: #166534; }
.download { background: #fef3c7; color: #92400e; }

.status { margin-top: 10px; font-weight: 800; color: #475569; overflow-wrap: anywhere; }
.status.error { color: #991b1b; }
#player { width: 100%; margin-top: 10px; }

.secret { position: relative; }
.secret input { padding-right: 84px; }
.secret button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); min-height: 36px; padding: 6px 12px; }

.section-title { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: 6px 12px; margin: 28px 0 12px; }
.section-title h2 { margin: 0; }
.small { font-size: .92rem; color: var(--muted); }
.hint { align-self: end; }

footer { text-align: center; padding: 36px 20px calc(36px + var(--safe-b)); color: var(--muted); }

/* ---------- PWA：安裝按鈕、離線提示、更新提示 ---------- */
.pwa-bar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .18);
  font-size: .95rem;
}
.pwa-bar[hidden] { display: none; }
.net-pill {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + var(--safe-r));
  z-index: 50;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 800;
  background: #fee2e2;
  color: #991b1b;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .1);
}
.net-pill[hidden] { display: none; }

/* ---------- 斷點 ---------- */
@media (max-width: 900px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 17px; }
  .container { width: calc(100% - 32px); } /* 左右各 16px */
  .hero { padding: 32px 4px 20px; }
  .toolbar { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .panel { padding: 16px; border-radius: 18px; }
  .controls .btn { flex: 1 1 100%; }
  .controls .badge { width: 100%; text-align: center; }
  .card-actions .mini { flex: 1 1 0; }
  footer { padding-top: 24px; }
}

/* 橫向手機：壓縮上方空間 */
@media (max-height: 500px) and (orientation: landscape) {
  .hero { padding: 16px 20px 10px; }
  .hero-icon { display: none; }
}

/* 以 PWA 獨立視窗開啟時 */
@media (display-mode: standalone) {
  .hero { padding-top: calc(28px + env(safe-area-inset-top, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}

@media print {
  .pwa-bar, .net-pill, .controls, .card-actions { display: none !important; }
  body { background: #fff; }
}
