/*
  StudyBuddy styles — Stage 1.

  The variables in :root (--bg, --accent, ...) are CSS "custom properties":
  named constants, read with var(--name). They can be overridden per scope —
  the body.phase-break block below redefines the accent colors, so flipping
  one class on <body> recolors the whole page for break mode.
*/
:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --ink: #1f2430;          /* main text color */
  --muted: #6b7280;        /* secondary text */
  --line: #e3e6ec;         /* hairline borders */
  --accent: #4f46e5;       /* indigo: focus (and idle) */
  --accent-ink: #ffffff;   /* text on top of the accent color */
  --accent-soft: #eef0fe;  /* pale accent, e.g. progress track */
}

/* Break mode: JavaScript toggles this class on <body>. */
body.phase-break {
  --bg: #ecfaf5;
  --accent: #0d9488;       /* teal */
  --accent-soft: #d9f4ee;
}

/* Make width/height include padding and border (saner size math). */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  transition: background 0.3s;   /* smooth focus <-> break color change */
}

/* One centered column; 16px side gutters keep it readable on phones. */
.page { max-width: 460px; margin: 0 auto; padding: 32px 16px 48px; }

.page-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 0; }

.test-badge {
  background: #fef3c7; color: #92400e;
  font-size: 12px; font-weight: 600;
  padding: 2px 10px; border-radius: 999px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 6px 24px rgba(31, 36, 48, 0.05);
}
.card + .card { margin-top: 16px; }   /* space between stacked cards */

.timer-card { text-align: center; }

.phase-label {
  margin: 0;
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent);
}

.clock {
  margin: 6px 0 18px;
  font-size: 76px; font-weight: 700; line-height: 1;
  /* Every digit gets the same width, so the clock doesn't wobble as it ticks. */
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px; border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
  margin-bottom: 22px;
}
.progress-fill {
  height: 100%; width: 0%;
  background: var(--accent); border-radius: 999px;
  transition: width 0.25s linear, background 0.3s;
}

.controls { display: flex; justify-content: center; gap: 10px; }

.btn {
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 10px 22px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { filter: brightness(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.history-card h2 { margin: 0 0 6px; font-size: 16px; }
.total-line { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

/* --- The contribution grid ---------------------------------------------
   The clever part: .grid is a CSS grid with 7 fixed ROWS and
   grid-auto-flow: column — new children fill a column top-to-bottom
   (Sun..Sat), then start the next column (week). JavaScript just appends
   one square per day in date order; CSS does all the positioning. */

.grid-scroller { overflow-x: auto; padding-bottom: 4px; }

.grid {
  display: grid;
  grid-template-rows: repeat(7, 12px);
  grid-auto-flow: column;
  grid-auto-columns: 12px;
  gap: 3px;
}

/* Month names above the grid: 26 slots, one per week column, same widths. */
.grid-months {
  display: grid;
  grid-template-columns: repeat(26, 12px);
  gap: 3px;
  height: 14px;
  margin-bottom: 4px;
  font-size: 10px;
  color: var(--muted);
}
.grid-months div { white-space: nowrap; }  /* let "Sep" spill past its 12px slot */

/* One day. The data-level attribute (0–4) is set by JavaScript; these
   attribute selectors turn it into a shade of green. */
.cell { width: 12px; height: 12px; border-radius: 3px; background: #e9ebef; }
.cell[data-level="1"] { background: #9be9a8; }
.cell[data-level="2"] { background: #40c463; }
.cell[data-level="3"] { background: #30a14e; }
.cell[data-level="4"] { background: #216e39; }

.legend {
  display: flex; align-items: center; gap: 4px;
  margin-top: 10px;
  font-size: 12px; color: var(--muted);
}
.legend span { margin: 0 2px; }

/* --- Account / auth ----------------------------------------------------- */

.auth-card h2 { margin: 0 0 4px; font-size: 16px; }
.auth-hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

#auth-form { display: flex; flex-direction: column; gap: 10px; }
#auth-form input {
  font: inherit; font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
}
#auth-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.auth-message { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.auth-message.error { color: #b91c1c; }

.auth-switch { margin: 12px 0 0; font-size: 13px; }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* --- Friends ------------------------------------------------------------ */

.friends-card h2 { margin: 0 0 10px; font-size: 16px; }

.friend-form { display: flex; gap: 8px; margin-bottom: 6px; }
.friend-form input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
}
.friend-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.friend-list { list-style: none; margin: 0; padding: 0; }
.friend-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.friend-list li:last-child { border-bottom: none; }
.friend-list .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The presence dot: gray = offline/idle, green = mid-focus-block. */
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.dot.studying { background: #22c55e; }

.friends-empty { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.history-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
#history-back { font-size: 13px; color: var(--accent); text-decoration: none; white-space: nowrap; }
#history-back:hover { text-decoration: underline; }

.account-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
/* Gotcha the review caught: any author `display` beats the browser's
   built-in [hidden] { display: none }, so hidden must be re-asserted. */
.account-row[hidden] { display: none; }
.account-email { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.btn-small { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
