/* web-hamster — styles */
/* Light is the default palette. The theme switch writes light|system|dark to
   <html data-theme>; "light" simply matches no dark rule below, "dark" forces
   the dark palette, "system" defers to the OS via the @media block. */
:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #ffffff;
  --panel-2: #faf8f3;
  --ink: #2c2a26;
  --ink-soft: #6f6a61;
  --ink-faint: #9b958a;
  --line: #e7e2d8;
  --line-strong: #d8d2c5;
  --accent: #c8632b;        /* hamster orange */
  --accent-soft: #f3dcc9;
  --accent-ink: #a44e1f;
  --running: #2f8f5b;
  --running-soft: #e3f3ea;
  --running-edit-hover: rgba(255,255,255,.5);  /* tint on a running row's editable fields */
  --danger: #b23b3b;
  --shadow: 0 1px 2px rgba(40,34,25,.06), 0 6px 18px rgba(40,34,25,.06);
  --radius: 10px;
  --cat-0: #95CACF; --cat-1: #A2CFB6; --cat-2: #D1DEA1;
  --cat-3: #E4C384; --cat-4: #DE9F7B; --cat-5: #C9A8CE; --cat-6: #B8C4D9;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
}

/* ---- Dark palette ----
   Applied in two cases that MUST stay in sync (no build step = no mixin):
     (a) the user explicitly chose Dark           -> :root[data-theme="dark"]
     (b) the user is on System and the OS is dark  -> the @media block below
   If you edit a dark token, edit it in BOTH places. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #211f1c; --panel: #2b2926; --panel-2: #322f2b;
  --ink: #ece8e0; --ink-soft: #b3ada2; --ink-faint: #837d72;
  --line: #3b3833; --line-strong: #4a463f;
  --accent: #e2814b; --accent-soft: #4a382c; --accent-ink: #f0a071;
  --running: #5cc488; --running-soft: #2a3a30;
  --running-edit-hover: rgba(0,0,0,.25);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
}
:root[data-theme="system"] { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"], :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #211f1c; --panel: #2b2926; --panel-2: #322f2b;
    --ink: #ece8e0; --ink-soft: #b3ada2; --ink-faint: #837d72;
    --line: #3b3833; --line-strong: #4a463f;
    --accent: #e2814b; --accent-soft: #4a382c; --accent-ink: #f0a071;
    --running: #5cc488; --running-soft: #2a3a30;
    --running-edit-hover: rgba(0,0,0,.25);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
  }
}

/* One-shot cross-fade when the user flips themes (added by JS for ~320ms).
   Excludes the switch thumb so its glide stays a transform, not a fade. */
