/* ============================================================
   100 天 · 体重打卡
   Palette
     canvas   #F4F6F5   surface  #FFFFFF
     ink      #17251F   muted    #5E6E67
     green    #16876E   green-lt #D4EDE6
     coral    #EC7A5B   hairline #E2E7E4
============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700;12..96,800&family=Inter:wght@400;500;600&display=swap');

:root {
    --canvas: #F4F6F5;
    --surface: #FFFFFF;
    --ink: #17251F;
    --muted: #5E6E67;
    --green: #16876E;
    --green-dark: #0F6152;
    --green-lt: #D4EDE6;
    --coral: #EC7A5B;
    --coral-lt: #FBE3DB;
    --hairline: #E2E7E4;
    --cell-empty: #E8ECEA;

    --display: 'Bricolage Grotesque', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --body: 'Inter', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;

    --r: 14px;
    --r-sm: 10px;
}

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

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

body {
    font-family: var(--body);
    background: var(--canvas);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding: 0 20px 80px;
}

.wrap { max-width: 940px; margin: 0 auto; }

/* ---------- 顶部 ---------- */
.masthead {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 40px 0 28px;
    border-bottom: 1px solid var(--hairline);
    margin-bottom: 32px;
}
.brand {
    font-family: var(--display);
    font-weight: 800;
    font-size: 26px;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand .dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px var(--green-lt);
}
.daycount {
    font-family: var(--display);
    font-weight: 700;
    font-size: 15px;
    color: var(--muted);
}
.daycount b { color: var(--green); font-size: 19px; }

