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

/* the hidden attribute must always win over author display rules */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #fff;
  color: #111;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(48px + env(safe-area-inset-top)) 28px calc(48px + env(safe-area-inset-bottom));
  touch-action: manipulation;
}

/* header */

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

h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.actions { display: flex; gap: 18px; }

button {
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

button.ghost {
  border: 0;
  background: none;
  color: #999;
  font-size: 16px;
  padding: 4px 0;
}

button.ghost.add { font-size: 26px; line-height: 0.7; }
button.ghost:active { color: #111; }

/* add form */

#add { margin: 4px 0 8px; }

#add input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid #eee;
  padding: 14px 0;
  font: inherit;
  font-size: 20px;
  outline: none;
}

#add input::placeholder { color: #bbb; }

/* list */

ul { list-style: none; margin: 0; padding: 0; }

li {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid #f1f1f1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

li .top {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.dot {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #ccc;
  position: relative;
}

li.done .dot { border-color: #111; background: #111; }

li.done .dot::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 3px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* last-7-days mini strip */

.week {
  display: flex;
  gap: 6px;
  padding-left: 38px; /* aligns under the habit name */
}

button.wdot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 0;
  background: #e2e2e2;
  padding: 0;
  position: relative;
}

button.wdot::after { content: ""; position: absolute; inset: -6px; }
button.wdot.on { background: #111; }
button.wdot.today { outline: 1.5px solid #111; outline-offset: 1px; }

/* weekly target badge in the list row */

.target {
  font-size: 14px;
  color: #bbb;
  white-space: nowrap;
}

.target.met { color: #111; font-weight: 600; }

.name { font-size: 19px; flex: 1; }

li.done .name { color: #999; text-decoration: line-through; }

.streak {
  margin-left: auto;
  font-size: 15px;
  color: #999;
  white-space: nowrap;
}

button.cal {
  flex: none;
  border: 0;
  background: none;
  color: #ccc;
  padding: 6px;
  margin: -6px;
  display: flex;
}

button.cal:active { color: #111; }

/* edit mode */

button.mv, button.rn {
  flex: none;
  border: 0;
  background: none;
  color: #ccc;
  font-size: 18px;
  padding: 0;
  min-width: 18px;
  height: 22px;
  line-height: 0.8;
}

button.mv:active, button.rn:active { color: #111; }

button.del {
  flex: none;
  border: 0;
  background: none;
  color: #ccc;
  font-size: 26px;
  line-height: 0.8;
  min-width: 22px;
  height: 22px;
  padding: 0;
}

button.del:active { color: #111; }

button.del.armed {
  color: #e5484d;
  font-size: 14px;
  font-weight: 600;
}

.rn-input {
  flex: 1;
  min-width: 0;
  border: 0;
  border-bottom: 1px solid #111;
  padding: 2px 0;
  font: inherit;
  font-size: 19px;
  outline: none;
}

/* empty state */

.empty {
  margin: 56px 0;
  text-align: center;
  color: #bbb;
  font-size: 16px;
}

/* version label */

.version {
  margin: 36px 0 0;
  text-align: center;
  font-size: 12px;
  color: #ccc;
  user-select: none;
  -webkit-user-select: none;
}

/* bottom sheet / overlay */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

#sheet {
  width: 100%;
  max-width: 560px;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 22px 28px calc(26px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from { transform: translateY(48px); opacity: 0.3; }
  to { transform: none; opacity: 1; }
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
}

.sheet-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.stats { margin: 12px 0 4px; font-size: 15px; color: #999; }

/* weekly target picker in the habit sheet */

.g-target {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 4px;
  font-size: 13px;
  color: #999;
}

.g-target-select {
  border: 0;
  border-bottom: 1px solid #eee;
  background: none;
  font: inherit;
  font-size: 14px;
  color: #111;
  padding: 2px 0;
  outline: none;
}

/* week marks under the calendar: dark = that week met the target */

.g-weekmarks {
  display: grid;
  grid-template-columns: 18px repeat(var(--weeks, 5), 1fr);
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}

.g-wm {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #e2e2e2;
  justify-self: center;
}

.g-wm.met { background: #111; }

/* history calendar */

.g-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 2px 0 12px;
}

button.g-nav-btn {
  border: 0;
  background: none;
  color: #999;
  font-size: 24px;
  line-height: 1;
  padding: 6px 14px;
}

button.g-nav-btn:disabled { opacity: 0.25; }
button.g-nav-btn:active { color: #111; }

button.g-nav-title {
  border: 0;
  background: none;
  color: #111;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 6px 10px;
}

/* columns: weekday label + weeks of the month; rows: Mon..Sun */
.g-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: 18px repeat(var(--weeks, 5), 1fr);
  grid-template-rows: repeat(7, auto);
  gap: 6px;
  width: 100%;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.g-wk {
  font-size: 11px;
  color: #bbb;
  display: flex;
  align-items: center;
  justify-content: center;
}

.g-dot {
  position: relative;
  width: 100%;
  max-width: 36px;
  aspect-ratio: 1 / 1;
  justify-self: center;
  border-radius: 50%;
  background: #e2e2e2;
  cursor: pointer;
}

/* bigger invisible hit area for fingers */
.g-dot::after { content: ""; position: absolute; inset: -8px; }

.g-dot.on { background: #111; }
.g-dot.today { outline: 1.5px solid #111; outline-offset: 1px; }
.g-dot.future { background: transparent; cursor: default; }
.g-dot.bleed { background: #fafafa; cursor: default; }

.g-hint { margin: 14px 0 0; font-size: 13px; color: #bbb; }

/* sync sheet */

.sync-status { margin: 12px 0 4px; font-size: 13px; color: #999; }

.sync-row {
  display: flex;
  gap: 10px;
  margin: 12px 0;
  align-items: center;
  flex-wrap: wrap;
}

.code {
  flex: 1;
  min-width: 0;
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #555;
  background: #f7f7f7;
  border-radius: 6px;
  padding: 7px 9px;
  overflow-wrap: anywhere;
}

button.sheet-btn {
  border: 1px solid #e5e5e5;
  background: #fff;
  color: #111;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 15px;
}

button.sheet-btn:active { background: #f5f5f5; }

.sync-input {
  flex: 1;
  min-width: 140px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 15px;
  outline: none;
}

.sync-input:focus { border-color: #111; }

.sheet-label {
  margin: 20px 0 4px;
  font-size: 12px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
