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

:root {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-elevated: #252525;
  --text-primary: rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.4);
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --overlay: rgba(0, 0, 0, 0.5);
  --border: rgba(255, 255, 255, 0.1);
  --radius: 16px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  min-height: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}

#main-view {
  position: relative;
}

/* Header modes */
.fullscreen-mode header {
  position: absolute;
  background: transparent;
}

.fullscreen-mode header .logo,
.fullscreen-mode header .icon-btn {
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.fullscreen-mode header .icon-btn {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.list-mode header {
  position: sticky;
  background: var(--bg);
}

.logo {
  font-size: 1.5rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Buttons */
.icon-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: none;
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--accent);
}

.icon-btn.danger:hover {
  background: var(--danger);
}

.btn-primary {
  padding: 14px 28px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-full {
  width: 100%;
}

.btn-text {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 8px;
}

/* Countdown Grid */
.countdown-grid {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 76px);
  min-height: calc(100dvh - 76px);
}

.countdown-grid.grid-1 {
  padding: 0;
}

.countdown-grid.grid-2 {
  padding: 0;
}

.countdown-grid.grid-3 {
  padding: 0;
}

.countdown-grid.grid-many {
  padding: 0 20px 20px;
  gap: 16px;
  min-height: auto;
}

/* Full-height cards for 1-3 */
.grid-1 .countdown-card,
.grid-2 .countdown-card,
.grid-3 .countdown-card {
  flex: 1;
  border-radius: 0;
  min-height: 0;
}

.grid-1 .countdown-card {
  min-height: calc(100vh - 76px);
  min-height: calc(100dvh - 76px);
}

.grid-2 .countdown-card {
  min-height: calc((100vh - 76px) / 2);
  min-height: calc((100dvh - 76px) / 2);
}

.grid-3 .countdown-card {
  min-height: calc((100vh - 76px) / 3);
  min-height: calc((100dvh - 76px) / 3);
}

/* Larger text for fullscreen cards */
.grid-1 .countdown-value {
  font-size: 4rem;
}

.grid-1 .card-title {
  font-size: 2rem;
}

.grid-2 .countdown-value {
  font-size: 3rem;
}

.grid-2 .card-title {
  font-size: 1.5rem;
}

.grid-3 .countdown-value {
  font-size: 2rem;
}

/* Fullscreen card layout - bottom left positioning */
.grid-1 .card-content,
.grid-2 .card-content,
.grid-3 .card-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  text-align: left;
  padding: 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* Time display above title */
.grid-1 .countdown-display,
.grid-2 .countdown-display,
.grid-3 .countdown-display {
  order: -1;
  justify-content: flex-start;
  margin-bottom: 16px;
}

/* Ultra subtle - focus on image */
.grid-1 .countdown-display,
.grid-2 .countdown-display,
.grid-3 .countdown-display {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-radius: 0;
  padding: 0;
  border: none;
  gap: 12px;
}

.grid-1 .card-title,
.grid-2 .card-title,
.grid-3 .card-title {
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 2px;
  opacity: 0.9;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}

.grid-2 .card-title {
  font-size: 1.125rem;
}

.grid-3 .card-title {
  font-size: 1rem;
}

.grid-1 .card-subtitle,
.grid-2 .card-subtitle,
.grid-3 .card-subtitle {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.6;
  margin-bottom: 0;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}

/* Lighter countdown values */
.grid-1 .countdown-value {
  font-size: 2rem;
  font-weight: 300;
  opacity: 0.95;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.grid-2 .countdown-value {
  font-size: 1.75rem;
  font-weight: 300;
}

.grid-3 .countdown-value {
  font-size: 1.25rem;
  font-weight: 300;
}

.grid-1 .countdown-label,
.grid-2 .countdown-label,
.grid-3 .countdown-label {
  opacity: 0.6;
  font-size: 0.65rem;
}

/* Countdown Card */
.countdown-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.countdown-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.countdown-card.has-image {
  background-size: cover;
  background-position: center;
}

.countdown-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.1) 40%, transparent 100%);
  pointer-events: none;
}

