/* Me Today — the grid is the only saturated thing on the screen. */

:root {
  color-scheme: light dark;

  --ground: #EDEFEA;
  --raised: #FAFCF9;
  --sunk:   #E2E6E0;
  --ink:    #16211E;
  --ink-soft: #55635E;
  --ink-faint: #8A968F;
  --rule:   #D9DFD9;
  --tile-off: #D7DCD6;
  --tile-off-ink: #6B7671;
  --sheet:  #FAFCF9;
  --strip:  #1B2422;
  --strip-ink: #EDF1EE;
  --accent: #0F6B57;

  --p-teal:#2F6F66;      --p-ochre:#A87F1E;   --p-vermilion:#B84A22;
  --p-olive:#5E7A2E;     --p-blue:#35619A;    --p-violet:#614391;
  --p-sage:#757B77;      --p-mulberry:#9B3A5E;--p-clay:#8A5A34;
  --p-forest:#2C5E3F;    --p-indigo:#3B4A8C;  --p-slate:#4A5B63;
  --pigment-ink: #F3F0EA;

  --ease: cubic-bezier(.32,.72,0,1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground:#0F1614; --raised:#18211E; --sunk:#1D2724;
    --ink:#E7ECE8; --ink-soft:#A3B0AA; --ink-faint:#7C8983;
    --rule:#28332F; --tile-off:#232D2A; --tile-off-ink:#7E8A85;
    --sheet:#141C1A; --strip:#E7ECE8; --strip-ink:#131B19;
    --accent:#63D2B1;
  }
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--ground); color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

#app {
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ------------------------------------------------------------------ header */
header {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1.25rem .4rem;
  font-size: .8rem; letter-spacing: .01em; color: var(--ink-faint);
  flex: none;
}
header .date { font-variant-numeric: tabular-nums; }
header .spacer { flex: 1; }
header button {
  appearance: none; border: none; background: none; cursor: pointer;
  font: inherit; font-weight: 590; color: var(--ink-soft);
  padding: .3rem .1rem; border-radius: 6px;
}
header button:active { opacity: .55; }
.dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  opacity: 0; transition: opacity .3s;
}
.dot.on { opacity: .8; }

/* -------------------------------------------------------------------- grid */
main { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
       padding: .5rem 1rem 1rem; overflow: hidden; }
/* Four rows of squares plus gaps come to ~1.35x the grid's width, so cap the
   width by the height available. Twelve tiles fit any phone without scrolling. */
#grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4.2%; touch-action: manipulation;
  width: min(380px, 92vw, calc((100dvh - 7.5rem) / 1.35));
}

.tile {
  --fill: 1;
  position: relative; appearance: none; border: none; font: inherit; cursor: pointer;
  aspect-ratio: 1; border-radius: 25%; overflow: hidden; padding: 6% 4%;
  background: var(--tile-off); color: var(--tile-off-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  transition: transform .18s var(--ease);
}
.tile::before {
  content: ""; position: absolute; inset: 0; background: var(--hue);
  opacity: var(--fill); transition: opacity .55s var(--ease);
}
.tile > * { position: relative; z-index: 1; }
.tile .sym { font-size: clamp(1.4rem, 7.5vw, 2rem); line-height: 1; transition: filter .55s ease, opacity .55s ease; }
.tile .lbl {
  font-size: clamp(.58rem, 2.7vw, .72rem); font-weight: 590; line-height: 1.1;
  text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile[data-lit="1"] { color: var(--pigment-ink); }
.tile[data-lit="0"] .sym { filter: grayscale(1); opacity: .45; }
.tile:active { transform: scale(.93); }
.tile:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.tile .pip {
  position: absolute; top: 9%; right: 9%; width: 5px; height: 5px;
  border-radius: 50%; background: rgba(255,255,255,.8); z-index: 2;
}
.tile[data-lit="0"] .pip { background: var(--tile-off-ink); }

.tile .clock { display: none; font-family: var(--mono); font-size: .95rem; font-variant-numeric: tabular-nums; }
.tile.running { color: var(--pigment-ink); }
.tile.running .sym { display: none; }
.tile.running .clock { display: block; }
.tile.running::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; z-index: 2;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.85);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { opacity: .22; } 50% { opacity: .9; } }

/* edit mode */
#grid.editing .tile { animation: jiggle .28s ease-in-out infinite alternate; }
#grid.editing .tile:nth-child(even) { animation-delay: .14s; }
@keyframes jiggle { from { transform: rotate(-.7deg); } to { transform: rotate(.7deg); } }
.tile .kill {
  display: none; position: absolute; top: 6%; left: 6%; z-index: 3;
  width: 24px; height: 24px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--ink); color: var(--ground); font-size: 14px; line-height: 24px;
  padding: 0; font-weight: 600;
}
#grid.editing .tile .kill { display: block; }
.tile.dragging { animation: none !important; z-index: 10; transform: scale(1.08); transition: none; }
.tile.shifting { transition: transform .22s var(--ease); animation: none !important; }
.tile.add {
  background: none; border: 2px dashed var(--rule); color: var(--ink-faint);
  display: none; align-items: center; justify-content: center;
}
#grid.editing .tile.add { display: flex; animation: none; }
.tile.add .sym { font-size: 1.6rem; opacity: .5; }

