/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-header: #0f3460;
  --bg-today: #1e2a4a;
  --text: #e8e8e8;
  --text-muted: #a0a0b0;
  --text-dim: #505068;
  --text-time: #c0c0d0;
  --border: #2a2a4a;
  --radius: 6px;
}

html, body {
  height: 100%;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.3;
  -webkit-user-select: none;
  user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Header --- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-header);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

/* --- Weather Widget --- */
#weather {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.weather-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.weather-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.weather-icon {
  font-size: 20px;
  line-height: 1;
}

.weather-temps {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}

.weather-hi {
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}

.weather-lo {
  color: var(--text-muted);
  font-size: 12px;
}

.weather-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  opacity: 0.7;
}

.weather-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

#status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

#refresh-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s;
}

#refresh-btn:active {
  opacity: 0.5;
}

#refresh-btn.spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#error-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e74c3c;
  color: white;
  font-weight: 700;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

/* --- Main Content --- */
main {
  padding: 6px;
  padding-bottom: 48px; /* space for legend */
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#loading, #empty-message {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 20px;
}

/* --- Week Grid --- */
.week-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.dow-cell {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  min-height: 0;
}

/* --- Day Cell --- */
.day-cell {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 4px;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.day-cell.today {
  background: var(--bg-today);
  outline: 2px solid #60A5FA;
  outline-offset: -1px;
}

.day-cell.past {
  opacity: 0.45;
}

.day-header {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding-bottom: 2px;
}

.day-num {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.day-cell.today .day-num {
  color: #60A5FA;
}

.month-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* --- Event Chips --- */
.event-chip {
  background: rgba(255, 255, 255, 0.06);
  border-left: 3px solid;
  border-radius: 3px;
  padding: 3px 5px;
  min-height: 0;
  overflow: hidden;
}

.chip-title {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.chip-time {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
}

/* --- Legend (Footer) --- */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 6px 12px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

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

/* --- Portrait: taller cells --- */
@media (orientation: portrait) {
  .day-cell {
    min-height: 120px;
  }

  .chip-title {
    font-size: 13px;
  }

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

  .day-num {
    font-size: 18px;
  }
}

/* --- Large iPad Pro --- */
@media (min-width: 1024px) {
  .day-cell {
    min-height: 110px;
    padding: 6px;
  }

  .chip-title {
    font-size: 13px;
  }

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

  .day-num {
    font-size: 18px;
  }
}
