/* ==========================================================================
   Theme Variables
   这些值会被 config.md 里的 --- theme --- 覆盖
   ========================================================================== */
:root {
    --accent-hue: 165;
    --accent: hsl(var(--accent-hue), 70%, 60%);
    /* 强调色底上的文字色（深色，保证对比度） */
    --accent-ink: #06201a;

    --glass-bg: rgba(255, 255, 255, 0.18);
    --glass-border: rgba(255, 255, 255, 0.28);
    --glass-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);

    /* 壁纸：JS 会写入绝对 URL；此处是 JS 不可用时的兜底
       （style.css 在 assets/css/ 里，所以引用 images 要用 ../） */
    --bg-wallpaper: url('../images/background.jpg');
    --bg-blur: 8px;

    /* 版心与网格 */
    --page-width: 1100px;
    --pad: clamp(12px, 4vh, 40px);
    --grid-gap: 14px;
    --grid-row: 140px;   /* 网格 1 个单位的高度；宽度由 6 等分列决定 */
}

/* ==========================================================================
   基础
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

[hidden] { display: none !important; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--pad) 3vw;
    background-color: #1a1a1a;
    color: var(--text-primary);
    font-family: 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}
button {
    background: none;
    border: 0;
    cursor: pointer;
}
a { color: inherit; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- 整页背景 ---------- */
body::before {
    content: '';
    position: fixed;
    inset: calc(var(--bg-blur) * -1.25);
    background: var(--bg-wallpaper) center/cover no-repeat;
    filter: blur(var(--bg-blur));
    z-index: -1;
}

/* ---------- 首屏淡入（仅 JS 可用时启用） ---------- */
.desktop-container,
.bottom-dock {
    transition: opacity 0.35s ease;
}
.js .is-loading .desktop-container,
.js .is-loading .bottom-dock {
    opacity: 0;
}

/* ---------- 玻璃态通用 ---------- */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 24px;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .glass-panel { background: rgba(30, 30, 30, 0.72); }
}

/* ---------- 错误 / 提示条 ---------- */
.notice {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    max-width: min(92vw, 640px);
    padding: 10px 16px;
    border-radius: 12px;
    background: rgba(140, 30, 30, 0.9);
    color: #fff;
    font-size: 0.85rem;
    line-height: 1.5;
    text-align: center;
}

/* ==========================================================================
   版心：整体最大宽度 1100px（含侧边栏）
   ========================================================================== */
.desktop-container {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    width: 100%;
    max-width: var(--page-width);
}

/* ---------- 侧边栏 ---------- */
.sidebar {
    flex: 0 0 64px;
    position: sticky;
    top: var(--pad);
    align-self: flex-start;
    height: calc(100vh - var(--pad) * 2);
    height: calc(100dvh - var(--pad) * 2);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 14px;
    overflow-y: auto;
}
.link-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}
.sidebar-tools {
    margin-top: auto;
    padding-top: 14px;
}

.sidebar-btn,
.dock-icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.3s ease, color 0.3s ease;
}
.sidebar-btn:hover,
.dock-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}
.sidebar-btn[aria-pressed="true"] {
    background: var(--accent);
    color: var(--accent-ink);
}

/* ==========================================================================
   网格卡片流（类 iTab）
   6 列等分；1 个单位 = 1 列宽 × --grid-row 高。
   卡片尺寸由 data-w / data-h 决定（JS 写入，可在编辑模式中修改）。
   ========================================================================== */
.card-grid {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: var(--grid-row);
    grid-auto-flow: row dense;
    gap: var(--grid-gap);
    align-content: start;
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 16px;
    overflow: hidden;
    border-radius: 20px;
    /* 在玻璃底色上叠一层淡黑，保证浅色壁纸区域文字也清晰 */
    background:
        linear-gradient(rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.22)),
        var(--glass-bg);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}
.card.is-hidden { display: none; }

