*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #059669;
  --accent-hover: #047857;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  }
}

html {
  color-scheme: light dark;
  height: 100%;
}

body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(24px + var(--safe-bottom));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
}

.header-btn:hover {
  color: var(--text);
  border-color: var(--primary);
}

.sync-status {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
}

.sync-status.online {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.sync-status.pending {
  color: #d97706;
  border-color: color-mix(in srgb, #d97706 40%, var(--border));
}

.view {
  text-align: center;
  padding: 32px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.hidden {
  display: none !important;
}

.hint {
  color: var(--muted);
  margin-bottom: 20px;
}

.timer {
  font-size: 3.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  margin: 12px 0 24px;
}

.project-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--badge-color, var(--primary)) 18%, var(--surface));
  color: var(--badge-color, var(--primary));
}

.project-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--badge-color, var(--primary));
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 12px 20px;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-large {
  min-width: 160px;
  padding: 16px 32px;
  font-size: 1.1rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  width: 100%;
  margin-top: 8px;
}

.project-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.project-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 88px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.project-btn:hover,
.project-btn:focus-visible {
  border-color: var(--project-color);
  background: color-mix(in srgb, var(--project-color) 12%, var(--surface));
  outline: none;
}

.project-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--project-color);
}

.today-section h2,
.section-subtitle {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 12px;
  font-weight: 600;
}

.section-subtitle {
  margin-top: 20px;
}

.day-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.day-nav-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}

.day-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.day-nav-label {
  flex: 1;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sheet-section-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.edit-project-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 148px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.edit-project-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 6px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.edit-project-chip.is-selected {
  border-color: var(--chip-color);
  background: color-mix(in srgb, var(--chip-color) 14%, var(--surface));
  color: var(--chip-color);
}

.edit-project-chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chip-color);
  flex-shrink: 0;
}

.timeline {
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 14px 10px;
}

.timeline-summary {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.timeline-summary-main {
  font-size: 0.85rem;
  color: var(--text);
}

.timeline-summary-main strong {
  font-weight: 700;
}

.timeline-summary-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.timeline-bar {
  position: relative;
  height: 40px;
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.timeline-segment {
  position: absolute;
  top: 4px;
  bottom: 4px;
  min-width: 3px;
  border: none;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  opacity: 0.92;
  transition: opacity 0.15s, transform 0.1s;
}

.timeline-segment:hover,
.timeline-segment:focus-visible {
  opacity: 1;
  transform: scaleY(1.08);
  outline: 2px solid color-mix(in srgb, var(--primary) 50%, transparent);
  outline-offset: 1px;
}

.timeline-hours {
  position: relative;
  height: 18px;
  margin-top: 6px;
}

.timeline-hour-label {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.timeline-hour-label:first-child {
  transform: translateX(0);
}

.timeline-hour-label:last-child {
  transform: translateX(-100%);
}

.today-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.today-item {
  display: flex;
  gap: 12px;
  align-items: stretch;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s;
}

.today-item:hover {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
}

.today-item-times {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  padding: 2px 0;
  min-width: 42px;
}

.today-item-content {
  flex: 1;
  min-width: 0;
}

.today-item-row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.today-item-duration {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.today-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--item-color, var(--primary));
  flex-shrink: 0;
}

.today-item-note {
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-word;
  line-height: 1.45;
}

.today-item-note:empty {
  display: none;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 16px;
}

.dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100% - 32px);
  width: 400px;
  margin: auto;
}

.dialog:not([open]) {
  display: none;
}

.dialog:modal {
  max-height: calc(100dvh - 32px);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dialog-header h2 {
  margin-bottom: 0;
}

.dialog-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.dialog-close:hover {
  background: var(--bg);
  color: var(--text);
}

.dialog h2 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.note-summary {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  min-height: 100px;
}

textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 50%, transparent);
  border-color: var(--primary);
}

.dialog-actions {
  margin-top: 14px;
}

.dialog-actions .btn {
  width: 100%;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="email"],
