/* 照片魔法師｜暖橘金 + 深色魔法師風（小面積紫點綴），手機優先 */
:root {
  --bg: #17120d;
  --bg-card: #241a12;
  --bg-card2: #2e2116;
  --gold: #f2b544;
  --orange: #e8792b;
  --orange-deep: #c85a1a;
  --ink: #f6ead6;
  --ink-dim: #c9b795;
  --purple: #7a5c9e;        /* 僅小面積點綴 */
  --green: #58b368;
  --red: #d9534f;
  --radius: 16px;
  --touch: 48px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #3a2a16 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: 90px; /* bottom nav 留白 */
}

/* header */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(23, 18, 13, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #3a2c1c;
}
.topbar h1 { font-size: 20px; margin: 0; color: var(--gold); letter-spacing: 1px; }
.icon-btn {
  min-width: var(--touch); min-height: var(--touch);
  border-radius: 12px; border: 1px solid #4a3620;
  background: var(--bg-card2); color: var(--ink); font-size: 18px;
}

/* 主區單欄 */
main { max-width: 640px; margin: 0 auto; padding: 14px; }
.page { display: none; animation: fade .25s ease; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.card {
  background: var(--bg-card); border: 1px solid #3a2c1c;
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 17px; color: var(--gold); }
.muted { color: var(--ink-dim); font-size: 13px; }

/* 表單 */
label { display: block; font-size: 14px; color: var(--ink-dim); margin: 10px 0 4px; }
textarea, input[type=text], input[type=search], select {
  width: 100%; min-height: 52px; padding: 12px;
  background: #161009; color: var(--ink);
  border: 1px solid #4a3620; border-radius: 12px; font-size: 16px;
}
textarea { min-height: 96px; resize: vertical; }

/* ✨🎤 按鈕掛在輸入框旁 */
.magic-wrap { position: relative; }
.magic-bar { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.magic-btn {
  min-width: 48px; min-height: 40px; border-radius: 10px; font-size: 18px;
  border: 1px solid #4a3620; background: var(--bg-card2); color: var(--ink);
}
.mic-btn.recording { background: var(--red); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.magic-btn.undo-btn:disabled { opacity: .35; }
.magic-btn.undo-btn:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.opt-panel {
  margin-top: 8px; border: 1px dashed var(--gold); border-radius: 12px;
  padding: 10px; background: #1d1509;
}
.opt-note { font-size: 12px; color: var(--gold); margin-bottom: 6px; }
.opt-result { font-size: 14px; color: var(--ink); white-space: pre-wrap; max-height: 160px; overflow: auto; }
.opt-actions { display: flex; gap: 8px; margin-top: 8px; }
.mini-btn {
  min-height: 40px; padding: 0 14px; border-radius: 10px;
  border: 1px solid #4a3620; background: var(--bg-card2); color: var(--ink);
}
.mini-btn.ok { background: var(--orange-deep); border-color: var(--orange); color: #fff; }

/* CTA */
.cta {
  display: block; width: 100%; min-height: 56px; margin-top: 14px;
  border-radius: 14px; border: none; font-size: 18px; font-weight: 700;
  background: linear-gradient(135deg, var(--gold), var(--orange));
  color: #2a1605;
}
.cta:disabled { opacity: .5; }
.cta.sticky-cta { position: sticky; bottom: 84px; }

/* 上傳元件 */
.dropzone {
  border: 2px dashed #5a4225; border-radius: var(--radius);
  padding: 22px; text-align: center; color: var(--ink-dim); background: #1b130b;
}
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumb { position: relative; width: 84px; height: 116px; }
.thumb img { width: 100%; height: 84px; object-fit: cover; border-radius: 10px; }
.thumb .del {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--red); color: #fff; border: none; font-size: 13px;
}
.thumb .char-name {
  width: 100%; margin-top: 3px; font-size: 11px; padding: 2px 4px;
  border-radius: 6px; border: 1px solid #3a2c1c; background: #1b130b; color: var(--ink);
  box-sizing: border-box;
}
.thumb .char-idx {
  position: absolute; left: 4px; top: 4px; font-size: 10px; padding: 1px 5px;
  border-radius: 6px; background: rgba(0,0,0,.65); color: var(--gold);
}

/* 選擇照片按鈕 + 預覽（圖片/影片頁） */
.pick-btn {
  display: block; width: 100%; min-height: 52px; margin-top: 8px;
  border-radius: 12px; border: 1.5px solid var(--gold);
  background: #221809; color: var(--gold); font-size: 16px; font-weight: 700;
}
.pick-preview {
  display: flex; align-items: center; gap: 12px; margin-top: 10px;
  background: #1b130b; border: 1px solid #3a2c1c; border-radius: 12px; padding: 10px;
}
.pick-preview img {
  width: 64px; height: 84px; object-fit: cover; border-radius: 8px; flex: none;
}
.pick-preview span { color: var(--ink-dim); font-size: 13px; word-break: break-all; }
.adv { margin-top: 8px; }
.adv summary { color: var(--ink-dim); font-size: 13px; cursor: pointer; }
.adv input { margin-top: 6px; }

/* 旁白模式開關 */
.switch-row {
  display: flex; align-items: center; gap: 10px; margin: 10px 0 4px;
  font-size: 13px; color: var(--ink-dim); line-height: 1.35;
}
.switch-row input[type="checkbox"] {
  width: 22px; height: 22px; flex: 0 0 22px; accent-color: #f59e0b;
}

/* 任務列 */
.job { border: 1px solid #3a2c1c; border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; background: #1b130b; }
.job .bar { height: 8px; background: #332614; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.job .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--orange)); }
.job .meta { font-size: 12px; color: var(--ink-dim); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 8px; background: #332614; }
.badge.done { background: #1e3a24; color: var(--green); }
.badge.error { background: #4a2220; color: #ff9a93; }
.badge.running { background: #3a2c1c; color: var(--gold); }

/* Gallery */
.gal-grid { display: grid; grid-template-columns: 1fr; gap: 16px; max-width: 560px; margin: 0 auto; }
.gal-item { background: var(--bg-card); border-radius: 14px; overflow: hidden; border: 1px solid #3a2c1c; }
.gal-item video { width: 100%; aspect-ratio: 9/16; object-fit: cover; display: block; background: #000; }
.gal-item img { width: 100%; height: auto; display: block; background: #000; }
.gal-item .gname { font-size: 14px; padding: 10px 12px; color: var(--ink-dim); }

/* 狀態 chip */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 13px; padding: 6px 10px; border-radius: 999px; background: #332614; border: 1px solid #4a3620; }
.chip.ok { background: #1e3a24; color: var(--green); border-color: #2c5a36; }
.chip.warn { background: #4a3316; color: var(--gold); }
.chip.off { background: #4a2220; color: #ff9a93; }

/* bottom nav：5 顆等寬，390px 必完整顯示 */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(20, 15, 9, .97); border-top: 1px solid #3a2c1c;
  overflow: hidden;
}
nav.bottom button {
  flex: 1 1 0; min-width: 0; max-width: 16.6%; min-height: 56px; padding: 4px 0;
  background: none; border: none; color: var(--ink-dim); font-size: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  white-space: nowrap; overflow: hidden; line-height: 1.2;
}
nav.bottom button .ico { font-size: 18px; display: block; line-height: 1.2; margin-bottom: 2px; }
nav.bottom button.active { color: var(--gold); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(20px);
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 12px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90%; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* 設定頁 */
.set-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid #332614; }
.purple-dot { color: var(--purple); }

/* ═══════ V4：頂欄品牌 / 帳號選單 / Modal / 功能格子 / AI 工具 ═══════ */
.top-right { display: flex; align-items: center; gap: 10px; }
.brand-ohiyoyo {
  font-size: 16px; font-weight: 900; letter-spacing: 1.5px;
  background: linear-gradient(135deg, #f2b544, #e8792b);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.hide { display: none !important; }

/* 帳號選單 */
.menu {
  position: fixed; top: 58px; right: 12px; z-index: 120; min-width: 235px;
  background: var(--bg-card); border: 1px solid #4a3620; border-radius: 14px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, .45); padding: 8px;
  display: grid; gap: 4px;
}
.menu button {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--ink);
  text-align: left; cursor: pointer; background: none; border: none; width: 100%;
}
.menu button:hover { background: rgba(242, 181, 68, .12); color: var(--gold); }
.menu button em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--gold); }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, .65);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal-box {
  position: relative; width: 100%; max-width: 420px; max-height: 88vh; overflow: auto;
  background: var(--bg-card); border: 1px solid #4a3620; border-radius: 18px;
  padding: 22px 20px; box-shadow: 0 16px 50px rgba(0, 0, 0, .5);
}
.modal-box h3 { margin: 0 0 14px; color: var(--gold); font-size: 19px; }
.modal-box input { margin-top: 10px; }
.modal-x {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px;
  border-radius: 50%; border: 1px solid #4a3620; background: var(--bg-card2);
  color: var(--ink); font-size: 14px; cursor: pointer;
}
.btn {
  width: 100%; min-height: 50px; margin-top: 12px; border-radius: 12px;
  border: none; font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--gold), var(--orange)); color: #2a1605; }
.btn-ghost { background: var(--bg-card2); border: 1px solid #4a3620; color: var(--ink); }
.errbox {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: #4a2220; color: #ff9a93; font-size: 13px;
}
.auth-switch { margin-top: 14px; text-align: center; font-size: 13px; color: var(--ink-dim); }
.auth-switch a { color: var(--gold); font-weight: 700; cursor: pointer; }
.auth-note { margin-top: 10px; font-size: 12px; color: var(--ink-dim); text-align: center; }

/* 儲值 */
.credit-bal { font-size: 17px; margin: 8px 0 2px; }
.credit-bal b { color: var(--gold); font-size: 26px; }
.refer-box { margin-top: 16px; padding: 12px; border: 1px dashed var(--gold); border-radius: 12px; background: #1d1509; }
.refer-box .mini-btn { margin-top: 8px; }

/* 功能入口格子 */
.fun-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.fun-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 96px; padding: 10px 6px; border-radius: 14px;
  background: var(--bg-card2); border: 1px solid #4a3620; color: var(--ink); cursor: pointer;
}
.fun-cell .fi { font-size: 24px; }
.fun-cell b { font-size: 13px; }
.fun-cell i { font-size: 10px; color: var(--ink-dim); font-style: normal; text-align: center; line-height: 1.3; }
.fun-cell:active { transform: scale(.96); }

/* AI 工具 */
.ai-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ai-tab {
  min-height: 40px; padding: 0 12px; border-radius: 999px;
  border: 1px solid #4a3620; background: var(--bg-card2); color: var(--ink-dim);
  font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.ai-tab.active { background: linear-gradient(135deg, var(--gold), var(--orange)); color: #2a1605; border-color: transparent; }
.ai-panel { display: none; }
.ai-panel.active { display: block; }
.ai-result { margin-top: 12px; }
.ai-result img, .ai-result video { width: 100%; border-radius: 12px; background: #000; margin-top: 8px; }
.ai-result audio { width: 100%; margin-top: 8px; }

/* AI 對話 */
.chat-box {
  min-height: 180px; max-height: 320px; overflow: auto;
  background: #161009; border: 1px solid #3a2c1c; border-radius: 12px; padding: 10px;
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px;
}
.msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg-user { align-self: flex-end; background: linear-gradient(135deg, var(--gold), var(--orange)); color: #2a1605; }
.msg-ai { align-self: flex-start; background: var(--bg-card2); border: 1px solid #4a3620; color: var(--ink); }
