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

:root {
    --primary: #8a6d1f;
    --primary-light: #7a5f0e;
    --brand-grad: linear-gradient(180deg, #FFE34C 0%, #FFD700 50%, #998100 100%);
    --hero-ink: #3a2c05;
    --bg: #f4f6f9;
    --card: #ffffff;
    --text: #2b2b2b;
    --muted: #777;
    --green: #2e7d32;
    --orange: #ef6c00;
    --red: #c62828;
    --radius: 12px;
}

body {
    font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--primary-light); text-decoration: none; }

/* ---------- 公開頁面 (登入/註冊) ---------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--brand-grad);
}
.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.auth-logo { text-align: center; margin-bottom: 8px; }
.auth-logo .icon { font-size: 48px; }
.auth-title { text-align: center; font-size: 26px; font-weight: 700; color: var(--primary); }
.auth-sub { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* ---------- 表單 ---------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 15px;
    background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(138,109,31,.18);
}
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* ---------- 按鈕 ---------- */
.btn {
    display: inline-block;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    text-align: center;
}
.btn:hover { background: var(--primary-light); }
.btn-block { width: 100%; }
.btn-green { background: var(--green); }
.btn-green:hover { background: #1b5e20; }
.btn-orange { background: var(--orange); }
.btn-orange:hover { background: #e65100; }
.btn-red { background: var(--red); }
.btn-red:hover { background: #b71c1c; }
.btn-gray { background: #78909c; }
.btn-gray:hover { background: #546e7a; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 訊息 ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #ffebee; color: var(--red); border: 1px solid #ef9a9a; }
.alert-success { background: #e8f5e9; color: var(--green); border: 1px solid #a5d6a7; }

/* ---------- 版面 ---------- */
.container { max-width: 720px; margin: 0 auto; padding: 16px; }
.page-header {
    background: var(--primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}
.page-header h1 { font-size: 18px; font-weight: 600; }
.logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,.18);
    border: 1.5px solid rgba(255,255,255,.8);
    color: #fff;
    border-radius: 8px;
    padding: 5px 11px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 8px;
}
.logout-btn:hover { background: rgba(255,255,255,.34); }
.logout-btn svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.page-header .points-badge {
    background: rgba(255,255,255,.2);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 700;
}

/* ---------- 卡片 ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }

.hero-card {
    background: var(--brand-grad);
    color: var(--hero-ink);
    border-radius: var(--radius);
    padding: 24px 20px;
    margin-bottom: 16px;
}
.hero-card .label { font-size: 14px; opacity: .8; }
.hero-card .value { font-size: 36px; font-weight: 800; margin-top: 4px; }
.hero-card .sub { font-size: 14px; opacity: .85; margin-top: 4px; }
.hero-card .pos { color: #1b5e20; }
.hero-card .neg { color: #b71c1c; }
.hero-card.has-photo {
    color: #fff;
    background-color: var(--primary);
    background-image: linear-gradient(rgba(0,0,0,.38), rgba(0,0,0,.48)), var(--hero-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* ---------- 主題顏色 ---------- */
.theme-picker { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.theme-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 999px;
    background: #fff;
    font-size: 14px;
    cursor: pointer;
}
.theme-option input { display: none; }
.theme-option:has(input:checked) { border-color: var(--primary); font-weight: 700; }
.theme-dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.08); }

/* ---------- 功能選單 ---------- */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.menu-item {
    background: #fff;
    border-radius: var(--radius);
    padding: 18px 14px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    color: var(--text);
    display: block;
    transition: transform .1s;
}
.menu-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.menu-item .emoji { font-size: 32px; display: block; margin-bottom: 8px; }
.menu-item .label { font-size: 14px; font-weight: 600; }

/* ---------- 列表 ---------- */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid #eee;
}
.list-item:last-child { border-bottom: none; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; font-size: 15px; }
.list-item .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-item .points { font-weight: 700; color: var(--green); white-space: nowrap; }
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}
.badge-green { background: #e8f5e9; color: var(--green); }
.badge-orange { background: #fff3e0; color: var(--orange); }
.badge-gray { background: #eceff1; color: #546e7a; }
.badge-blue { background: #e3f2fd; color: #1565c0; }
.badge-pink { background: #fce4ec; color: #c2185b; }
.badge-purple { background: #f3e5f5; color: #7b1fa2; }
.badge-red { background: #ffebee; color: var(--red); }

/* ---------- 表格 ---------- */
table.data { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { padding: 10px 12px; text-align: left; font-size: 14px; border-bottom: 1px solid #eee; }
table.data th { background: #f5f7fa; font-weight: 600; }
table.data tr:last-child td { border-bottom: none; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }

/* ---------- 導航列 ---------- */
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-links a {
    color: rgba(255,255,255,.85);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 14px;
}
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,.15); color: #fff; }

.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    display: flex;
    border-top: 1px solid #ddd;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
    flex: 1;
    text-align: center;
    padding: 10px 4px;
    font-size: 12px;
    color: var(--muted);
}
.bottom-nav a .emoji { display: block; font-size: 20px; margin-bottom: 2px; }
.bottom-nav a.active { color: var(--primary); font-weight: 700; }

.has-bottom-nav { padding-bottom: 70px; }

/* ---------- 其他 ---------- */
.muted { color: var(--muted); }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.flex { display: flex; gap: 12px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-box { text-align: center; padding: 12px; }
.stat-box .num { font-size: 24px; font-weight: 800; color: var(--primary); }
.stat-box .lbl { font-size: 12px; color: var(--muted); }

@media (max-width: 480px) {
    .form-row { flex-direction: column; gap: 0; }
    .menu-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- 趨勢圖切換器 ---------- */
.seg {
    display: inline-flex;
    background: #eef1f6;
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
}
.seg-btn {
    border: none;
    background: transparent;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
}
.seg-btn.active {
    background: #fff;
    color: var(--primary);
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.range-btn {
    border: 1px solid #e0e0e0;
    background: #fff;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
}
.range-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 700;
}

/* ---------- 股票搜尋 ---------- */
.stock-search { flex-wrap: wrap; }
.stock-search-input {
    flex: 1 1 100%;
    min-width: 0;
    padding: 14px 16px;
    border: 1.5px solid #ccc;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 600;
    text-transform: uppercase;
    background: #fff;
}
.stock-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(138,109,31,.18);
}
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 14px;
}
.chip-label { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.chip {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    background: #fdf6e3;
    border: 1.5px solid #e8d48a;
    color: #7a5f0e;
    font-size: 14px;
    font-weight: 600;
}
.chip:hover { background: #f9eeb8; border-color: var(--primary); color: var(--primary); }
.chip .code { font-size: 12px; opacity: .65; margin-left: 4px; font-weight: 500; }