/* 尺寸：列 1–6、行 1–4 */
.card[data-w="1"] { grid-column: span 1; }
.card[data-w="2"] { grid-column: span 2; }
.card[data-w="3"] { grid-column: span 3; }
.card[data-w="4"] { grid-column: span 4; }
.card[data-w="5"] { grid-column: span 5; }
.card[data-w="6"] { grid-column: span 6; }
.card[data-h="1"] { grid-row: span 1; }
.card[data-h="2"] { grid-row: span 2; }
.card[data-h="3"] { grid-row: span 3; }
.card[data-h="4"] { grid-row: span 4; }

/* 桌面端：卡片作为「尺寸容器」，内部元素可按卡片自身大小自适应 */
@media (min-width: 861px) {
    .card { container: card / size; }
}

/* ---------- 个人 ---------- */
.card-profile {
    flex-direction: row;
    align-items: center;
    gap: 16px;
}
.card-profile .user-avatar {
    flex: none;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #fff center/cover;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}
.profile-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
.user-tag {
    padding: 2px 10px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.4);
    color: var(--text-primary);
    font-size: 0.8rem;
    text-decoration: none;
    transition: background 0.2s;
}
.user-tag[href]:hover { background: rgba(0, 0, 0, 0.6); }
.greeting {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.greeting-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* ---------- 时钟 ---------- */
.card-clock { justify-content: center; }
.clock-widget .time {
    font-family: 'Share Tech Mono', monospace;
    font-size: 3.2rem;
    line-height: 1;
    color: var(--text-primary);
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}
.clock-widget .date {
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}
@media (min-width: 861px) {
    .clock-widget .time { font-size: clamp(1.6rem, min(21cqw, 48cqh), 5.5rem); }
    .clock-widget .date { font-size: clamp(0.75rem, 6cqh, 1.05rem); }
}

/* ---------- 日历 ---------- */
.calendar-header {
    flex: none;
    margin-bottom: 8px;
    text-align: center;
    font-weight: 500;
}
.calendar-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(28px, 1fr);
    gap: 2px;
    font-size: 0.8rem;
}
.calendar-grid span {
    display: grid;
    place-items: center;
    border-radius: 8px;
}
.calendar-grid .day-name {
    opacity: 0.6;
    font-size: 0.7rem;
}
.calendar-grid .active {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
}
@media (min-width: 861px) {
    .calendar-grid { grid-auto-rows: 1fr; }
}

/* ---------- 格言 ---------- */
.card-quote { justify-content: center; }
.quotes-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.quotes-text {
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--text-primary);
}
.quotes-author {
    margin-top: 6px;
    font-size: 0.75rem;
    text-align: right;
    color: var(--text-secondary);
}
@container card (min-height: 220px) {
    .quotes-text { font-size: 1.3rem; line-height: 1.6; }
    .quotes-author { font-size: 0.85rem; }
}

