:root {
    --bg: #F2F3F5;
    --surface: #FFFFFF;
    --line: #E3E5E8;
    --hair: #EDEFF1;
    --ink: #14171A;
    --ink-2: #4A5057;
    --ink-3: #6B7178;
    --ink-4: #9AA0A7;
    --ink-5: #B7BDC4;
    --on-bg: #1A1D21;
    --radius: 15px;
    --shadow: 4.5px 4.5px 0 rgba(20, 23, 26, 0.07);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 元素自带 display 会盖掉 hidden 的默认隐藏，这里强制生效 */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }

.screen {
    padding: 4px 16px calc(40px + env(safe-area-inset-bottom));
    max-width: 820px;
    margin: 0 auto;
}

/* ---------- 连接页 ---------- */

.connect {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
}

.connect-inner { width: 100%; max-width: 360px; }

.connect-title { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: 0.5px; }

.connect-text { margin: 10px 0 24px; color: var(--ink-3); font-size: 13px; line-height: 1.7; }

.connect-status { min-height: 18px; margin: 12px 0 0; color: var(--ink-3); font-size: 12.5px; }
.connect-status.error { color: var(--ink); font-weight: 500; }

/* ---------- 顶部 ---------- */

.steps { display: flex; height: 17px; align-items: flex-end; margin-top: 8px; }
.step { display: block; width: 9px; margin-right: 4px; border-radius: 3px 3px 0 0; }
.step-a { height: 7px; background: var(--ink-5); }
.step-b { height: 11px; background: var(--ink-4); }
.step-c { height: 16px; background: var(--ink); }

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 2px 0;
}

.topbar-main { min-width: 0; }

.device-name {
    overflow: hidden;
    font-size: 19px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-line { display: flex; align-items: baseline; margin-top: 5px; }

.dot {
    width: 5px; height: 5px;
    margin-right: 5px;
    border-radius: 50%;
    align-self: center;
    background: var(--ink-5);
}
.dot-on { background: var(--ink); }

.status-text { color: var(--ink-3); font-size: 12px; }
.status-divider { margin: 0 5px; color: var(--ink-5); font-size: 12px; }
.power-chip { color: var(--ink-4); font-size: 11px; letter-spacing: 0.5px; }
.power-chip-value { margin-left: 4px; font-size: 15px; font-weight: 600; letter-spacing: -0.2px; }
.power-chip-unit { margin-left: 2px; color: var(--ink-3); font-size: 10px; }

.pill-button {
    display: inline-flex;
    height: 28px;
    align-items: center;
    justify-content: center;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.5px;
    box-shadow: 2px 2px 0 rgba(20, 23, 26, 0.10);
}
.pill-button:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 rgba(20, 23, 26, 0.10); }

.tabs { display: flex; gap: 18px; margin-top: 14px; overflow-x: auto; }
.tabs .tab {
    padding-bottom: 5px;
    color: var(--ink-4);
    font-size: 13px;
    white-space: nowrap;
}
.tabs .tab.active { border-bottom: 1.5px solid var(--ink); color: var(--ink); font-weight: 600; }

/* ---------- 全部插口 ---------- */

.master-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    padding: 0 2px 9px;
}

.master-label { color: var(--ink-3); font-size: 12px; letter-spacing: 1.5px; }
.master-actions { display: flex; gap: 6px; }

/* ---------- 插口卡片 ---------- */

.grid { display: flex; flex-wrap: wrap; justify-content: space-between; }

.tile {
    position: relative;
    width: 48.4%;
    margin-bottom: 10px;
    padding: 14px 14px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: left;
    transition: transform 0.06s ease, box-shadow 0.06s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.tile.pressed { transform: translate(3px, 3px); box-shadow: 2px 2px 0 rgba(20, 23, 26, 0.07); }

.tile.on {
    border-color: var(--ink);
    background: var(--on-bg);
    box-shadow: 4.5px 4.5px 0 rgba(0, 0, 0, 0.18);
}
.tile.on.pressed { box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.18); }

.tile-head { display: flex; align-items: center; justify-content: space-between; }

