:root {
  color-scheme: light dark;
  --active-scheme: light;

  --bg-light: #f1f5f9;
  --bg-dark: #0b1120;
  --surface-light: #ffffff;
  --surface-dark: #131c2e;
  --surface-subtle-light: #f8fafc;
  --surface-subtle-dark: #0f172a;
  --text-light: #0f172a;
  --text-dark: #f1f5f9;
  --muted-light: #475569;
  --muted-dark: #94a3b8;
  --border-light: #cbd5e1;
  --border-dark: #293548;

  --accent-light: #2563eb;
  --accent-dark: #60a5fa;
  --accent-hover-light: #1d4ed8;
  --accent-hover-dark: #93c5fd;
  --accent-text-light: #ffffff;
  --accent-text-dark: #09101d;
  --focus-light: #3b82f6;
  --focus-dark: #60a5fa;
  --info-bg-light: #eff6ff;
  --info-bg-dark: #172554;
  --info-border-light: #bfdbfe;
  --info-border-dark: #1e3a8a;

  --success-bg-light: #ecfdf5;
  --success-bg-dark: #064e3b;
  --success-border-light: #a7f3d0;
  --success-border-dark: #065f46;
  --success-text-light: #065f46;
  --success-text-dark: #a7f3d0;

  --error-bg-light: #fef2f2;
  --error-bg-dark: #450a0a;
  --error-border-light: #fecaca;
  --error-border-dark: #7f1d1d;
  --error-text-light: #991b1b;
  --error-text-dark: #fecaca;

  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --surface-subtle: var(--surface-subtle-light);
  --text: var(--text-light);
  --muted: var(--muted-light);
  --border: var(--border-light);
  --accent: var(--accent-light);
  --accent-hover: var(--accent-hover-light);
  --accent-text: var(--accent-text-light);
  --focus: var(--focus-light);
  --info-bg: var(--info-bg-light);
  --info-border: var(--info-border-light);
  --success-bg: var(--success-bg-light);
  --success-border: var(--success-border-light);
  --success-text: var(--success-text-light);
  --error-bg: var(--error-bg-light);
  --error-border: var(--error-border-light);
  --error-text: var(--error-text-light);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  @media (prefers-color-scheme: dark) {
    --active-scheme: dark;
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-subtle: var(--surface-subtle-dark);
    --text: var(--text-dark);
    --muted: var(--muted-dark);
    --border: var(--border-dark);
    --accent: var(--accent-dark);
    --accent-hover: var(--accent-hover-dark);
    --accent-text: var(--accent-text-dark);
    --focus: var(--focus-dark);
    --info-bg: var(--info-bg-dark);
    --info-border: var(--info-border-dark);
    --success-bg: var(--success-bg-dark);
    --success-border: var(--success-border-dark);
    --success-text: var(--success-text-dark);
    --error-bg: var(--error-bg-dark);
    --error-border: var(--error-border-dark);
    --error-text: var(--error-text-dark);
  }

  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
    --active-scheme: dark;
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-subtle: var(--surface-subtle-dark);
    --text: var(--text-dark);
    --muted: var(--muted-dark);
    --border: var(--border-dark);
    --accent: var(--accent-dark);
    --accent-hover: var(--accent-hover-dark);
    --accent-text: var(--accent-text-dark);
    --focus: var(--focus-dark);
    --info-bg: var(--info-bg-dark);
    --info-border: var(--info-border-dark);
    --success-bg: var(--success-bg-dark);
    --success-border: var(--success-border-dark);
    --success-text: var(--success-text-dark);
    --error-bg: var(--error-bg-dark);
    --error-border: var(--error-border-dark);
    --error-text: var(--error-text-dark);
  }

  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
    --active-scheme: light;
    --bg: var(--bg-light);
    --surface: var(--surface-light);
    --surface-subtle: var(--surface-subtle-light);
    --text: var(--text-light);
    --muted: var(--muted-light);
    --border: var(--border-light);
    --accent: var(--accent-light);
    --accent-hover: var(--accent-hover-light);
    --accent-text: var(--accent-text-light);
    --focus: var(--focus-light);
    --info-bg: var(--info-bg-light);
    --info-border: var(--info-border-light);
    --success-bg: var(--success-bg-light);
    --success-border: var(--success-border-light);
    --success-text: var(--success-text-light);
    --error-bg: var(--error-bg-light);
    --error-border: var(--error-border-light);
    --error-text: var(--error-text-light);
  }

  @supports (color: light-dark(white, black)) {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --surface-subtle: light-dark(var(--surface-subtle-light), var(--surface-subtle-dark));
    --text: light-dark(var(--text-light), var(--text-dark));
    --muted: light-dark(var(--muted-light), var(--muted-dark));
    --border: light-dark(var(--border-light), var(--border-dark));
    --accent: light-dark(var(--accent-light), var(--accent-dark));
    --accent-hover: light-dark(var(--accent-hover-light), var(--accent-hover-dark));
    --accent-text: light-dark(var(--accent-text-light), var(--accent-text-dark));
    --focus: light-dark(var(--focus-light), var(--focus-dark));
    --info-bg: light-dark(var(--info-bg-light), var(--info-bg-dark));
    --info-border: light-dark(var(--info-border-light), var(--info-border-dark));
    --success-bg: light-dark(var(--success-bg-light), var(--success-bg-dark));
    --success-border: light-dark(var(--success-border-light), var(--success-border-dark));
    --success-text: light-dark(var(--success-text-light), var(--success-text-dark));
    --error-bg: light-dark(var(--error-bg-light), var(--error-bg-dark));
    --error-border: light-dark(var(--error-border-light), var(--error-border-dark));
    --error-text: light-dark(var(--error-text-light), var(--error-text-dark));
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

/* Role-specific themes */
body.sender-view {
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --focus: #3b82f6;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;
  background-image: radial-gradient(ellipse 80% 45% at 50% -10%, rgba(37, 99, 235, 0.14), transparent);

  @supports (color: light-dark(white, black)) {
    --accent: light-dark(#2563eb, #60a5fa);
    --accent-hover: light-dark(#1d4ed8, #93c5fd);
    --focus: light-dark(#3b82f6, #60a5fa);
    --info-bg: light-dark(#eff6ff, #172554);
    --info-border: light-dark(#bfdbfe, #1e40af);
  }
}

body.admin-view {
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --focus: #6366f1;
  --info-bg: #eef2ff;
  --info-border: #c7d2fe;
  background-image: radial-gradient(ellipse 80% 45% at 50% -10%, rgba(79, 70, 229, 0.16), transparent);

  @supports (color: light-dark(white, black)) {
    --accent: light-dark(#4f46e5, #818cf8);
    --accent-hover: light-dark(#4338ca, #a5b4fc);
    --focus: light-dark(#6366f1, #818cf8);
    --info-bg: light-dark(#eef2ff, #1e1b4b);
    --info-border: light-dark(#c7d2fe, #3730a3);
  }
}

body.recipient-view {
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --focus: #14b8a6;
  --info-bg: #ecfdf5;
  --info-border: #99f6e4;
  background-image: radial-gradient(ellipse 80% 45% at 50% -10%, rgba(13, 148, 136, 0.18), transparent);

  @supports (color: light-dark(white, black)) {
    --accent: light-dark(#0d9488, #2dd4bf);
    --accent-hover: light-dark(#0f766e, #5eead4);
    --accent-text: light-dark(#ffffff, #042f2e);
    --focus: light-dark(#14b8a6, #2dd4bf);
    --info-bg: light-dark(#ecfdf5, #064e3b);
    --info-border: light-dark(#99f6e4, #115e59);
  }
}

@supports not (color: light-dark(white, black)) {
  @media (prefers-color-scheme: dark) {
    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) body.sender-view {
      --accent: #60a5fa; --accent-hover: #93c5fd; --focus: #60a5fa; --info-bg: #172554; --info-border: #1e40af;
    }
    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) body.admin-view {
      --accent: #818cf8; --accent-hover: #a5b4fc; --focus: #818cf8; --info-bg: #1e1b4b; --info-border: #3730a3;
    }
    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) body.recipient-view {
      --accent: #2dd4bf; --accent-hover: #5eead4; --accent-text: #042f2e; --focus: #2dd4bf; --info-bg: #064e3b; --info-border: #115e59;
    }
  }
  :root:has(> head > meta[name="color-scheme"][content="dark"]) body.sender-view {
    --accent: #60a5fa; --accent-hover: #93c5fd; --focus: #60a5fa; --info-bg: #172554; --info-border: #1e40af;
  }
  :root:has(> head > meta[name="color-scheme"][content="dark"]) body.admin-view {
    --accent: #818cf8; --accent-hover: #a5b4fc; --focus: #818cf8; --info-bg: #1e1b4b; --info-border: #3730a3;
  }
  :root:has(> head > meta[name="color-scheme"][content="dark"]) body.recipient-view {
    --accent: #2dd4bf; --accent-hover: #5eead4; --accent-text: #042f2e; --focus: #2dd4bf; --info-bg: #064e3b; --info-border: #115e59;
  }
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

body.admin-view .site-header {
  background: #312e81;
  border-bottom-color: #3730a3;
}

body.recipient-view .site-header {
  background: #0f766e;
  border-bottom-color: #115e59;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand svg {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--accent);
  flex: none;
}

body.admin-view .brand,
body.recipient-view .brand {
  color: #ffffff;
}

body.admin-view .brand svg {
  color: #a5b4fc;
}

body.recipient-view .brand svg {
  color: #99f6e4;
}

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

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

body.admin-view .role-badge,
body.recipient-view .role-badge {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--info-bg);
}

body.admin-view .theme-toggle,
body.recipient-view .theme-toggle {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

body.admin-view .theme-toggle:hover,
body.recipient-view .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
}

.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-to-light {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-to-dark {
    display: none;
  }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-to-light {
    display: inline-flex;
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-to-dark {
  display: none;
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-to-light {
  display: inline-flex;
}

main {
  width: 100%;
  max-width: 30rem;
  margin: 2.25rem auto 3rem;
  padding: 0 1rem;
}

.card {
  padding: 2rem;
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 40px -12px rgba(15, 23, 42, 0.12), 0 4px 12px -4px rgba(15, 23, 42, 0.06);
}

.eyebrow {
  display: inline-block;
  margin: 0 0 0.55rem;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.trust-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.35rem;
}

.trust-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

h1 {
  margin: 0 0 0.45rem;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

p {
  margin: 0 0 1rem;
}

.lead {
  color: var(--muted);
  font-size: 0.95rem;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

input,
textarea {
  display: block;
  width: 100%;
  margin-bottom: 1.15rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-subtle);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
}

input[readonly],
textarea[readonly] {
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
}

.code-input {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 1.15rem;
}

.copy-row input,
.copy-row .with-toggle {
  margin-bottom: 0;
}

.copy-row button {
  width: auto;
  padding: 0 1rem;
  white-space: nowrap;
}

button,
.button {
  display: inline-block;
  width: 100%;
  padding: 0.7rem 1.05rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

button:hover,
.button:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

button:active,
.button:active {
  transform: translateY(1px);
}

button.secondary,
.button.secondary {
  border-color: var(--border);
  background: var(--surface-subtle);
  color: var(--text);
}

button.secondary:hover,
.button.secondary:hover {
  border-color: var(--accent);
  background: var(--info-bg);
}

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

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

a {
  color: var(--accent);
}

.actions {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.notice {
  margin: 1.25rem 0 0;
  padding: 0.8rem 1rem;
  border: 1px solid var(--info-border);
  border-radius: 8px;
  background: var(--info-bg);
  font-size: 0.92rem;
}

.notice.success {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--success-text);
}

.notice.error {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
}

[hidden] {
  display: none !important;
}

.result {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.result .meta {
  margin-top: 0.75rem;
}

.meta {
  color: var(--muted);
  font-size: 0.85rem;
}

textarea {
  resize: vertical;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.field {
  margin: 0 0 1.25rem;
  padding: 0;
  border: 0;
}

.field legend {
  margin-bottom: 0.35rem;
  padding: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-subtle);
}

.segmented label {
  position: relative;
  margin: 0;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  padding: 0.5rem;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}

.segmented label:hover span {
  color: var(--text);
}

.segmented input:checked + span {
  background: var(--accent);
  color: var(--accent-text);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.counter {
  margin: -0.85rem 0 1.15rem;
  text-align: right;
}

.counter.over {
  color: var(--error-text);
}

.with-toggle {
  position: relative;
  margin-bottom: 1.15rem;
}

.with-toggle input {
  margin-bottom: 0;
  padding-right: 2.75rem;
}

.eye-toggle {
  position: absolute;
  top: 50%;
  right: 0.35rem;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0.4rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  transform: translateY(-50%);
}

.eye-toggle:hover {
  border: 0;
  background: var(--surface);
  color: var(--text);
}

.eye-toggle svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.eye-toggle .eye-closed,
.eye-toggle[aria-pressed="true"] .eye-open {
  display: none;
}

.eye-toggle[aria-pressed="true"] .eye-closed {
  display: block;
}

.switch {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0 0 1.4rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-subtle);
  font-weight: 400;
  cursor: pointer;
}

.switch input {
  position: absolute;
  width: 2.5rem;
  height: 1.4rem;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: relative;
  flex: none;
  width: 2.5rem;
  height: 1.4rem;
  margin-top: 0.1rem;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s;
}

.switch-track::after {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: #ffffff;
  content: "";
  transition: transform 0.15s;
}

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

.switch input:checked + .switch-track::after {
  transform: translateX(1.1rem);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch-text {
  display: grid;
  gap: 0.1rem;
}

.switch-title {
  font-weight: 600;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.concealed {
  margin-bottom: 1.15rem;
  padding: 0.75rem 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-subtle);
  color: var(--muted);
}

.spaced-top {
  margin-top: 1.25rem;
}

.result .spaced {
  margin-top: 1rem;
}

.result .button {
  margin-top: 1.5rem;
}

.footer-link {
  margin-top: 1.5rem;
  font-size: 0.875rem;
}

.qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 1.15rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-subtle);
  text-align: center;
}

.qr-box {
  padding: 0.65rem;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  margin-bottom: 0.5rem;
}

.qr canvas {
  display: block;
  width: 11rem;
  height: 11rem;
  image-rendering: pixelated;
}

.info {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.info summary {
  font-weight: 600;
  cursor: pointer;
}

.info ul {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

@media print {
  #form,
  #result {
    display: none !important;
  }

  .card::after {
    content: "Secrets cannot be printed or exported to PDF.";
    display: block;
    margin-top: 1rem;
    color: #000;
  }
}