/* ---------- 音乐播放器 ---------- */
.card-music { justify-content: center; }
.music-player {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 0;
}
.album-art {
    flex: none;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1) center/cover;
}
.track-info {
    flex: 1;
    min-width: 0;
}
.track-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.player-controls {
    display: flex;
    gap: 4px;
    margin-top: 2px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.player-controls button {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: inherit;
    transition: color 0.2s;
}
.player-controls button:hover:not(:disabled),
.player-controls button[aria-pressed="true"] {
    color: var(--accent);
}
.player-controls button:disabled {
    opacity: 0.35;
    cursor: default;
}
/* 卡片够高时：封面放大，改为竖排 */
@container card (min-height: 220px) {
    .music-player {
        flex-direction: column;
        text-align: center;
    }
    .album-art {
        width: min(48cqh, 70cqw);
        height: min(48cqh, 70cqw);
    }
    .track-info { width: 100%; flex: none; }
    .player-controls { justify-content: center; }
}

/* ---------- 列表卡片（纪念日 / 书架 / 观影） ---------- */
.card-list h4 {
    flex: none;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.card-list ul {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    list-style: none;
    font-size: 0.8rem;
}
.card-list li {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
}
.card-list li:last-child { border-bottom: 0; }
.item-main {
    min-width: 0;
    overflow-wrap: anywhere;
}
.item-main small {
    display: block;
    opacity: 0.6;
}
.item-side {
    flex-shrink: 0;
    text-align: right;
    white-space: nowrap;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
}
.item-side.is-accent { color: var(--accent); }
.card-list li.empty {
    justify-content: center;
    color: var(--text-secondary);
}

/* ==========================================================================
   布局编辑模式
   ========================================================================== */
.card-tools,
.resize-grip { display: none; }

.is-editing .card {
    outline: 2px dashed rgba(255, 255, 255, 0.4);
    outline-offset: -2px;
}
.is-editing .card.is-hidden {
    display: flex;
    opacity: 0.4;
}
.is-editing .card.is-dragging { opacity: 0.35; }
.is-editing .card.is-resizing { outline: 2px solid var(--accent); }

/* 编辑时压暗内容，避免误点，突出工具条 */
.is-editing .card > :not(.card-tools):not(.resize-grip) {
    opacity: 0.3;
    pointer-events: none;
}

.is-editing .card-tools {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.6);
    font-size: 0.75rem;
}
.tool-title {
    flex: 1;
    min-width: 0;
    padding-left: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tool-btn {
    width: 28px;
    height: 28px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 8px;
    transition: background 0.2s;
}
.tool-btn:hover { background: rgba(255, 255, 255, 0.2); }
.tool-drag { cursor: grab; }
.tool-drag:active { cursor: grabbing; }
.tool-size {
    flex: none;
    padding: 4px 6px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.16);
    cursor: pointer;
}
.tool-size option { color: #111; }
@container card (max-width: 230px) {
    .tool-title { display: none; }
    .card-tools { justify-content: space-between; }
}

.is-editing .resize-grip {
    display: block;
    position: absolute;
    right: 4px;
    bottom: 4px;
    z-index: 3;
    width: 26px;
    height: 26px;
    cursor: nwse-resize;
    touch-action: none;
    border-radius: 8px;
    background: linear-gradient(135deg,
        transparent 0 52%,
        var(--accent) 52% 60%,
        transparent 60% 72%,
        var(--accent) 72% 80%,
        transparent 80%);
}

.edit-bar {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100vw - 24px);
    padding: 10px 14px 10px 18px;
    border-radius: 18px;
    background: rgba(20, 20, 20, 0.7);
    font-size: 0.85rem;
}
.pill-btn {
    flex: none;
    padding: 6px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.18);
    transition: background 0.2s;
}
.pill-btn:hover { background: rgba(255, 255, 255, 0.3); }
.pill-btn.primary {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
}

/* ---------- 底部栏（窄屏） ---------- */
.bottom-dock {
    display: none;
    position: fixed;
    left: 50%;
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 20;
    max-width: calc(100vw - 24px);
    padding: 8px 12px;
    gap: 6px;
    border-radius: 22px;
    overflow-x: auto;
}

/* ---------- 搜索浮层 ---------- */
.search-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 18vh;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}
.search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    width: min(560px, 92vw);
    padding: 14px 20px;
    border-radius: 18px;
    background: rgba(30, 30, 30, 0.55);
}
.search-box input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    outline: none;
    font-size: 1rem;
}
.search-box input::placeholder { color: var(--text-secondary); }
.search-box:focus-within { border-color: var(--accent); }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

/* ==========================================================================
   响应式
   ≤ 860px：侧边栏换成底部栏；网格改为 2 列、按内容自动增高；不提供布局编辑
   ≤ 560px：单列
   ========================================================================== */
@media (max-width: 860px) {
    body { padding-bottom: 96px; }
    .sidebar { display: none; }
    .bottom-dock { display: flex; }
    .desktop-container { display: block; }

    .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: auto;
    }
    .card { min-height: 130px; }
    .card[data-w] { grid-column: span 1; }
    .card[data-h] { grid-row: auto; }
    .card[data-w="4"],
    .card[data-w="5"],
    .card[data-w="6"],
    .card[data-card="calendar"] { grid-column: 1 / -1; }
    .card-list ul { max-height: 220px; }
}

@media (max-width: 560px) {
    .card-grid { grid-template-columns: 1fr; }
    .card[data-w] { grid-column: 1 / -1; }
}

/* ---------- 减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}
