:root {
  --bg: #0b0b0f;
  --bg2: #15151c;
  --tile: #1b1b24;
  --tile2: #22222e;
  --text: #f4f4f6;
  --muted: #8b8b97;
  --line: #2a2a36;
  --accent: #ff9f0a;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 8px) 14px calc(var(--safe-bottom) + 80px);
  max-width: 640px;
  margin: 0 auto;
  user-select: none;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 16px;
}
.date {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.sync-dot {
  position: relative; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.sync-dot::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.sync-dot.ok::before { background: #30d158; }
.sync-dot.busy::before { background: var(--accent); animation: pulse 1s ease infinite; }
.sync-dot.off::before { background: #ff453a; }
@keyframes pulse { 50% { opacity: .35; } }
.brand {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .5px;
  text-align: center;
}
.icon-btn {
  justify-self: end;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--tile);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform .1s ease, background .2s ease;
}
.icon-btn.small { width: 32px; height: 32px; font-size: 16px; }
.icon-btn:active { transform: scale(.9); background: var(--tile2); }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 460px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 120% at 50% 0%, var(--tile2), var(--tile));
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: min(2cqmin, 6px);
  cursor: pointer;
  overflow: hidden;
  transition: transform .12s ease;
  touch-action: manipulation;
  container-type: size;   /* let tile contents scale to the tile's size */
}
.tile:active { transform: scale(.96); }
.tile.done { border-color: var(--c); }

/* in-tile progress sparkline: area fills toward the current level, line shows the trend */
.tile .fillchart {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  z-index: 0;
}
.tile .fc-area { fill: var(--c); opacity: .26; }
.tile.done .fc-area { opacity: .42; }
.tile .fc-line {
  fill: none;
  stroke: var(--c);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  opacity: .8;
  vector-effect: non-scaling-stroke;   /* keep the line crisp despite stretching */
}
.tile.done { box-shadow: 0 0 0 1px var(--c), 0 6px 22px -8px var(--c); }

.tile .donecheck {
  position: absolute;
  top: 7%; right: 9%;
  font-size: min(16cqmin, 15px); font-weight: 900;
  color: var(--c);
  z-index: 1;
}
.tile .emoji {
  font-size: min(34cqmin, 42px);
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.35));
  z-index: 1;
}
.tile .name {
  font-size: min(15cqmin, 14px);
  font-weight: 650;
  text-align: center;
  padding: 0 6px;
  z-index: 1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile .goalnum {
  font-size: min(13cqmin, 12px);
  font-weight: 800;
  color: var(--muted);
  z-index: 1;
  text-align: center;
}
.tile.done .goalnum { color: var(--c); }

/* pop animation on completion */
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.tile.justdone .emoji { animation: pop .4s ease; }

.wiggle .tile { animation: wiggle .25s ease infinite alternate; }
@keyframes wiggle {
  from { transform: rotate(-1deg); }
  to { transform: rotate(1deg); }
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  margin-top: 22vh;
  color: var(--muted);
}
.empty-mark {
  width: 76px; height: 76px;
  margin: 0 auto 14px;
  border-radius: 24px;
  background: var(--tile);
  display: grid; place-items: center;
  font-size: 34px; color: var(--accent);
}
.empty p { margin: 0 0 18px; }

/* ---------- Version footer ---------- */
.version {
  margin-top: auto;       /* pin to the bottom of the screen when content is short */
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  padding: 26px 0 4px;
  opacity: .55;
}

/* ---------- Buttons ---------- */
.primary {
  background: var(--accent);
  color: #1a1200;
  border: none;
  font-weight: 750;
  font-size: 15px;
  padding: 12px 20px;
  border-radius: 14px;
  cursor: pointer;
}
.primary:active { filter: brightness(.92); }
.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 650;
  font-size: 15px;
  padding: 12px 18px;
  border-radius: 14px;
  cursor: pointer;
}
.ghost.danger { color: #ff5d57; border-color: transparent; }

/* ---------- Sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-end;
  z-index: 50;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg2);
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 18px);
  max-height: 92dvh;
  overflow-y: auto;
  animation: slideup .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle {
  width: 40px; height: 5px;
  background: var(--line);
  border-radius: 3px;
  margin: 4px auto 14px;
}
.sheet h2 { margin: 0 0 16px; font-size: 19px; }
.sheet-note { margin: -8px 0 18px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.key-status {
  margin: -8px 0 16px;
  color: #ff5d57; font-size: 13px; font-weight: 600;
}
input[type=password] {
  width: 100%;
  background: var(--tile);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  outline: none;
}
input[type=password]:focus { border-color: var(--accent); }

.field { display: block; margin-bottom: 18px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 8px;
}
input[type=text] {
  width: 100%;
  background: var(--tile);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  outline: none;
}
input[type=text]:focus { border-color: var(--accent); }

.seg {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--tile);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.seg-item {
  border: none; background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 700; padding: 9px;
  border-radius: 9px; cursor: pointer;
}
.seg-item.active { background: var(--accent); color: #1a1200; }

.emoji-search { margin-bottom: 10px; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  max-height: 216px;
  overflow-y: auto;
  padding-right: 2px;
}
.emoji-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
  padding: 16px 4px;
  text-align: center;
}
.emoji-grid button {
  aspect-ratio: 1; border: 1px solid transparent;
  background: var(--tile); border-radius: 11px;
  font-size: 21px; cursor: pointer; padding: 0;
}
.emoji-grid button.active { border-color: var(--accent); background: var(--tile2); }

.color-row { display: flex; flex-wrap: wrap; gap: 10px; }
.color-row button {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
}
.color-row button.active { border-color: #fff; transform: scale(1.1); }

.stepper {
  display: inline-flex; align-items: center; gap: 18px;
  background: var(--tile); border-radius: 12px; padding: 6px 14px;
}
.stepper button {
  width: 30px; height: 30px; border-radius: 8px; border: none;
  background: var(--tile2); color: var(--text); font-size: 20px; cursor: pointer;
}
.stepper span { font-size: 17px; font-weight: 700; min-width: 20px; text-align: center; }

.sheet-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.sheet-actions .spacer { flex: 1; }

/* ---------- Detail ---------- */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.detail-icon {
  width: 52px; height: 52px; border-radius: 15px;
  display: grid; place-items: center; font-size: 28px;
  background: var(--tile);
}
.detail-head h2 { margin: 0; font-size: 19px; }
.detail-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.detail-head .icon-btn { margin-left: auto; }

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; margin-bottom: 22px;
}
.stat {
  background: var(--tile); border-radius: 14px; padding: 12px 6px;
  text-align: center;
}
.stat b { display: block; font-size: 20px; font-weight: 800; }
.stat span { font-size: 11px; color: var(--muted); }

