:root {
  color-scheme: light dark;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --text: #111827;
  --muted: #5b6472;
  --border: #d6dde7;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --danger-border: #f3b4ae;
  --focus: #0ea5e9;
  --shadow: 0 24px 70px rgb(15 23 42 / 12%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #07111f;
    --surface: #0f1b2d;
    --surface-subtle: #152238;
    --text: #f5f7fb;
    --muted: #a8b2c2;
    --border: #304057;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-contrast: #06201d;
    --danger: #ff8b82;
    --danger-bg: #331615;
    --danger-border: #74322f;
    --focus: #38bdf8;
    --shadow: 0 24px 70px rgb(0 0 0 / 35%);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 34rem),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.shell {
  min-height: 100vh;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.app {
  width: min(100%, 44rem);
  margin-inline: auto;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}

.app__header,
.identity,
.todo-form,
.todos,
.app__footer {
  padding-inline: clamp(1rem, 5vw, 2rem);
}

.app__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-block: clamp(1.4rem, 5vw, 2rem);
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.45rem;
  font-size: clamp(2.25rem, 10vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.055em;
}

h2 {
  margin-bottom: 0.35rem;
  font-size: 1rem;
  line-height: 1.3;
}

.lede,
.identity p,
.app__footer p {
  color: var(--muted);
  line-height: 1.55;
}

.lede {
  max-width: 31rem;
  margin-bottom: 0;
}

.status {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
  padding: 0.35rem 0.65rem;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.status__dot {
  width: 0.55rem;
  height: 0.55rem;
  background: #d97706;
  border-radius: 50%;
}

.status[data-state="connected"] .status__dot {
  background: #16a34a;
}

.status[data-state="error"] .status__dot {
  background: #dc2626;
}

.identity {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 1rem;
  padding-block: 1.25rem;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
}

.identity p {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.identity code {
  max-width: 11rem;
  overflow: hidden;
  padding: 0.35rem 0.55rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.todo-form {
  padding-block: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.todo-form > label {
  display: block;
  margin-bottom: 0.55rem;
  font-weight: 800;
}

.todo-form__controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
}

.todo-form input {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
}

.todo-form button,
.button {
  padding: 0.7rem 1rem;
  color: var(--accent-contrast);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 0.65rem;
  font-weight: 800;
}

.todo-form button:not(:disabled):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.field-hint {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

.error-panel {
  margin: 1.25rem clamp(1rem, 5vw, 2rem) 0;
  padding: 1rem;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 0.75rem;
}

.error-panel p {
  margin: 0.35rem 0 0.85rem;
  line-height: 1.5;
}

.button--secondary {
  min-height: 40px;
  color: var(--danger);
  background: transparent;
  border-color: currentColor;
}

.todos {
  min-height: 16rem;
  padding-block: 1.5rem 2rem;
}

.todos__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.todos__heading h2 {
  margin: 0;
  font-size: 1.15rem;
}

.count {
  display: inline-grid;
  min-width: 2rem;
  min-height: 2rem;
  place-items: center;
  padding-inline: 0.45rem;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--border));
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

.state {
  padding: 2.5rem 1rem;
  color: var(--muted);
  text-align: center;
}

.todo-list {
  display: grid;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.todo-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.85rem;
  padding: 0.85rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.todo-item__content {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 0.75rem;
  min-width: 0;
  padding-block: 0.32rem;
  cursor: pointer;
}

.todo-item__content input {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0.08rem 0 0;
  accent-color: var(--accent);
}

.todo-item__title {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.todo-item__title.is-complete {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 0.12em;
}

.delete-button {
  min-height: 36px;
  padding: 0.35rem 0.5rem;
  color: var(--danger);
  background: transparent;
  border: 0;
  border-radius: 0.4rem;
  font-size: 0.82rem;
  font-weight: 800;
}

.delete-button:hover {
  background: var(--danger-bg);
}

.app__footer {
  padding-block: 1rem;
  background: var(--surface-subtle);
  border-top: 1px solid var(--border);
}

.app__footer p {
  margin-bottom: 0;
  font-size: 0.78rem;
  text-align: center;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[hidden] {
  display: none !important;
}

@media (max-width: 34rem) {
  .shell {
    padding: 0;
  }

  .app {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app__header {
    display: grid;
  }

  .status {
    justify-self: start;
  }

  .identity {
    grid-template-columns: 1fr;
  }

  .identity code {
    max-width: 100%;
    justify-self: start;
  }
}

@media (max-width: 25rem) {
  .todo-form__controls {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Account and recoverable identity controls */
.identity__copy {
  min-width: 0;
}

.identity__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.identity__title-row h2 {
  margin: 0;
}

.identity__email {
  margin-top: 0.35rem;
  color: var(--text) !important;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.account-badge {
  display: inline-flex;
  min-height: 1.7rem;
  align-items: center;
  padding: 0.2rem 0.5rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
}

.account-badge[data-state="guest"] {
  color: #92400e;
  background: #fffbeb;
  border-color: #f5cf73;
}

.account-badge[data-state="permanent"] {
  color: #166534;
  background: #f0fdf4;
  border-color: #86d6a0;
}

@media (prefers-color-scheme: dark) {
  .account-badge[data-state="guest"] {
    color: #fcd34d;
    background: #3a2a0c;
    border-color: #7c5a16;
  }

  .account-badge[data-state="permanent"] {
    color: #86efac;
    background: #102e1b;
    border-color: #287443;
  }
}

.status[data-state="ready"] .status__dot {
  background: #64748b;
}

.account {
  padding: 1.35rem clamp(1rem, 5vw, 2rem);
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
  border-bottom: 1px solid var(--border);
}

.section-heading {
  margin-bottom: 1rem;
}

.section-heading h2 {
  margin-bottom: 0.3rem;
  font-size: 1.05rem;
}

.section-heading p,
.field-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.section-heading--action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 1rem;
  margin-bottom: 0;
}

.account-form > label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.86rem;
  font-weight: 800;
}

.account-form__controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
}

.account-form input {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
}

.account-form button,
.button--secondary-neutral {
  padding: 0.7rem 1rem;
  border-radius: 0.65rem;
  font-weight: 800;
}

.account-form button {
  color: var(--accent-contrast);
  background: var(--accent);
  border: 1px solid var(--accent);
}

.account-form button:not(:disabled):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

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

.button--secondary-neutral:not(:disabled):hover {
  background: var(--surface-subtle);
}

.field-note {
  margin-top: 0.55rem;
}

.account-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.65rem;
  margin: 1rem 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

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

.feedback {
  margin-top: 1rem;
  padding: 0.75rem 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  font-size: 0.84rem;
  line-height: 1.45;
}

.feedback[data-tone="success"] {
  color: #166534;
  background: #f0fdf4;
  border-color: #86d6a0;
}

@media (prefers-color-scheme: dark) {
  .feedback[data-tone="success"] {
    color: #bbf7d0;
    background: #102e1b;
    border-color: #287443;
  }
}

@media (max-width: 34rem) {
  .section-heading--action,
  .account-form__controls {
    grid-template-columns: 1fr;
  }

  .section-heading--action .button,
  .account-form button,
  .button--secondary-neutral {
    width: 100%;
  }
}
