/* Shared UI and motion base for hald.run and its apps.
   Copy ui.css and ui.js into a new app, then add only app-specific rules in its own stylesheet. */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e3e3e0;
  --accent: #2f6f5e;
  --review: #b26a00;
  --review-bg: #fff3df;
  --danger: #b3261e;
  --glass-bg: rgb(255 255 255 / 0.82);
  --glass-border: rgb(0 0 0 / 0.07);
  --glass-shadow: inset 0 0.5px 0 rgb(255 255 255 / 0.9), 0 8px 28px rgb(0 0 0 / 0.10);
  --pill-bg: rgb(0 0 0 / 0.075);
  --tab-icon: rgb(28 28 30 / 0.56);
  --tab-icon-active: #1c1c1e;
  --container-max: 640px;
  --ease-out: cubic-bezier(0.33, 1, 0.68, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214;
    --surface: #1c1c1f;
    --text: #ececef;
    --muted: #9a9aa1;
    --line: #2c2c31;
    --accent: #7cc4ad;
    --review: #f0b660;
    --review-bg: #3a2c14;
    --danger: #f2827a;
    --glass-bg: rgb(22 22 25 / 0.84);
    --glass-border: rgb(255 255 255 / 0.12);
    --glass-shadow: inset 0 0.5px 0 rgb(255 255 255 / 0.16), 0 10px 30px rgb(0 0 0 / 0.48);
    --pill-bg: rgb(255 255 255 / 0.16);
    --tab-icon: rgb(236 236 239 / 0.70);
    --tab-icon-active: #ffffff;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121214;
  --surface: #1c1c1f;
  --text: #ececef;
  --muted: #9a9aa1;
  --line: #2c2c31;
  --accent: #7cc4ad;
  --review: #f0b660;
  --review-bg: #3a2c14;
  --danger: #f2827a;
  --glass-bg: rgb(22 22 25 / 0.84);
  --glass-border: rgb(255 255 255 / 0.12);
  --glass-shadow: inset 0 0.5px 0 rgb(255 255 255 / 0.16), 0 10px 30px rgb(0 0 0 / 0.48);
  --pill-bg: rgb(255 255 255 / 0.16);
  --tab-icon: rgb(236 236 239 / 0.70);
  --tab-icon-active: #ffffff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
  animation: page-in 200ms var(--ease-out) both;
}

h1, h2 { margin: 0; font-weight: 600; }

a { color: var(--accent); text-decoration: none; }
a, button, summary { -webkit-tap-highlight-color: transparent; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

button, input, select { font: inherit; color: inherit; }

button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: transform 220ms var(--ease-out), opacity 180ms ease;
}

button:not(.link):not(.row-button):active { transform: scale3d(0.97, 0.97, 1); }

button[type="submit"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
button.secondary { background: none; border-color: var(--accent); color: var(--accent); font-size: 14px; }
button.link { border: 0; background: none; color: var(--muted); padding: 0; }
button.row-button { width: 100%; border: 0; border-radius: 0; background: none; color: var(--text); padding: 14px; text-align: left; }
button.danger, button.secondary.danger, button.link.danger, button.row-button.danger { color: var(--danger); }
button.secondary.danger { border-color: var(--danger); }

input, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.card :is(input, select), .detail :is(input, select), .modal-box :is(input, select) { background: var(--bg); }

.error { color: var(--danger); margin: 0; }
.muted, .help { margin: 0; font-size: 13px; color: var(--muted); }
.help code { overflow-wrap: anywhere; }
.notice { color: var(--accent); margin: 0; }
.loading, .empty { color: var(--muted); text-align: center; }

/* Reusable layout & surface primitives */
.card { background: var(--surface); border-radius: 12px; padding: 14px; margin-bottom: 16px; }
.card h2 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 10px; }
.panel { background: var(--surface); border-radius: 12px; overflow: hidden; }
.row-link { display: flex; justify-content: space-between; padding: 14px; color: var(--text); border-bottom: 1px solid var(--line); }
.row-link span { color: var(--muted); }

