:root {
  --bg: #f4f5f7;
  --sheet: #f4f5f7;
  --card: #fff;
  --hover: #f7f8fa;
  --text: #1c1e21;
  --muted: #666d78;
  --line: #dde0e5;
  --accent: #c2550a;
  --on-accent: #fff;
  --danger: #c0262d;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --sheet: #17181c;
    --card: #1c1e23;
    --hover: #24272d;
    --text: #e9eaed;
    --muted: #9aa1ac;
    --line: #31343c;
    --accent: #ff9a4d;
    --on-accent: #1c1006;
    --danger: #ff7b80;
    --warn-bg: #3a2f0e;
    --warn-text: #ffdf8a;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

h1 {
  font-size: 1.5rem;
  margin: 0.5rem 0;
}

h2 {
  font-size: 1.1rem;
  margin: 0;
}

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

button {
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 1rem;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--card);
  font-weight: 600;
}

button.small {
  flex: none;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
}

button.wide {
  width: 100%;
  margin-top: 0.75rem;
}

button.icon {
  display: inline-grid;
  place-items: center;
  background: none;
  border: 0;
  padding: 0;
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
  border-radius: 50%;
}

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

.svg-icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-more {
  stroke-width: 2.8;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:not([type="checkbox"]),
select,
textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
}

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

.mono {
  font-family: ui-monospace, Consolas, monospace;
}

.wrap {
  overflow-wrap: anywhere;
}

.center {
  text-align: center;
}

.warn,
.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.error-text {
  color: var(--danger);
  margin: 0.4rem 0;
  min-height: 1em;
  font-size: 0.9rem;
}

.field {
  display: block;
  margin-bottom: 0.8rem;
}

.field > span {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.field > small {
  display: block;
  margin-top: 0.2rem;
}

details {
  margin: 0.5rem 0;
}

summary {
  cursor: pointer;
  margin-bottom: 0.6rem;
}

.row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.row.end {
  justify-content: flex-end;
}

.row.between {
  justify-content: space-between;
}

.auth {
  max-width: 24rem;
  margin: 0 auto;
  padding: 10vh 1rem 2rem;
  text-align: center;
}

.auth form {
  text-align: left;
  margin-top: 1.5rem;
}

.auth form > button {
  width: 100%;
}

header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 0.25rem;
  max-width: 40rem;
  margin: 0 auto;
  padding: calc(0.75rem + env(safe-area-inset-top)) 1rem 0.75rem;
  background: var(--bg);
}

header input {
  border-radius: 999px !important;
}

header button.icon:hover {
  background: var(--card);
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 1rem 6rem;
}

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

.card {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.5rem 0.4rem 0.5rem 0;
  margin-bottom: 0.6rem;
}

.card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 0.8rem;
  align-items: center;
  text-align: left;
  border: 0;
  background: none;
  padding: 0.25rem 0.8rem;
}

.avatar {
  flex: none;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
}

.c0 { background: #2f6fd0; }
.c1 { background: #1f8a5b; }
.c2 { background: #8a4fc4; }
.c3 { background: #c4487a; }
.c4 { background: #a8650f; }
.c5 { background: #187f8f; }

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

.info strong,
.info small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code {
  font-size: 2rem;
  line-height: 1.25;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.expiring .code {
  color: var(--danger);
}

.ring {
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 3;
}

.ring .track {
  stroke: var(--line);
}

.ring .left {
  stroke: var(--accent);
}

.expiring .ring .left {
  stroke: var(--danger);
}

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

.fab {
  position: fixed;
  right: max(1.25rem, calc(50vw - 20rem));
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  border-radius: 18px;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.3);
}

.fab .svg-icon {
  width: 1.75rem;
  height: 1.75rem;
  stroke-width: 2.2;
}

/* ---------- 对话框 ---------- */

dialog {
  width: min(28rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--sheet);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

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

.dialog-head {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.75rem 0.5rem 1.35rem;
}

.dialog-head button.icon:hover {
  background: var(--card);
}

.dialog-body {
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 0.25rem 1rem 1.25rem;
}

.dialog-body form > button[type="submit"] {
  width: 100%;
}

/* ---------- 菜单与列表 ---------- */

.group + .group,
.group-body + .group,
div > .group:first-child {
  margin-top: 1rem;
}

.dialog-body > .group:first-child {
  margin-top: 0;
}

.group h3 {
  margin: 0 0 0.4rem 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

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

.item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 3.75rem;
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: none;
  border: 0;
  border-radius: 0;
  text-align: left;
}

.item.compact {
  min-height: 3.25rem;
}

.item + .item,
.fact + .fact,
.check + .check {
  border-top: 1px solid var(--line);
}

label.item {
  cursor: pointer;
}

button.item:hover,
label.item:hover {
  background: var(--hover);
}

.item:focus-visible {
  outline-offset: -2px;
}

.item-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
}

.item-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.item-text strong {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.4;
}

.item-text small {
  font-size: 0.8rem;
  line-height: 1.4;
}

.item .chevron {
  width: 1.1rem;
  height: 1.1rem;
  color: var(--muted);
}

.item.is-danger {
  color: var(--danger);
}

.item.is-danger .item-icon {
  background: color-mix(in srgb, var(--danger) 13%, transparent);
  color: var(--danger);
}

.item select {
  flex: none;
  width: auto;
  min-width: 6.5rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
}

input.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 2.75rem;
  height: 1.6rem;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.2s;
}

input.switch::after {
  content: "";
  position: absolute;
  top: 0.175rem;
  left: 0.175rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
  transition: transform 0.2s;
}

input.switch:checked {
  background: var(--accent);
}

input.switch:checked::after {
  transform: translateX(1.15rem);
}

.badge {
  flex: none;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 0.75rem;
}

.note {
  margin: 0 0.35rem 0.9rem;
  font-size: 0.85rem;
}

.fact {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.8rem;
  font-size: 0.9rem;
}

.fact span:last-child {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.list-box {
  max-height: 45dvh;
  overflow: auto;
  margin-bottom: 0.6rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.check {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.6rem 0.8rem;
}

.check input {
  margin-top: 0.35rem;
  accent-color: var(--accent);
}

.check span {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-wrap: anywhere;
}

.scanner {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #000;
  border-radius: 10px;
}

.qr {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 8px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 6rem;
  transform: translateX(-50%);
  max-width: calc(100vw - 2rem);
  background: var(--text);
  color: var(--bg);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
}

#toast.show {
  opacity: 1;
  visibility: visible;
}

#toast.error {
  background: var(--danger);
  color: var(--card);
}

/* 手机上对话框贴底显示。 */
@media (max-width: 480px) {
  dialog {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 20px 20px 0 0;
  }

  .dialog-body {
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
  }
}