input[type="text"],
input[type="password"],
input[type="datetime-local"],
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

input[type="email"]:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="datetime-local"]:focus,
select:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 50%, transparent);
  border-color: var(--primary);
}

.auth-submit {
  width: 100%;
}

.auth-error {
  color: #dc2626;
  font-size: 0.85rem;
  margin-top: 8px;
}

.logged-in-email {
  font-size: 0.9rem;
  margin-bottom: 8px;
  word-break: break-all;
}

.btn-danger {
  background: transparent;
  color: #dc2626;
  border: 1px solid color-mix(in srgb, #dc2626 40%, var(--border));
  width: 100%;
  margin-top: 8px;
}

.btn-compact {
  width: auto;
  padding: 12px 16px;
  flex-shrink: 0;
}

.manage-list {
  list-style: none;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.manage-item-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.manage-item-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.manage-item-delete {
  font-size: 0.8rem;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  font-family: inherit;
}

.manage-item-delete:hover {
  color: #dc2626;
}

.add-project-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.add-project-form input[type="text"] {
  flex: 1;
  margin-bottom: 0;
}

.add-project-form input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--bg);
}

/* 底部半屏编辑 */
.dialog.dialog-sheet {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  max-width: none;
  width: 100%;
  height: 100%;
  max-height: none;
}

.dialog-sheet:not([open]) {
  display: none;
}

.dialog-sheet[open] {
  display: block;
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.dialog-sheet::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}

.sheet-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.15);
  max-height: min(78dvh, 560px);
  overflow: hidden;
}

.sheet-inner {
  padding: 8px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  max-height: min(78dvh, 560px);
  -webkit-overflow-scrolling: touch;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 12px;
  min-height: 28px;
}

.sheet-title {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin: 0;
}

.sheet-delete-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.sheet-delete-btn:hover {
  color: #dc2626;
  background: color-mix(in srgb, #dc2626 8%, var(--surface));
}

.sheet-pickers {
  margin-bottom: 4px;
}

.sheet-picker-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 8px;
}

.sheet-picker-block {
  margin-bottom: 10px;
}

.sheet-picker-label-top {
  display: block;
  width: auto;
  margin-bottom: 6px;
  text-align: left;
}

.wheel-picker-row-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wheel-picker-slot-date {
  flex: 0 0 72px;
  width: 72px;
}

.wheel-picker-group-time {
  flex: 1;
  min-width: 0;
}

.sheet-picker-label {
  flex-shrink: 0;
  width: 36px;
  align-self: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.wheel-picker-slot {
  flex: 1;
  min-width: 0;
  height: 132px;
}

.wheel-picker-slot-narrow {
  flex: 1;
  min-width: 0;
  height: 132px;
}

.wheel-picker-slot-wide {
  flex: 1;
  height: 132px;
}

.wheel-picker-group {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 4px;
  height: 132px;
}

.wheel-sep {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}

.wheel-picker {
  position: relative;
  width: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.wheel-picker::before {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  height: 44px;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--border));
  border-radius: 8px;
  pointer-events: none;
  z-index: 0;
}

.wheel-viewport {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.wheel-viewport:active {
  cursor: grabbing;
}

.wheel-list {
  will-change: transform;
  position: relative;
  z-index: 1;
}

.wheel-item {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  opacity: 0.55;
}

.wheel-item.is-active {
  color: var(--text);
  opacity: 1;
  font-weight: 700;
  font-size: 1.15rem;
}

.sheet-note {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  resize: none;
  background: var(--bg);
  color: var(--text);
  margin: 8px 0 12px;
  min-height: auto;
}

.sheet-note:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 50%, transparent);
  border-color: var(--primary);
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-actions .btn {
  width: 100%;
}

.sheet-actions .btn-danger {
  margin-top: 0;
}

.wheel-picker-slot-date .wheel-item {
  font-size: 0.9rem;
}

.wheel-picker-slot-date .wheel-item.is-active {
  font-size: 0.95rem;
}

