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

:root {
  --color-bg: #fff;
  --color-text: #0a0a0a;
  --color-muted: #888;
  --color-border: #d0d0d0;
  --color-faint: #ececec;
  --cell-h: 17px;
  --col-gap: 3px;
}

html {
  font-size: 16px;
}

body {
  font-family: "Space Grotesk", sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---- HEADER ---- */

/* Match simonsure.com header spacing exactly. */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2rem 2.5rem;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-family: "Space Mono", monospace;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--color-text);
  transition: color 0.2s;
}

.logo:hover {
  color: var(--color-muted);
}

.logo-dot {
  color: var(--color-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.4rem;
}

.header-link {
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  color: var(--color-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.2s;
  padding: 0;
}

.header-link:hover {
  color: var(--color-text);
}

/* ---- BOARD / TABLE ---- */

.board {
  padding: 0.5rem 2.5rem 2.5rem;
  overflow-x: auto;
}

.grid {
  display: grid;
  grid-template-columns:
    minmax(130px, 240px)
    repeat(var(--days), minmax(15px, 1fr))
    max-content
    max-content;
  column-gap: var(--col-gap);
}

.grid-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: center;
}

/* ---- HEADER ROWS ---- */

.head-months {
  min-height: 15px;
}

.head-days {
  min-height: 18px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--color-faint);
  margin-bottom: 2px;
}

.mcell {
  font-family: "Space Mono", monospace;
  font-size: 0.55rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: visible;
  text-transform: uppercase;
}

.mcell.mstart {
  color: var(--color-text);
}

.dcell {
  font-family: "Space Mono", monospace;
  font-size: 0.52rem;
  color: var(--color-muted);
  text-align: center;
}

.dcell.wknd {
  color: #c4c4c4;
}

.dcell.dtoday {
  color: var(--color-text);
  font-weight: 700;
}

.axis-label {
  font-family: "Space Mono", monospace;
  font-size: 0.55rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats-head {
  text-align: right;
  padding-left: 0.9rem;
  white-space: nowrap;
}

/* ---- GOAL ROWS ---- */

.goal-row {
  border-top: 1px solid var(--color-faint);
  min-height: 30px;
}

.goal-row:last-child {
  border-bottom: 1px solid var(--color-faint);
}

.goal-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-right: 0.8rem;
  min-width: 0;
}

