:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e2e0da;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --live: #e8a33d;
  --danger: #c0392b;
  --ok: #2e7d4f;
  --chip: #eceae4;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #202328;
    --text: #eceef1;
    --muted: #9aa0a8;
    --line: #30343b;
    --accent: #4c8dff;
    --accent-text: #0d1117;
    --chip: #2b2f36;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px 24px;
}

main[aria-busy="true"] {
  opacity: 0.6;
}

h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card h2 {
  margin-top: 0;
}

a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.center {
  text-align: center;
}

/* --- controls --- */

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

button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.5;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  width: 100%;
}

button.danger {
  color: var(--danger);
}

button.ghost {
  background: transparent;
  border-color: transparent;
}

button.wide {
  width: 100%;
  margin-top: 16px;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.label {
  font-size: 0.85rem;
  color: var(--muted);
}

.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.inline input {
  width: 20px;
  height: 20px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row input {
  flex: 1;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

details.more {
  margin-bottom: 14px;
}

details.more summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 0;
}

/* --- chips --- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--chip);
  font-size: 0.95rem;
}

.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.shares {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.share {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.share input {
  width: 80px;
}

/* --- cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.current {
  border-left: 6px solid var(--live);
}

.current.idle {
  border-left-color: var(--line);
}

.eyebrow {
  font-size: 0.85rem;
  color: var(--muted);
}

.current .title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 4px 0;
  overflow-wrap: anywhere;
}

.sub {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.desc {
  margin-top: 6px;
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.current .row {
  margin-top: 14px;
}

.current .row button {
  flex: 1;
}

button.stop {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 700;
}

/* --- quick switch --- */

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 72px;
  text-align: left;
  border-radius: var(--radius);
}

.tile-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.tile-sub {
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* --- day --- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pager h2 {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 1.05rem;
  color: var(--text);
  text-align: center;
}

.pager a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.6rem;
  text-decoration: none;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry-button {
  display: flex;
  gap: 12px;
  width: 100%;
  text-align: left;
  border-radius: var(--radius);
  padding: 12px;
}

.entry.active .entry-button {
  border-left: 6px solid var(--live);
}

.when {
  display: flex;
  flex-direction: column;
  min-width: 96px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.when small {
  font-weight: 400;
  color: var(--muted);
}

.what {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.what .title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.gap button {
  width: 100%;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- week --- */

.bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bars li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
}

.bar-label {
  overflow-wrap: anywhere;
}

.bar-value {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.bar-track {
  grid-column: 1 / -1;
  height: 8px;
  border-radius: 4px;
  background: var(--chip);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
}

.days {
  list-style: none;
  margin: 0;
  padding: 0;
}

.days li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.days li:last-child {
  border-bottom: 0;
}

/* --- nav, dialog, toast --- */

nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

nav a {
  flex: 1;
  text-align: center;
  padding: 14px 0;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

nav a.active {
  color: var(--accent);
}

dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  padding: 16px;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dialog-head h2 {
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

.toast.ok {
  background: var(--ok);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
