:root {
  color-scheme: light;
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-sunken: #f2efe7;
  --text: #2b2a26;
  --text-muted: #837e70;
  --accent: #3f7d58;
  --accent-hover: #336548;
  --accent-soft: #e4efe6;
  --border: #e6e1d5;
  --danger: #b5533f;
  --info: #2f6fb0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1c1b17;
    --surface: #242320;
    --surface-sunken: #1a1917;
    --text: #ece8dd;
    --text-muted: #9b968a;
    --accent: #71c090;
    --accent-hover: #8ad0a5;
    --accent-soft: #26362c;
    --border: #3a382f;
    --danger: #d97e6a;
    --info: #7fb4e8;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1b17;
  --surface: #242320;
  --surface-sunken: #1a1917;
  --text: #ece8dd;
  --text-muted: #9b968a;
  --accent: #71c090;
  --accent-hover: #8ad0a5;
  --accent-soft: #26362c;
  --border: #3a382f;
  --danger: #d97e6a;
  --info: #7fb4e8;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Karla", ui-sans-serif, system-ui, sans-serif;
  display: flex;
  justify-content: center;
  padding: 48px 20px 80px;
  min-height: 100vh;
  margin: 0;
}

main {
  width: 100%;
  max-width: 720px;
}

.eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 6px;
}

section + section {
  margin-top: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.current-user {
  font-size: 0.85rem;
  color: var(--text-muted);
}

button.admin-toggle,
button.logout {
  font: inherit;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

button.admin-toggle:hover,
button.logout:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

button.refresh {
  display: flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

button.refresh svg {
  width: 15px;
  height: 15px;
  transition: transform 0.5s ease;
}

button.refresh:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

button.refresh.spinning svg {
  animation: refresh-spin 0.7s linear infinite;
}

button.refresh:disabled {
  cursor: default;
  opacity: 0.7;
}

@keyframes refresh-spin {
  to { transform: rotate(360deg); }
}

.section-title {
  font-family: "Fraunces", Georgia, serif;
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: clamp(1.6rem, 4.5vw, 1.95rem);
  text-wrap: balance;
  margin: 0;
  color: var(--text);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  font: inherit;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 6px 0 16px;
  margin: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
}

.section-header .chevron {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.section-header[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.section-panel[hidden] {
  display: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

form {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 480px) {
  #add-form {
    flex-wrap: wrap;
  }

  #add-form #item-input {
    flex-basis: 100%;
  }
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5.5px 7px;
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus-visible,
button:focus-visible,
input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.add {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 13px 22px;
  cursor: pointer;
  transition: background 0.15s ease;
}

button.add:hover { background: var(--accent-hover); }

button.add:disabled {
  background: var(--surface-sunken);
  color: var(--text-muted);
  cursor: default;
}

button.mic {
  flex-shrink: 0;
  width: 44px;
  display: grid;
  place-content: center;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

button.mic svg { width: 19px; height: 19px; }

button.mic:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

button.mic[disabled] {
  cursor: not-allowed;
  opacity: 0.45;
}

button.mic.listening {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--danger) 0%, transparent); }
}

.voice-hint {
  padding: 0 16px 14px;
  margin: -4px 0 0;
  font-size: 0.85rem;
  color: var(--accent);
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

li:last-child { border-bottom: none; }

input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface-sunken);
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}

input[type="checkbox"]::after {
  content: "";
  width: 11px;
  height: 7px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
  opacity: 0;
}

input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

input[type="checkbox"]:checked::after { opacity: 1; }

li label {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
  cursor: pointer;
  font-size: 1rem;
}

li:has(input:checked) label {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

li button.remove,
td button.remove {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}

li button.remove:hover,
td button.remove:hover {
  color: var(--danger);
  background: var(--surface-sunken);
}

td button.edit,
td button.remove {
  vertical-align: middle;
}

li button.edit,
td button.edit {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  display: grid;
  place-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}

li button.edit svg,
td button.edit svg {
  width: 16px;
  height: 16px;
}

li button.edit:hover,
td button.edit:hover {
  color: var(--accent);
  background: var(--surface-sunken);
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.status {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 4px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.status button {
  font: inherit;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.status button:hover { color: var(--accent-hover); text-decoration: underline; }

.status button:disabled {
  color: var(--text-muted);
  cursor: default;
  text-decoration: none;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 11px 12px;
  text-align: left;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.birthday-actions {
  display: flex;
  gap: 8px;
}

#birthdays-panel td,
#birthdays-panel th {
  padding-top: 7px;
  padding-bottom: 7px;
}

td:nth-child(3), td:nth-child(4) {
  white-space: normal;
}

th {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

th:first-child, td:first-child {
  width: 1%;
  padding-right: 4px;
}

tbody tr:last-child td {
  border-bottom: none;
}

tr.status-overdue td {
  color: var(--danger);
}

tr.status-today td {
  color: var(--info);
}

tr.status-future td {
  color: var(--text);
}

tr.is-done td {
  color: var(--text-muted);
}

tr.is-done td:not(:first-child) {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

tr.status-upcoming {
  background: var(--accent-soft);
}

tr.status-upcoming td:first-child {
  color: var(--accent);
  font-weight: 600;
}

.link-form {
  flex-wrap: wrap;
}

.link-form #link-title-input {
  flex: 1;
  min-width: 120px;
}

.link-form #link-url-input {
  flex: 2;
  min-width: 160px;
}

li .link-anchor {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
  color: var(--info);
  font-size: 1rem;
  text-decoration: none;
}

li .link-anchor:hover {
  text-decoration: underline;
}

.entry-card {
  padding: 16px;
}

.reminder-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field.grow {
  flex: 1;
  min-width: 160px;
}

.field label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field input,
.field select {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5.5px 7px;
}

.field input[type="number"] {
  width: 5.5em;
}

.login-view {
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  padding-top: 20vh;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}

.login-form h1 {
  margin: -4px 0 4px;
}

.login-form .field {
  gap: 6px;
}

.login-form input {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5.5px 7px;
}

.login-error {
  margin: 0;
  font-size: 0.85rem;
  color: var(--danger);
}

.admin-section .card {
  padding: 16px;
}

#users-list {
  margin-bottom: 8px;
}

#users-list li {
  padding: 10px 4px;
}

#users-list li span {
  flex: 1;
}

.new-user-form {
  padding: 16px 0 0;
  border-bottom: none;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: end;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
