/* style.css — index.php 與 download.php 共用的設計系統 */

/* ── 佈景主題 ───────────────────────────────────────────────────────────
 * 三種狀態：自動（跟隨系統）、淺色、深色。使用者選過就寫進 localStorage。
 *
 * 選擇器的優先順序是關鍵：
 *   :root                                  -> 淺色（預設值）
 *   媒體查詢 + :not([data-theme="light"])  -> 系統是深色且使用者沒有指定淺色
 *   :root[data-theme="dark"]               -> 使用者指定深色（在系統是淺色時也要贏）
 * 深色的變數因此必須寫兩次 —— CSS 沒辦法把一組自訂屬性「套用」到兩個選擇器上。
 * 改動深色配色時，兩塊都要一起改。
 * ─────────────────────────────────────────────────────────────────────── */
:root {
    color-scheme: light;        /* 讓捲軸、下拉選單這些原生元件也跟著換 */
    --bg: #f3f5f8;
    --card: #ffffff;
    --line: #e4e8ee;
    --text: #1b2431;
    --muted: #68737f;
    --brand: #17a45b;
    --brand-dark: #12854a;
    --brand-soft: #e7f6ee;
    --danger: #c62828;
    --danger-bg: #fdecea;
    --danger-line: #f5c6cb;
    --warn: #7a5b00;
    --warn-bg: #fff8e1;
    --warn-line: #ffe0a3;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 20px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #10151c;
        --card: #1a212c;
        --line: #2b3442;
        --text: #e8edf4;
        --muted: #93a0b0;
        --brand: #22c07a;
        --brand-dark: #1ca566;
        --brand-soft: #17301f;
        --danger: #ff8a80;
        --danger-bg: #3a1f1d;
        --danger-line: #5c2b28;
        --warn: #ffd54f;
        --warn-bg: #332b12;
        --warn-line: #52481f;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #10151c;
    --card: #1a212c;
    --line: #2b3442;
    --text: #e8edf4;
    --muted: #93a0b0;
    --brand: #22c07a;
    --brand-dark: #1ca566;
    --brand-soft: #17301f;
    --danger: #ff8a80;
    --danger-bg: #3a1f1d;
    --danger-line: #5c2b28;
    --warn: #ffd54f;
    --warn-bg: #332b12;
    --warn-line: #52481f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    padding: 16px 12px 90px;   /* 底部留給手機的固定操作列 */
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
                 "Microsoft JhengHei", Arial, sans-serif;
    line-height: 1.65;
    font-size: 16px;
}
[hidden] { display: none !important; }
a { color: var(--brand); }

.container { max-width: 720px; margin: 0 auto; }
.container.wide { max-width: 1000px; }

/* ── 頁首 ─────────────────────────────────────────── */
.hero { text-align: center; padding: 8px 0 18px; position: relative; }
.hero h1 {
    margin: 0 0 4px;
    font-size: 26px;
    letter-spacing: .5px;
    display: flex; align-items: center; justify-content: center; gap: 10px;
}
.hero h1 svg { width: 30px; height: 30px; flex: none; }
.hero p { margin: 0; color: var(--muted); font-size: 14px; }
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    margin-top: 10px; padding: 5px 12px;
    background: var(--brand-soft); color: var(--brand-dark);
    border: 1px solid var(--brand); border-radius: 999px;
    font-size: 13px; font-weight: 600;
}
/* 深色底時 --brand-dark 太暗，改用亮一階的 --brand */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .badge { color: var(--brand); }
}
:root[data-theme="dark"] .badge { color: var(--brand); }

/* ── 佈景切換按鈕 ─────────────────────────────────────── */
.theme-toggle {
    position: absolute; top: 0; right: 0;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    background: var(--card); color: var(--muted);
    border: 1px solid var(--line); border-radius: 999px;
    font-size: 13px; cursor: pointer;
    transition: border-color .15s, color .15s;
}
.theme-toggle:hover { border-color: var(--brand); color: var(--brand-dark); }
:root[data-theme="dark"] .theme-toggle:hover { color: var(--brand); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle:hover { color: var(--brand); }
}
.theme-toggle .ic { font-size: 14px; line-height: 1; }
@media (max-width: 520px) {
    .theme-toggle .tx { display: none; }   /* 手機只留圖示，不要擠壓標題 */
    .theme-toggle { padding: 6px 9px; }
}

/* ── 卡片 ─────────────────────────────────────────── */
.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 16px;
}

/* ── 訊息 ─────────────────────────────────────────── */
.msg { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 15px; }
.msg ul { margin: 4px 0 0; padding-left: 20px; }
.msg-error  { background: var(--danger-bg); border: 1px solid var(--danger-line); color: var(--danger); }
.msg-notice { background: var(--warn-bg);   border: 1px solid var(--warn-line);   color: var(--warn); }

/* ── 拖放區 ───────────────────────────────────────── */
.drop {
    border: 2px dashed var(--line);
    border-radius: var(--radius);
    padding: 34px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s, transform .1s;
    background: transparent;
}
.drop:hover, .drop.drag { border-color: var(--brand); background: var(--brand-soft); }
.drop.drag { transform: scale(1.01); }
.drop .icon { font-size: 34px; line-height: 1; }
.drop .t1 { font-weight: 700; margin: 8px 0 2px; }
.drop .t2 { color: var(--muted); font-size: 13px; }