:root.theme-animating *:not(.thumb) {
  transition: background-color .28s ease, border-color .28s ease,
              color .28s ease, box-shadow .28s ease, fill .28s ease !important;
}
@media (prefers-reduced-motion: reduce) {
  :root.theme-animating *:not(.thumb) { transition: none !important; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input { font-family: inherit; font-size: inherit; }

.app { max-width: 920px; margin: 0 auto; padding: 18px 16px 80px; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 18px; letter-spacing: -.2px; }
.brand .logo { font-size: 22px; filter: saturate(1.1); }
.brand small { font-weight: 500; color: var(--ink-faint); font-size: 12px; }
.spacer { flex: 1; }

.iconbtn {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-soft);
  width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 16px; box-shadow: var(--shadow);
}
.iconbtn:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---- Theme switch (light / system / dark) ---- */
:root {
  --ts-h: 34px;        /* matches .iconbtn height */
  --ts-seg: 28px;      /* per-segment width — JS reads this for the thumb step */
  --ts-pad: 3px;
  --ts-thumb-h: 26px;
  --ts-ease: cubic-bezier(.22,.61,.36,1);
}
.themeswitch {
  position: relative; display: inline-flex; align-items: center;
  height: var(--ts-h); padding: var(--ts-pad);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.themeswitch .thumb {
  position: absolute; top: var(--ts-pad); left: var(--ts-pad);
  width: var(--ts-seg); height: var(--ts-thumb-h); border-radius: 7px;
  background: var(--panel); box-shadow: var(--shadow);
  transform: translateX(0); pointer-events: none; z-index: 0;
}
.themeswitch.ready .thumb { transition: transform .26s var(--ts-ease); }
.themeswitch .ts-opt {
  position: relative; z-index: 1; flex: none;
  width: var(--ts-seg); height: var(--ts-thumb-h); padding: 0;
  border: none; background: transparent; color: var(--ink-faint);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px; transition: color .2s var(--ts-ease);
}
.themeswitch .ts-opt svg { display: block; }
.themeswitch .ts-opt:hover[aria-checked="false"] { color: var(--ink-soft); }
.themeswitch .ts-opt[aria-checked="true"] { color: var(--accent); }
.themeswitch .ts-opt:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.themeswitch .ts-opt:focus:not(:focus-visible) { box-shadow: none; }
@media (prefers-reduced-motion: reduce) {
  .themeswitch.ready .thumb, .themeswitch .ts-opt { transition: none; }
}
/* On narrow screens, drop the decorative subtitle so the switch + buttons fit */
@media (max-width: 480px) {
  .brand small { display: none; }
}

/* ---- Undo / redo ---- */
.histbar {
  display: inline-flex; align-items: center; gap: 1px;
  height: var(--ts-h); padding: var(--ts-pad);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.histbar .hist {
  background: transparent; border: none; color: var(--ink-soft);
  width: var(--ts-seg); height: var(--ts-thumb-h); padding: 0;
  border-radius: 7px; font-size: 17px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.histbar .hist:hover:not(:disabled) { color: var(--ink); background: var(--panel); box-shadow: var(--shadow); }
.histbar .hist:disabled { color: var(--ink-faint); opacity: .4; cursor: default; }
.histbar .hist:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.histbar .hist:focus:not(:focus-visible) { box-shadow: none; }

/* ---- Command bar ---- */
.entry {
  position: relative; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px;
  display: flex; align-items: center; gap: 6px;
}
.entry:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.entry .prompt { color: var(--accent); font-weight: 700; padding-left: 10px; font-family: var(--mono); }
#entry-input {
  flex: 1; border: none; outline: none; background: transparent; color: var(--ink);
  font-size: 15px; padding: 9px 4px; font-family: var(--mono);
}
#entry-input::placeholder { color: var(--ink-faint); font-family: var(--sans); }
.entry .addbtn {
  background: var(--running); color: #fff; border: none; border-radius: 8px;
  padding: 8px 16px; font-weight: 600;
}
.entry .addbtn:hover { filter: brightness(1.08); }
.entry .stopbtn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-weight: 600;
}
.entry .stopbtn:not([disabled]):hover { filter: brightness(1.08); }
.entry .stopbtn[disabled] { background: var(--line-strong); color: var(--ink-faint); cursor: default; }

/* ---- Live preview ---- */
.preview { min-height: 20px; margin: 7px 4px 0; font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.preview .chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; color: var(--ink-soft); }
.preview .chip b { color: var(--ink); font-weight: 600; }
.preview .chip.time { font-family: var(--mono); }
.preview .chip.cat { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.preview .chip.tag { color: var(--accent-ink); }
.preview .err { color: var(--danger); }
.preview .hint { color: var(--ink-faint); }

/* ---- Autocomplete ---- */
.ac {
  position: absolute; top: calc(100% + 4px); left: 4px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 9px;
  box-shadow: var(--shadow); min-width: 220px; max-height: 280px; overflow-y: auto; padding: 4px;
}
.ac .item { padding: 6px 10px; border-radius: 6px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ac .item .k { font-family: var(--mono); }
.ac .item .meta { margin-left: auto; color: var(--ink-faint); font-size: 11.5px; }
.ac .item.sel { background: var(--accent-soft); color: var(--accent-ink); }
.ac .item .dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* ---- Range nav ---- */
.range {
  display: flex; align-items: center; gap: 6px; margin: 16px 0 10px;
}
.range .nav { background: var(--panel); border: 1px solid var(--line); color: var(--ink-soft);
  width: 30px; height: 30px; border-radius: 8px; }
.range .nav:hover { color: var(--ink); }
.range .title { font-weight: 700; font-size: 16px; min-width: 180px; }
.range .title small { display: block; font-weight: 500; color: var(--ink-faint); font-size: 11.5px; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { background: transparent; border: none; color: var(--ink-soft); padding: 5px 12px; border-radius: 6px; font-weight: 500; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.todaybtn { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--ink-soft); }
.todaybtn:hover { color: var(--ink); }

.searchbar { margin: 8px 0 4px; display: none; }
.searchbar.open { display: block; }
.searchbar input { width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--panel); color: var(--ink); outline: none; }
.searchbar input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- Fact list ---- */
.facts { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.dayhdr { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 14px;
  background: var(--panel-2); border-bottom: 1px solid var(--line); font-size: 12.5px; }
.dayhdr .d { font-weight: 700; color: var(--ink); text-transform: uppercase; letter-spacing: .4px; }
.dayhdr .t { font-family: var(--mono); color: var(--ink-soft); font-weight: 600; }

.fact { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.fact:last-child { border-bottom: none; }
.fact:hover { background: var(--panel-2); }
.fact.sel { background: var(--accent-soft); }
.fact.running { background: var(--running-soft); }
.fact .catbar { width: 4px; align-self: stretch; border-radius: 3px; flex: none; background: var(--line-strong); }
.fact .time { font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft); width: 104px; flex: none; padding-top: 1px; white-space: nowrap; }
.fact .time .t-sep { margin: 0 3px; color: var(--ink-faint); }
.fact .time .ongoing { color: var(--running); }
.fact .body { flex: 1; min-width: 0; }
.fact .line1 { padding-top: 1px; }
.fact .act { font-weight: 600; }
.fact .cat { color: var(--ink-faint); font-weight: 500; }
.fact .cat-empty { opacity: 0; transition: opacity .12s; }
.fact:hover .cat-empty, .fact.sel .cat-empty { opacity: .55; }
.fact .desc { color: var(--ink-soft); font-style: italic; }
.fact .tags { display: inline-flex; gap: 4px; flex-wrap: wrap; vertical-align: middle; }

/* editable fields + the note block */
.fact .editable { border-radius: 4px; cursor: text; padding: 0 2px; margin: 0 -2px;
  box-shadow: inset 0 -1px 0 transparent; transition: background .1s, box-shadow .1s; }
.fact .editable:hover { background: var(--panel); box-shadow: inset 0 -1px 0 var(--line-strong); }
.fact.running .editable:hover { background: var(--running-edit-hover); }
.fact .note { margin-top: 3px; color: var(--ink-soft); font-style: italic; font-size: 13px;
  white-space: pre-wrap; word-break: break-word; cursor: text; border-radius: 5px;
  padding: 2px 5px; margin-left: -5px; max-width: 60ch; }
.fact .note:hover { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.fact.running .note:hover { background: var(--running-edit-hover); }
.fact .note-empty { font-style: normal; color: var(--ink-faint); opacity: 0; transition: opacity .12s; }
.fact:hover .note-empty, .fact.sel .note-empty { opacity: .8; }
.inline-edit { font-family: inherit; font-size: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--accent); border-radius: 6px; padding: 2px 6px; outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft); }
.inline-edit.time-edit { width: 64px; font-family: var(--mono); text-align: center; }
.inline-edit.note-edit { display: block; width: 100%; max-width: 60ch; margin-top: 3px; resize: vertical;
  line-height: 1.5; min-height: 2.6em; font-style: normal; }
.fact .tag { background: var(--accent-soft); color: var(--accent-ink); border-radius: 5px; padding: 0 6px; font-size: 11.5px; }
.fact .dur { font-family: var(--mono); font-weight: 600; color: var(--ink); white-space: nowrap; }
.fact.running .dur { color: var(--running); }
.fact .acts { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.fact:hover .acts, .fact.sel .acts { opacity: 1; }
.fact .acts button { background: transparent; border: none; color: var(--ink-faint); width: 26px; height: 26px; border-radius: 6px; font-size: 14px; }
.fact .acts button:hover { background: var(--line); color: var(--ink); }
.fact .acts button.del:hover { color: var(--danger); }
/* Two-step delete: the first click arms this red "Delete?" button (kept visible
   even when the row isn't hovered); a second click on the same row confirms. */
.fact.confirming .acts { opacity: 1; }
.fact .acts button.del.confirm { width: auto; padding: 0 9px; font-size: 12px; font-weight: 600; color: #fff; background: var(--danger); }
.fact .acts button.del.confirm:hover { color: #fff; background: var(--danger); filter: brightness(1.08); }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--running); margin-right: 5px; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.empty { padding: 44px 20px; text-align: center; color: var(--ink-faint); }
.empty .big { font-size: 30px; margin-bottom: 8px; }
.empty code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-family: var(--mono); color: var(--ink-soft); }

/* ---- Totals ---- */
.totals { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.totals .head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; }
.totals .head .grand { font-weight: 700; font-family: var(--mono); }
.totals .head .summary { color: var(--ink-soft); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.totals .head .caret { color: var(--ink-faint); transition: transform .15s; }
.totals.open .head .caret { transform: rotate(90deg); }
.totals .body { display: none; padding: 4px 14px 16px; }
.totals.open .body { display: block; }
.stackbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 6px 0 16px; background: var(--panel-2); }
.stackbar > span { height: 100%; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.chart h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-faint); }
.bar { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 8px; margin: 5px 0; font-size: 12.5px; }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.bar .track { background: var(--panel-2); border-radius: 5px; height: 14px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 5px; background: var(--accent); }
.bar .val { font-family: var(--mono); color: var(--ink-soft); }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(20,16,12,.45); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-bg.open { display: flex; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 540px; max-height: 88vh; overflow-y: auto; }
.modal h2 { margin: 0; padding: 16px 18px; border-bottom: 1px solid var(--line); font-size: 16px; display: flex; align-items: center; }
.modal h2 .x { margin-left: auto; background: transparent; border: none; color: var(--ink-faint); font-size: 20px; }
.modal .section { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .section:last-child { border-bottom: none; }
.modal .section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-faint); }
.modal label { display: block; margin-bottom: 6px; color: var(--ink-soft); }
.modal input[type=time], .modal input[type=file], .modal input[type=password], .modal input[type=text] { padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel-2); color: var(--ink); }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; }

/* Cloud-sync controls */
#sync-status.sync-err { color: var(--danger); }
.modal input:disabled { opacity: .5; cursor: not-allowed; }

/* On/off toggle switch for "Sync this browser" */
.switchrow { display: flex; align-items: center; gap: 10px; cursor: pointer; margin-bottom: 12px; color: var(--ink); }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
.switch .switch-track { position: absolute; inset: 0; background: var(--line-strong); border-radius: 999px; transition: background .18s; }
.switch .switch-track::before { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: transform .18s; }
.switch input:checked + .switch-track { background: var(--running); }
.switch input:checked + .switch-track::before { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.switch input:disabled + .switch-track { opacity: .5; cursor: not-allowed; }

/* Identity row: a read-only, click-to-copy box + a small reveal toggle */
.idlabel { margin-bottom: 6px; }
.idrow { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.idrow .sharelink { flex: 1; margin: 0; min-width: 0; }
.eyebtn { flex: none; width: 34px; height: 34px; border-radius: 8px; font-size: 14px; line-height: 1;
  background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--ink-soft); cursor: pointer; }
.eyebtn:hover:not(:disabled) { border-color: var(--accent); color: var(--ink); }
.eyebtn[aria-pressed="true"] { border-color: var(--accent); }
.eyebtn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.eyebtn:disabled { opacity: .5; cursor: not-allowed; }

/* The identity box: tap to copy the share link (not a select-the-text field) */
.sharelink { display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel-2);
  cursor: pointer; user-select: none; -webkit-user-select: none; }
.sharelink:hover { border-color: var(--accent); }
.sharelink:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.sharelink.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.sharelink .sharelink-url { font-family: var(--mono); font-size: 13px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.sharelink .sharelink-url.masked { color: var(--ink-faint); letter-spacing: 2px; } /* placeholder dots read as masked */
.sharelink .sharelink-copy { color: var(--accent); font-size: 12px; font-weight: 600; flex: none; white-space: nowrap; }
.sharelink.copied { border-color: var(--running); }
.sharelink.copied .sharelink-copy { color: var(--running); }
/* Inline import form (replaces the native prompt — works on mobile) */
.importbox { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.importbox[hidden] { display: none; }
#sync-import-input { flex: 1 1 200px; min-width: 0; }
.btn { background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--ink); border-radius: 8px; padding: 7px 13px; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.muted { color: var(--ink-faint); font-size: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

kbd { font-family: var(--mono); font-size: 11px; background: var(--panel-2); border: 1px solid var(--line-strong);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--ink-soft); }
.shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: 12.5px; }
.shortcuts div { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-soft); }

/* =========================================================================
   LONG-WORD WRAPPING (all viewports)
   User content — activity names, categories, tags, notes, and the URLs/words
   echoed in the live preview — can contain long unbreakable strings. Without
   this they overflow their box: clipped & cut off in the fact list, and forcing
   horizontal PAGE scroll in the un-clipped live preview. `overflow-wrap:anywhere`
   also shrinks each element's min-content, so the flex/grid tracks can shrink
   and nothing pushes past a phone's viewport. min-width:0 lets the flex/grid
   ancestors actually shrink below their content.
   ========================================================================= */
.fact .body, .fact .line1, .fact .tags, .preview { min-width: 0; }
.fact .act, .fact .cat, .fact .tag, .fact .note,
.preview .chip, .ac .item .k { overflow-wrap: anywhere; }
.preview .chip { min-width: 0; max-width: 100%; }

/* =========================================================================
   MOBILE & TOUCH
   All rules below are additive — they only take effect on narrow viewports
   (max-width:540px), no-hover devices (hover:none), or coarse pointers
   (pointer:coarse). The desktop experience above is left untouched.
   NOTE: never override --ts-seg in a media query — app.js caches it once on
   load to position the theme-switch thumb; changing it desyncs the thumb.
   ========================================================================= */

/* ---- Global base (safe everywhere) ---- */
:root {
  -webkit-tap-highlight-color: rgba(200, 99, 43, .24);  /* branded tap flash */
  -webkit-text-size-adjust: 100%;                       /* no text inflation on rotate */
  text-size-adjust: 100%;
}
.ac, .modal { overscroll-behavior-y: contain; }          /* don't chain scroll to the page */

/* ---- Layout at phone widths ----
   Breakpoint is 540px, NOT 430px: modern large phones are wider than people
   expect — the iPhone 16/17 Pro Max report a 440px CSS viewport, big Androids
   430–450px. A 430px cutoff left those phones on the desktop layout (the bug
   report: "responsive looks right on my desktop but my Pro Max shows the old
   layout"). 540px covers every current phone in portrait with headroom while
   still leaving tablets (≥600px) and desktop on the rich multi-column layout. */
@media (max-width: 540px) {
  .app { padding: 14px 12px calc(72px + env(safe-area-inset-bottom)); }

  /* Topbar: put the brand on its own row so the controls (undo/redo + theme +
     search + settings — too many to fit beside the brand on a phone) cluster
     together, right-aligned, on a tidy second row instead of orphaning one. */
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar .brand { flex: 1 1 100%; font-size: 16px; white-space: nowrap; }
  .brand .logo { font-size: 19px; }

  /* Range nav: wrap, put the title on its own line, drop the pushing spacer */
  .range { flex-wrap: wrap; gap: 6px; margin: 12px 0 10px; }
  .range .title { min-width: 0; font-size: 15px; flex: 1 1 100%; order: -1; }
  .range .spacer { display: none; }

  /* Command bar: slimmer buttons, and let the input shrink (a flex <input>
     defaults to min-width:auto = its intrinsic ~170px, which overflows the bar
     and pushes "Add" off-screen on a ~320px phone). */
  .entry .stopbtn, .entry .addbtn { padding: 8px 12px; }
  #entry-input { min-width: 0; }

  /* Fact rows: a compact 2-row grid that actually fills the width. The body
     (activity + category + tags + note) leads with the duration pinned
     top-right — the headline pairing — and the time-range shares one bottom
     utility row with the action buttons, reclaiming the space the old
     "time …… dur" gap and the dedicated actions row left empty. A long
     multi-line note just grows the body; the bottom row stays beneath it. */
  .fact {
    display: grid;
    grid-template-columns: 4px minmax(0, 1fr) auto;
    grid-template-areas:
      "bar body dur"
      "bar time acts";
    column-gap: 10px;
    row-gap: 7px;
    padding: 11px 13px;
  }
  .fact .catbar { grid-area: bar; }                                  /* spans both rows */
  .fact .body   { grid-area: body; align-self: start; }
  .fact .dur    { grid-area: dur;  justify-self: end; align-self: start; }
  .fact .time   { grid-area: time; width: auto; align-self: center; }
  .fact .acts   { grid-area: acts; justify-self: end; align-self: center; opacity: 1; }
  .fact .note   { max-width: none; margin-top: 4px; }

  /* Chart bars: narrower name column */
  .bar { grid-template-columns: 64px 1fr auto; gap: 8px; }

  /* Shortcuts: one column */
  .shortcuts { grid-template-columns: 1fr; }
}

/* ---- Reveal hover-gated affordances on no-hover (touch) devices ---- */
@media (hover: none) {
  .fact .acts       { opacity: 1; }    /* edit/resume/delete: unreachable on touch otherwise */
  .fact .cat-empty  { opacity: .55; }  /* the "@…" add-category hint */
  .fact .note-empty { opacity: .8; }   /* the "+ note" hint */
}

/* ---- Enlarge tap targets on coarse pointers (desktop is pointer:fine) ---- */
@media (pointer: coarse) {
  .iconbtn { width: 44px; height: 44px; font-size: 18px; }
  .range .nav { width: 40px; height: 40px; }
  .seg button { padding: 9px 14px; }
  .fact .acts button { width: 40px; height: 40px; font-size: 16px; }
  .entry .stopbtn, .entry .addbtn { padding: 11px 16px; }

  /* Grow the theme switch to a 44px-tall tap target. Only the VERTICAL vars are
     touched — --ts-seg (horizontal) is cached by app.js for the thumb, so
     changing it would desync the slider; the height vars are never read. */
  .themeswitch { --ts-h: 44px; --ts-thumb-h: 38px; }
  /* Match the undo/redo control to the same 44px tap target. */
  .histbar { --ts-h: 44px; --ts-thumb-h: 38px; }
  .histbar .hist { width: 38px; font-size: 20px; }

  /* Kill iOS Safari focus-zoom: every focusable control must be >=16px.
     The explicit ID/class line beats #entry-input's higher specificity. */
  input, textarea, select { font-size: 16px; }
  #entry-input, .searchbar input, .modal input { font-size: 16px; }
}
