:root {
  color-scheme: light dark;
  --background: #f4f4f4;
  --surface: #ffffff;
  --surface-muted: #eeeeee;
  --text: #111111;
  --text-muted: #686868;
  --border: #d8d8d8;
  --brand: #191919;
  --brand-strong: #000000;
  --brand-soft: #e9e9e9;
  --on-brand: #ffffff;
  --danger: #111111;
  --status: #2b2b2b;
  --status-muted: #888888;
  --status-error: #111111;
  --focus: rgb(0 0 0 / 28%);
  --glow: rgb(0 0 0 / 5%);
  --shadow: 0 12px 40px rgb(0 0 0 / 9%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

:root[data-theme-mode="custom"] {
  --brand: var(--theme-light-brand);
  --brand-strong: var(--theme-light-strong);
  --brand-soft: var(--theme-light-soft);
  --on-brand: var(--theme-light-on-brand);
  --status: var(--theme-light-brand);
  --focus: var(--theme-light-focus);
  --glow: var(--theme-light-glow);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-width: 300px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top right, var(--glow), transparent 32rem),
    var(--background);
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

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

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  max-width: 48rem;
  margin: 0 auto;
  padding: calc(1.25rem + env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 1rem max(1.25rem, env(safe-area-inset-left));
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--brand);
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 7vw, 2.45rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.connection-status {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0.4rem 0.65rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgb(255 255 255 / 60%);
  font-size: 0.76rem;
  font-weight: 650;
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.share-button,
.theme-button {
  min-height: 2.1rem;
  padding: 0.42rem 0.72rem;
  color: var(--on-brand);
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--brand);
  font-size: 0.78rem;
  font-weight: 750;
  cursor: pointer;
}

.share-button:hover {
  background: var(--brand-strong);
}

.theme-button {
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface);
}

.theme-button:hover {
  background: var(--surface-muted);
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--status);
  box-shadow: 0 0 0 3px rgb(0 0 0 / 10%);
}

.connection-status.is-offline .status-dot,
.connection-status.is-pending .status-dot {
  background: var(--status-muted);
  box-shadow: 0 0 0 3px rgb(0 0 0 / 10%);
}

.connection-status.is-error .status-dot {
  background: var(--status-error);
  box-shadow: 0 0 0 3px rgb(0 0 0 / 16%);
}

main {
  width: min(100%, 48rem);
  margin: 0 auto;
  padding: 0 max(1rem, env(safe-area-inset-right)) calc(2rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.install-tip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.9rem;
  padding: 0.9rem 0.9rem 0.9rem 1rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--brand-soft);
}

.install-tip[hidden] {
  display: none;
}

.install-tip p {
  margin: 0.25rem 0 0;
  font-size: 0.86rem;
  line-height: 1.4;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  place-items: center;
  color: inherit;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.6rem;
  cursor: pointer;
}

.icon-button:hover {
  background: rgb(0 0 0 / 6%);
}

.add-item-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5rem auto;
  gap: 0.55rem;
  margin-bottom: 1rem;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

input[type="text"] {
  min-width: 0;
  min-height: 3rem;
  padding: 0.65rem 0.8rem;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 0.75rem;
  background: var(--surface-muted);
  font-size: 1rem;
}

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

.add-button,
.primary-button,
.secondary-button {
  min-height: 3rem;
  padding: 0.65rem 1rem;
  border-radius: 0.75rem;
  font-weight: 750;
  cursor: pointer;
}

.add-button,
.primary-button {
  color: var(--on-brand);
  border: 1px solid var(--brand);
  background: var(--brand);
}

.add-button:hover,
.primary-button:hover {
  background: var(--brand-strong);
}

.add-button:disabled {
  opacity: 0.55;
}

.list-panel {
  overflow: hidden;
  min-height: 12rem;
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-heading {
  margin: 0;
  padding: 0.95rem 1rem 0.55rem;
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 750;
  letter-spacing: 0.085em;
  text-transform: uppercase;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 0.65rem;
}

.section-title-row .section-heading {
  flex: 1;
}

.completed-section {
  border-top: 1px solid var(--border);
  background: rgb(0 0 0 / 1.5%);
}

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

.item-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-height: 3.85rem;
  padding: 0.55rem 0.65rem 0.55rem 1rem;
  border-top: 1px solid var(--border);
}