.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.switch { width: 30px; height: 18px; border-radius: 9px; background: var(--line); position: relative; }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%; background: var(--surface);
  transition: transform 180ms var(--ease-out);
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(12px); }

.more { margin-top: 12px; }
.more summary { display: block; color: var(--accent); font-size: 14px; cursor: pointer; list-style: none; }
.more summary::-webkit-details-marker { display: none; }

/* Floating iOS capsule tab bar (supports 2..5 tabs via --tabs and --active). */
body.with-tabs main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

.tabs {
  --tabs: 3;
  --active: 0;
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(12px, calc(env(safe-area-inset-bottom) - 14px));
  margin-inline: auto;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(var(--tabs), 1fr);
  width: min(calc(var(--tabs) * 76px + 8px), calc(100vw - 32px));
  padding: 4px;
  border-radius: 999px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

.tabs::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc((100% - 8px) / var(--tabs));
  border-radius: 999px;
  background: var(--pill-bg);
  transform: translate3d(calc(var(--active, 0) * 100%), 0, 0);
  transition: transform 300ms var(--ease-out);
  will-change: transform;
  pointer-events: none;
}

.tabs a {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  height: 46px;
  border-radius: 999px;
  color: var(--tab-icon);
  transition: color 220ms var(--ease-out), transform 180ms var(--ease-out), opacity 180ms ease;
}

.tabs a.active { color: var(--tab-icon-active); }
.tabs a:active { transform: scale3d(0.92, 0.92, 1); opacity: 0.75; }

.tabs svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-width 220ms var(--ease-out);
}
.tabs a.active svg { stroke-width: 2.15; }

/* Subtle theme toggle button ([data-theme-toggle]); swaps moon/sun purely via CSS. */
button.theme-toggle {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
}
button.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
button.theme-toggle .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) button.theme-toggle .icon-moon { display: none; }
  :root:not([data-theme="light"]) button.theme-toggle .icon-sun { display: block; }
}
:root[data-theme="dark"] button.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] button.theme-toggle .icon-sun { display: block; }

/* Subtle inline circular '+' action button, sized to match 13px uppercase section headings. */
.add-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--line);
  color: var(--muted);
  transition: transform 180ms var(--ease-out), opacity 180ms ease, color 180ms ease;
}
/* Generous thumb hit area without enlarging the visual circle. */
.add-button::after { content: ""; position: absolute; inset: -10px; }
.add-button:active { transform: scale3d(0.9, 0.9, 1); opacity: 0.65; }
.add-button svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

/* Centered modal dialog (opened by [data-modal] links in ui.js). */
dialog.modal {
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  width: min(360px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  overflow: visible;
}
dialog.modal::backdrop {
  background: rgb(0 0 0 / 0.32);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in 200ms var(--ease-out) both;
}
dialog.modal.closing::backdrop { animation: fade-out 170ms ease forwards; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 18px 48px rgb(0 0 0 / 0.22);
  animation: modal-in 220ms var(--ease-out) both;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-head h2 { font-size: 17px; font-weight: 600; color: var(--text); margin: 0; }
.modal-close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--line);
  color: var(--muted);
}
.modal-close svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Subtle touch feedback & disclosure fade */
.row-link, .back, .more summary, .toggle {
  transition: opacity 180ms ease, color 200ms ease;
}
.row-link:active, button.row-button:active, button.link:active,
.back:active, .more summary:active, .toggle:active {
  opacity: 0.55;
}

details[open] .detail > :not(.loading),
details.more[open] > :not(summary) {
  animation: fade-in 260ms var(--ease-out);
}

@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes modal-in {
  from { opacity: 0; transform: scale3d(0.95, 0.95, 1); }
  to { opacity: 1; transform: scale3d(1, 1, 1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}
