:root {
  color-scheme: light;

  /* ── paper-elegant monochrome palette ── */
  --bg: #FAF9F6;
  --bg-deep: #F3F1EC;
  --surface: #FFFFFF;
  --surface-soft: #FBFAF7;
  --surface-hover: #F6F4EF;

  --text: #1A1714;
  --muted: #6E665C;
  --dim: #9C948A;
  --faint: #C2BBB0;

  --line: rgba(26,23,20,0.10);
  --line-soft: rgba(26,23,20,0.06);
  --line-strong: rgba(26,23,20,0.18);

  --primary: #1A1714;          /* ink — used as button bg & dark text */
  --primary-soft: #2E2A25;
  --accent: #4B463F;           /* refined charcoal accent */
  --cyan: #4B463F;             /* legacy alias → charcoal */

  /* muted, desaturated semantic tones (earthy, paper-friendly) */
  --green:   #4F7355;
  --warning: #9A7B3C;
  --danger:  #A4554C;

  /* legacy aliases referenced by inline styles */
  --color-text-secondary: var(--muted);
  --color-text-primary: var(--text);
  --color-border-tertiary: var(--line);

  --shadow:    0 30px 70px -28px rgba(26,23,20,0.28), 0 8px 24px -12px rgba(26,23,20,0.12);
  --shadow-sm: 0 14px 34px -20px rgba(26,23,20,0.22), 0 2px 8px -4px rgba(26,23,20,0.08);
  --shadow-xs: 0 1px 2px rgba(26,23,20,0.05);

  --radius: 18px;
  --radius-sm: 11px;

  --font-serif: "Fraunces", "Songti SC", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; scroll-behavior: smooth; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  font-family: var(--font-sans);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background:
    radial-gradient(ellipse 80% 50% at 50% -8%, rgba(26,23,20,0.035), transparent 70%),
    radial-gradient(ellipse 50% 40% at 92% 8%, rgba(26,23,20,0.02), transparent 70%),
    var(--bg);
}

body::before {
  position: fixed; inset: 0; z-index: -3; pointer-events: none;
  background-image:
    linear-gradient(rgba(26,23,20,0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(26,23,20,0.028) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent 60%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent 60%);
  content: "";
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { border: 0; cursor: pointer; }

h1, h2, h3, .brand-mark, .preview-orb { font-family: var(--font-serif); }

#particle-canvas { position: fixed; inset: 0; z-index: -2; width: 100%; height: 100%; opacity: 0.5; }

.site-glow {
  position: fixed; inset: auto 0 0; z-index: -1; height: 34vh; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(26,23,20,0.025));
}

/* ── header ── */
.site-header-wrap {
  position: sticky; top: 0; z-index: 20;
  width: 100%;
  isolation: isolate;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  background: rgba(250,249,246,0.78);
  -webkit-backdrop-filter: saturate(140%) blur(18px);
  backdrop-filter: saturate(140%) blur(18px);
  border-bottom: 1px solid var(--line-soft);
}

.site-header {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 16px 0;
}

.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); font-weight: 600; letter-spacing: -0.01em; }

.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--line-strong); border-radius: 11px;
  background: var(--primary); color: var(--bg);
  box-shadow: var(--shadow-xs);
  font-size: 17px; font-weight: 500; letter-spacing: 0.01em;
}

.site-nav {
  display: flex; align-items: center; gap: 2px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); padding: 4px;
  box-shadow: var(--shadow-xs);
}
.site-nav a {
  border-radius: 999px; color: var(--muted); font-size: 14px; font-weight: 500; padding: 8px 15px;
  transition: background 180ms, color 180ms;
}
.site-nav a:hover { background: var(--surface-hover); color: var(--text); }

/* ── buttons ── */
.ghost-button, .secondary-button, .primary-button, .danger {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; border-radius: 999px; padding: 0 20px;
  font-weight: 600; font-size: 14px; letter-spacing: 0.005em;
  transition: transform 180ms, background 180ms, box-shadow 180ms, border-color 180ms, color 180ms;
}

.ghost-button, .secondary-button {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-xs);
}
.ghost-button:hover, .secondary-button:hover {
  background: var(--surface-hover); border-color: var(--text); transform: translateY(-1px);
}