/* Even subtler overlay for fullscreen cards */
.grid-1 .countdown-card::before,
.grid-2 .countdown-card::before,
.grid-3 .countdown-card::before {
  background: linear-gradient(to top, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.05) 30%, transparent 100%);
}

.card-content {
  position: relative;
  padding: 24px;
  z-index: 1;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.countdown-display {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.countdown-unit {
  text-align: center;
}

.countdown-value {
  font-size: 2.5rem;
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.countdown-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.countdown-done {
  font-size: 1.5rem;
  color: var(--accent);
}

/* Empty State */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

#empty-state svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

#empty-state p {
  margin-bottom: 24px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.modal.active {
  transform: translateX(0);
}

.modal-content {
  padding: 0 20px 40px;
  max-width: 500px;
  margin: 0 auto;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.modal-header h2 {
  flex: 1;
  font-size: 1.25rem;
  font-weight: 500;
}

/* Form */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="time"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row {
  display: flex;
  gap: 12px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

/* Toggle Group */
.toggle-group {
  display: flex;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.toggle-btn {
  flex: 1;
  padding: 10px 16px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: var(--accent);
  color: white;
}

/* Checkbox Group */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.checkbox:has(input:checked) {
  background: var(--accent);
}

.checkbox input {
  display: none;
}

/* Image Upload */
.image-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px;
  background: var(--bg-elevated);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.image-preview:hover {
  border-color: var(--accent);
  color: var(--text-secondary);
}

.image-preview.has-image {
  padding: 0;
  border-style: solid;
  min-height: 150px;
  background-size: cover;
  background-position: center;
}

.image-preview.has-image svg,
.image-preview.has-image span {
  display: none;
}

/* Color Picker */
.color-picker {
  display: flex;
  align-items: center;
  gap: 16px;
}

.color-picker input[type="color"] {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  padding: 0;
}

.color-picker input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
}

.color-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-preset {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.color-preset:hover {
  transform: scale(1.15);
  border-color: var(--text-secondary);
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.countdown-card {
  animation: fadeIn 0.3s ease;
}

/* Dark mode input fixes */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

/* Safe area for iOS */
@supports (padding: max(0px)) {
  #app {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
}

/* Lock Screen */
.lock-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.lock-content {
  text-align: center;
  padding: 40px 20px;
  width: 100%;
  max-width: 320px;
}

.lock-icon {
  margin-bottom: 24px;
  color: var(--accent);
}

.lock-content h2 {
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.lock-content > p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.pin-input-container {
  margin-bottom: 20px;
}

#pin-input {
  width: 100%;
  padding: 16px;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 0.5em;
  font-family: inherit;
}

#pin-input:focus {
  outline: none;
  border-color: var(--accent);
}

#pin-input::placeholder {
  letter-spacing: 0.3em;
  color: var(--text-muted);
}

.pin-error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 16px;
}

.lock-screen.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

/* Fullscreen View */
.fullscreen-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullscreen-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
}

.fullscreen-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.4) 0%,
    rgba(0,0,0,0.2) 30%,
    rgba(0,0,0,0.2) 70%,
    rgba(0,0,0,0.6) 100%
  );
}

.fullscreen-btn {
  position: absolute;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  z-index: 10;
  transition: all 0.2s;
}

.fullscreen-btn:hover {
  background: rgba(0, 0, 0, 0.7);
}

.fullscreen-btn.top-left {
  top: max(20px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
}

.fullscreen-btn.top-right {
  top: max(20px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
}

.fullscreen-content {
  position: relative;
  z-index: 5;
  text-align: center;
  padding: 20px;
  max-width: 100%;
}

.fullscreen-content h2 {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 8px;
  text-shadow: 0 2px 20px rgba(0,0,0,0.5);
}

.fullscreen-content > p {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 40px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.fullscreen-content .countdown-display {
  justify-content: center;
  gap: 24px;
}

.fullscreen-content .countdown-value {
  font-size: 4rem;
  text-shadow: 0 4px 30px rgba(0,0,0,0.5);
}

.fullscreen-content .countdown-label {
  font-size: 0.875rem;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.fullscreen-view.hidden {
  display: none;
}