.cal-head { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 10px; }
.cal-head span { font-weight: 700; min-width: 130px; text-align: center; }
.cal-dow {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 6px; margin-bottom: 6px;
}
.cal-dow span { text-align: center; font-size: 11px; color: var(--muted); font-weight: 700; }
.calendar {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 6px; margin-bottom: 18px;
}
.cell {
  aspect-ratio: 1; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 12px; color: var(--muted);
  background: var(--tile);
}
.cell.empty { background: transparent; }
.cell.done { color: #fff; font-weight: 700; }
.cell.today { outline: 2px solid var(--muted); outline-offset: -2px; }
.cell.future { opacity: .35; }

/* ---------- Goal quick-pick chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips button {
  border: 1px solid var(--line);
  background: var(--tile);
  color: var(--text);
  font-size: 14px; font-weight: 700;
  padding: 8px 14px; border-radius: 11px; cursor: pointer;
}
.chips button.active { background: var(--accent); color: #1a1200; border-color: transparent; }

/* ---------- Detail: big progress ---------- */
.bigprogress { text-align: center; margin-bottom: 22px; }
.bigprogress-pct { font-size: 44px; font-weight: 850; line-height: 1; margin-bottom: 12px; }
.bar {
  height: 14px; border-radius: 8px;
  background: var(--tile); overflow: hidden;
}
.bar-fill {
  height: 100%; width: 0;
  border-radius: 8px;
  transition: width .55s cubic-bezier(.2,.8,.2,1);
}
.bigprogress-num { margin-top: 10px; color: var(--muted); font-size: 14px; font-weight: 700; }

/* ---------- Detail: counter ---------- */
.counter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 22px;
}
.counter button {
  flex: 1 1 auto;
  min-width: 60px;
  border: none; border-radius: 16px; cursor: pointer;
  font-size: 19px; font-weight: 800; padding: 18px 0;
  background: var(--tile); color: var(--text);
}
.counter button:active { background: var(--tile2); }
.counter button.add {
  background: var(--accent); color: #1a1200;
  flex-basis: 28%;
}
.counter button.add:active { filter: brightness(.92); }