.primary-button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--bg); box-shadow: var(--shadow-sm);
}
.primary-button:hover { background: var(--primary-soft); transform: translateY(-1px); box-shadow: var(--shadow); }

.danger {
  border: 1px solid rgba(164,85,76,0.30); background: rgba(164,85,76,0.07); color: var(--danger);
}
.danger:hover { background: rgba(164,85,76,0.13); transform: translateY(-1px); }

/* ── hero ── */
.hero-section {
  display: grid; grid-template-columns: minmax(0,1fr) minmax(300px,400px);
  align-items: center; gap: 56px;
  width: min(1180px, calc(100% - 32px)); min-height: calc(100vh - 76px);
  margin: 0 auto; padding: 80px 0 100px;
}

.hero-content { max-width: 660px; }

.hero-badge {
  display: inline-flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font-size: 12px; font-weight: 600; padding: 7px 15px; letter-spacing: 0.04em;
  box-shadow: var(--shadow-xs);
}

.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 0 rgba(79,115,85,0.5); animation: pulse 2s infinite;
}

.hero-content h1 {
  margin: 26px 0 22px;
  font-size: clamp(46px, 7.6vw, 94px);
  font-weight: 400;
  line-height: 0.98; letter-spacing: -0.02em; color: var(--text);
}
.hero-content h1 .grad {
  font-style: italic;
  font-weight: 400;
  background: linear-gradient(120deg, var(--text) 35%, #8C8377);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

.hero-content p { max-width: 540px; margin: 0; color: var(--muted); font-size: 17px; line-height: 1.85; }

.hero-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 34px; }

.hero-card {
  position: relative; overflow: hidden;
  border: 1px solid var(--line); border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow); padding: 26px;
}
.hero-card::before {
  position: absolute; inset: 0; z-index: 0; border-radius: 22px;
  background: linear-gradient(150deg, rgba(26,23,20,0.035), transparent 50%);
  content: "";
}
.client-preview { position: relative; z-index: 1; }

.client-preview { display: grid; gap: 18px; align-content: start; }

.preview-orb {
  display: grid; place-items: center; width: 70px; height: 70px; border-radius: 20px;
  background: var(--primary);
  color: var(--bg); font-size: 30px; font-weight: 400;
  box-shadow: var(--shadow-sm);
}

.preview-stats {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface-soft); padding: 13px 16px;
}
.preview-stats span { color: var(--muted); font-size: 13px; }
.preview-stats strong { color: var(--text); font-size: 13px; font-weight: 600; }

/* ── sections ── */
.content-section, .admin-shell {
  width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 64px 0;
}

.section-title { max-width: 660px; margin-bottom: 30px; }
.section-title p, .section-kicker {
  margin: 0 0 12px; color: var(--dim); font-size: 11px; font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase;
}
.section-title h2 { margin: 0; font-size: clamp(30px, 4vw, 46px); font-weight: 400; letter-spacing: -0.015em; }

/* ── feature grid ── */
.feature-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }

.feature-card, .guide-card, .status-strip, .admin-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.feature-card {
  min-height: 212px; padding: 26px;
  transition: transform 200ms, border-color 200ms, box-shadow 200ms;
}
.feature-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-4px); }

.card-icon {
  display: inline-grid; place-items: center; width: 44px; height: 44px;
  border-radius: 13px; background: var(--bg-deep);
  border: 1px solid var(--line); font-size: 20px;
  filter: grayscale(1) contrast(0.92);
}

.feature-card h3 { margin: 20px 0 9px; font-size: 21px; font-weight: 500; letter-spacing: -0.01em; color: var(--text); }

.feature-tag {
  display: inline-flex; align-items: center; width: fit-content; margin-bottom: 13px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-soft); color: var(--dim);
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em; padding: 4px 10px;
}

.feature-card p, .guide-card p, .dialog-copy { margin: 0; color: var(--muted); line-height: 1.74; font-size: 14px; }

.split-section { padding-top: 20px; }
.guide-card { padding: 26px; }

.status-strip { display: grid; grid-template-columns: repeat(3,1fr); gap: 1px; overflow: hidden; padding: 0; background: var(--line); }
.status-strip div { display: grid; gap: 7px; min-height: 120px; place-items: center; background: var(--surface); }
.status-strip strong { font-size: 26px; font-weight: 400; font-family: var(--font-serif); color: var(--text); }
.status-strip span { color: var(--muted); font-size: 12px; font-weight: 500; }

