/* ============================================================
 *  FreshTrace · NFC 温度曲线
 *  移动端优先 · 深空玻璃拟态主题
 * ============================================================ */

:root {
    --text: #eaf0ff;
    --muted: #8b98b8;
    --muted-2: #5f6b88;
    --line: rgba(255, 255, 255, .08);
    --line-2: rgba(255, 255, 255, .05);
    --accent: #3ddcff;
    --accent-2: #7c5cff;
    --hot: #ff6b81;
    --radius-lg: 24px;
    --radius-md: 16px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --ease: cubic-bezier(.22, .61, .36, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--text);
    line-height: 1.5;
    background:
        radial-gradient(720px 420px at 8% -6%, rgba(124, 92, 255, .38), transparent 62%),
        radial-gradient(640px 380px at 108% 4%, rgba(61, 220, 255, .24), transparent 58%),
        linear-gradient(180deg, #0a1020 0%, #060913 55%, #04060d 100%);
    background-attachment: fixed;
    overflow-x: hidden;
}

/* 细网格纹理，增强科技感 */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
    background-size: 46px 46px;
    -webkit-mask-image: radial-gradient(74% 58% at 50% 0%, #000 0%, transparent 76%);
    mask-image: radial-gradient(74% 58% at 50% 0%, #000 0%, transparent 76%);
}

.glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    z-index: 0;
    opacity: .5;
}

.glow-a { width: 320px; height: 320px; left: -130px; top: -110px; background: rgba(124, 92, 255, .55); }
.glow-b { width: 260px; height: 260px; right: -120px; top: 140px; background: rgba(61, 220, 255, .32); }

/* ---------------------------------------------------------- 布局 */
.app {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    /* 撑满一屏：多余高度留给「数据详情」下方的空白，页脚贴底（工具栏显隐时 dvh 会自动跟随） */
    min-height: 100vh;
    min-height: 100dvh;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px calc(10px + var(--safe-b));
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app > * {
    animation: rise .55s var(--ease) both;
}

.app > *:nth-child(2) { animation-delay: .06s; }
.app > *:nth-child(3) { animation-delay: .12s; }
.app > *:nth-child(4) { animation-delay: .18s; }
.app > *:nth-child(5) { animation-delay: .24s; }

@keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------- 头部 */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 2px 0;
}

.brand {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand h1 {
    font-size: 16px;
    font-weight: 650;
    letter-spacing: .2px;
    line-height: 1.25;
}

.brand p {
    font-size: 10.5px;
    color: var(--muted-2);
    letter-spacing: .3px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .2px;
    white-space: nowrap;
    color: var(--muted);
    background: rgba(255, 255, 255, .06);
    border: 1px solid var(--line);
    transition: color .3s var(--ease), background .3s var(--ease), border-color .3s var(--ease);
}

.chip::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 9px currentColor;
}

.chip.is-ok {
    color: #4ade9a;
    background: rgba(74, 222, 154, .1);
    border-color: rgba(74, 222, 154, .26);
}

.chip.is-empty {
    color: #f0b45c;
    background: rgba(240, 180, 92, .1);
    border-color: rgba(240, 180, 92, .26);
}

/* ---------------------------------------------------------- 主温度卡 */
.hero {
    position: relative;
    overflow: hidden;
    flex: 0 0 auto;
    padding: 10px 15px 9px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, .1);
    background:
        linear-gradient(155deg, rgba(61, 220, 255, .16), rgba(124, 92, 255, .13) 48%, rgba(255, 255, 255, .03));
    box-shadow:
        0 26px 60px -30px rgba(61, 220, 255, .55),
        inset 0 1px 0 rgba(255, 255, 255, .16);
}

.hero::after {
    content: "";
    position: absolute;
    right: -60px;
    top: -70px;
    width: 190px;
    height: 190px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(61, 220, 255, .4), transparent 68%);
    filter: blur(6px);
    pointer-events: none;
}

.hero-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.hero-label {
    font-size: 10.5px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: rgba(220, 235, 255, .6);
}