/* ---------- 统计条 ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--hairline);
    border: 1px solid var(--hairline);
    border-radius: var(--r);
    overflow: hidden;
    margin-bottom: 28px;
}
.stat {
    background: var(--surface);
    padding: 20px 18px;
}
.stat .k {
    font-size: 12px;
    color: var(--muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 8px;
}
.stat .v {
    font-family: var(--display);
    font-weight: 700;
    font-size: 30px;
    letter-spacing: -0.02em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.stat .v small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.stat .v.down { color: var(--green); }
.stat .v.up { color: var(--coral); }

/* ---------- 进度条 ---------- */
.progress-card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r);
    padding: 22px 24px;
    margin-bottom: 28px;
}
.progress-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 14px;
}
.progress-head .lbl { font-size: 13px; color: var(--muted); }
.progress-head .pct {
    font-family: var(--display); font-weight: 800; font-size: 22px; color: var(--green);
    font-variant-numeric: tabular-nums;
}
.bar { height: 12px; background: var(--cell-empty); border-radius: 999px; overflow: hidden; }
.bar > span {
    display: block; height: 100%;
    background: linear-gradient(90deg, var(--green), #2FB59A);
    border-radius: 999px;
    transition: width .6s cubic-bezier(.2,.7,.2,1);
}
.progress-ends {
    display: flex; justify-content: space-between;
    font-size: 12px; color: var(--muted); margin-top: 8px;
    font-variant-numeric: tabular-nums;
}

/* ---------- 今日打卡 ---------- */
.today-card {
    background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
    color: #fff;
    border-radius: var(--r);
    padding: 26px 28px;
    margin-bottom: 34px;
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 20px;
}
.today-card .tc-label {
    font-size: 13px; opacity: .85; letter-spacing: .04em; margin-bottom: 6px;
}
.today-card .tc-date {
    font-family: var(--display); font-weight: 700; font-size: 22px;
}
.today-form { display: flex; align-items: stretch; gap: 10px; }
.today-form input[type=number] {
    width: 130px;
    font-family: var(--display); font-weight: 700; font-size: 22px;
    padding: 10px 14px; border: none; border-radius: var(--r-sm);
    background: rgba(255,255,255,.16); color: #fff;
    font-variant-numeric: tabular-nums;
}
.today-form input[type=number]::placeholder { color: rgba(255,255,255,.55); }
.today-form input:focus { outline: 2px solid #fff; }
.today-form .unit-tag {
    display: flex; align-items: center; color: rgba(255,255,255,.8);
    font-weight: 600; font-size: 15px; margin-left: -4px;
}
.btn-log {
    font-family: var(--body); font-weight: 600; font-size: 15px;
    background: #fff; color: var(--green-dark);
    border: none; border-radius: var(--r-sm); padding: 0 22px; cursor: pointer;
    transition: transform .1s ease;
}
.btn-log:hover { transform: translateY(-1px); }
.btn-log:active { transform: translateY(0); }

/* ---------- 区块标题 ---------- */
.section-title {
    display: flex; align-items: baseline; gap: 12px;
    margin: 0 0 18px;
}
.section-title h2 {
    font-family: var(--display); font-weight: 700; font-size: 19px; letter-spacing: -.01em;
}
.section-title .hint { font-size: 12px; color: var(--muted); }

/* ---------- 100 格网格(签名元素) ---------- */
.grid-card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r);
    padding: 26px 26px 22px;
    margin-bottom: 34px;
}
.grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 7px;
}
.cell {
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    background: var(--cell-empty);
    border: 1px solid transparent;
    cursor: pointer;
    position: relative;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600; color: transparent;
    transition: transform .12s ease, box-shadow .12s ease;
}
.cell:hover { transform: scale(1.09); box-shadow: 0 4px 12px rgba(23,37,31,.12); z-index: 2; }
.cell .n {
    position: absolute; top: 3px; left: 5px; font-size: 9px; color: rgba(23,37,31,.28);
    font-variant-numeric: tabular-nums;
}
.cell .w {
    font-family: var(--display); font-weight: 700; font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.cell.down { background: var(--green); color: #fff; }
.cell.goal { background: var(--green-dark); color: #fff; box-shadow: inset 0 0 0 2px var(--coral); }
.cell.up { background: var(--coral-lt); color: var(--coral); }
.cell.flat { background: var(--green-lt); color: var(--green-dark); }
.cell.missed { background: var(--cell-empty); }
.cell.missed::after {
    content: ''; position: absolute; width: 4px; height: 4px; border-radius: 50%;
    background: rgba(23,37,31,.18);
}
.cell.future { background: repeating-linear-gradient(45deg,#EEF1F0,#EEF1F0 4px,#F4F6F5 4px,#F4F6F5 8px); cursor: not-allowed; }
.cell.future:hover { transform: none; box-shadow: none; }
.cell.today-empty, .cell.is-today {
    box-shadow: 0 0 0 2px var(--coral), 0 0 0 4px var(--coral-lt);
}
.cell.today-empty { background: #fff; border: 1px dashed var(--coral); }

.legend {
    display: flex; flex-wrap: wrap; gap: 16px;
    margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--hairline);
    font-size: 12px; color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }
.lg-down { background: var(--green); }
.lg-goal { background: var(--green-dark); box-shadow: inset 0 0 0 2px var(--coral); }
.lg-up { background: var(--coral-lt); }
.lg-today { background: #fff; border: 1px dashed var(--coral); }
.lg-missed { background: var(--cell-empty); }

/* ---------- 图表 ---------- */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r);
    padding: 26px;
    margin-bottom: 34px;
}
.chart-box { position: relative; height: 300px; }
.chart-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 60px 0; }

/* ---------- footer ---------- */
.foot {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 14px;
    font-size: 12px; color: var(--muted);
    border-top: 1px solid var(--hairline); padding-top: 22px;
}
.reset-btn {
    background: none; border: 1px solid var(--hairline); color: var(--muted);
    border-radius: 999px; padding: 6px 16px; font-size: 12px; cursor: pointer;
    font-family: var(--body);
}
.reset-btn:hover { border-color: var(--coral); color: var(--coral); }

/* ---------- 弹窗 ---------- */
.modal-back {
    position: fixed; inset: 0; background: rgba(23,37,31,.4);
    display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
    backdrop-filter: blur(2px);
}
.modal-back.on { display: flex; }
.modal {
    background: var(--surface); border-radius: 18px; padding: 28px;
    width: 100%; max-width: 380px;
    box-shadow: 0 20px 60px rgba(23,37,31,.25);
}
.modal h3 { font-family: var(--display); font-weight: 700; font-size: 20px; margin-bottom: 4px; }
.modal .m-sub { font-size: 13px; color: var(--muted); margin-bottom: 22px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .03em; }
.field input, .field textarea {
    width: 100%; font-family: var(--body); font-size: 15px;
    padding: 11px 14px; border: 1px solid var(--hairline); border-radius: var(--r-sm);
    background: var(--canvas); color: var(--ink); resize: none;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--green); border-color: transparent; }
.field input[type=number] { font-family: var(--display); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions button { flex: 1; font-family: var(--body); font-weight: 600; font-size: 15px; padding: 12px; border-radius: var(--r-sm); cursor: pointer; border: none; }
.btn-save { background: var(--green); color: #fff; }
.btn-save:hover { background: var(--green-dark); }
.btn-del { background: none; color: var(--coral); border: 1px solid var(--hairline) !important; flex: 0 0 auto !important; padding: 12px 16px !important; }
.btn-del:hover { border-color: var(--coral) !important; }

/* ---------- setup 页 ---------- */
.setup-wrap { max-width: 460px; margin: 0 auto; padding-top: 8vh; }
.setup-card {
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: 20px; padding: 40px 36px;
}
.setup-card .eyebrow { font-size: 13px; color: var(--green); font-weight: 600; letter-spacing: .05em; margin-bottom: 10px; }
.setup-card h1 { font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: -.02em; line-height: 1.15; margin-bottom: 10px; }
.setup-card p.lede { font-size: 14px; color: var(--muted); margin-bottom: 28px; }
.setup-row { display: flex; gap: 14px; }
.setup-row .field { flex: 1; }
.unit-toggle { display: flex; gap: 8px; }
.unit-toggle label {
    flex: 1; text-align: center; padding: 10px; border: 1px solid var(--hairline);
    border-radius: var(--r-sm); cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted);
}
.unit-toggle input { display: none; }
.unit-toggle input:checked + span { color: var(--green); }
.unit-toggle label:has(input:checked) { border-color: var(--green); background: var(--green-lt); }
.btn-start {
    width: 100%; margin-top: 8px; font-family: var(--body); font-weight: 600; font-size: 16px;
    background: var(--green); color: #fff; border: none; border-radius: var(--r-sm);
    padding: 14px; cursor: pointer;
}
.btn-start:hover { background: var(--green-dark); }
.setup-note { font-size: 12px; color: var(--muted); margin-top: 18px; text-align: center; line-height: 1.6; }

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
    body { padding: 0 14px 60px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat .v { font-size: 26px; }
    .today-card { flex-direction: column; align-items: stretch; }
    .today-form { justify-content: space-between; }
    .today-form input[type=number] { flex: 1; width: auto; }
    .grid { gap: 5px; }
    .cell .w { font-size: 10px; }
    .cell .n { display: none; }
    .masthead { padding: 28px 0 20px; }
    .brand { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ============================================================
   多用户 / 认证 / 后台
============================================================ */

/* 表单错误提示 */
.form-error {
    background: var(--coral-lt); color: #B23C1E;
    border: 1px solid #F3C6BA; border-radius: var(--r-sm);
    padding: 11px 14px; font-size: 13px; margin-bottom: 20px;
}

/* 登录/注册 切换链接 */
.auth-switch { font-size: 13px; color: var(--muted); margin-top: 20px; text-align: center; }
.auth-switch a { color: var(--green); font-weight: 600; text-decoration: none; margin-left: 4px; }
.auth-switch a:hover { text-decoration: underline; }

/* 顶部条:用户 + 退出 */
.topbar {
    display: flex; align-items: center; justify-content: flex-end; gap: 16px;
    padding-top: 22px;
}
.topbar-center { justify-content: center; margin-bottom: 8px; }
.user-chip {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 14px; font-weight: 600; color: var(--ink);
}
.user-chip .ua {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--green); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-family: var(--display); font-weight: 700; font-size: 14px;
}
.link-muted {
    font-size: 13px; color: var(--muted); text-decoration: none;
    border: 1px solid var(--hairline); border-radius: 999px; padding: 5px 14px;
}
.link-muted:hover { border-color: var(--coral); color: var(--coral); }

/* ---------- 后台 ---------- */
.wrap-wide { max-width: 1160px; }

.admin-card { border-top: 3px solid var(--ink); }
.admin-eyebrow { color: var(--ink); letter-spacing: .12em; }
.btn-admin { background: var(--ink); }
.btn-admin:hover { background: #000; }

.admin-nav { display: flex; align-items: center; gap: 12px; }
.btn-export {
    font-size: 13px; font-weight: 600; text-decoration: none;
    background: var(--green); color: #fff;
    border-radius: 999px; padding: 7px 16px;
}
.btn-export:hover { background: var(--green-dark); }

.table-card {
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: var(--r); overflow: hidden; margin-bottom: 34px;
    overflow-x: auto;
}
.utable { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 900px; }
.utable thead th {
    text-align: left; font-weight: 600; font-size: 11px; letter-spacing: .04em;
    text-transform: uppercase; color: var(--muted);
    padding: 14px 14px; border-bottom: 1px solid var(--hairline); white-space: nowrap;
    background: #FAFBFB;
}
.utable tbody td { padding: 13px 14px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.utable tbody tr:last-child td { border-bottom: none; }
.utable tbody tr:hover { background: #FAFBFB; }
.utable tr.row-banned { opacity: .55; }
.td-name { font-weight: 600; }
.td-mono { font-family: var(--display); font-weight: 600; font-variant-numeric: tabular-nums; }
.td-dim { color: var(--muted); font-weight: 400; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.c-down { color: var(--green); }
.c-up { color: var(--coral); }

.tag { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.tag-ok { background: var(--green-lt); color: var(--green-dark); }
.tag-ban { background: var(--coral-lt); color: #B23C1E; }

.td-actions { white-space: nowrap; }
.mini-btn {
    font-family: var(--body); font-size: 12px; font-weight: 600;
    background: #fff; color: var(--muted);
    border: 1px solid var(--hairline); border-radius: 7px;
    padding: 5px 11px; cursor: pointer; margin-left: 6px;
}
.mini-btn:hover { border-color: var(--ink); color: var(--ink); }
.mini-danger:hover { border-color: var(--coral); color: var(--coral); background: var(--coral-lt); }

@media (max-width: 640px) {
    .topbar { padding-top: 16px; }
}

/* ============================================================
   移动端强化（放在最后，优先生效）
============================================================ */
@media (max-width: 640px) {
    /* 今日打卡卡片：修复输入框撑破屏幕 */
    .today-card { padding: 20px; }
    .today-card > div { min-width: 0; }
    .today-card .tc-date { font-size: 18px; overflow-wrap: anywhere; }
    .today-form { flex-wrap: wrap; gap: 8px; }
    .today-form input[type=number] { min-width: 0; flex: 1 1 90px; width: auto; }
    .today-form .unit-tag { margin-left: 0; }
    .btn-log { flex: 0 0 auto; padding: 0 18px; }

    .topbar { padding-top: 14px; }

    /* 卡片内边距收紧 */
    .stat { padding: 16px 14px; }
    .progress-card, .grid-card, .chart-card { padding: 18px 16px; }
    .chart-box { height: 240px; }

    /* 100 格：更适合手指点按 */
    .grid { gap: 4px; }
    .cell { border-radius: 6px; }
    .cell .w { font-size: 9px; }

    /* 图例换行更自然 */
    .legend { gap: 10px 14px; }

    /* 弹窗贴合小屏 */
    .modal { padding: 22px; border-radius: 16px; }

    /* 后台：可横向滑动的表格加个提示，边距收紧 */
    .wrap-wide { }
    .masthead { flex-wrap: wrap; }
    .admin-nav { width: 100%; justify-content: space-between; }
    .table-card { -webkit-overflow-scrolling: touch; }
    .utable { font-size: 12px; }
    .utable thead th, .utable tbody td { padding: 10px 10px; }
}

/* 全局兜底：任何情况下都不出现整页横向滚动 */
html, body { max-width: 100%; overflow-x: hidden; }

/* ============================================================
   排行榜 / 徽章 / 动态墙
============================================================ */
.topbar-spacer { flex: 1; }
.link-accent {
    font-size: 13px; font-weight: 600; color: var(--green); text-decoration: none;
    border: 1px solid var(--green-lt); background: var(--green-lt);
    border-radius: 999px; padding: 5px 14px;
}
.link-accent:hover { background: var(--green); color: #fff; border-color: var(--green); }

/* 徽章条 */
.badge-strip {
    display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px;
    margin-bottom: 34px; -webkit-overflow-scrolling: touch;
}
.badge {
    flex: 0 0 auto; width: 84px; text-align: center;
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: var(--r-sm); padding: 14px 8px;
}
.badge.got { border-color: var(--green); background: var(--green-lt); }
.badge.locked { opacity: .5; filter: grayscale(1); }
.badge-ico { font-size: 26px; line-height: 1; display: block; margin-bottom: 8px; }
.badge.locked .badge-ico { filter: grayscale(1) opacity(.6); }
.badge-name { font-size: 12px; font-weight: 600; color: var(--ink); }

/* 榜单切换 tab */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
    flex: 1; text-align: center; text-decoration: none;
    font-size: 14px; font-weight: 600; color: var(--muted);
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: var(--r-sm); padding: 10px;
}
.tab:hover { border-color: var(--green); color: var(--green); }
.tab.on { background: var(--green); color: #fff; border-color: var(--green); }

/* 榜单 */
.board-card {
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: var(--r); overflow: hidden; margin-bottom: 10px;
}
.board-row {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px; border-bottom: 1px solid var(--hairline);
}
.board-row:last-child { border-bottom: none; }
.board-row.me { background: var(--green-lt); }
.rank {
    flex: 0 0 34px; text-align: center;
    font-family: var(--display); font-weight: 800; font-size: 17px; color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.rank-1, .rank-2, .rank-3 { font-size: 20px; }
.bl-name { flex: 1; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.me-tag { font-size: 11px; background: var(--green); color: #fff; border-radius: 999px; padding: 1px 8px; }
.bl-streak { font-size: 12px; color: var(--muted); white-space: nowrap; }
.bl-pct {
    flex: 0 0 auto; min-width: 66px; text-align: right;
    font-family: var(--display); font-weight: 700; font-size: 17px;
    font-variant-numeric: tabular-nums; color: var(--muted);
}
.bl-pct.pos { color: var(--green); }
.bl-pct.neg { color: var(--coral); }
.board-note { font-size: 12px; color: var(--muted); margin-bottom: 34px; }
.empty-hint { padding: 40px 24px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7; }

/* 动态墙 */
.feed { display: flex; flex-direction: column; gap: 10px; margin-bottom: 34px; }
.feed-item {
    display: flex; align-items: flex-start; gap: 12px;
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: var(--r); padding: 16px 18px;
}
.ua-feed { flex: 0 0 auto; width: 34px; height: 34px; font-size: 15px; margin-top: 2px; }
.feed-body { flex: 1; min-width: 0; }
.feed-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.feed-head b { font-size: 15px; }
.feed-act { font-size: 13px; color: var(--muted); }
.feed-time { font-size: 12px; color: var(--muted); margin-left: auto; }
.feed-note {
    margin-top: 6px; font-size: 14px; color: var(--ink);
    background: var(--canvas); border-radius: 8px; padding: 8px 12px;
    overflow-wrap: anywhere;
}
.cheer-form { flex: 0 0 auto; }
.cheer-btn {
    font-family: var(--body); font-size: 13px; font-weight: 600;
    background: var(--surface); color: var(--muted);
    border: 1px solid var(--hairline); border-radius: 999px;
    padding: 6px 13px; cursor: pointer; white-space: nowrap;
}
.cheer-btn:hover { border-color: var(--coral); }
.cheer-btn.cheered { background: var(--coral-lt); color: #B23C1E; border-color: var(--coral); }
.cheer-btn.self { cursor: default; opacity: .55; }

@media (max-width: 640px) {
    .badge { width: 76px; padding: 12px 6px; }
    .board-row { padding: 12px 14px; gap: 8px; }
    .bl-streak { display: none; }
    .feed-item { padding: 14px; }
    .link-accent { padding: 5px 10px; }
}