/* ── admin layout ── */
.admin-shell[hidden], .admin-hero[hidden] { display: none; }
.admin-shell { scroll-margin-top: 90px; }
.admin-page main { padding-top: 80px; }

.admin-hero {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; margin-bottom: 20px; padding: 22px 0 4px;
}
.admin-hero h1 { margin: 0; font-size: clamp(32px,5vw,54px); font-weight: 400; line-height: 1.02; letter-spacing: -0.02em; color: var(--text); }
.admin-hero p:not(.section-kicker) { max-width: 640px; margin: 14px 0 0; color: var(--muted); }

.admin-heading, .records-head, .api-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.admin-actions, .form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.admin-actions button:disabled, .form-actions button:disabled { cursor: not-allowed; opacity: 0.4; transform: none; }

.admin-card { margin-top: 16px; padding: 24px; }

.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }

label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }

input, select, textarea {
  width: 100%; min-height: 44px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-soft); color: var(--text); outline: none; padding: 10px 13px;
  transition: border-color 180ms, box-shadow 180ms, background 180ms;
}
select { color-scheme: light; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  border-color: var(--text); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(26,23,20,0.07);
}

.wide { grid-column: 1 / -1; }

.api-card h3, .records-head h3 { margin: 0; font-size: 22px; font-weight: 500; color: var(--text); }
.api-card p:not(.section-kicker) { margin: 8px 0 0; color: var(--muted); }

.package-card .admin-heading { align-items: flex-start; }
.package-card h3 { margin: 0; font-size: 22px; font-weight: 500; color: var(--text); }
.package-card p:not(.section-kicker) { max-width: 720px; margin: 8px 0 0; color: var(--muted); line-height: 1.68; }
.package-form { margin-top: 20px; }

.manual-upload-tip {
  display: grid; grid-template-columns: auto minmax(0,1fr);
  gap: 8px 12px; align-items: center; margin-top: 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-soft); padding: 14px;
}
.manual-upload-tip strong { color: var(--text); }
.manual-upload-tip code { overflow-wrap: anywhere; }
.manual-upload-tip span { grid-column: 1/-1; color: var(--muted); line-height: 1.6; font-size: 13px; }

.package-status { margin-top: 16px; }
.package-empty {
  display: grid; gap: 6px; border: 1px dashed var(--line-strong); border-radius: 12px;
  background: var(--surface-soft); padding: 18px;
}
.package-empty strong, .package-meta strong { color: var(--text); }
.package-empty span, .package-meta span, .package-meta p { color: var(--muted); }

.package-meta { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 10px; }
.package-meta div {
  display: grid; gap: 5px; min-width: 0;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-soft); padding: 13px;
}
.package-meta span { font-size: 10px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: 0.1em; }
.package-meta strong, .package-meta code, .package-meta p { overflow-wrap: anywhere; }
.package-meta code { color: var(--accent); font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.package-meta p { margin: 0; line-height: 1.6; }
.wide-meta { grid-column: span 2; }

.search-box { min-width: min(320px, 100%); }
.table-scroll { margin-top: 18px; overflow-x: auto; }

table { width: 100%; min-width: 880px; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 14px 12px; text-align: left; vertical-align: top; }
th { color: var(--dim); font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
td { font-size: 13px; color: var(--text); }

td code {
  display: inline-block; max-width: 220px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface-soft); color: var(--accent);
  font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px;
  padding: 3px 7px; text-overflow: ellipsis; white-space: nowrap;
}

.owner { display: block; margin-bottom: 4px; font-weight: 600; }
.notes {
  display: -webkit-box; max-width: 230px; overflow: hidden;
  color: var(--muted); font-size: 12px;
  -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}

.status-pill {
  display: inline-flex; align-items: center; min-height: 26px;
  border: 1px solid currentColor; border-radius: 999px;
  padding: 0 10px; font-size: 11px; font-weight: 700;
}
.status-active  { background: rgba(79,115,85,0.09);  color: var(--green); }
.status-paused  { background: rgba(154,123,60,0.10); color: var(--warning); }
.status-blocked, .status-expired { background: rgba(164,85,76,0.09); color: var(--danger); }

.usage, .last-seen { color: var(--muted); white-space: nowrap; font-size: 12px; }

.row-actions { display: grid; grid-template-columns: repeat(auto-fill,minmax(64px,1fr)); gap: 6px; }
.row-actions button {
  min-height: 32px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-soft); color: var(--muted); cursor: pointer; font-size: 12px;
  transition: background 160ms, color 160ms, border-color 160ms;
}
.row-actions button:hover { background: var(--surface-hover); color: var(--text); border-color: var(--line-strong); }
.row-actions button.btn-danger { border-color: rgba(164,85,76,0.3); color: var(--danger); }
.row-actions button.btn-danger:hover { background: rgba(164,85,76,0.1); color: var(--danger); border-color: rgba(164,85,76,0.55); }