.tile-name {
    overflow: hidden;
    max-width: 74%;
    color: var(--ink-2);
    font-size: 13.5px;
    letter-spacing: 0.3px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tile.on .tile-name { color: #C9CDD2; }

.tile-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-5); }
.tile.on .tile-dot { background: #FFFFFF; }

.tile-state {
    margin-top: 11px;
    color: #5F656C;
    font-size: 26px;
    font-weight: 500;
    letter-spacing: 2px;
    line-height: 1.1;
}
.tile.on .tile-state { color: #FFFFFF; font-weight: 600; }

.tile-task {
    margin-top: 5px;
    min-height: 14px;
    color: var(--ink-5);
    font-size: 10.5px;
    letter-spacing: 0.3px;
}
.tile.on .tile-task { color: #8E959C; }

.hint { margin: 3px 0 0; text-align: center; color: var(--ink-4); font-size: 11px; letter-spacing: 0.5px; }

/* ---------- 列表 ---------- */

.section-title {
    margin: 26px 0 8px;
    padding: 0 2px;
    color: var(--ink-3);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 1.5px;
}

.card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 5px 5px 0 rgba(20, 23, 26, 0.06);
}

.list { overflow: hidden; border-radius: 14px; }

.record {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    font-size: 13.5px;
}
.record + .record { border-top: 1px solid var(--hair); }
.record-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-action { margin-right: 12px; color: var(--ink-4); font-size: 12px; }
.record-action.on { color: var(--ink); font-weight: 500; }
.record-time { color: var(--ink-4); font-size: 11.5px; }
.empty { padding: 24px 14px; color: var(--ink-4); font-size: 12.5px; text-align: center; }

.footer { margin: 18px 0 0; text-align: center; color: var(--ink-5); font-size: 11px; }

/* ---------- 弹层 ---------- */

.mask {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.32);
    animation: fade 0.15s ease;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

.sheet {
    position: fixed;
    z-index: 50;
    right: 0;
    bottom: 0;
    left: 0;
    max-width: 560px;
    margin: 0 auto;
    padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
    max-height: 82vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 20px 20px 0 0;
    background: var(--surface);
    box-shadow: 0 -6px 24px rgba(20, 23, 26, 0.12);
    animation: rise 0.18s ease;
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-title { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.5px; }

.text-btn { color: var(--ink-3); font-size: 13.5px; }
.text-btn.danger { display: block; width: 100%; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--hair); color: var(--ink-3); }

.sheet-row {
    display: block;
    width: 100%;
    padding: 16px 2px;
    border-top: 1px solid var(--hair);
    font-size: 15px;
    text-align: left;
}
.sheet-row:active { background: var(--bg); }

.primary-button {
    display: block;
    width: 100%;
    margin-top: 18px;
    padding: 13px 0;
    border-radius: 12px;
    background: var(--ink);
    color: #FFFFFF;
    font-size: 15px;
    font-weight: 500;
    text-align: center;
}

.ghost-button {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 12px 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
    font-size: 14px;
    text-align: center;
}

/* ---------- 表单 ---------- */

.field { display: block; margin-top: 14px; }
.field-name { display: block; color: var(--ink-3); font-size: 12px; letter-spacing: 0.5px; }

.field-input {
    display: block;
    width: 100%;
    margin-top: 7px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    font-size: 14px;
    outline: none;
}
.field-input:focus { border-color: var(--ink); }
.field-input.solo { margin-top: 12px; }

.field-label { margin: 22px 0 0; color: var(--ink-3); font-size: 12px; letter-spacing: 1px; }
.field-hint { margin: 8px 0 0; color: var(--ink-4); font-size: 11.5px; line-height: 1.6; }
.field-hint.about { margin-top: 20px; }

.pref-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}
.pref-main { display: flex; flex-direction: column; padding-right: 12px; }
.pref-title { font-size: 14px; }
.pref-desc { margin-top: 4px; color: var(--ink-4); font-size: 11.5px; }

.switch {
    position: relative;
    width: 46px;
    height: 27px;
    flex-shrink: 0;
    border-radius: 14px;
    background: #D8DCE1;
    transition: background 0.15s;
}
.switch i {
    position: absolute;
    top: 3px; left: 3px;
    width: 21px; height: 21px;
    border-radius: 50%;
    background: #FFFFFF;
    transition: transform 0.15s;
}
.switch[aria-checked="true"] { background: var(--ink); }
.switch[aria-checked="true"] i { transform: translateX(19px); }

/* ---------- 定时 ---------- */

.task-row {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    padding: 14px 2px;
    border-top: 1px solid var(--hair);
    text-align: left;
}
.task-main { display: flex; flex-direction: column; }
.task-time { font-size: 19px; font-weight: 500; letter-spacing: 0.5px; }
.task-time.off { color: var(--ink-5); }
.task-desc { margin-top: 4px; color: var(--ink-3); font-size: 11.5px; }
.task-state { color: var(--ink-4); font-size: 11.5px; }

.time-input {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 30px;
    font-weight: 300;
    letter-spacing: 1px;
    text-align: center;
    outline: none;
}

.week-row { display: flex; justify-content: space-between; margin-top: 10px; }

.week-item {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--ink-3);
    font-size: 12.5px;
}
.week-item.on { border-color: var(--ink); background: var(--ink); color: #FFFFFF; }

.action-row {
    display: flex;
    margin-top: 10px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 11px;
}
.action-item { flex: 1; padding: 11px 0; color: var(--ink-3); font-size: 14px; text-align: center; }
.action-item.on { background: var(--ink); color: #FFFFFF; }

/* ---------- 设备列表 ---------- */

.device-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 14px;
    border-top: 1px solid var(--hair);
}
.device-row:first-child { border-top: none; }
.device-main { min-width: 0; flex: 1; text-align: left; }
.device-name { display: block; font-size: 14px; }
.device-meta { display: block; margin-top: 3px; color: var(--ink-4); font-size: 11.5px; }
.device-remove { color: var(--ink-4); font-size: 12.5px; }

/* ---------- 大屏 / 折叠屏展开：三列 ---------- */

@media (min-width: 520px) {
    .screen { padding: 6px 28px 56px; }

    .device-name { font-size: 23px; }
    .status-line { margin-top: 7px; }
    .status-text, .status-divider { font-size: 13px; }
    .status-divider { margin: 0 7px; }
    .dot { width: 6px; height: 6px; margin-right: 7px; }
    .power-chip { font-size: 12px; }
    .power-chip-value { font-size: 18px; }
    .power-chip-unit { font-size: 11px; }

    .pill-button { height: 34px; padding: 0 15px; border-radius: 10px; font-size: 13px; }
    .tabs { gap: 22px; }
    .tabs .tab { font-size: 14px; }

    .master-row { margin-top: 26px; padding-bottom: 12px; }
    .master-label { font-size: 12px; letter-spacing: 2px; }

    .tile {
        width: 31.6%;
        margin-bottom: 16px;
        padding: 18px 18px 16px;
        border-radius: 18px;
        box-shadow: 6px 6px 0 rgba(20, 23, 26, 0.07);
    }
    .tile.on { box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.18); }
    .tile-name { font-size: 15px; }
    .tile-state { margin-top: 15px; font-size: 34px; }
    .tile-task { margin-top: 7px; min-height: 16px; font-size: 12px; }

    .hint { font-size: 12px; }
    .section-title { margin-top: 34px; font-size: 12px; letter-spacing: 2px; }
    .record { padding: 15px 18px; }
    .record-name { font-size: 15px; }
    .record-action, .record-time { font-size: 13px; }
    .footer { font-size: 12px; }

    .sheet { max-width: 580px; padding: 22px 26px calc(22px + env(safe-area-inset-bottom)); }
    .sheet-title { font-size: 20px; }
    .sheet-row { font-size: 16px; padding: 18px 2px; }
    .task-time { font-size: 21px; }
    .week-item { width: 42px; height: 42px; font-size: 14px; }
    .action-item { padding: 13px 0; font-size: 15px; }
    .time-input { font-size: 34px; }
}
