:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: #f6f4ee;
  color: #20201e;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
  --ink: #20201e;
  --muted: #85827a;
  --line: #e8e4da;
  --paper: #fffefa;
  --accent: #f47b42;
  --accent-dark: #d85e28;
  --accent-soft: #fff0e7;
  --danger: #c94242;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 100% 0, rgba(244, 123, 66, 0.11), transparent 33%),
    #f6f4ee;
  overscroll-behavior-y: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(244, 123, 66, 0.26);
  outline-offset: 2px;
}

#app {
  min-height: 100dvh;
}

.app-shell {
  width: min(100%, 680px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0px) 16px calc(104px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 2px 12px;
}

.brand {
  min-width: 0;
  flex: 1;
}

.brand h1 {
  margin: 0;
  font-size: clamp(27px, 7vw, 34px);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.summary {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
}

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 254, 250, 0.84);
  color: #6e6b64;
  font-size: 20px;
  box-shadow: 0 4px 16px rgba(63, 53, 38, 0.06);
}

.token-button {
  width: auto;
  min-width: 52px;
  flex-basis: auto;
  padding: 0 12px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
}

.tabs {
  position: sticky;
  top: max(0px, env(safe-area-inset-top, 0px));
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 4px 0 18px;
  padding: 4px;
  border: 1px solid rgba(223, 217, 205, 0.8);
  border-radius: 15px;
  background: rgba(235, 231, 222, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.tab {
  min-height: 40px;
  padding: 8px 6px;
  border-radius: 11px;
  background: transparent;
  color: #76736c;
  font-size: 14px;
  font-weight: 650;
}

.tab.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 2px 9px rgba(54, 46, 35, 0.09);
}

.todo-group {
  margin: 0 0 22px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 2px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.group-title::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.todo-list {
  overflow: hidden;
  border: 1px solid rgba(229, 224, 213, 0.86);
  border-radius: 18px;
  background: rgba(255, 254, 250, 0.9);
  box-shadow: 0 10px 34px rgba(62, 49, 29, 0.055);
}

.todo-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 76px;
  padding: 8px 7px 8px 4px;
  border-bottom: 1px solid var(--line);
}

.todo-row:last-child {
  border-bottom: 0;
}

.toggle {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
}

.toggle::before {
  position: absolute;
  inset: 11px;
  border: 2px solid #b9b4aa;
  border-radius: 50%;
  content: "";
  transition: 160ms ease;
}

.toggle.completed::before {
  border-color: var(--accent);
  background: var(--accent);
}

.toggle.completed::after {
  position: absolute;
  left: 17px;
  top: 13px;
  width: 6px;
  height: 11px;
  border-right: 2px solid white;
  border-bottom: 2px solid white;
  content: "";
  transform: rotate(42deg);
}

.todo-copy {
  min-width: 0;
  padding-right: 4px;
}

.title-input {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 5px 2px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
}

.todo-row.is-completed .title-input {
  color: #8e8a82;
  text-decoration: line-through;
  text-decoration-color: #bcb7ad;
}

.timestamps {
  display: block;
  overflow: hidden;
  margin: 2px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete {
  min-width: 48px;
  min-height: 42px;
  padding: 0 8px;
  border-radius: 11px;
  background: transparent;
  color: #aaa59b;
  font-size: 13px;
  font-weight: 650;
}

.delete.confirm {
  background: #fff0ef;
  color: var(--danger);
}

.empty-state {
  padding: 58px 24px 72px;
  text-align: center;
}

.empty-mark {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  place-items: center;
  border: 1px solid #e9e1d5;
  border-radius: 22px;
  background: var(--paper);
  color: var(--accent);
  font-size: 29px;
  box-shadow: 0 10px 30px rgba(63, 51, 34, 0.07);
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  font-size: 17px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.composer-wrap {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(12px + var(--safe-bottom)) max(16px, env(safe-area-inset-left, 0px));
  background: linear-gradient(to top, #f6f4ee 68%, rgba(246, 244, 238, 0));
}

.composer {
  display: flex;
  width: min(100%, 648px);
  margin: 0 auto;
  padding: 6px;
  border: 1px solid #ded8cc;
  border-radius: 18px;
  background: rgba(255, 254, 250, 0.96);
  box-shadow: 0 10px 36px rgba(53, 43, 28, 0.16);
}

.composer input {
  min-width: 0;
  flex: 1;
  height: 46px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
}

.composer input::placeholder {
  color: #aaa69d;
}

.add-button {
  min-width: 72px;
  height: 46px;
  border-radius: 13px;
  background: var(--accent);
  color: white;
  font-weight: 750;
  box-shadow: 0 5px 14px rgba(216, 94, 40, 0.22);
}

.add-button:active {
  background: var(--accent-dark);
  transform: scale(0.98);
}

.add-button:disabled,
.icon-button:disabled,
.delete:disabled,
.toggle:disabled {
  cursor: wait;
  opacity: 0.5;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: calc(92px + var(--safe-bottom));
  left: 20px;
  z-index: 30;
  width: fit-content;
  max-width: calc(100% - 40px);
  margin: auto;
  padding: 11px 16px;
  border-radius: 12px;
  background: #2a2926;
  color: white;
  font-size: 13px;
  box-shadow: 0 9px 30px #0003;
  animation: toast-in 180ms ease-out;
}

.connection-page {
  display: grid;
  min-height: 100dvh;
  padding: max(30px, env(safe-area-inset-top, 0px)) 18px calc(28px + var(--safe-bottom));
  place-items: center;
}

.connection-card {
  width: min(100%, 440px);
  padding: 28px 22px 22px;
  border: 1px solid rgba(229, 223, 211, 0.9);
  border-radius: 26px;
  background: rgba(255, 254, 250, 0.94);
  box-shadow: 0 22px 70px rgba(59, 45, 23, 0.12);
}

.connection-mark {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 24px;
  place-items: center;
  border-radius: 19px;
  background: var(--accent);
  color: white;
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 9px 24px rgba(216, 94, 40, 0.24);
}

.connection-card h1 {
  margin: 0;
  font-size: 29px;
  letter-spacing: -0.04em;
}

.connection-card > p {
  margin: 10px 0 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.field-label {
  display: block;
  margin: 0 0 8px 2px;
  color: #68655e;
  font-size: 12px;
  font-weight: 700;
}

.token-field {
  width: 100%;
  min-height: 104px;
  resize: none;
  padding: 13px;
  border: 1px solid #ddd7cc;
  border-radius: 14px;
  background: #f8f6f1;
  color: var(--ink);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.connection-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.secondary-button,
.connect-button {
  min-height: 48px;
  border-radius: 14px;
  font-weight: 700;
}

.secondary-button {
  background: #efede7;
  color: #55524c;
}

.connect-button {
  background: var(--accent);
  color: white;
}

.connection-note {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  margin-top: 18px;
  color: #928d84;
  font-size: 12px;
  line-height: 1.45;
}

.connection-error {
  min-height: 20px;
  margin: 12px 2px 0;
  color: var(--danger);
  font-size: 13px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(31, 28, 23, 0.34);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 160ms ease-out;
}

.token-sheet {
  width: min(100%, 540px);
  padding: 10px 18px calc(18px + var(--safe-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 26px 26px 0 0;
  background: var(--paper);
  box-shadow: 0 -18px 60px rgba(48, 37, 21, 0.16);
  animation: sheet-in 220ms cubic-bezier(0.22, 0.75, 0.25, 1);
}

.sheet-handle {
  width: 38px;
  height: 5px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: #d1ccc2;
}

.sheet-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.sheet-heading > div {
  min-width: 0;
  flex: 1;
}

.sheet-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.sheet-heading h2 {
  margin: 3px 0 0;
  font-size: 23px;
  letter-spacing: -0.03em;
}

.sheet-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #efede7;
  color: #716d65;
  font-size: 25px;
  line-height: 1;
}

.visible-token {
  width: 100%;
  min-height: 88px;
  resize: none;
  padding: 13px;
  border: 1px solid #ddd7cc;
  border-radius: 14px;
  background: #f8f6f1;
  color: var(--ink);
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

.token-hint {
  margin: 10px 2px 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.copy-token-button,
.change-token-button {
  min-height: 48px;
  border-radius: 14px;
  font-weight: 700;
}

.copy-token-button {
  background: var(--accent);
  color: white;
}

.change-token-button {
  background: #efede7;
  color: #615e57;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(100%);
  }
}

@media (min-width: 681px) {
  .app-shell {
    padding-right: 24px;
    padding-left: 24px;
  }

  .topbar {
    padding-top: 28px;
  }

  .todo-row {
    padding-right: 10px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #f3f0e9;
    --muted: #969188;
    --line: #383630;
    --paper: #24231f;
    --accent-soft: #42291f;
    background: #191815;
  }

  body {
    background:
      radial-gradient(circle at 100% 0, rgba(244, 123, 66, 0.12), transparent 32%),
      #191815;
  }

  .tabs {
    border-color: #3b3933;
    background: rgba(42, 40, 35, 0.88);
  }

  .tab.active,
  .todo-list,
  .icon-button,
  .composer,
  .connection-card,
  .token-sheet {
    background: rgba(36, 35, 31, 0.96);
  }

  .icon-button,
  .todo-list,
  .composer,
  .connection-card,
  .token-field,
  .visible-token {
    border-color: #3d3a34;
  }

  .composer-wrap {
    background: linear-gradient(to top, #191815 68%, rgba(25, 24, 21, 0));
  }

  .token-field,
  .visible-token,
  .secondary-button,
  .sheet-close,
  .change-token-button {
    background: #2e2c27;
  }

  .delete.confirm {
    background: #432523;
  }
}

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