:root[data-tl-theme="dark"] {
    --tl-bg: #0f172a;
    --tl-surface: #1e293b;
    --tl-surface-2: #334155;
    --tl-border: #334155;
    --tl-text: #f1f5f9;
    --tl-text-dim: #94a3b8;
    --tl-primary: #6366f1;
    --tl-primary-2: #4f46e5;
    --tl-danger: #ef4444;
    --tl-overlay: rgba(0, 0, 0, 0.65);
}

:root[data-tl-theme="light"] {
    --tl-bg: #f8fafc;
    --tl-surface: #ffffff;
    --tl-surface-2: #f1f5f9;
    --tl-border: #e2e8f0;
    --tl-text: #0f172a;
    --tl-text-dim: #64748b;
    --tl-primary: #4f46e5;
    --tl-primary-2: #4338ca;
    --tl-danger: #dc2626;
    --tl-overlay: rgba(15, 23, 42, 0.45);
}

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

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--tl-bg);
    color: var(--tl-text);
}

body {
    min-height: 100vh;
}

.tl-app {
    max-width: 640px;
    margin: 0 auto;
    padding-bottom: 40px;
}

.tl-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--tl-bg);
    border-bottom: 1px solid var(--tl-border);
}

.tl-title {
    flex: 1;
    text-align: center;
    font-size: 17px;
    font-weight: 600;
}

.tl-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--tl-surface);
    color: var(--tl-text);
    border: none;
    font-size: 18px;
    cursor: pointer;
    text-decoration: none;
}

.tl-icon-btn.tl-small {
    width: 32px;
    height: 32px;
    font-size: 15px;
}

.tl-running {
    margin: 12px 16px 0;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--tl-primary), var(--tl-primary-2));
    color: #fff;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}

.tl-running-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    animation: tl-pulse 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes tl-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.6); }
}

.tl-running-info {
    flex: 1;
    min-width: 0;
}

.tl-running-label {
    font-size: 12px;
    opacity: 0.8;
}

.tl-running-name {
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tl-running-time {
    font-size: 22px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.tl-running-stop {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    border: none;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.tl-main {
    padding: 0 16px;
}

.tl-date-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    margin: 18px 0 12px;
}

.tl-date-label {
    flex: 1;
    max-width: 260px;
    background: var(--tl-surface);
    border: 1px solid var(--tl-border);
    color: var(--tl-text);
    padding: 9px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

.tl-day-card {
    background: var(--tl-surface);
    border: 1px solid var(--tl-border);
    border-radius: 16px;
    padding: 18px 20px;
    margin-bottom: 16px;
}

.tl-day-total {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 14px;
}

.tl-day-total-num {
    font-size: 34px;
    font-weight: 700;
    color: var(--tl-text);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.tl-day-total-unit {
    font-size: 14px;
    color: var(--tl-text-dim);
}

.tl-day-bar {
    height: 14px;
    border-radius: 7px;
    overflow: hidden;
    background: var(--tl-surface-2);
    display: flex;
}

.tl-day-bar-seg {
    height: 100%;
}

.tl-day-bar-empty {
    font-size: 12px;
    color: var(--tl-text-dim);
    padding: 0 10px;
    line-height: 14px;
    width: 100%;
    text-align: center;
}

.tl-day-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-top: 12px;
    font-variant-numeric: tabular-nums;
}

.tl-day-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--tl-text-dim);
}

.tl-day-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tl-section {
    margin-bottom: 18px;
}

.tl-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 10px;
}