/* ------------------------------------------------------------------- strip */
#strip {
  position: fixed; left: max(.85rem, env(safe-area-inset-left));
  right: max(.85rem, env(safe-area-inset-right));
  bottom: calc(.85rem + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--strip); color: var(--strip-ink); border-radius: 18px;
  padding: .7rem .6rem .55rem .95rem; display: flex; flex-direction: column; gap: .5rem;
  transform: translateY(160%); transition: transform .34s var(--ease);
  box-shadow: 0 14px 34px -18px rgba(0,0,0,.5);
  max-width: 460px; margin: 0 auto;
}
#strip.up { transform: translateY(0); }
.strip-row { display: flex; align-items: center; gap: .35rem; }
.strip-name { flex: 1; min-width: 0; font-size: .82rem; font-weight: 590; opacity: .72;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  appearance: none; border: none; cursor: pointer; font: inherit;
  font-size: .78rem; font-weight: 590; border-radius: 999px; padding: .32rem .7rem;
  background: rgba(128,128,128,.24); color: inherit; font-variant-numeric: tabular-nums;
}
.chip:active { opacity: .6; }
#offsets { display: none; gap: .3rem; grid-template-columns: repeat(3, 1fr); }
#offsets.show { display: grid; }
#bar { height: 2px; background: currentColor; opacity: .3; border-radius: 2px; transform-origin: left; }

/* ------------------------------------------------------------------ sheets */
.sheet {
  position: fixed; inset: 0; z-index: 60; background: var(--sheet);
  display: none; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: rise .3s var(--ease);
}
.sheet.show { display: flex; }
@keyframes rise { from { transform: translateY(3%); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex; align-items: center; gap: .75rem; padding: .95rem 1.15rem;
  flex: none; border-bottom: 1px solid var(--rule);
}
.sheet-head h2 { margin: 0; font-size: 1.02rem; font-weight: 640; flex: 1; letter-spacing: -.01em; }
.sheet-head button {
  appearance: none; border: none; background: none; font: inherit; font-weight: 590;
  color: var(--accent); cursor: pointer; padding: .2rem; font-size: .95rem;
}
.sheet-head button.quiet { color: var(--ink-faint); }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 1rem 1.15rem 2rem; }

textarea, input[type="text"], input[type="number"] {
  width: 100%; border: none; background: var(--sunk); border-radius: 12px;
  padding: .8rem .9rem; font: inherit; font-size: 1rem; color: var(--ink);
  outline: none; user-select: text; -webkit-user-select: text;
}
textarea { resize: none; min-height: 8.5rem; line-height: 1.45; }
textarea:focus, input:focus { box-shadow: inset 0 0 0 2px var(--accent); }

.tagrow { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .8rem; }
.tag {
  appearance: none; border: 1px solid var(--rule); background: none; color: var(--ink-soft);
  border-radius: 999px; padding: .35rem .8rem; font: inherit; font-size: .82rem;
  font-weight: 590; cursor: pointer;
}
.tag[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--raised); }

.field { margin-bottom: 1.05rem; }
.field label {
  display: block; font-size: .72rem; font-weight: 640; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-faint); margin-bottom: .4rem;
}
.seg { display: flex; gap: .35rem; flex-wrap: wrap; }
.seg button {
  appearance: none; border: 1px solid var(--rule); background: none; color: var(--ink-soft);
  border-radius: 10px; padding: .45rem .75rem; font: inherit; font-size: .85rem;
  font-weight: 590; cursor: pointer; flex: 1; min-width: 4.5rem;
}
.seg button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--ground); }
.swatches { display: flex; gap: .5rem; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 30%; border: none; cursor: pointer;
  background: var(--hue); padding: 0;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ground), 0 0 0 4px var(--ink); }

.rows { display: flex; flex-direction: column; }
.row {
  display: flex; gap: .8rem; align-items: baseline; padding: .8rem 0;
  border-bottom: 1px solid var(--rule); cursor: pointer;
}
.row:last-child { border-bottom: none; }
.row .t { font-family: var(--mono); font-size: .78rem; color: var(--ink-faint);
  font-variant-numeric: tabular-nums; flex: none; width: 3.2rem; }
.row .body { flex: 1; min-width: 0; }
.row .who { font-size: .92rem; font-weight: 590; }
.row .txt { font-size: .92rem; color: var(--ink-soft); line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; }
.row .mark { font-size: .7rem; color: var(--accent); font-weight: 640; }
.empty { color: var(--ink-faint); font-size: .92rem; padding: 2rem 0; text-align: center; }

.composer { display: flex; flex-direction: column; gap: .55rem; margin-bottom: 1.4rem; }
.btn {
  appearance: none; border: none; cursor: pointer; font: inherit; font-weight: 600;
  border-radius: 12px; padding: .7rem 1rem; background: var(--accent); color: var(--raised);
  font-size: .95rem;
}
.btn.ghost { background: var(--sunk); color: var(--ink); }
.btn:active { opacity: .7; }
.btn:disabled { opacity: .35; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  #grid.editing .tile { animation: none; }
}
