:root {
  --cell: 14px;
  --gap: 3px;
  --months-h: 18px;
  --empty: #eceef1;
  --ink: #1d2025;
  --muted: #6d7480;
  --line: #e3e5e8;
  --bg: #f6f7f8;
  --cycle: #5b5bd6;
  --accent: #1d2025;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main { max-width: 740px; margin: 0 auto; padding: 18px 16px 40px; }

h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .01em; }

header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
}
.ghost:hover { color: var(--ink); border-color: #cfd3d8; }

/* connexion */
.login { display: flex; min-height: 80vh; align-items: center; justify-content: center; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 10px; }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login label { font-size: 13px; color: var(--muted); }
.login input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}
.login input:focus-visible, .date:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login button {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 550;
}
.error { margin: 0; min-height: 18px; font-size: 13px; color: #b3122e; }

/* saisie */
.entry-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
#date {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  font-size: 14px;
}
.state { margin-left: auto; font-size: 13px; color: var(--muted); }

.moods { display: flex; flex-wrap: wrap; gap: 6px; }
.mood {
  flex: 1 1 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 9px 8px;
  font-size: 13px;
  min-height: 44px;
}
.mood .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.mood[aria-pressed="true"] {
  background: color-mix(in srgb, var(--c) 12%, #fff);
  border-color: var(--c);
  box-shadow: inset 0 0 0 1px var(--c);
  font-weight: 600;
}

.toggle { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.toggle input { width: 18px; height: 18px; accent-color: var(--cycle); }

/* cycle */
.cycle {
  margin: 12px 0;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
}
.cycle p { margin: 0; }
.cycle .cycle-next { font-size: 14px; }
.cycle .cycle-next strong { font-weight: 600; }
.cycle p.cycle-meta { margin-top: 4px; font-size: 12px; color: var(--muted); }
.cycle .cycle-empty { color: var(--muted); }

/* grille */
.grid-card { padding: 12px 10px 10px; }
.grid { display: flex; gap: 6px; }

.weekdays {
  display: grid;
  grid-template-rows: repeat(7, var(--cell));
  gap: var(--gap);
  padding-top: var(--months-h);
  font-size: 9px;
  line-height: var(--cell);
  color: var(--muted);
  text-align: right;
}
.weekdays span { white-space: nowrap; }

.scroller { overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; padding-right: 10px; }

.months {
  display: grid;
  gap: var(--gap);
  height: var(--months-h);
  font-size: 10px;
  color: var(--muted);
}
.months .month { white-space: nowrap; }

.weeks {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cell));
  gap: var(--gap);
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  background: var(--empty);
}
.cell:hover { border-color: #9aa1ab; }
.cell.future { background: transparent; border-color: var(--line); cursor: default; }
.cell.future:hover { border-color: var(--line); }
.cell.today { box-shadow: 0 0 0 1.5px var(--ink); }
.cell.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.cell.period::after {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 1px;
  height: 3px;
  border-radius: 2px;
  background: var(--cycle);
}
.cell.predicted::after {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 1px;
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--cycle) 0 2px, transparent 2px 4px);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 12px);
  max-width: 92vw;
  padding: 9px 14px;
  border-radius: 9px;
  background: #1d2025;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  main { padding: 14px 10px 32px; }
  .mood { flex: 1 1 30%; font-size: 12px; padding: 8px 4px; }
  .state { width: 100%; margin-left: 0; }
}