.tl-section-head h3 {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--tl-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.tl-link-btn {
    background: none;
    border: none;
    color: var(--tl-primary);
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    padding: 4px 6px;
}

.tl-cat-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tl-cat-row {
    background: var(--tl-surface);
    border: 1px solid var(--tl-border);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.tl-cat-row.is-running {
    border-color: transparent;
    box-shadow: 0 0 0 2px var(--tl-primary);
}

.tl-cat-tap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    color: var(--tl-text);
    font-family: inherit;
}

.tl-cat-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tl-cat-info {
    flex: 1;
    min-width: 0;
}

.tl-cat-name {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tl-cat-meta {
    font-size: 12px;
    color: var(--tl-text-dim);
    margin-top: 3px;
    font-variant-numeric: tabular-nums;
}

.tl-cat-meta strong {
    color: var(--tl-text);
    font-weight: 600;
}

.tl-cat-goal {
    margin-top: 7px;
    height: 4px;
    border-radius: 2px;
    background: var(--tl-surface-2);
    overflow: hidden;
}

.tl-cat-goal-fg {
    height: 100%;
    transition: width 0.3s;
}

.tl-cat-action {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--tl-surface-2);
    color: var(--tl-text);
    border: none;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.tl-cat-action.is-running {
    background: var(--tl-primary);
    color: #fff;
}

.tl-cat-action:disabled {
    cursor: default;
}

.tl-entry-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tl-entry-row {
    background: var(--tl-surface);
    border: 1px solid var(--tl-border);
    border-radius: 10px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.tl-entry-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tl-entry-main {
    flex: 1;
    min-width: 0;
}

.tl-entry-cat {
    color: var(--tl-text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tl-entry-time {
    color: var(--tl-text-dim);
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    margin-top: 1px;
}

.tl-entry-dur {
    color: var(--tl-text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-left: auto;
    flex-shrink: 0;
}

.tl-entry-del {
    background: none;
    border: none;
    color: var(--tl-text-dim);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    flex-shrink: 0;
}

.tl-entry-empty {
    text-align: center;
    color: var(--tl-text-dim);
    padding: 20px;
    font-size: 13px;
}

.tl-tip {
    margin-top: 24px;
    padding: 10px 14px;
    font-size: 12px;
    color: var(--tl-text-dim);
    background: var(--tl-surface);
    border: 1px solid var(--tl-border);
    border-radius: 10px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    line-height: 1.5;
}

/* ===== Overlay & modal ===== */
.tl-overlay {
    position: fixed;
    inset: 0;
    background: var(--tl-overlay);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
}

.tl-overlay.is-open {
    display: flex;
    animation: tl-fade 0.15s ease-out;
}

@keyframes tl-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.tl-modal {
    background: var(--tl-surface);
    width: 100%;
    max-width: 520px;
    border-radius: 20px 20px 0 0;
    padding: 22px 22px calc(22px + env(safe-area-inset-bottom));
    animation: tl-slide 0.25s ease-out;
    max-height: 92vh;
    overflow-y: auto;
}

.tl-modal-lg {
    max-height: 88vh;
}

@keyframes tl-slide {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.tl-modal h2 {
    margin: 0 0 4px;
    font-size: 17px;
    font-weight: 600;
}

.tl-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.tl-modal-head h2 {
    margin: 0;
}

.tl-label {
    display: block;
    font-size: 12px;
    color: var(--tl-text-dim);
    margin: 14px 0 6px;
    font-weight: 500;
}

.tl-modal input[type="text"],
.tl-modal input[type="number"],
.tl-modal select {
    width: 100%;
    background: var(--tl-surface-2);
    border: 1px solid var(--tl-border);
    color: var(--tl-text);
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    font-family: inherit;
}

.tl-modal input:focus, .tl-modal select:focus {
    border-color: var(--tl-primary);
}

.tl-color-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
}

.tl-color-dot {
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.15s;
}

.tl-color-dot.selected {
    border-color: var(--tl-text);
    transform: scale(1.08);
}

.tl-preset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.tl-preset {
    background: var(--tl-surface-2);
    border: 1px solid var(--tl-border);
    color: var(--tl-text);
    padding: 11px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
}

.tl-preset.selected {
    background: var(--tl-primary);
    color: #fff;
    border-color: var(--tl-primary);
}

.tl-modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}

.tl-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: 10px;
    border: none;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

.tl-btn-primary {
    background: var(--tl-primary);
    color: #fff;
}

.tl-btn-ghost {
    background: var(--tl-surface-2);
    color: var(--tl-text);
}

.tl-btn-danger {
    color: var(--tl-danger);
}

.tl-btn-block {
    display: block;
    width: 100%;
    margin-top: 10px;
}

.tl-theme-pill {
    display: inline-flex;
    background: var(--tl-surface-2);
    border-radius: 14px;
    padding: 3px;
}

.tl-theme-pill button {
    background: none;
    border: none;
    color: var(--tl-text-dim);
    width: 36px;
    height: 28px;
    border-radius: 11px;
    cursor: pointer;
    font-family: inherit;
}

.tl-theme-pill button.active {
    background: var(--tl-surface);
    color: var(--tl-text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ===== Detail ===== */
.tl-detail-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.tl-detail-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tl-detail-head h2 {
    flex: 1;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tl-range-tabs {
    display: flex;
    background: var(--tl-surface-2);
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 14px;
}

.tl-range-tab {
    flex: 1;
    padding: 8px;
    background: none;
    border: none;
    color: var(--tl-text-dim);
    font-size: 13px;
    cursor: pointer;
    border-radius: 8px;
    font-family: inherit;
}

.tl-range-tab.active {
    background: var(--tl-surface);
    color: var(--tl-text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.tl-detail-summary {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.tl-detail-stat {
    flex: 1;
    background: var(--tl-surface-2);
    border-radius: 12px;
    padding: 12px 14px;
}

.tl-detail-stat-label {
    font-size: 11px;
    color: var(--tl-text-dim);
}

.tl-detail-stat-val {
    font-size: 19px;
    font-weight: 700;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

.tl-detail-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 160px;
    padding: 20px 4px 6px;
    overflow-x: auto;
}

.tl-chart-col {
    flex: 1 0 auto;
    min-width: 14px;
    max-width: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    position: relative;
    cursor: pointer;
}

.tl-chart-bar {
    width: 70%;
    max-width: 28px;
    min-height: 2px;
    border-radius: 4px 4px 0 0;
    transition: height 0.3s;
}

.tl-chart-label {
    font-size: 10px;
    color: var(--tl-text-dim);
    margin-top: 4px;
    white-space: nowrap;
}

.tl-chart-val {
    font-size: 10px;
    color: var(--tl-text);
    position: absolute;
    top: -16px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tl-chart-col.is-today .tl-chart-label {
    color: var(--tl-primary);
    font-weight: 600;
}

.tl-detail-hint {
    font-size: 11px;
    color: var(--tl-text-dim);
    text-align: center;
    margin: 4px 0 14px;
}