.item-row:first-child {
  border-top: 0;
}

.item-checkbox {
  appearance: none;
  display: grid;
  width: 1.6rem;
  height: 1.6rem;
  margin: 0;
  place-content: center;
  border: 2px solid #8c8c8c;
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.item-checkbox::before {
  width: 0.68rem;
  height: 0.38rem;
  content: "";
  border-bottom: 2px solid var(--on-brand);
  border-left: 2px solid var(--on-brand);
  transform: translateY(-1px) rotate(-45deg) scale(0);
  transition: transform 100ms ease-in-out;
}

.item-checkbox:checked {
  border-color: var(--brand);
  background: var(--brand);
}

.item-checkbox:checked::before {
  transform: translateY(-1px) rotate(-45deg) scale(1);
}

.item-details {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.2rem;
}

.item-main {
  display: flex;
  min-width: 0;
  max-width: 100%;
  align-items: baseline;
  gap: 0.55rem;
}

.item-name {
  overflow: hidden;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-quantity {
  flex: 0 0 auto;
  padding: 0.15rem 0.4rem;
  color: var(--text-muted);
  border-radius: 0.45rem;
  background: var(--surface-muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.item-timestamps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.65rem;
  color: var(--text-muted);
  font-size: 0.67rem;
  line-height: 1.35;
}

.item-timestamps time + time::before {
  margin-right: 0.65rem;
  content: "•";
}

.is-checked .item-name {
  color: var(--text-muted);
  text-decoration: line-through;
}

.row-actions {
  display: flex;
  align-items: center;
}

.row-action,
.text-button {
  min-height: 2.5rem;
  padding: 0.45rem;
  color: var(--text-muted);
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.row-action:hover,
.text-button:hover {
  color: var(--brand);
  background: var(--brand-soft);
}

.row-action[data-action="delete"]:hover {
  color: var(--danger);
  background: rgb(0 0 0 / 10%);
}

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
}

.empty-icon {
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  margin: 0 auto 0.8rem;
  place-items: center;
  color: var(--brand);
  border-radius: 50%;
  background: var(--brand-soft);
  font-size: 1.5rem;
  font-weight: 800;
}

.empty-state h2 {
  margin: 0;
  font-size: 1.12rem;
}

.empty-state p {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.list-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0.2rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.edit-dialog,
.sharing-dialog,
.theme-dialog {
  width: min(calc(100% - 2rem), 28rem);
  max-height: min(46rem, calc(100dvh - 2rem));
  padding: 0;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  background: var(--surface);
  box-shadow: 0 24px 80px rgb(0 0 0 / 28%);
}

.edit-dialog::backdrop,
.sharing-dialog::backdrop,
.theme-dialog::backdrop {
  background: rgb(0 0 0 / 58%);
  backdrop-filter: blur(2px);
}

.edit-dialog form {
  display: grid;
  gap: 0.55rem;
  padding: 1rem;
}

.sharing-dialog,
.theme-dialog {
  padding: 1rem;
}

.sharing-dialog > .dialog-heading,
.theme-dialog > .dialog-heading {
  margin-bottom: 0.75rem;
}

.sharing-dialog .eyebrow,
.theme-dialog .eyebrow {
  margin-bottom: 0.15rem;
}

.theme-choice {
  display: flex;
  width: 100%;
  min-height: 3.5rem;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0.8rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.theme-choice[aria-pressed="true"] {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--focus);
}

.monochrome-swatch {
  display: grid;
  overflow: hidden;
  width: 2rem;
  height: 2rem;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: linear-gradient(90deg, #161616 0 50%, #eeeeee 50%);
}

.theme-choice-copy {
  display: grid;
  gap: 0.1rem;
}

.theme-choice-copy small {
  color: var(--text-muted);
}

.theme-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.75rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
}

.theme-form.is-active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--focus);
}

.theme-form label {
  display: grid;
  gap: 0.1rem;
  font-weight: 700;
}

.theme-form label small {
  color: var(--text-muted);
  font-weight: 500;
}

.theme-color-input {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0.15rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.theme-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.theme-color-input::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}

.theme-apply-button {
  min-height: 2.5rem;
  padding: 0.5rem 0.8rem;
  color: var(--on-brand);
  border: 1px solid var(--brand);
  border-radius: 0.65rem;
  background: var(--brand);
  font-weight: 750;
  cursor: pointer;
}

.dialog-description {
  margin: 0.5rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.sharing-form {
  display: grid;
  gap: 0.5rem;
}

.sharing-form h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
}

.sharing-form label {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.sharing-form .primary-button {
  margin-top: 0.45rem;
}

.sharing-divider {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin: 1.15rem 0;
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.sharing-divider::before,
.sharing-divider::after {
  flex: 1;
  height: 1px;
  content: "";
  background: var(--border);
}

.invite-input {
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.connected-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--brand-soft);
}

.connected-mark {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;
  color: var(--on-brand);
  border-radius: 50%;
  background: var(--brand);
  font-weight: 800;
}

.connected-card p {
  margin: 0.18rem 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.full-width {
  width: 100%;
}

.invite-result {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.8rem;
  padding: 1rem;
  border: 1px dashed var(--brand);
  border-radius: 0.85rem;
  text-align: center;
}

.invite-result span,
.invite-result small {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.invite-result strong {
  color: var(--brand);
  font-size: 1.65rem;
  letter-spacing: 0.12em;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 1.2rem;
}

.edit-dialog label {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.secondary-button {
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface);
}

.toast {
  position: fixed;
  z-index: 10;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  left: 1rem;
  width: fit-content;
  max-width: calc(100% - 2rem);
  margin: auto;
  padding: 0.75rem 1rem;
  color: var(--on-brand);
  border-radius: 999px;
  background: var(--brand);
  box-shadow: 0 8px 30px rgb(0 0 0 / 25%);
  font-size: 0.86rem;
  font-weight: 650;
  text-align: center;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 31rem) {
  .app-header {
    align-items: center;
  }

  .header-actions {
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 0.35rem;
  }

  .header-buttons {
    gap: 0.35rem;
  }

  .theme-form {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .theme-apply-button {
    grid-column: 1 / -1;
  }

  .connection-status {
    max-width: 8rem;
  }

  .add-item-form {
    grid-template-columns: minmax(0, 1fr) 4.3rem;
  }

  .add-button {
    grid-column: 1 / -1;
  }

  .item-row {
    gap: 0.6rem;
    padding-left: 0.8rem;
  }

  .row-action {
    width: 2.65rem;
    overflow: hidden;
    color: transparent;
    font-size: 0;
  }

  .row-action::before {
    color: var(--text-muted);
    font-size: 1rem;
  }

  .row-action[data-action="edit"]::before {
    content: "✎";
  }

  .row-action[data-action="delete"]::before {
    content: "×";
    font-size: 1.35rem;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0d0d0d;
    --surface: #181818;
    --surface-muted: #252525;
    --text: #f3f3f3;
    --text-muted: #a5a5a5;
    --border: #3a3a3a;
    --brand: #f0f0f0;
    --brand-strong: #ffffff;
    --brand-soft: #2b2b2b;
    --on-brand: #111111;
    --danger: #f0f0f0;
    --status: #e0e0e0;
    --status-muted: #999999;
    --status-error: #f5f5f5;
    --focus: rgb(255 255 255 / 30%);
    --glow: rgb(255 255 255 / 5%);
    --shadow: 0 12px 40px rgb(0 0 0 / 28%);
  }

  :root[data-theme-mode="custom"] {
    --brand: var(--theme-dark-brand);
    --brand-strong: var(--theme-dark-strong);
    --brand-soft: var(--theme-dark-soft);
    --on-brand: var(--theme-dark-on-brand);
    --status: var(--theme-dark-brand);
    --focus: var(--theme-dark-focus);
    --glow: var(--theme-dark-glow);
  }

  .connection-status {
    background: rgb(24 24 24 / 75%);
  }

  .install-tip {
    color: var(--text);
    border-color: var(--border);
  }

  .item-checkbox {
    background: var(--surface);
  }

  .toast {
    color: #111111;
    background: #eeeeee;
  }
}