/* ---------- Confetti ---------- */
.confetti-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 9px; height: 9px;
  border-radius: 2px;
  will-change: transform, opacity;
}

/* ---------- Detail: progress-over-time chart + analytics ---------- */
.chart-wrap {
  background: var(--tile);
  border-radius: 16px;
  padding: 10px 8px 4px;
  margin-bottom: 14px;
}
.chart { width: 100%; height: 120px; display: block; }
.chart-axis { fill: var(--muted); font-size: 9px; font-weight: 600; }
.chart-lbl { fill: var(--muted); font-size: 9px; font-weight: 700; }
.ministats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 22px;
}
.ministats > div {
  background: var(--tile); border-radius: 14px; padding: 12px 6px; text-align: center;
}
.ministats b { display: block; font-size: 17px; font-weight: 800; }
.ministats span { font-size: 11px; color: var(--muted); }

/* ---------- "Added today" indicators ---------- */
.today-summary {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin: -4px 0 14px;
}
.today-summary.none { color: var(--muted); font-weight: 600; }

.tile .today-badge {
  position: absolute;
  top: 7%; left: 8%;
  font-size: min(11cqmin, 10.5px); font-weight: 800;
  color: var(--c);
  background: rgba(0,0,0,.4);
  padding: 2px 7px;
  border-radius: 9px;
  z-index: 1;
  line-height: 1.35;
  max-width: 84%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---------- Analytics screen ---------- */
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }

.section-label {
  font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .6px;
  margin: 20px 0 10px;
}
.time-banner {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  background: var(--tile); border-radius: 14px; padding: 14px 16px;
  margin-top: 14px;
}
.time-banner b { font-size: 22px; font-weight: 850; color: var(--accent); }
.time-banner span { font-size: 13px; color: var(--muted); font-weight: 600; }

