:root {
  --bg: #121212;
  --fg: #f5f5f5;
  --muted: #999;
  --block-fg: #1a1a1a;
  --accent: #4a90e2;
  --danger: #e25c5c;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  padding:
    calc(16px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(96px + var(--safe-bot))
    calc(16px + var(--safe-left));
}

main#events {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* event block */
.event {
  background: var(--ev-color, #888);
  color: var(--block-fg);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  position: relative;
  transition: transform 120ms ease, opacity 120ms ease;
}

.event.dragging {
  opacity: 0.4;
}

.event.drop-target-before {
  box-shadow: 0 -3px 0 0 var(--accent);
}
.event.drop-target-after {
  box-shadow: 0 3px 0 0 var(--accent);
}

.event .info { min-width: 0; }

.event .title {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event .days {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.event .days .label {
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0.75;
  margin-left: 6px;
}

.event .date {
  font-size: 0.85rem;
  opacity: 0.75;
  margin-top: 4px;
}

.event.past .days { opacity: 0.7; }

.event .handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 44px;
  cursor: grab;
  opacity: 0.5;
  touch-action: none;
}
.event .handle:active { cursor: grabbing; }
.event .handle svg { width: 20px; height: 20px; }

/* Empty state */
#empty {
  text-align: center;
  color: var(--muted);
  margin-top: 30vh;
  font-size: 1.05rem;
}

/* Floating add button */
#add-btn {
  position: fixed;
  right: calc(20px + var(--safe-right));
  bottom: calc(20px + var(--safe-bot));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  z-index: 10;
}
#add-btn:active { transform: scale(0.96); }

/* Modal */
#modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.modal-sheet {
  position: relative;
  background: #1e1e1e;
  width: 100%;
  max-width: 480px;
  border-radius: 18px 18px 0 0;
  padding:
    20px
    calc(20px + var(--safe-right))
    calc(20px + var(--safe-bot))
    calc(20px + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 90vh;
  overflow-y: auto;
}

@media (min-width: 600px) {
  #modal { align-items: center; }
  .modal-sheet {
    border-radius: 18px;
    padding: 24px;
  }
}

.modal-sheet h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-sheet label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.modal-sheet input[type=text],
.modal-sheet input[type=date] {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  color: var(--fg);
  padding: 12px;
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  min-height: 44px;
}

.modal-sheet fieldset {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-sheet fieldset legend {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.type-group {
  flex-direction: row !important;
  gap: 16px !important;
}
.type-group label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--fg);
  font-size: 1rem;
}

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

.color-grid button {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  min-height: 36px;
}

.color-grid button.selected {
  border-color: var(--fg);
  transform: scale(1.08);
}

.modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

.modal-actions .spacer { flex: 1; }

.modal-actions button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

#cancel-btn { background: #333; color: var(--fg); }
.modal-actions button[type=submit] { background: var(--accent); color: white; font-weight: 600; }
#delete-btn { background: var(--danger); color: white; }

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bot));
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 12px 18px;
  border-radius: 22px;
  font-size: 0.9rem;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
