:root {
  color-scheme: dark;
  --bg-0: #070b0a;
  --bg-1: #0b1311;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --ink: #eaf2ee;
  --ink-dim: #c3d1cb;
  --muted: #8b9d95;
  --primary: #10b981;
  --primary-bright: #34d399;
  --primary-ink: #04140e;
  --amber: #f4b740;
  --danger: #f2705c;
  --danger-dark: #c04a3a;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  --radius-sm: 11px;
  --font:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 640px at 12% -8%, rgba(16, 185, 129, 0.22), transparent 60%),
    radial-gradient(900px 560px at 92% 4%, rgba(244, 183, 64, 0.14), transparent 58%),
    radial-gradient(1000px 900px at 78% 118%, rgba(16, 185, 129, 0.1), transparent 60%),
    var(--bg-0);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- buttons ---------- */
button,
.download-button {
  border: 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--primary-bright), var(--primary));
  color: var(--primary-ink);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  min-height: 48px;
  padding: 0 22px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 10px 24px rgba(16, 185, 129, 0.22);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease, opacity 0.16s ease;
}

button:hover,
.download-button:hover {
  filter: brightness(1.05);
  box-shadow: 0 14px 32px rgba(16, 185, 129, 0.32);
  transform: translateY(-1px);
}

button:active,
.download-button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

.ghost-button {
  min-height: 40px;
  background: var(--panel-strong);
  color: var(--ink-dim);
  border: 1px solid var(--line);
  box-shadow: none;
  padding: 0 16px;
  font-weight: 600;
}

.ghost-button:hover {
  filter: none;
  background: rgba(255, 255, 255, 0.11);
  color: var(--ink);
  box-shadow: none;
}

.danger-button {
  min-height: 38px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(242, 112, 92, 0.4);
  box-shadow: none;
  padding: 0 14px;
  font-weight: 600;
}

.danger-button:hover {
  filter: none;
  background: rgba(242, 112, 92, 0.14);
  border-color: var(--danger);
  color: #ffd9d1;
  box-shadow: none;
}

/* ---------- fields ---------- */
input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.28);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input,
select {
  min-height: 48px;
  padding: 0 15px;
}

textarea {
  min-height: 128px;
  resize: vertical;
  padding: 13px 15px;
  line-height: 1.55;
  font-family: var(--mono);
  font-size: 14px;
}

input::placeholder,
textarea::placeholder {
  color: #64756e;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  background: rgba(0, 0, 0, 0.34);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.16);
}

label {
  color: var(--ink-dim);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  margin: -4px 0 0;
}

/* ---------- shared bits ---------- */
.eyebrow {
  color: var(--primary-bright);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  margin: 0 0 12px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.12;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 800;
}

h2 {
  font-size: 20px;
  font-weight: 700;
}

.message {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.message.error {
  color: #ffb1a3;
}

.message.success {
  color: var(--primary-bright);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--ok {
  color: var(--primary-bright);
  background: rgba(16, 185, 129, 0.13);
  border-color: rgba(16, 185, 129, 0.32);
}

.badge--amber {
  color: var(--amber);
  background: rgba(244, 183, 64, 0.13);
  border-color: rgba(244, 183, 64, 0.32);
}

.badge--muted {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}

.badge--danger {
  color: #ff9d8d;
  background: rgba(242, 112, 92, 0.14);
  border-color: rgba(242, 112, 92, 0.34);
}

.badge--danger::before,
.badge--muted::before {
  opacity: 0.85;
}

/* ---------- redeem page ---------- */
.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.redeem-panel {
  width: min(100%, 560px);
  padding: clamp(28px, 5vw, 48px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(155deg, rgba(16, 185, 129, 0.25), rgba(255, 255, 255, 0.04));
  border: 1px solid var(--line-strong);
  display: grid;
  place-items: center;
  margin-bottom: 26px;
}

.brand-mark span {
  width: 26px;
  height: 18px;
  border-radius: 5px;
  background:
    linear-gradient(90deg, transparent 0 32%, rgba(4, 20, 14, 0.9) 32% 44%, transparent 44%),
    linear-gradient(180deg, var(--primary-bright), var(--primary));
}

h1 .accent {
  color: var(--primary-bright);
}

.redeem-form,
.stack-form {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.download-box {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.09), rgba(255, 255, 255, 0.02));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  animation: rise 0.28s ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.download-box .file-meta {
  min-width: 0;
}

.file-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 5px;
}

#fileName {
  display: block;
  font-size: 15px;
  overflow-wrap: anywhere;
}

#fileSize {
  color: var(--muted);
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.redeem-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.redeem-meta:empty {
  display: none;
}

/* ---------- admin layout ---------- */
.admin-layout {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 60px;
}

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

.admin-header h1 {
  font-size: clamp(26px, 3.4vw, 38px);
}

.admin-panel {
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#loginPanel {
  max-width: 420px;
  margin: 8vh auto 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 20px;
  align-items: start;
}

.upload-panel {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.keys-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.link-button {
  background: none;
  border: 0;
  box-shadow: none;
  color: var(--primary-bright);
  min-height: auto;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
}

.link-button:hover {
  filter: none;
  box-shadow: none;
  transform: none;
  text-decoration: underline;
}

.drop-zone {
  position: relative;
  min-height: 150px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.drop-zone:hover {
  border-color: var(--muted);
}

.drop-zone.dragging {
  border-color: var(--primary);
  background: rgba(16, 185, 129, 0.1);
}

.drop-zone input {
  display: none;
}

.drop-zone strong {
  font-size: 15px;
}

.drop-zone span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.drop-zone .drop-icon {
  width: 34px;
  height: 34px;
  opacity: 0.6;
}

/* ---------- batch result ---------- */
.batch-result {
  border: 1px solid rgba(16, 185, 129, 0.28);
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.07);
  padding: 14px;
  animation: rise 0.28s ease;
}

.batch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-dim);
}

.batch-list {
  display: grid;
  gap: 7px;
  max-height: 240px;
  overflow-y: auto;
}

.batch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.batch-file {
  color: var(--muted);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- card list ---------- */
.list-panel {
  min-width: 0;
}

.list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.list-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input {
  min-height: 40px;
  width: 200px;
}

.count-pill {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.card-list {
  display: grid;
  gap: 10px;
}

.card-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.22);
  padding: 15px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.card-row:hover {
  border-color: var(--line-strong);
  background: rgba(0, 0, 0, 0.3);
}

.card-row.is-dead {
  opacity: 0.62;
}

.card-main {
  min-width: 0;
}

.key-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.key-code {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-bright);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.22);
  border-radius: 8px;
  padding: 3px 9px;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.key-code:hover {
  background: rgba(16, 185, 129, 0.16);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.card-meta .file {
  color: var(--ink-dim);
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 12px;
  font-size: 14px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: rgba(10, 20, 16, 0.95);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .input-row,
  .field-inline,
  .download-box,
  .card-row {
    grid-template-columns: 1fr;
  }

  .admin-header {
    align-items: flex-start;
  }

  .download-box {
    align-items: stretch;
  }

  .input-row button,
  .download-button {
    width: 100%;
  }

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

  .search-input {
    width: 100%;
  }
}
