:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #263347;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #6366f1;
  --radius: 16px;
  --slot-r: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Header ─────────────────────────────────────────── */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) 14px calc(20px + env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-date {
  font-size: 13px;
  color: var(--muted);
}

.install-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 12px #6366f155;
  transition: transform 0.15s, background 0.15s;
}

.install-btn:active { transform: scale(0.95); }
.install-btn[hidden] { display: none; }

/* ─── Week scroll ─────────────────────────────────────── */

.week-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 0;
  scrollbar-width: none;
}

.week-scroll::-webkit-scrollbar { display: none; }

.week-inner {
  display: flex;
  gap: 10px;
  height: 100%;
  padding-bottom: 90px;
}

/* ─── Day card ────────────────────────────────────────── */

.day-card {
  flex-shrink: 0;
  min-width: calc(100vw - 48px);
  max-width: 400px;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  scroll-snap-align: start;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.day-card::-webkit-scrollbar { display: none; }

.day-card.is-today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 28px #6366f125;
}

.day-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  flex-shrink: 0;
}

.day-name {
  font-size: 15px;
  font-weight: 700;
}

.day-full-date {
  font-size: 13px;
  color: var(--muted);
  flex: 1;
}

.today-badge {
  font-size: 10px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 2px 9px;
  border-radius: 999px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

/* ─── Timeslots ───────────────────────────────────────── */

.day-slots {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.time-slot {
  background: var(--surface-2);
  border-radius: var(--slot-r);
  border: 1.5px solid transparent;
  padding: 10px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.time-slot.drag-over {
  border-color: var(--accent);
  background: #6366f112;
  box-shadow: inset 0 0 0 1px #6366f140;
}

.slot-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 8px;
}

.slot-time {
  font-size: 10px;
  color: #475569;
  margin-left: auto;
  letter-spacing: 0;
  font-weight: 400;
}

.slot-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  align-items: flex-start;
}

.drop-hint {
  font-size: 11px;
  color: #475569;
  display: flex;
  align-items: center;
  gap: 4px;
}

.drop-hint::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1.5px dashed #475569;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Activity chips ──────────────────────────────────── */

.activity-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--cat-bg, #6366f118);
  border: 1.5px solid var(--cat-color, #6366f1);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform 0.1s, opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.activity-chip:active { cursor: grabbing; }

.activity-chip.dragging {
  opacity: 0.3;
  pointer-events: none;
}

.chip-emoji { font-size: 13px; line-height: 1; }

.chip-remove {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  margin-left: 1px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}

.chip-remove:hover {
  color: #f87171;
  background: #f8717120;
}

/* ─── FAB ─────────────────────────────────────────────── */

.fab {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom));
  right: calc(20px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 13px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 24px #6366f155;
  z-index: 50;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.fab:active { transform: scale(0.95); }

.fab.open {
  background: #475569;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.fab-icon { font-size: 17px; }

/* ─── Activity drawer ─────────────────────────────────── */

.activity-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--border);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
              max-height 0.3s ease;
  max-height: 78vh;
  overflow: hidden;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.activity-drawer.open { transform: translateY(0); }

.activity-drawer.shrink { max-height: 38vh; }

.drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 10px auto 0;
  flex-shrink: 0;
  cursor: pointer;
}

.drawer-content {
  overflow-y: auto;
  flex: 1;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.drawer-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.drawer-header h2 { font-size: 17px; font-weight: 700; }

.drawer-hint { font-size: 12px; color: var(--muted); }

.edit-toggle {
  margin-left: auto;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}

.edit-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ─── Category filters ────────────────────────────────── */

.category-filters {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 12px;
}

.category-filters::-webkit-scrollbar { display: none; }

.cat-filter {
  flex-shrink: 0;
  padding: 5px 13px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.cat-filter.active {
  background: var(--cat-color, var(--accent));
  border-color: var(--cat-color, var(--accent));
  color: #fff;
}

.cat-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 5px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 13px;
  line-height: 1;
}

.cat-add {
  border-style: dashed !important;
  color: var(--accent) !important;
  border-color: var(--accent) !important;
}

.cat-empty {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.color-select {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, border-color 0.12s;
}

.color-swatch.selected {
  border-color: #fff;
  transform: scale(1.12);
}

/* ─── Library grid ────────────────────────────────────── */

.library-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

.group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  margin-bottom: 7px;
}

.group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.library-chip.editing {
  cursor: default;
  animation: wiggle 0.35s ease-in-out infinite alternate;
}

.chip-delete {
  background: #ef4444;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
  width: 17px;
  height: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

@keyframes wiggle {
  from { transform: rotate(-1.2deg); }
  to   { transform: rotate(1.2deg); }
}

.add-activity-btn {
  width: 100%;
  margin-top: 4px;
  padding: 11px;
  background: transparent;
  border: 1.5px dashed var(--border);
  border-radius: var(--slot-r);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.add-activity-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Drag ghost ──────────────────────────────────────── */

.drag-ghost {
  position: fixed;
  z-index: 9999;
  background: var(--cat-color, var(--accent));
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transform: rotate(-3deg) scale(1.08);
  white-space: nowrap;
  transition: none;
  will-change: transform, left, top;
}

/* ─── Modal ───────────────────────────────────────────── */

.activity-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  align-items: flex-end;
}

.activity-modal.open { display: flex; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(40px + env(safe-area-inset-bottom));
  animation: slideUp 0.28s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0.5; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-sheet h3 { font-size: 17px; font-weight: 700; margin-bottom: 20px; }

.modal-field { margin-bottom: 14px; }

.modal-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  margin-bottom: 7px;
}

.modal-field input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--slot-r);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.modal-field input:focus { border-color: var(--accent); }
.modal-field input::placeholder { color: #475569; }

.cat-select {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  transition: outline 0.15s;
}

.cat-select.shake { animation: shake 0.28s ease; }

.cat-option {
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--cat-bg, var(--surface-2));
  border: 1.5px solid var(--cat-color, var(--border));
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.cat-option.selected {
  background: var(--cat-color, var(--accent));
  color: #fff;
  border-color: var(--cat-color, var(--accent));
}

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

.btn-cancel, .btn-save {
  flex: 1;
  padding: 13px;
  border-radius: var(--slot-r);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: transform 0.12s, opacity 0.12s;
}

.btn-cancel { background: var(--surface-2); color: var(--muted); }
.btn-save   { background: var(--accent); color: #fff; }
.btn-save:active { transform: scale(0.97); }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

/* ─── Desktop tweaks ──────────────────────────────────── */

@media (min-width: 640px) {
  .day-card { min-width: 300px; }
  .week-inner { padding-right: 14px; }
  .activity-drawer { max-width: 520px; left: 50%; transform: translateX(-50%) translateY(100%); border-radius: 22px 22px 0 0; }
  .activity-drawer.open { transform: translateX(-50%) translateY(0); }
  .fab { right: calc(50% - 260px + 20px); }
}
