:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a202c;
  --muted: #64748b;
  --accent: #0f62fe;
  --accent-hover: #0043ce;
  --error-bg: #fdecec;
  --error-text: #9b1c1c;
  --notice-bg: #e6f4ea;
  --notice-text: #1e6b34;
  --warn-text: #92600a;
  --border: #e2e8f0;
  --tip-bg: #fff8e6;
  --tip-border: #f0d98c;
  --tip-text: #6b5416;
  --danger: #b42318;
  --danger-hover: #912018;
}

/* Dark mode follows the OS preference. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --card: #1a2129;
    --text: #e6e9ee;
    --muted: #8b98a9;
    --accent: #4d8dff;
    --accent-hover: #6ba1ff;
    --error-bg: #3a1d1d;
    --error-text: #ffb4ab;
    --notice-bg: #15301e;
    --notice-text: #86d9a2;
    --warn-text: #e2b93b;
    --border: #2b3440;
    --tip-bg: #2e2712;
    --tip-border: #6b5416;
    --tip-text: #f0d98c;
    --danger: #d13c2f;
    --danger-hover: #e25548;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.brand { font-weight: 700; letter-spacing: 0.02em; }

.site-header nav { display: flex; gap: 1.1rem; align-items: center; }
.site-header a { color: var(--muted); text-decoration: none; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
.site-header a:hover { color: var(--text); }
.site-header a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

main { max-width: 64rem; margin: 2rem auto; padding: 0 1rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
}

.card.narrow { max-width: 26rem; margin: 3rem auto; }

h1 { margin-top: 0; font-size: 1.4rem; }
h2 { font-size: 1.05rem; margin-top: 2rem; border-top: 1px solid var(--border); padding-top: 1.25rem; }

label { display: block; margin: 0.9rem 0 0.25rem; font-weight: 600; font-size: 0.9rem; }
.hint { color: var(--muted); font-weight: 400; font-size: 0.85rem; }

input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

button {
  margin-top: 1.1rem;
  padding: 0.55rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }

.link-button {
  margin: 0;
  padding: 0;
  background: none;
  color: var(--text);
  font-size: 1rem;
}
.link-button:hover { background: none; color: var(--accent); text-decoration: underline; }

form.inline { display: inline; }

.error { background: var(--error-bg); color: var(--error-text); padding: 0.6rem 0.9rem; border-radius: 6px; }
.notice { background: var(--notice-bg); color: var(--notice-text); padding: 0.6rem 0.9rem; border-radius: 6px; }

.qr { text-align: center; }
.qr img { border: 1px solid var(--border); border-radius: 8px; }

.codes { columns: 2; list-style: none; padding: 0; }
.codes li { margin: 0.3rem 0; }
.codes code { font-size: 1.05rem; }

.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin: 1rem 0; }
.stat {
  flex: 1 1 10rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.3rem; font-weight: 700; margin-top: 0.25rem; }

table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }

.chip {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.08rem 0.55rem;
  margin: 0.12rem 0.2rem 0.12rem 0;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}
.perm-cell { max-width: 24rem; }

details { margin: 0.75rem 0; }
code { background: var(--bg); padding: 0.1rem 0.35rem; border-radius: 4px; }

details.step {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0.5rem 0;
  padding: 0;
  background: var(--card);
}
details.step summary {
  cursor: pointer;
  padding: 0.65rem 0.9rem;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
details.step summary::-webkit-details-marker { display: none; }
details.step summary::after { content: "▸"; margin-left: auto; color: var(--muted); }
details.step[open] summary::after { content: "▾"; }
details.step[open] summary { border-bottom: 1px solid var(--border); }
details.step > ol, details.step > p { padding: 0.25rem 1.1rem 0.9rem 1.1rem; margin: 0.5rem 0 0 0; }
details.step ol li { margin: 0.45rem 0; }
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.tip {
  background: var(--tip-bg);
  border: 1px solid var(--tip-border);
  color: var(--tip-text);
  border-radius: 6px;
  padding: 0.55rem 0.8rem;
  margin: 0.5rem 1.1rem 0.9rem 1.1rem !important;
  font-size: 0.9rem;
}

.ok { color: var(--notice-text); font-weight: 600; }
.warn { color: var(--warn-text); font-weight: 600; }
.muted { color: var(--muted); }

/* Small in-table actions: quiet outline buttons, consistent with links. */
button.small {
  margin: 0;
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.small:hover { background: var(--bg); color: var(--text); }
button.small.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.small.danger:hover { background: var(--danger); color: #fff; }
button.danger:not(.small) { background: var(--danger); }
button.danger:not(.small):hover { background: var(--danger-hover); }

td.actions { white-space: nowrap; text-align: right; }
td.actions > * { display: inline-block; vertical-align: middle; margin-left: 0.45rem; }
td.actions a { color: var(--text); font-size: 0.85rem; padding: 0.28rem 0.2rem; text-decoration: none; }
td.actions a:hover { color: var(--accent); text-decoration: underline; }
tbody tr:hover td { background: rgba(125, 135, 150, 0.07); }

fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0.9rem 0; padding: 0.7rem 1rem 0.9rem; max-width: 34rem; }
legend { font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0 0.4rem; }
label.check { display: block; font-weight: 400; margin: 0.3rem 0; }
label.check input { width: auto; margin-right: 0.5rem; }
label.check.indent { margin-left: 1.6rem; }

.error-text { color: var(--error-text); }
.token code { font-size: 1.05rem; word-break: break-all; display: block; padding: 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
pre { background: #0f172a; color: #e2e8f0; padding: 0.9rem 1.1rem; border-radius: 8px; overflow-x: auto; font-size: 0.85rem; }
.filters { display: flex; gap: 0.6rem; align-items: center; margin: 0.75rem 0; flex-wrap: wrap; }
.filters select { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; }
.filters button { margin: 0; }

/* Copy-to-clipboard (copy.js) */
.copy-wrap { position: relative; display: block; }
.copy-wrap.inline { display: inline-flex; align-items: center; gap: 0.3rem; }
.copy-clickable { cursor: pointer; }
button.copy-btn {
  margin: 0;
  padding: 0.28rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  line-height: 0;
}
button.copy-btn:hover { background: var(--bg); color: var(--text); }
button.copy-btn.copied { color: var(--notice-text); border-color: var(--notice-text); }
.copy-wrap:not(.inline) > .copy-btn { position: absolute; top: 0.45rem; right: 0.45rem; }
.copy-wrap > pre { padding-right: 3rem; }
.copy-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(1rem);
  background: var(--text);
  color: var(--card);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}
.copy-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

ul.examples { list-style: none; padding: 0; }
ul.examples li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  margin: 0.4rem 0;
}
