:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-raised: #fbfcfc;
  --text: #202326;
  --muted: #6e767d;
  --faint: #a6adb3;
  --line: #dfe5e8;
  --line-soft: #edf1f2;
  --accent: #20745f;
  --accent-strong: #155f4c;
  --accent-soft: #e5f2ee;
  --danger: #a84545;
  --danger-soft: #f6e8e8;
  --warning: #c17b2a;
  --shadow: 0 18px 44px rgba(32, 35, 38, 0.08);
  --radius: 8px;
  --axis-width: 72px;
  --minute-height: 1.6px;
  --step-height: 24px;
  --timeline-height: 1392px;
  --touch-size: 44px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(260px, 1.15fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  margin: 0 auto 16px;
  max-width: 1320px;
  background: rgba(246, 247, 248, 0.92);
  border: 1px solid rgba(223, 229, 232, 0.72);
  border-radius: var(--radius);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  min-width: 0;
  gap: 11px;
  align-items: center;
}

.brand-mark {
  display: grid;
  flex: 0 0 var(--touch-size);
  width: var(--touch-size);
  height: var(--touch-size);
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius);
}

.brand-copy {
  min-width: 0;
}

.brand h1,
.timeline-head h2 {
  margin: 0;
  overflow: hidden;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p,
.timeline-head p {
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-nav,
.top-actions,
.editor-actions,
.time-row {
  display: flex;
  align-items: center;
}

.day-nav {
  gap: 7px;
}

.top-actions {
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.icon-button,
.soft-button,
.primary-button,
.danger-button,
.quiet-button {
  min-height: var(--touch-size);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.icon-button {
  display: grid;
  width: var(--touch-size);
  padding: 0;
  place-items: center;
  color: var(--text);
  background: var(--surface);
}

.soft-button,
.primary-button,
.danger-button,
.quiet-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  white-space: nowrap;
}

.soft-button,
.quiet-button {
  color: var(--text);
  background: var(--surface);
}

.primary-button {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.danger-button {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

.icon-button:hover,
.soft-button:hover,
.quiet-button:hover {
  background: var(--surface-raised);
  border-color: #cfd8dc;
}

.primary-button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.danger-button:hover {
  border-color: rgba(168, 69, 69, 0.22);
}

.icon-button:active,
.soft-button:active,
.primary-button:active,
.danger-button:active,
.quiet-button:active {
  transform: translateY(1px);
}

#datePicker,
.time-row input,
.editor-form textarea {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

#datePicker {
  min-height: var(--touch-size);
  width: 148px;
  padding: 0 10px;
}

#datePicker:focus,
.time-row input:focus,
.editor-form textarea:focus {
  border-color: rgba(32, 116, 95, 0.55);
  box-shadow: 0 0 0 4px rgba(32, 116, 95, 0.1);
}

.planner-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  max-width: 1320px;
  margin: 0 auto;
  align-items: start;
}

.timeline-panel,
.editor-panel,
.mobile-editor-sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.timeline-panel {
  min-width: 0;
  overflow: hidden;
}

.timeline-head {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
}

.save-state {
  flex: 0 0 auto;
  padding: 6px 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  background: var(--surface-raised);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
}

.save-state.is-dirty {
  color: var(--warning);
}

.timeline-scroll {
  height: calc(100vh - 166px);
  min-height: 520px;
  overflow: auto;
  border-top: 1px solid var(--line-soft);
  overscroll-behavior: contain;
}

.timeline {
  position: relative;
  width: 100%;
  min-width: 560px;
  height: var(--timeline-height);
  background:
    linear-gradient(to right, transparent 0, transparent calc(var(--axis-width) - 1px), var(--line-soft) calc(var(--axis-width) - 1px), var(--line-soft) var(--axis-width), transparent var(--axis-width)),
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--step-height) - 1px), rgba(223, 229, 232, 0.72) var(--step-height));
}

.ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tick {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  border-top: 1px solid var(--line-soft);
}

.tick.is-hour {
  border-top-color: var(--line);
}

.tick-label {
  position: absolute;
  top: -9px;
  left: 14px;
  width: 46px;
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
  text-align: right;
  background: var(--surface);
}

.blocks-layer {
  position: absolute;
  inset: 0 12px 0 var(--axis-width);
}

.empty-day {
  position: absolute;
  top: 40px;
  right: 24px;
  left: calc(var(--axis-width) + 24px);
  display: grid;
  min-height: 112px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #cfd8dc;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
}

.time-block {
  position: absolute;
  display: flex;
  min-height: 24px;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  overflow: hidden;
  color: #17362e;
  background: linear-gradient(180deg, #eef8f4, #e5f2ee);
  border: 1px solid rgba(32, 116, 95, 0.18);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(32, 116, 95, 0.08);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.time-block:focus-visible {
  outline: 3px solid rgba(32, 116, 95, 0.2);
  outline-offset: 2px;
}

.time-block.is-active {
  border-color: rgba(32, 116, 95, 0.78);
  box-shadow: 0 10px 26px rgba(32, 116, 95, 0.16);
}

.time-block.is-dragging {
  z-index: 8;
  cursor: grabbing;
  opacity: 0.94;
}

.time-block.is-compact {
  justify-content: center;
  padding: 4px 9px;
}

.block-time {
  overflow: hidden;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.block-copy {
  display: -webkit-box;
  overflow: hidden;
  color: #203d36;
  font-size: 13px;
  line-height: 1.28;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.time-block.is-compact .block-copy {
  display: none;
}

.resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  height: 12px;
  cursor: ns-resize;
}

.resize-handle::after {
  position: absolute;
  left: 50%;
  width: 28px;
  height: 3px;
  content: "";
  background: rgba(32, 116, 95, 0.34);
  border-radius: 99px;
  transform: translateX(-50%);
}

.resize-handle.start {
  top: 0;
}

.resize-handle.start::after {
  top: 3px;
}

.resize-handle.end {
  bottom: 0;
}

.resize-handle.end::after {
  bottom: 3px;
}

.editor-panel {
  position: sticky;
  top: 98px;
  overflow: hidden;
}

.editor-card {
  padding: 18px;
}

.editor-empty {
  display: grid;
  min-height: 260px;
  align-content: center;
  justify-items: start;
  gap: 9px;
  color: var(--muted);
}

.editor-empty svg {
  width: 24px;
  height: 24px;
  color: var(--accent);
}

.editor-empty h2,
.editor-title h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.editor-empty p,
.editor-title p,
.form-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.editor-form {
  display: grid;
  gap: 16px;
}

.editor-title {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.sheet-close {
  display: none;
}

.editor-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.time-row {
  gap: 8px;
}

.time-row input {
  min-width: 0;
  min-height: var(--touch-size);
  width: 100%;
  padding: 0 10px;
}

.time-row span {
  color: var(--faint);
}

.editor-form textarea {
  min-height: 180px;
  max-height: 42vh;
  padding: 12px;
  line-height: 1.55;
  resize: vertical;
  overflow-wrap: anywhere;
}

.form-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.editor-actions {
  gap: 10px;
  justify-content: space-between;
}

.editor-actions .primary-button,
.editor-actions .danger-button {
  flex: 1;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(32, 35, 38, 0.22);
}

.mobile-editor-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  max-height: min(76vh, 640px);
  overflow: auto;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -18px 46px rgba(32, 35, 38, 0.16);
}

.mobile-editor-sheet .editor-card {
  padding: 16px;
}

.mobile-editor-sheet .sheet-close {
  display: grid;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1060px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .day-nav,
  .top-actions {
    justify-content: flex-start;
  }

  .top-actions .primary-button {
    flex: 1 1 180px;
  }
}

@media (max-width: 860px) {
  :root {
    --axis-width: 58px;
    --minute-height: 1.55px;
    --step-height: 23.25px;
    --timeline-height: 1348.5px;
  }

  .app-shell {
    padding: 10px;
  }

  .topbar {
    gap: 10px;
    padding: 10px;
    margin-bottom: 10px;
  }

  .brand-mark {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .planner-grid {
    display: block;
  }

  .editor-panel {
    display: none;
  }

  .timeline-head {
    padding: 13px;
  }

  .timeline-scroll {
    height: calc(100dvh - 206px);
    min-height: 420px;
  }

  .timeline {
    min-width: 360px;
  }

  .tick-label {
    left: 5px;
    width: 44px;
    font-size: 11px;
  }

  .blocks-layer {
    right: 8px;
  }

  .time-block {
    padding: 8px 8px;
  }

  .resize-handle {
    height: 16px;
  }

  .soft-button,
  .primary-button,
  .danger-button,
  .quiet-button {
    padding: 0 11px;
  }

  .day-nav {
    width: 100%;
  }

  #datePicker {
    width: 100%;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .top-actions .primary-button,
  .top-actions .danger-button {
    grid-column: span 2;
  }
}

@media (max-width: 430px) {
  .top-actions {
    grid-template-columns: 1fr;
  }

  .top-actions .primary-button,
  .top-actions .danger-button {
    grid-column: auto;
  }

  .timeline-scroll {
    height: calc(100dvh - 258px);
  }

  .timeline-head {
    align-items: flex-start;
  }

  .save-state {
    margin-top: 1px;
  }

  .block-time {
    font-size: 11px;
  }

  .block-copy {
    font-size: 12px;
  }
}