/* NFC 徽标：一眼看出数据来自 NFC 标签（图在上、字在下的纵向锁排） */
.nfc-mark {
    display: inline-flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.nfc-mark-img {
    display: block;
    width: 33px;
    height: 33px;
    object-fit: contain;
    /* 白色标志 + 青色光晕，融入深色卡片 */
    filter: drop-shadow(0 0 9px rgba(61, 220, 255, .5))
            drop-shadow(0 4px 10px rgba(0, 0, 0, .45));
}

.nfc-mark-word {
    font-size: 9.5px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 1.4px;
    color: #e8f6ff;
    text-shadow: 0 0 12px rgba(61, 220, 255, .5);
}

.hero-value {
    display: flex;
    align-items: baseline;
    gap: 5px;
    margin-top: 3px;
    line-height: 1;
}

.hero-num {
    font-size: clamp(36px, 11.5vw, 46px);
    font-weight: 700;
    letter-spacing: -1.6px;
    font-variant-numeric: tabular-nums;
    background: linear-gradient(118deg, #ffffff 10%, #9fe8ff 55%, #bda9ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.hero-unit {
    font-size: 15px;
    font-weight: 600;
    color: rgba(220, 235, 255, .68);
}

.hero-delta {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    background: rgba(255, 255, 255, .07);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .35s var(--ease), transform .35s var(--ease);
}

.hero-delta.show { opacity: 1; transform: none; }
.hero-delta.up { color: #ffb27a; background: rgba(255, 178, 122, .13); }
.hero-delta.down { color: #63dcff; background: rgba(99, 220, 255, .13); }

.hero-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 8px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 6px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--line-2);
}

.stat-label {
    font-size: 10px;
    letter-spacing: .4px;
    color: rgba(210, 225, 250, .58);
}

.stat-value {
    font-size: 14.5px;
    font-weight: 650;
    letter-spacing: -.3px;
    font-variant-numeric: tabular-nums;
}

.stat-value.cool { color: #63dcff; }
.stat-value.hot  { color: #ff8a9c; }

/* ---------------------------------------------------------- 通用卡片 */
.card {
    background: rgba(255, 255, 255, .045);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    box-shadow:
        0 26px 60px -34px rgba(0, 0, 0, .95),
        inset 0 1px 0 rgba(255, 255, 255, .06);
}

.chart-card {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    padding: 12px 11px 9px;
}

.card-head {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 4px 8px;
}

.card-head h2 {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .2px;
    color: #dbe4fa;
}

.card-head .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: linear-gradient(140deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 10px rgba(93, 200, 255, .9);
}

.card-note {
    font-size: 11.5px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- 图表 */
.chart-wrapper {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    /* 固定舒适高度，不参与拉伸 —— 否则曲线上下会留出大片空白 */
    height: clamp(175px, 31vh, 275px);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, .004));
}

#tempChart {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    touch-action: pan-y;
    cursor: crosshair;
}

.tooltip {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 3;
    padding: 6px 10px;
    border-radius: 10px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -132%) scale(.94);
    background: rgba(9, 13, 24, .94);
    border: 1px solid rgba(255, 255, 255, .14);
    box-shadow: 0 14px 30px -14px rgba(0, 0, 0, .95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity .16s var(--ease), transform .16s var(--ease);
}

.tooltip.show {
    opacity: 1;
    transform: translate(-50%, -132%) scale(1);
}

.tooltip b {
    font-size: 13px;
    color: #eaf6ff;
    font-variant-numeric: tabular-nums;
}

.tooltip span {
    margin-left: 7px;
    font-size: 11.5px;
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
}

.chart-legend {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 7px;
    padding: 0 4px;
    font-size: 10.5px;
    color: var(--muted-2);
}

.legend-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 5px;
    border-radius: 50%;
}

.legend-dot.max { background: var(--hot); box-shadow: 0 0 9px rgba(255, 107, 129, .85); }
.legend-dot.min { background: var(--accent); box-shadow: 0 0 9px rgba(61, 220, 255, .85); }

.chart-legend[hidden] { display: none; }

.chart-legend .hint {
    margin-left: auto;
    color: #4d5872;
}

/* ---------------------------------------------------------- 详情折叠卡 */
.detail-card {
    flex: 0 0 auto;
    /* 剩余高度都留在「数据详情」下方，页脚贴底 */
    margin-bottom: auto;
    overflow: hidden;
}

.detail-card summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 15px;
    font-size: 12.5px;
    font-weight: 600;
    color: #cdd7ee;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.detail-card summary::-webkit-details-marker { display: none; }

.detail-card[open] summary {
    border-bottom: 1px solid var(--line-2);
}

.chev {
    width: 16px;
    height: 16px;
    color: var(--muted-2);
    transition: transform .25s var(--ease);
}

.detail-card[open] .chev { transform: rotate(180deg); }

.kv {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    padding: 9px 15px;
    font-size: 12px;
    border-top: 1px dashed var(--line-2);
}

.kv:first-of-type { border-top: 0; }
.kv > span:first-child { color: var(--muted); flex: 0 0 auto; }

.kv > span:last-child {
    color: #dce4f7;
    text-align: right;
    word-break: break-all;
    font-variant-numeric: tabular-nums;
}

.kv .url {
    font-size: 11.5px;
    color: #7fb8ff !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------------------------------------------------------- 页脚 */
.footer {
    flex: 0 0 auto;
    padding: 0 6px;
    text-align: center;
    font-size: 10.5px;
    letter-spacing: .2px;
    color: var(--muted-2);
    opacity: .85;
}

/* ---------------------------------------------------------- 大屏微调 */
@media (min-width: 560px) {
    .app {
        max-width: 620px;
        padding-left: 22px;
        padding-right: 22px;
        gap: 12px;
    }
    .brand h1 { font-size: 17px; }
    .hero { padding: 16px 18px 15px; }
    .hero-num { font-size: 52px; }
    .chart-card { padding: 15px 14px 11px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}