:root {
  /* Design tokens */
  --primary: #1f2937;
  --accent: #374151;
  --bg: #ffffff;
  --card: #f5f5f5;
  --text: #111827;
  --muted: #4b5563;
  --border: #d1d5db;

  --header-height: 64px;
  --player-height: 92px;

  --radius: 6px;
  --gap-xs: 4px;
  --gap-sm: 6px;
  --gap-md: 10px;
  --gap-lg: 18px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* Fixed header */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

header h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: none;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.icon-btn span {
  font-size: 18px;
}

/* App container */
#app-root {
  max-width: 500px;
  margin: 0 auto;
  padding-top: var(--header-height);
  height: 100%;
  position: relative;
}

#screens-wrapper {
  position: absolute;
  inset: var(--header-height) 0 0 0;
  max-width: 500px;
  margin: 0 auto;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

#screens {
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  will-change: transform;
}

.screen {
  flex: 0 0 100%;
  padding: 1rem 1rem 1.5rem;
}

/* Main grid screen */
#main-screen-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

#year-label {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
}

#day-grid {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: var(--gap-sm);
  padding: 0.5rem 0 1.5rem;
}

.day-dot {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
}

.day-dot.today {
  background: var(--primary);
  border-color: var(--primary);
}

.day-dot.past {
  opacity: 0.9;
}

.day-dot.future {
  opacity: 0.4;
}

#swipe-hint {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5rem;
}

/* Habits screen */
#habits-screen-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

#habit-count-label {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 0.8rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
}

#empty-habits {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

#empty-habits p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

#create-habit-main-btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.9rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
}

#habit-view {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  height: 100%;
}

/* Habit cards carousel */
#habit-carousel {
  overflow: hidden;
  margin-top: 0.4rem;
}

#habit-track {
  display: flex;
  gap: 12px;
  padding: 0 16px 0 16px;
  transition: transform 0.3s ease;
  will-change: transform;
}

.habit-card {
  flex: 0 0 86%;   /* <100% so next card edge peeks in */
  max-width: 86%;
}

.habit-card.card {
  /* inherits basic card styling */
}

.habit-card.active {
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.1);
}

/* Habit card content */
.habit-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--gap-sm);
}

.habit-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
}

.habit-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.habit-days {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-xs);
  margin-top: 0.4rem;
}

.day-chip {
  font-size: 0.75rem;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: #ffffff;
}

.day-chip.active {
  background: #e5e7eb;
  color: var(--text);
  border-color: #e5e7eb;
}

.habit-nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.habit-index-label {
  font-weight: 600;
}

/* Timer card */
#timer-card {
  margin-top: 0.4rem;
}

#timer-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

#timer-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#timer-display {
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

#timer-controls-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: var(--gap-sm);
}

#timer-toggle-btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.8rem 1.4rem;
  background: var(--primary);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

#timer-icon {
  font-size: 1.2rem;
}

/* Habit modal */
#habit-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  z-index: 40;
}

#habit-modal {
  background: #ffffff;
  width: 100%;
  max-width: 500px;
  border-radius: 18px 18px 0 0;
  padding: 1rem 1.1rem 1.3rem;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15);
}

#habit-modal header {
  position: static;
  border-bottom: none;
  padding: 0;
  margin-bottom: 0.6rem;
}

#habit-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.25rem;
  margin-top: 0.75rem;
}

#habit-name-input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

#habit-days-select {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-xs);
}

.day-toggle {
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 4px 8px;
  font-size: 0.8rem;
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
}

.day-toggle.selected {
  background: #e5e7eb;
  color: var(--text);
  border-color: #e5e7eb;
}

#habit-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--gap-sm);
  margin-top: 0.9rem;
}

#habit-modal-actions button {
  border-radius: var(--radius);
  border: none;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
}

#habit-cancel-btn {
  background: var(--card);
}

#habit-save-btn {
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

/* Small screen tweaks */
@media (max-width: 380px) {
  #day-grid {
    gap: 4px;
  }
  #timer-display {
    font-size: 1.4rem;
  }
  #timer-toggle-btn {
    padding-inline: 1.1rem;
  }
}