/* ── 檔案列表 ─────────────────────────────────────── */
.file-list { list-style: none; margin: 14px 0 0; padding: 0; }
.file-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--card);
}
.file-row { display: flex; align-items: center; gap: 10px; }
.file-ic { flex: none; font-size: 20px; }
.file-name { flex: 1; min-width: 0; word-break: break-all; font-size: 14px; font-weight: 600; }
.file-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.file-meta.err { color: var(--danger); }
.remove-btn {
    flex: none; border: none; cursor: pointer;
    background: transparent; color: var(--muted);
    font-size: 20px; line-height: 1; padding: 4px 8px; border-radius: 8px;
}
.remove-btn:hover { background: var(--danger-bg); color: var(--danger); }
.pw-inline { margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.pw-inline input { flex: 1; min-width: 0; }
.pw-note { font-size: 12px; color: var(--warn); margin-top: 4px; }

/* 共用密碼面板 */
.panel-inset {
    border: 1px solid var(--brand);
    background: var(--brand-soft);
    border-radius: 10px;
    padding: 12px;
    margin-top: 12px;
}
.check-row { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 14px; font-weight: 600; }
.check-row input { margin-top: 4px; flex: none; }

/* 每檔進度條 */
.pbar { height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 8px; }
.pbar > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

/* ── 表單元素 ─────────────────────────────────────── */
input[type="password"], input[type="text"], select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 16px;      /* <16px 時 iOS 會自動縮放頁面 */
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
label.f { display: block; font-weight: 700; margin: 14px 0 6px; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.radio-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-pills label {
    display: flex; align-items: center; gap: 6px;
    border: 1px solid var(--line); border-radius: 999px;
    padding: 7px 14px; cursor: pointer; font-size: 14px;
}
.radio-pills label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ── 按鈕 ─────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px;
    background: var(--brand); color: #fff;
    border: none; border-radius: 10px;
    font-size: 15px; font-weight: 700;
    cursor: pointer; text-decoration: none;
    transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: var(--line); color: var(--muted); cursor: default; transform: none; }
.btn.sec { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.btn.sec:hover { background: var(--brand-soft); border-color: var(--brand); }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn.sm { padding: 6px 12px; font-size: 13px; font-weight: 600; }

/* ── 工具列（結果頁）──────────────────────────────── */
.bar {
    position: sticky; top: 0; z-index: 5;
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
}
.bar .count { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ── 結果縮圖網格 ─────────────────────────────────── */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
    gap: 12px;
    margin: 0; padding: 0;
    list-style: none;
}
.card.page {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px;
    display: flex; flex-direction: column; gap: 7px;
    transition: box-shadow .15s, border-color .15s;
}
.card.page:hover { box-shadow: var(--shadow); }
.card.page:has(input:checked) { border-color: var(--brand); }
.card.page img {
    width: 100%; height: auto; display: block;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.card .cap { font-size: 12.5px; color: var(--muted); word-break: break-all; }
.card label { display: flex; gap: 7px; align-items: flex-start; cursor: pointer; font-size: 13px; }
.card .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.card .acts .btn { padding: 6px 10px; font-size: 12.5px; font-weight: 600; flex: 1; }
.card .view { font-size: 12.5px; text-decoration: none; }
.card .view:hover { text-decoration: underline; }

/* ── 手機底部固定操作列 ───────────────────────────── */
.stickybar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(16, 24, 40, .08);
}
.stickybar .btn { flex: 1; padding: 12px 8px; font-size: 14px; }
@media (min-width: 700px) { .stickybar { display: none; } }

/* ── 提示框 ───────────────────────────────────────── */
#lpHint {
    background: var(--warn-bg);
    border: 1px solid var(--warn-line);
    color: var(--warn);
    padding: 10px 12px;
    border-radius: 10px;
    margin-top: 14px;
    font-size: 14px;
}

/* ── 步驟指示 ─────────────────────────────────────── */
.steps { display: flex; gap: 6px; justify-content: center; margin: 14px 0 4px; }
.steps span {
    display: flex; align-items: center; gap: 5px;
    font-size: 12.5px; color: var(--muted);
}
.steps span::before {
    content: attr(data-n);
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--line); color: var(--muted);
    font-size: 12px; font-weight: 700;
}
.steps span.on { color: var(--brand-dark); font-weight: 700; }
.steps span.on::before { background: var(--brand); color: #fff; }
.steps i { width: 18px; height: 1px; background: var(--line); align-self: center; }

/* ── 其他 ─────────────────────────────────────────── */
.footer { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 20px; }
.notes { font-size: 13.5px; color: var(--muted); }
.notes ol { margin: 6px 0 0; padding-left: 20px; }
.notes > strong { color: var(--text); font-size: 15px; }
.faq { margin: 10px 0 0; }
.faq dt {
    font-weight: 700; color: var(--text); font-size: 14px;
    margin-top: 14px; display: flex; gap: 7px; align-items: baseline;
}
.faq dt:first-of-type { margin-top: 8px; }
.faq dd { margin: 4px 0 0; padding-left: 24px; line-height: 1.7; }
.faq dd strong { color: var(--text); }
.faq .dim { opacity: .75; font-size: 12.5px; }
.toggle-password-button {
    padding: 6px 12px; font-size: 13px;
    background: transparent; color: var(--muted);
    border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.toggle-password-button:hover { border-color: var(--brand); color: var(--brand-dark); }