/* heatmap: weeks as columns, weekdays as the 7 rows */
.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
}
.hm-cell { aspect-ratio: 1; border-radius: 3px; background: var(--tile); }
.hm-cell.l0 { background: #20202a; }
.hm-cell.l1 { background: rgba(48,209,88,.4); }
.hm-cell.l2 { background: rgba(48,209,88,.7); }
.hm-cell.l3 { background: #30d158; }
.hm-cell.hm-today { outline: 1.5px solid var(--text); outline-offset: -1.5px; }
.heatmap-legend {
  display: flex; align-items: center; gap: 5px;
  justify-content: flex-end; margin-top: 8px;
  font-size: 11px; color: var(--muted);
}
.heatmap-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.heatmap-legend .l0 { background: #20202a; }
.heatmap-legend .l1 { background: rgba(48,209,88,.4); }
.heatmap-legend .l2 { background: rgba(48,209,88,.7); }
.heatmap-legend .l3 { background: #30d158; }

.goal-list { display: flex; flex-direction: column; gap: 8px; }
.goal-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: var(--tile); border: none; border-radius: 14px;
  padding: 12px 14px; cursor: pointer; color: var(--text);
}
.goal-row:active { background: var(--tile2); }
.gr-icon { font-size: 24px; flex: 0 0 auto; }
.gr-main { flex: 1 1 auto; min-width: 0; }
.gr-name { font-size: 15px; font-weight: 700; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gr-bar { height: 7px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.gr-bar > div { height: 100%; background: var(--c); border-radius: 4px; }
.gr-stat { flex: 0 0 auto; text-align: right; }
.gr-num { font-size: 13px; font-weight: 800; }
.gr-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- Reminder settings ---------- */
.reminder { background: var(--tile); border-radius: 14px; padding: 4px 14px; }
.reminder-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 0; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.reminder-row:last-of-type { border-bottom: none; }
.reminder-row > span { font-size: 15px; font-weight: 600; }
.reminder-row input[type=time] {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  font-size: 16px; font-weight: 700; padding: 8px 12px; border-radius: 10px;
}
.reminder-row input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 46px; height: 28px; border-radius: 999px;
  background: var(--line); position: relative; cursor: pointer; transition: background .2s;
  flex: 0 0 auto;
}
.reminder-row input[type=checkbox]::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s;
}
.reminder-row input[type=checkbox]:checked { background: var(--accent); }
.reminder-row input[type=checkbox]:checked::after { transform: translateX(18px); }
.reminder-foot { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.reminder-foot .ghost { padding: 9px 14px; font-size: 14px; }
.reminder-status { font-size: 13px; color: var(--muted); font-weight: 600; flex: 1 1 auto; }

/* ---------- Reorder / edit mode ---------- */
.icon-btn.active { background: var(--accent); color: #1a1200; }
.editing .tile:not(.dragging) { animation: wiggle .28s ease-in-out infinite alternate; }
/* in reorder mode the drag must not be hijacked by the browser as a scroll gesture */
.editing .tile { touch-action: none; }
.tile.dragging { z-index: 5; box-shadow: 0 12px 34px rgba(0,0,0,.55); opacity: .97; transition: none; }
.tile.drop-target { outline: 2px dashed var(--text); outline-offset: -4px; }
.reorder-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--tile); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 8px 8px 16px; margin-bottom: 12px;
}
.reorder-bar span { font-size: 14px; font-weight: 700; color: var(--muted); }
.reorder-bar button {
  background: var(--accent); color: #1a1200; border: none;
  border-radius: 10px; padding: 9px 18px; font-weight: 750; cursor: pointer;
}

/* Device-specific appearance and explicit controls. */
:root { color-scheme: dark; }
:root[data-theme="light"], :root[data-theme="eink"] {
  color-scheme: light;
  --bg: #ffffff; --bg2: #ffffff; --tile: #f0f1f3; --tile2: #e6e8eb;
  --text: #151515; --muted: #494949; --line: #747474; --accent: #b95800;
}
:root[data-theme="eink"] {
  --tile: #ffffff; --tile2: #ffffff; --text: #000000; --muted: #222222;
  --line: #000000; --accent: #27665d;
}
[data-theme="eink"] *, [data-theme="eink"] *::before, [data-theme="eink"] *::after {
  animation: none !important; transition: none !important; box-shadow: none !important;
  text-shadow: none !important; filter: none !important; backdrop-filter: none !important;
}
[data-theme="eink"] .tile { background: #fff; border: 2px solid #000; }
[data-theme="eink"] .tile .fc-area { fill: var(--c); opacity: .24; }
[data-theme="eink"] .tile .fc-line { stroke: var(--c); stroke: color-mix(in srgb, var(--c) 75%, #222); stroke-width: 3; opacity: 1; }
[data-theme="eink"] .sheet-backdrop { background: #aaa; }
[data-theme="eink"] .donecheck, [data-theme="eink"] .goalnum,
[data-theme="eink"] .bigprogress-pct { color: #000 !important; }
[data-theme="eink"] .primary, [data-theme="eink"] .seg-item.active { background: var(--accent); color: #fff; }
[data-theme="eink"] .chart path[stroke], [data-theme="eink"] .chart line { stroke: var(--c); stroke: color-mix(in srgb, var(--c) 75%, #222); }
[data-theme="eink"] .chart circle { fill: var(--c); stroke: #000; stroke-width: 1; }
[data-theme="eink"] .confetti-layer { display: none; }
[data-theme="eink"] .today-badge { background: #fff; color: #000; border: 1px solid #000; }
[data-theme="eink"] .hm-cell { border: 1px solid #000; }
[data-theme="eink"] .hm-cell.l0 { background: #fff; }
[data-theme="eink"] .hm-cell.l1 { background: #d3e6dd; }
[data-theme="eink"] .hm-cell.l2 { background: #7ba997; }
[data-theme="eink"] .hm-cell.l3 { background: #27665d; }
.primary { color: #1a1200; }
.sync-dot { padding: 0; border: 0; }
.notice { padding: 14px; border: 2px solid var(--accent); border-radius: 10px; color: var(--text); }
.help { color: var(--muted); font-size: 13px; line-height: 1.5; }
.control-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.control-row input { min-width: 0; flex: 1 1 140px; }
input[type="date"], input[type="number"], select {
  padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--tile); color: var(--text); font: inherit; max-width: 100%;
}
select { width: 100%; }
.file-label { position: relative; cursor: pointer; overflow: hidden; }
.file-label input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.file-label:focus-within { outline: 2px solid var(--accent); }
.history-list { max-height: 180px; overflow: auto; display: grid; gap: 5px; }
.history-row { padding: 12px; background: var(--tile); color: var(--text); border: 1px solid var(--line); border-radius: 8px; text-align: left; font: inherit; }

.tile { padding-bottom: 20px; }
.tile:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.entry-controls { border-top: 1px solid var(--line); padding-top: 14px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.tile-add { position: absolute; inset: 0; z-index: 1; border: 0; background: transparent; cursor: pointer; border-radius: inherit; }
/* Keep undo out of document flow: logging must never shift the tiles. */
.undo {
  position: fixed;
  right: max(14px, calc((100vw - 612px) / 2));
  bottom: calc(var(--safe-bottom) + 16px);
  z-index: 10;
  margin: 0;
  min-height: 44px;
  background: var(--bg2);
  border-color: var(--text);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .16);
}
[data-theme="eink"] .undo { box-shadow: none; }
[data-theme="light"] .primary, [data-theme="light"] .counter button.add,
[data-theme="light"] .chips button.active, [data-theme="light"] .seg-item.active,
[data-theme="light"] .icon-btn.active, [data-theme="light"] .reorder-bar button,
[data-theme="eink"] .counter button.add, [data-theme="eink"] .chips button.active,
[data-theme="eink"] .icon-btn.active, [data-theme="eink"] .reorder-bar button { color: #fff; }
[data-theme="light"] .hm-cell.l0, [data-theme="light"] .heatmap-legend .l0 { background: #e0e0e0; }
[data-theme="light"] .today-badge { background: #fff; color: #111; border: 1px solid var(--line); }
[data-theme="eink"] .counter button { border: 1px solid #000; }
[data-theme="eink"] .gr-bar > div { background: var(--c); background: color-mix(in srgb, var(--c) 75%, #222); }
[data-theme="eink"] .heatmap-legend i { border: 1px solid #000; }
[data-theme="eink"] .heatmap-legend .l0 { background: #fff; }
[data-theme="eink"] .heatmap-legend .l1 { background: #d3e6dd; }
[data-theme="eink"] .heatmap-legend .l2 { background: #7ba997; }
[data-theme="eink"] .heatmap-legend .l3 { background: #27665d; }

[data-theme="eink"] .chart path[fill^="url"] { fill: var(--c); opacity: .24; }
[data-theme="eink"] .detail-icon { background: #fff !important; border: 1px solid #000; }

/* Selected date remains legible in every theme, including E-ink. */
.entry-controls [aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 700; outline: 2px solid var(--text); outline-offset: 2px; }
.entry-status { padding: 12px; border: 1px solid var(--text); border-radius: 10px; font-weight: 600; }
.sheet-drag { position: sticky; top: -10px; z-index: 3; background: var(--bg2); padding: 6px 0 12px; text-align: center; touch-action: none; cursor: grab; user-select: none; }
.sheet-drag .sheet-handle { margin: 0 auto 6px; }
.sheet-drag span { color: var(--muted); font-size: 12px; }

.pair-code { display: block; padding: 16px 0; color: var(--text); font: 700 clamp(24px, 7vw, 38px) monospace; letter-spacing: .06em; text-align: center; user-select: all; }
#keySheet details { margin-top: 20px; }
#emptyConnectBtn { margin-top: 12px; }

/* Colour E-ink keeps labels and outlines black; colour is a secondary cue. */
[data-theme="eink"] .entry-controls [aria-pressed="true"] { background: #d3e6dd; color: #000; border-color: #000; outline-color: #000; }

.connection-status { border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-weight: 600; }
.recent-changes { margin-top: 16px; }
.recent-changes summary, #devicesDetails summary { padding: 12px 0; cursor: pointer; }
.change-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.change-row span { font-size: 14px; }
.change-row button { flex-shrink: 0; }

/* Account controls stay secondary to the everyday pairing flow. */
#keySheet.account-sheet .sheet-note { margin: 12px 0 18px; }
#accountRecovery > summary { padding: 10px 0; cursor: pointer; }

/* "Set up on your phone" guidance: account mode only; hidden in the legacy app. */
.setup-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0 0 14px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg2); }
.setup-banner .setup-text { flex: 1 1 220px; }
.setup-banner strong { display: block; font-size: 15px; }
.setup-banner .help, .setup-section .help { margin: 4px 0 0; }
.setup-banner .control-row { margin: 0; }
.setup-section { margin: 14px 0 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; }
.setup-section h3 { margin: 0; font-size: 15px; }
.setup-section .primary { margin-top: 12px; }

