:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-card-light: #ffffff;
  --fg: #e2e8f0;
  --fg-light: #1e293b;
  --primary: #38bdf8;
  --primary-dark: #0ea5e9;
  --border: rgba(255, 255, 255, 0.12);
  --border-light: rgba(15, 23, 42, 0.12);
  --muted: rgba(226, 232, 240, 0.7);
  --body-bg: linear-gradient(135deg, #1f2937, #0f172a 60%, #020617);
  --body-bg-light: linear-gradient(135deg, #f8fafc, #e2e8f0 60%, #cbd5f5);
  --dynamic-bg-image: none;
  --dynamic-bg-size: cover;
  font-family: "Inter", "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--body-bg);
  color: var(--fg);
  display: flex;
  justify-content: center;
  padding: 48px 16px 64px;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

body::before {
  z-index: -2;
  background-image: var(--dynamic-bg-image);
  background-size: var(--dynamic-bg-size);
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  filter: saturate(110%) contrast(105%) brightness(110%);
  opacity: 0;
  will-change: opacity;
}

body::after {
  z-index: -1;
  background: linear-gradient(
    135deg,
    rgba(15, 23, 42, 0.85),
    rgba(15, 23, 42, 0.6) 40%,
    rgba(2, 6, 23, 0.6)
  );
  will-change: opacity;
}

body[data-has-background="true"]::before {
  opacity: 0.75;
}

.layout {
  width: min(960px, 100%);
  display: flex;
  flex-direction: column;
  gap: 24px;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.hero {
  text-align: center;
  padding: 32px 24px;
  background: rgba(15, 23, 42, 0.65);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.4);
}

.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 40px);
}

.hero p {
  margin: 0;
  line-height: 1.6;
  color: var(--muted);
}

.card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 28px;
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
}

.background-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.background-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.background-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.background-source-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.background-source-row textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  color: inherit;
  font: inherit;
  line-height: 1.5;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.background-source-row button {
  align-self: flex-end;
}

.background-source-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.background-card label {
  font-size: 14px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.background-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.background-actions button {
  flex: 0 0 auto;
}

.small-text {
  font-size: 13px;
  line-height: 1.5;
}

.background-status {
  text-align: left;
  min-height: 1.5em;
  overflow-wrap: anywhere;
}

.card h2 {
  margin-top: 0;
  font-size: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.field label {
  font-size: 14px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field textarea {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  color: inherit;
  font: inherit;
  resize: vertical;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  border: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #0f172a;
  font-weight: 600;
}

button.ghost {
  background: rgba(148, 163, 184, 0.14);
  color: var(--fg);
  border: 1px solid rgba(148, 163, 184, 0.24);
}

button.small {
  padding: 6px 14px;
  font-size: 14px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.credential-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 16px;
}

.credential-item {
  background: rgba(15, 23, 42, 0.55);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  position: relative;
  overflow: hidden;
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}

.item-name {
  margin: 0;
  font-size: 18px;
}

.item-meta {
  font-size: 13px;
  color: var(--muted);
}

.item-note {
  margin: 8px 0 12px;
  color: rgba(226, 232, 240, 0.85);
}

.secret {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  letter-spacing: 0.02em;
  word-break: break-all;
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.secret[data-hidden="true"] {
  filter: blur(6px);
  user-select: none;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.muted {
  color: var(--muted);
  text-align: center;
}

.background-card .muted {
  text-align: left;
}

.background-card a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.4);
}

.background-card a:hover {
  text-decoration-color: rgba(255, 255, 255, 0.8);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.85);
  color: var(--fg);
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast[data-visible="true"] {
  opacity: 1;
  transform: translate(-50%, -6px);
}

body.immersive-mode {
  background: transparent;
}

body.immersive-mode::before {
  opacity: 1;
  filter: none;
}

body.immersive-mode:not([data-has-background="true"])::before {
  opacity: 0;
}

body.immersive-mode::after {
  opacity: 0;
}

body.immersive-mode .layout {
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
}

.immersive-exit-button {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.7);
  color: var(--fg);
  font-size: 14px;
  letter-spacing: 0.02em;
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

body.immersive-mode .immersive-exit-button {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

@media (max-width: 720px) {
  body {
    padding: 32px 12px 48px;
  }

  .card {
    padding: 22px;
  }

  .item-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .item-actions {
    justify-content: flex-start;
  }

  .immersive-exit-button {
    top: auto;
    right: 16px;
    left: 16px;
    bottom: 24px;
    width: auto;
    transform: translateY(16px);
  }

  body.immersive-mode .immersive-exit-button {
    transform: translateY(0);
  }
}

@media (prefers-color-scheme: light) {
  body {
    background: var(--body-bg-light);
    color: var(--fg-light);
  }

  body::after {
    background: linear-gradient(
      135deg,
      rgba(241, 245, 249, 0.78),
      rgba(226, 232, 240, 0.7) 40%,
      rgba(226, 232, 240, 0.65)
    );
  }

  body[data-has-background="true"]::before {
    opacity: 0.6;
    filter: saturate(120%) contrast(105%) brightness(102%);
  }

  .hero {
    background: rgba(255, 255, 255, 0.85);
    border-color: var(--border-light);
    box-shadow: 0 18px 55px rgba(15, 23, 42, 0.08);
  }

  .hero p {
    color: rgba(71, 85, 105, 0.8);
  }

  .card {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(15, 23, 42, 0.08);
    box-shadow: 0 18px 55px rgba(15, 23, 42, 0.08);
  }

  .background-card label {
    color: rgba(100, 116, 139, 0.8);
  }

  .background-card a {
    color: var(--fg-light);
    text-decoration-color: rgba(15, 23, 42, 0.24);
  }

  .background-card a:hover {
    text-decoration-color: rgba(15, 23, 42, 0.5);
  }

  .field input,
  .field textarea {
    background: rgba(248, 250, 252, 0.85);
    color: inherit;
  }

  .background-source-row textarea {
    background: rgba(248, 250, 252, 0.85);
    color: inherit;
  }

  .credential-item {
    background: rgba(248, 250, 252, 0.85);
    border-color: rgba(15, 23, 42, 0.1);
  }

  button.ghost {
    background: rgba(15, 23, 42, 0.04);
    color: var(--fg-light);
    border-color: rgba(15, 23, 42, 0.08);
  }

  #toast {
    background: rgba(15, 23, 42, 0.9);
    color: #f8fafc;
  }

  .immersive-exit-button {
    background: rgba(255, 255, 255, 0.9);
    color: var(--fg-light);
    border-color: rgba(15, 23, 42, 0.1);
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
  }
}
