/* =========================================================
   Google 中文語音實驗室｜BYOK — 樣式表（RWD）
   斷點：≥1200 桌機｜≤900 平板｜≤640 手機｜≤380 小手機
   ========================================================= */
:root {
  --bg: #f7fbff;
  --ink: #18324a;
  --muted: #627489;
  --card: #fff;
  --blue: #4285f4;
  --red: #ea4335;
  --yellow: #fbbc05;
  --green: #34a853;
  --line: #dbe7ff;
  --shadow: 0 14px 36px rgba(66, 133, 244, .12);
  --radius: 24px;
  --gutter: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 18px;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 4%, #dff7ff 0, transparent 26%),
    radial-gradient(circle at 92% 2%, #fff1cf 0, transparent 27%),
    var(--bg);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

img, svg, audio { max-width: 100%; }
button, input, textarea, select { font: inherit; }
h2 { font-size: clamp(1.25rem, 3.6vw, 1.6rem); }

/* ---------- 版面 ---------- */
.container {
  width: min(1180px, calc(100% - var(--gutter) * 2));
  margin: auto;
}

.hero {
  padding: calc(50px + var(--safe-top)) 20px 30px;
  text-align: center;
}
.hero-emoji { font-size: clamp(2.2rem, 8vw, 3rem); }
.hero h1 {
  font-size: clamp(1.9rem, 6vw, 3.8rem);
  line-height: 1.2;
  margin: .25em 0;
  background: linear-gradient(90deg, var(--blue), var(--red), var(--yellow), var(--green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  max-width: 920px;
  margin: auto;
  line-height: 1.75;
  color: var(--muted);
}

.panel {
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.panel h2 { margin-top: 0; }

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

/* ---------- 表單 ---------- */
label {
  display: block;
  font-weight: 800;
  margin-bottom: 7px;
}
input, textarea, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid #bfd6ff;
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
}
input[type="range"] { min-height: 32px; padding: 0; border: 0; accent-color: var(--blue); }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(66, 133, 244, .35);
  outline-offset: 1px;
}
textarea {
  min-height: 125px;
  resize: vertical;
  line-height: 1.65;
}

.secret-wrap { position: relative; }
.secret-wrap input { padding-right: 92px; }
.toggle {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: #eef4ff;
  color: #2457a6;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}

/* ---------- 按鈕 ---------- */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
}
.btn {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 12px 17px;
  font-weight: 800;
  cursor: pointer;
  transition: .2s;
  box-shadow: 0 8px 20px rgba(66, 133, 244, .12);
}
.btn:focus-visible, .mini:focus-visible, .toggle:focus-visible {
  outline: 3px solid rgba(66, 133, 244, .5);
  outline-offset: 2px;
}
.primary { background: linear-gradient(135deg, var(--blue), #6b5cff); color: #fff; }
.secondary { background: #e3f2fd; color: #0b57d0; }
.ghost { background: #f8fafc; color: #334155; border: 1px solid #cbd5e1; }
.danger { background: #fee2e2; color: #991b1b; }

.notice {
  border-left: 5px solid var(--yellow);
  background: #fff8df;
  padding: 14px 16px;
  border-radius: 12px;
  color: #6b4c00;
  line-height: 1.65;
  margin-top: 14px;
}
.status {
  min-height: 28px;
  margin-top: 10px;
  font-weight: 800;
  color: #475569;
  overflow-wrap: anywhere;
}
#player { width: 100%; margin-top: 10px; display: none; }

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

/* ---------- 語音卡片 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  transition: .2s;
}
.icon { font-size: 2.2rem; }
.card h3 { font-size: 1.25rem; margin: .3em 0; }
.id {
  font-size: .85rem;
  color: #174ea6;
  background: #eef4ff;
  padding: 8px;
  border-radius: 10px;
  word-break: break-all;
}
.meta { display: flex; gap: 7px; flex-wrap: wrap; margin: 10px 0; }
.tag {
  font-size: .86rem;
  background: #ecfdf5;
  color: #166534;
  padding: 5px 9px;
  border-radius: 999px;
}
.scene { line-height: 1.55; color: #475569; }
.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 13px;
}
.mini {
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
  background: #eef4ff;
  color: #174ea6;
}
.play { background: #dcfce7; color: #166534; }
.download { background: #fef3c7; color: #92400e; }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  margin: 30px 0 14px;
}
.section-title h2 { margin: 0; }
.small { font-size: .92rem; color: #64748b; line-height: 1.6; }
.empty { grid-column: 1 / -1; text-align: center; padding: 30px; color: var(--muted); }

.spinner { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.rate-disabled { opacity: .55; pointer-events: none; }

footer {
  text-align: center;
  padding: 38px 20px calc(38px + var(--safe-bottom));
  color: #64748b;
}

/* ---------- PWA：安裝／離線／更新提示 ---------- */
.pwa-bar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 10px;
  align-items: center;
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 10px 12px 10px 16px;
  background: #18324a;
  color: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .25);
  font-size: .95rem;
}
.pwa-bar[hidden] { display: none; }
.pwa-bar .btn { min-height: 40px; padding: 8px 14px; box-shadow: none; }
.pwa-bar .close {
  background: transparent;
  color: #cbd5e1;
  border: 0;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
}
.net-badge {
  position: fixed;
  top: calc(10px + var(--safe-top));
  right: calc(10px + var(--safe-right));
  z-index: 50;
  background: #fee2e2;
  color: #991b1b;
  font-weight: 800;
  font-size: .85rem;
  padding: 6px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.net-badge[hidden] { display: none; }

/* ---------- 只在可 hover 的裝置加入浮起效果 ---------- */
@media (hover: hover) and (pointer: fine) {
  .btn:hover { transform: translateY(-2px); }
  .card:hover { transform: translateY(-3px); }
}

/* ---------- 大螢幕 ---------- */
@media (min-width: 1400px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
  .container { width: min(1360px, calc(100% - 48px)); }
}

/* ---------- 平板 ---------- */
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .full { grid-column: 1 / -1; }
}

/* ---------- 手機 ---------- */
@media (max-width: 640px) {
  body { font-size: 17px; }
  .hero { padding: calc(32px + var(--safe-top)) 16px 20px; }
  .grid, .toolbar { grid-template-columns: 1fr; }
  .toolbar .full { grid-column: auto; }
  .panel { padding: 16px; border-radius: 18px; margin-bottom: 16px; }
  .controls .btn { flex: 1 1 calc(50% - 10px); }
  .controls .btn.primary:first-child { flex-basis: 100%; }
  .card-actions .mini { flex: 1 1 0; }
  .section-title { margin-top: 22px; }
  .pwa-bar { width: calc(100% - 24px); }
  .pwa-bar span { flex: 1; }
}

/* ---------- 小手機 ---------- */
@media (max-width: 380px) {
  :root { --gutter: 10px; }
  .controls .btn { flex-basis: 100%; }
  .hero p { font-size: .95rem; }
}

/* ---------- 橫向手機：壓縮標題區 ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  .hero { padding-top: calc(18px + var(--safe-top)); padding-bottom: 12px; }
  .hero-emoji { display: none; }
}

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

/* ---------- 減少動態 ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