.goal-text {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.goal-title {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.goal-desc {
  font-family: "Space Mono", monospace;
  font-size: 0.58rem;
  color: var(--color-muted);
  letter-spacing: 0.02em;
  line-height: 1.45;
  white-space: pre-line; /* respect line breaks in the description */
  overflow-wrap: anywhere;
}

.retiring {
  font-family: "Space Mono", monospace;
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  color: #c0392b;
}

.drag-dot {
  display: none;
  flex: 0 0 auto;
  width: 9px;
  height: 15px;
  cursor: grab;
  background-image: radial-gradient(var(--color-border) 1px, transparent 1px);
  background-size: 4px 4px;
  background-position: 0 1px;
}

body[data-authed="1"] .drag-dot {
  display: block;
}

body[data-authed="1"] .goal-head {
  cursor: grab;
}

/* ---- CELLS ---- */

.cell {
  width: 100%;
  height: var(--cell-h);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: 2px;
  padding: 0;
}

/* week separator: small gap before each Monday, applied identically to the
   day-header and body cells so columns stay aligned. */
.cell.wkstart,
.dcell.wkstart {
  margin-left: 2px;
}

.cell-off {
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 2px,
    #f4f4f4 2px,
    #f4f4f4 3px
  );
  border-color: var(--color-faint);
}

.cell-done {
  background: var(--color-text);
  border-color: var(--color-text);
}

.cell-today {
  box-shadow: 0 0 0 1.5px var(--color-text);
}

button.cell {
  cursor: default;
}

body[data-authed="1"] button.cell {
  cursor: pointer;
}

body[data-authed="1"] button.cell:hover {
  border-color: var(--color-text);
  transform: scale(1.15);
}

/* ---- STATS ---- */

.goal-stats {
  display: flex;
  gap: 0.8rem;
  justify-content: flex-end;
  padding-left: 0.9rem;
  font-family: "Space Mono", monospace;
  font-size: 0.78rem;
  white-space: nowrap;
}

.goal-stats i {
  font-style: normal;
  font-size: 0.6rem;
  color: var(--color-muted);
  margin-left: 1px;
}

.stat-rate {
  color: var(--color-muted);
}

/* ---- TOOLS ---- */

.goal-tools {
  display: flex;
  gap: 0.15rem;
  padding-left: 0.5rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.goal-row:hover .goal-tools {
  opacity: 1;
}

.goal-menu-btn {
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.goal-menu-btn:hover {
  color: var(--color-text);
}

/* ---- DRAG STATE ---- */

.goal-row.dragging {
  opacity: 0.35;
}

.goal-row.drag-over-top {
  box-shadow: inset 0 2px 0 var(--color-text);
}

.goal-row.drag-over-bottom {
  box-shadow: inset 0 -2px 0 var(--color-text);
}

.empty {
  font-size: 0.9rem;
  color: var(--color-muted);
  padding: 1.5rem 0;
}

/* ---- MODAL ---- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--color-bg);
  border: 1px solid var(--color-text);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.2);
}

.modal h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 1.4rem;
}

.modal label {
  display: block;
  font-family: "Space Mono", monospace;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-muted);
  margin-bottom: 0.4rem;
  margin-top: 1rem;
}

.modal label:first-of-type {
  margin-top: 0;
}

.modal input,
.modal textarea {
  width: 100%;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.9rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
}

.modal input:focus,
.modal textarea:focus {
  outline: none;
  border-color: var(--color-text);
}

.modal textarea {
  resize: vertical;
  min-height: 60px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.8rem;
  margin-top: 1.8rem;
}

.modal-actions button {
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.6rem 1rem;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: none;
  color: var(--color-text);
  transition: border-color 0.2s, background 0.2s;
}

.modal-actions button:hover {
  border-color: var(--color-text);
}

.modal-actions button.primary {
  background: var(--color-text);
  color: #fff;
  border-color: var(--color-text);
}

.modal-actions button.danger {
  color: #c0392b;
  border-color: #c0392b;
}

.modal .hint {
  font-size: 0.75rem;
  color: var(--color-muted);
  line-height: 1.5;
  margin-top: 1rem;
}

/* ---- RESPONSIVE ---- */

/* On phones the 8-week table is unusable. Collapse to a vertical list of
   cards where the only interactive element is a large TODAY toggle. */
@media (max-width: 680px) {
  header {
    padding: 1.4rem 1.25rem;
  }
  .board {
    padding: 0.5rem 1.25rem 2rem;
    overflow-x: hidden;
  }

  .grid {
    display: block;
  }
  /* higher specificity than the .grid-row flex rule below so headers stay hidden */
  .grid-row.head-months,
  .grid-row.head-days {
    display: none;
  }

  .grid-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 0;
    padding: 1rem 0;
  }

  body[data-authed="1"] .drag-dot {
    display: none;
  }

  .goal-head {
    flex: 1 1 auto;
    padding-right: 0;
  }
  .goal-title {
    font-size: 1.02rem;
  }
  .goal-desc,
  .retiring {
    font-size: 0.68rem;
  }

  /* hide the full history; keep only the editable today cell */
  .grid-row .cell {
    display: none;
  }
  .grid-row .cell-today {
    display: block;
    position: relative;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border-width: 2px;
    margin-left: 0;
  }
  /* logged-out visitors on mobile see only streak + rate, not today's state */
  body[data-authed="0"] .grid-row .cell-today {
    display: none;
  }
  .grid-row .cell-today::after {
    content: "today";
    position: absolute;
    top: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    font-family: "Space Mono", monospace;
    font-size: 0.45rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-muted);
  }
  body[data-authed="1"] button.cell.cell-today:hover {
    transform: none;
  }

  .goal-stats {
    flex: 0 0 auto;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
    padding-left: 0;
    font-size: 0.82rem;
  }

  .goal-tools {
    flex: 0 0 auto;
    opacity: 1;
    padding-left: 0;
  }
  .goal-menu-btn {
    font-size: 1rem;
    padding: 0 0.25rem;
  }
}