.empty-state { display: none; padding: 40px 16px; text-align: center; }
.empty-state h3 { color: var(--text); font-weight: 500; }
.empty-state p { margin: 8px 0 0; color: var(--muted); }
.records-card.empty .table-scroll { display: none; }
.records-card.empty .empty-state { display: block; }

.log-card table { min-width: 1040px; }
.log-card .reported-ip, .log-card .token-tail, .log-card .version,
.log-card .loader, .log-card .client-time, .log-card .timestamp {
  display: block; margin-top: 4px; color: var(--muted); font-size: 11px;
}
.log-card .created-at { color: var(--muted); white-space: nowrap; }

/* ── login dialog ── */
.login-dialog {
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); padding: 0;
}
.login-dialog::backdrop { background: rgba(26,23,20,0.32); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.login-dialog form { position: relative; display: grid; gap: 16px; padding: 30px; }

.dialog-close {
  position: absolute; top: 18px; right: 18px;
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-soft); color: var(--muted); cursor: pointer; font-size: 18px;
}
.dialog-close:hover { background: var(--surface-hover); color: var(--text); }
.login-dialog h2 { margin: 0 38px 0 0; font-size: 24px; font-weight: 500; }

/* ── toast ── */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  max-width: min(380px, calc(100vw - 40px));
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); padding: 12px 16px; font-size: 14px;
  opacity: 0; pointer-events: none; transform: translateY(10px);
  transition: opacity 200ms, transform 200ms;
}
.toast.show { opacity: 1; transform: translateY(0); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(79,115,85,0.5); }
  70%  { box-shadow: 0 0 0 9px rgba(79,115,85,0); }
  100% { box-shadow: 0 0 0 0 rgba(79,115,85,0); }
}

/* ── responsive ── */
@media (max-width: 920px) {
  .site-nav { display: none; }
  .hero-section { grid-template-columns: 1fr; min-height: auto; padding-top: 64px; }
  .hero-card { max-width: 520px; }
  .feature-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .status-strip { grid-template-columns: 1fr; }
  .admin-heading, .records-head, .api-card,
  .package-card .admin-heading { align-items: stretch; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .package-meta { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 640px) {
  .site-header, .hero-section, .content-section, .admin-shell { width: min(100% - 20px, 1180px); }
  .site-header { padding: 10px 0; }
  .brand span:last-child { display: none; }
  .hero-section { gap: 28px; padding-bottom: 52px; }
  .hero-content h1 { font-size: clamp(40px, 13vw, 62px); }
  .hero-content p { font-size: 15px; }
  .hero-actions, .hero-actions a, .hero-actions button,
  .admin-hero, .admin-hero button,
  .admin-actions, .admin-actions button,
  .form-actions, .form-actions button,
  .package-card .admin-actions button,
  .api-card button { width: 100%; }
  .feature-grid { grid-template-columns: 1fr; }
  .feature-card { min-height: auto; }
  .package-meta { grid-template-columns: 1fr; }
  .manual-upload-tip { grid-template-columns: 1fr; }
  .wide-meta { grid-column: auto; }
  table, thead, tbody, tr, th, td { display: block; }
  table { min-width: 0; }
  thead { display: none; }
  tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  td { display: grid; grid-template-columns: 96px minmax(0,1fr); gap: 10px; border-bottom: 0; padding: 7px 0; }
  td::before { color: var(--muted); font-weight: 700; font-size: 11px; content: attr(data-label); }
  td code, .notes { max-width: 100%; }
  .row-actions { grid-template-columns: 1fr; }
}
