:root {
  --bg: #0f1114;
  --bg-soft: #14181d;
  --panel: #171c21;
  --panel-2: #1d242b;
  --panel-3: #232b33;
  --border: #2d3640;
  --border-soft: #252d36;
  --text: #e9edf1;
  --muted: #97a3af;
  --muted-2: #72808d;
  --green: #63c132;
  --green-bright: #8bdc60;
  --green-dark: #3f8f1c;
  --blue: #4aa8e8;
  --blue-bright: #7cc4f4;
  --amber: #e0a63c;
  --amber-bright: #f0c574;
  --red: #e85d5d;
  --red-bright: #ff9b9b;
  --purple: #b083f0;
  --mono: "SFMono-Regular", "Consolas", "Liberation Mono", "Courier New", monospace;
  color-scheme: dark;
  accent-color: var(--green);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(12px, 2.2vw, 22px);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 420px at 18% -10%, rgba(76, 140, 43, 0.22), transparent 62%),
    radial-gradient(800px 380px at 88% -6%, rgba(45, 111, 158, 0.16), transparent 64%);
  background-repeat: no-repeat;
  overflow-x: hidden;
}

body.has-savebar { padding-bottom: 118px; }
body.is-busy { cursor: progress; }

a { color: var(--blue-bright); }
code {
  font-family: var(--mono);
  font-size: 0.82em;
  color: #cfe4bb;
  background: #0c0f12;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 0.08em 0.36em;
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  left: 12px;
  top: -80px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--green);
  color: #081208;
  font-weight: 700;
  transition: top 0.15s;
}
.skip-link:focus { top: 12px; }

h1, h2, h3 { line-height: 1.2; }
h1 { margin: 0; font-size: clamp(1.15rem, 1rem + 1vw, 1.45rem); letter-spacing: 0.01em; }
h1 span { color: var(--green-bright); }
h2 { margin: 0; font-size: 1.06rem; }
h3 { margin: 0 0 6px; font-size: 0.92rem; }
p { margin: 0; }
.mono { font-family: var(--mono); }

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 8px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  width: min(1280px, 100%);
  margin: 0 auto 16px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(15, 18, 22, 0.86);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 11px;
  color: #0a1406;
  background: linear-gradient(145deg, var(--green-bright), var(--green-dark));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 5px 16px rgba(63, 143, 28, 0.28);
}
.logo svg { width: 25px; height: 25px; }
.brand-text { min-width: 0; }
.brand-text p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.world-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
}
.world-picker label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.world-picker select {
  max-width: min(290px, 46vw);
  padding: 6px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.world-picker select:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.world-static { padding-right: 10px; font-weight: 650; overflow-wrap: anywhere; }

/* ---------- Cards / layout ---------- */
main { width: min(1280px, 100%); margin: 0 auto; }
.card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: linear-gradient(180deg, rgba(31, 37, 44, 0.96), var(--panel));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
  padding: 16px;
  margin-bottom: 16px;
}
.cardhead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 13px;
}
.cardhead h2 { overflow-wrap: anywhere; }
.hint { color: var(--muted); font-size: 0.8rem; line-height: 1.45; margin-top: 3px; }
.count { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.banner:empty { display: none; }
.banner { margin-bottom: 16px; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 11px;
  background: rgba(74, 168, 232, 0.08);
  margin-bottom: 10px;
}
.notice:last-child { margin-bottom: 0; }
.notice svg { flex: 0 0 auto; width: 19px; height: 19px; margin-top: 1px; color: var(--blue-bright); }
.notice strong { display: block; font-size: 0.9rem; }
.notice p { color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; white-space: pre-line; margin-top: 2px; }
.notice.error { border-left-color: var(--red); background: rgba(232, 93, 93, 0.09); }
.notice.error svg { color: var(--red-bright); }
.notice.warn { border-left-color: var(--amber); background: rgba(224, 166, 60, 0.08); }
.notice.warn svg { color: var(--amber-bright); }
.notice.success { border-left-color: var(--green); background: rgba(99, 193, 50, 0.08); }
.notice.success svg { color: var(--green-bright); }
.notice .notice-body { min-width: 0; flex: 1; }
.notice .notice-dismiss {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 2px;
  border-radius: 5px;
  cursor: pointer;
}
.notice .notice-dismiss:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

.connection {
  width: min(1280px, 100%);
  margin: 0 auto 16px;
  padding: 10px 14px;
  border: 1px solid rgba(232, 93, 93, 0.45);
  border-radius: 11px;
  background: rgba(232, 93, 93, 0.08);
  color: var(--red-bright);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

/* ---------- Section navigation ---------- */
.section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  width: min(1280px, 100%);
  margin: 0 auto 16px;
}
.section-nav a {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(20, 24, 29, 0.8);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.section-nav a:hover,
.section-nav a:focus-visible {
  color: var(--text);
  border-color: var(--green-dark);
  background: rgba(99, 193, 50, 0.1);
}
.section-nav a:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

html { scroll-padding-top: 96px; }
.section-anchor { scroll-margin-top: 96px; }

.section-head {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin: 22px 0 12px;
}
.section-head h2 { font-size: 1.12rem; }
.section-head .hint { max-width: 74ch; margin-top: 3px; }
.stepnum {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  margin-right: 8px;
  border: 1px solid rgba(99, 193, 50, 0.42);
  border-radius: 999px;
  background: rgba(99, 193, 50, 0.12);
  color: var(--green-bright);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  vertical-align: middle;
}
.section-head .stepnum { margin-right: 0; margin-top: 1px; }
.staged-note { margin: 0 0 12px; }
.staged-note:empty { display: none; }

/* ---------- Empty / world bar ---------- */
.empty-state {
  min-width: 0;
  text-align: center;
  padding: clamp(30px, 6vw, 64px) clamp(8px, 4vw, 20px);
}
.empty-state h2 { margin: 12px 0 6px; overflow-wrap: anywhere; }
.empty-state p {
  color: var(--muted);
  max-width: min(620px, 100%);
  margin: 0 auto 18px;
  overflow-wrap: anywhere;
}
.empty-icon {
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  color: var(--green);
  background: rgba(99, 193, 50, 0.09);
  border: 1px solid rgba(99, 193, 50, 0.28);
}
.empty-icon svg { width: 34px; height: 34px; }

/* ---------- SFTP login ---------- */
.login-card {
  width: min(760px, 100%);
  max-width: 100%;
  margin-inline: auto;
  padding: clamp(18px, 3vw, 28px);
}
.login-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 20px; }
.login-head > div { flex: 1 1 auto; min-width: 0; }
.login-head h2 { overflow-wrap: anywhere; }
.login-head .hint { max-width: 60ch; }
.login-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  color: var(--blue-bright);
  background: rgba(74, 168, 232, 0.09);
  border: 1px solid rgba(74, 168, 232, 0.28);
}
.login-icon svg { width: 26px; height: 26px; }
.login-form { display: grid; gap: 14px; }
.login-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 12px;
}
.field { display: grid; gap: 5px; min-width: 0; }
.field > span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.field > span em { font-style: normal; font-weight: 500; color: var(--muted-2); letter-spacing: 0; text-transform: none; }
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #101419;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  min-height: 40px;
}
.field textarea { font-family: var(--mono); font-size: 0.8rem; resize: vertical; line-height: 1.45; }
.field input::placeholder,
.field textarea::placeholder { color: var(--muted-2); }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--green);
  outline-offset: 1px;
  border-color: transparent;
}
.field-grow { grid-column: 1; }
.field-port { grid-column: 2; }
.field-wide { grid-column: 1 / -1; }
.login-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding-top: 2px;
}
.login-actions .hint { flex: 1 1 220px; margin-top: 0; }
.login-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(232, 93, 93, 0.45);
  border-left: 4px solid var(--red);
  border-radius: 9px;
  background: rgba(232, 93, 93, 0.08);
  color: var(--red-bright);
  font-size: 0.84rem;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.worldbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  background:
    linear-gradient(100deg, rgba(63, 143, 28, 0.16), transparent 48%),
    linear-gradient(180deg, var(--panel-2), var(--panel));
}
.worldbar-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.world-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 11px;
  color: var(--green-bright);
  border: 1px solid rgba(99, 193, 50, 0.3);
  background: rgba(99, 193, 50, 0.1);
}
.world-icon svg { width: 24px; height: 24px; }
.worldbar-title { min-width: 0; }
.worldbar-title h2 { overflow-wrap: anywhere; }
.worldbar-title p { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.worldstats { display: flex; flex-wrap: wrap; gap: 7px; }
.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(12, 15, 18, 0.45);
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
}
.stat b { color: var(--text); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.stat.green b { color: var(--green-bright); }
.stat.amber b { color: var(--amber-bright); }
.stat.blue b { color: var(--blue-bright); }
.stat.red b { color: var(--red-bright); }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-3);
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 750;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.55;
}
.badge.neutral { color: var(--muted); }
.badge.enabled { color: var(--green-bright); border-color: rgba(99, 193, 50, 0.42); background: rgba(99, 193, 50, 0.12); }
.badge.disabled { color: #b9c2cb; border-color: #4a545e; background: rgba(120, 132, 144, 0.1); }
.badge.pending { color: var(--blue-bright); border-color: rgba(74, 168, 232, 0.42); background: rgba(74, 168, 232, 0.12); }
.badge.warning { color: var(--amber-bright); border-color: rgba(224, 166, 60, 0.45); background: rgba(224, 166, 60, 0.12); }
.badge.danger { color: var(--red-bright); border-color: rgba(232, 93, 93, 0.45); background: rgba(232, 93, 93, 0.12); }
.badge.muted { color: var(--muted-2); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }

.kindpill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 31px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.5;
  flex: 0 0 auto;
}
.kindpill.bp { color: var(--green-bright); border: 1px solid rgba(99, 193, 50, 0.45); background: rgba(99, 193, 50, 0.12); }
.kindpill.rp { color: var(--blue-bright); border: 1px solid rgba(74, 168, 232, 0.45); background: rgba(74, 168, 232, 0.12); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42em;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-3);
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.14s, background 0.14s, transform 0.07s, filter 0.14s;
}
.btn:hover { border-color: #4b5a69; background: #29323c; }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn .ic { width: 15px; height: 15px; }
.btn.primary {
  color: #081307;
  border-color: #4b9f25;
  background: linear-gradient(180deg, var(--green-bright), var(--green));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 14px rgba(63, 143, 28, 0.2);
  font-weight: 750;
}
.btn.primary:hover { background: linear-gradient(180deg, #9ae870, #6ccd3a); filter: none; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.btn.danger { color: #2b0606; border-color: #b53d3d; background: linear-gradient(180deg, #ff8a8a, var(--red)); font-weight: 750; }
.btn.danger:hover { background: linear-gradient(180deg, #ffa3a3, #ef6a6a); }
.btn.danger-ghost { color: var(--red-bright); border-color: rgba(232, 93, 93, 0.34); background: rgba(232, 93, 93, 0.06); }
.btn.danger-ghost:hover { border-color: var(--red); background: rgba(232, 93, 93, 0.13); }
.btn.success-ghost { color: var(--green-bright); border-color: rgba(99, 193, 50, 0.36); background: rgba(99, 193, 50, 0.07); }
.btn.success-ghost:hover { border-color: var(--green); background: rgba(99, 193, 50, 0.14); }
.btn.small { padding: 4px 8px; font-size: 0.73rem; border-radius: 7px; }
.btn.small .ic { width: 13px; height: 13px; }
.btn.on { border-color: var(--green); color: var(--green-bright); background: rgba(99, 193, 50, 0.13); }
.filebtn { cursor: pointer; }
.filebtn input { display: none; }
.ic { width: 16px; height: 16px; flex: 0 0 auto; }

.spinner {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 2px solid rgba(0, 0, 0, 0.24);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  html { scroll-behavior: auto; }
  .btn, .dropzone, .toast, .badge { transition: none !important; }
}

/* ---------- Packs ---------- */
.packs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}
.packs-grid > .card { margin-bottom: 0; }
.pack-panel { padding-bottom: 10px; }
.panel-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: rgba(12, 15, 18, 0.36);
}
.packtable { width: 100%; border-collapse: collapse; font-size: 0.84rem; table-layout: fixed; min-width: 520px; }
.packtable col:first-child { width: auto; }
.packtable .col-version { width: 78px; }
.packtable .col-status { width: 128px; }
.packtable .col-actions { width: 190px; }
.packtable th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: #171c21;
  color: var(--muted-2);
  font-size: 0.67rem;
  font-weight: 750;
  letter-spacing: 0.075em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}
.packtable td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.packtable tbody tr:last-child td { border-bottom: 0; }
.packtable tbody tr:hover td { background: rgba(255, 255, 255, 0.018); }
.packtable th:last-child, .packtable td:last-child { text-align: right; }
.packcell { display: flex; align-items: center; gap: 9px; min-width: 0; }
.packicon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #0b0d10;
  image-rendering: auto;
}
.packicon-fallback {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: linear-gradient(145deg, #25302a, #151a18);
  color: var(--green);
}
.packicon-fallback svg { width: 19px; height: 19px; }
.packinfo { min-width: 0; }
.packname { display: block; font-weight: 650; color: var(--text); overflow-wrap: anywhere; }
.packmeta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 7px; margin-top: 2px; color: var(--muted-2); font-size: 0.71rem; }
.packmeta .sep { opacity: 0.45; }
.packmeta .desc { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uuidbtn {
  max-width: 100%;
  padding: 0 5px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: #0c0f12;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.5;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.uuidbtn:hover { color: var(--text); border-color: #46525f; }
.version { font-family: var(--mono); font-size: 0.75rem; color: #c6d0d9; white-space: nowrap; }
.statuscell { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.rowactions { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; }
.actions-head { text-align: right !important; }
.empty { color: var(--muted); font-size: 0.84rem; font-style: italic; padding: 14px 4px 8px; }
.packtable + .empty { text-align: center; }
.subtle { color: var(--muted-2); font-size: 0.7rem; }
.version-mobile { display: none; }
.mismatch { color: var(--amber-bright); }

/* ---------- Pending ---------- */
.pending-card {
  border-color: rgba(224, 166, 60, 0.38);
  background:
    linear-gradient(120deg, rgba(224, 166, 60, 0.09), transparent 55%),
    linear-gradient(180deg, var(--panel-2), var(--panel));
}
.pending-list { list-style: none; margin: 0 0 13px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.pending-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: rgba(12, 15, 18, 0.36);
  font-size: 0.81rem;
}
.pending-item .grow { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.pending-item .detail { color: var(--muted); font-size: 0.73rem; }
.pending-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Import ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 26px 18px;
  border: 2px dashed #3b4a36;
  border-radius: 13px;
  background: rgba(99, 193, 50, 0.045);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.dropzone:hover { border-color: var(--green-dark); background: rgba(99, 193, 50, 0.075); }
.dropzone:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
.dropzone.over { border-color: var(--green); background: rgba(99, 193, 50, 0.13); box-shadow: 0 0 0 4px rgba(99, 193, 50, 0.12); }
.dropzone strong { color: var(--text); font-size: 0.97rem; }
.dropzone span { font-size: 0.78rem; }
.dropzone .drop-hint { color: var(--muted-2); font-size: 0.74rem; }
.drop-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
  border-radius: 13px;
  color: var(--green);
  background: rgba(99, 193, 50, 0.1);
}
.drop-icon svg { width: 28px; height: 28px; }
.import-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
#importLimits { max-width: 45%; text-align: right; }

.progress { margin-top: 12px; }
.progress-label { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 0.78rem; margin-bottom: 5px; overflow-wrap: anywhere; }
.track { height: 9px; border-radius: 999px; border: 1px solid var(--border); background: #0b0e11; overflow: hidden; }
.bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(-55deg, var(--green) 0 8px, var(--green-dark) 8px 16px);
  background-size: 200% 100%;
  animation: stripes 1s linear infinite;
  transition: width 0.18s linear;
}
.bar.indeterminate { width: 100%; opacity: 0.7; }
@keyframes stripes { to { background-position: 32px 0; } }
@media (prefers-reduced-motion: reduce) { .bar { animation: none; } }

/* ---------- JSON ---------- */
.json-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.json-panel {
  min-width: 0;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: rgba(10, 13, 16, 0.44);
  overflow: hidden;
}
.json-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
}
.json-path { font-family: var(--mono); font-size: 0.71rem; color: var(--muted); overflow-wrap: anywhere; flex: 1 1 150px; }
.json-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tabs { display: inline-flex; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: #0c0f12; }
.tab {
  padding: 3px 7px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 650;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: #081307; background: var(--green); }
.tab:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.json-pre {
  margin: 0;
  padding: 12px;
  max-height: 310px;
  overflow: auto;
  color: #c9d5df;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
}
.json-pre:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.json-pre.invalid { color: var(--red-bright); white-space: pre-wrap; }

/* ---------- Warnings / help ---------- */
.warnings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.warnings li {
  padding: 8px 10px;
  border-left: 3px solid var(--amber);
  border-radius: 0 7px 7px 0;
  background: rgba(224, 166, 60, 0.07);
  color: #e7d3ad;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}
.help-card { padding: 0; overflow: hidden; }
.help-card > summary {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 15px 16px;
  cursor: pointer;
  list-style: none;
}
.help-card > summary::-webkit-details-marker { display: none; }
.help-card > summary:hover { background: rgba(255, 255, 255, 0.025); }
.help-card > summary:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.help-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: var(--blue-bright);
  background: rgba(74, 168, 232, 0.1);
  border: 1px solid rgba(74, 168, 232, 0.28);
}
.help-icon svg { width: 19px; height: 19px; }
.help-summary { min-width: 0; flex: 1; }
.help-summary strong { display: block; font-size: 0.95rem; }
.help-summary .hint { margin-top: 1px; }
.help-card > summary::after {
  content: "";
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s;
}
.help-card[open] > summary::after { transform: rotate(225deg); }
.help-body { padding: 0 16px 16px; border-top: 1px solid var(--border-soft); }
.help-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 14px; }
.help-grid p { color: var(--muted); font-size: 0.81rem; line-height: 1.55; margin-top: 6px; }
.help-grid h3 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.help-body > .hint { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border-soft); }

/* ---------- Save bar ---------- */
.savebar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  z-index: 45;
  width: min(1280px, calc(100vw - 24px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid rgba(99, 193, 50, 0.38);
  border-radius: 14px;
  background: rgba(18, 23, 27, 0.96);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
}
.savebar-info { min-width: 0; }
.savebar-info strong { display: block; font-size: 0.88rem; }
.savebar-info span { display: block; color: var(--muted); font-size: 0.75rem; overflow-wrap: anywhere; }
.savebar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 70;
  max-width: min(560px, calc(100vw - 28px));
  padding: 10px 15px;
  border: 1px solid var(--green-dark);
  border-radius: 10px;
  background: #10150f;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  overflow-wrap: anywhere;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.compact {
  max-width: min(360px, calc(100vw - 28px));
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 0.76rem;
  line-height: 1.35;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.36);
}
.toast.error { border-color: var(--red); color: var(--red-bright); }
.toast.warn { border-color: var(--amber); color: var(--amber-bright); }
body.has-savebar .toast { bottom: 100px; }

/* ---------- Dialog ---------- */
.confirm-dialog {
  width: min(460px, 92vw);
  max-width: 92vw;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--text);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.62);
}
.confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.64); backdrop-filter: blur(2px); }
.confirm-dialog h2 { margin-bottom: 8px; overflow-wrap: anywhere; }
.confirm-dialog p { color: var(--muted); font-size: 0.88rem; line-height: 1.55; overflow-wrap: anywhere; white-space: pre-line; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 1040px) {
  .packs-grid, .json-grid { grid-template-columns: 1fr; }
  .help-grid { grid-template-columns: 1fr 1fr; }
  .packtable { min-width: 560px; }
}
@media (max-width: 760px) {
  html { scroll-padding-top: 132px; }
  body {
    padding: max(8px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }
  .topbar {
    top: max(4px, env(safe-area-inset-top));
    gap: 10px;
    padding: 9px 11px;
    border-radius: 13px;
  }
  .brand { gap: 9px; }
  .logo { width: 34px; height: 34px; border-radius: 9px; }
  .logo svg { width: 20px; height: 20px; }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 1.02rem; }
  .header-actions {
    width: 100%;
    gap: 7px;
    justify-content: space-between;
    align-items: stretch;
  }
  .world-picker { flex: 1 1 100%; min-width: 0; }
  .world-picker label { display: none; }
  .world-picker select { max-width: none; width: 100%; flex: 1; min-width: 0; min-height: 40px; }
  #syncBtn { flex: 1 1 auto; }
  #logoutBtn { flex: 0 0 auto; }

  /* Let the step nav scroll sideways instead of wrapping into the page. */
  .section-nav {
    flex-wrap: nowrap;
    gap: 6px;
    margin-bottom: 12px;
    padding: 1px 1px 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .section-nav::-webkit-scrollbar { display: none; }
  .section-nav a {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  .section-head { margin: 16px 0 10px; }
  .section-anchor { scroll-margin-top: 132px; }
  .help-card > summary { padding: 13px; min-height: 48px; }
  .help-body { padding: 0 13px 13px; }
  .help-grid { grid-template-columns: 1fr; }
  .packs-grid { gap: 12px; margin-bottom: 12px; }
  .card { padding: 13px; border-radius: 13px; }
  .login-card { width: 100%; padding: 16px; }
  .login-head { gap: 11px; margin-bottom: 16px; }
  .login-head h2 { font-size: 1.02rem; }
  .login-icon { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 11px; }
  .login-icon svg { width: 22px; height: 22px; }
  .login-grid { grid-template-columns: 1fr; }
  .field-grow, .field-port, .field-wide { grid-column: 1 / -1; }
  .login-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  .login-actions .btn { width: 100%; min-height: 46px; }
  .login-actions .hint { flex: 1 1 auto; margin-top: 0; text-align: center; }
  .empty-state { padding: 28px 8px 22px; }
  .empty-state h2 { margin-top: 10px; }
  .empty-state p { margin-bottom: 16px; }
  .empty-icon { width: 56px; height: 56px; border-radius: 16px; }
  .empty-icon svg { width: 30px; height: 30px; }
  .worldstats { width: 100%; }
  .stat { flex: 1 1 auto; justify-content: center; }
  #importLimits { max-width: 100%; text-align: left; }

  /* 16px inputs stop iOS from zooming the page on focus. */
  .field input,
  .field select,
  .field textarea,
  .world-picker select { font-size: 16px; }
  .field input,
  .field select { min-height: 44px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 40px; padding: 8px 11px; font-size: 0.78rem; }
  .tab { min-height: 38px; padding: 8px 12px; }

  .import-actions { flex-direction: column; }
  .import-actions .btn { width: 100%; }
  .pending-actions { flex-direction: column; }
  .pending-actions .btn { width: 100%; }
  .dialog-actions .btn { flex: 1 1 auto; }
  .savebar {
    bottom: max(8px, env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    padding: 10px 12px;
  }
  .savebar-info { width: 100%; }
  .savebar-actions { width: 100%; }
  .savebar-actions .btn { flex: 1; min-height: 44px; }
  body.has-savebar {
    padding-bottom: calc(160px + env(safe-area-inset-bottom));
  }
  .toast {
    bottom: calc(22px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 20px);
    padding: 12px 14px;
    font-size: 0.86rem;
  }
  body.has-savebar .toast {
    bottom: calc(146px + env(safe-area-inset-bottom));
  }

  /* Stack pack table rows into cards for small screens. */
  .packtable { min-width: 0; }
  .packtable, .packtable tbody, .packtable tr, .packtable td { display: block; width: 100%; }
  .packtable thead { display: none; }
  .packtable tr { border-bottom: 1px solid var(--border-soft); padding: 10px 10px 11px; }
  .packtable tr:last-child { border-bottom: 0; }
  .packtable td { border: 0; padding: 1px 0; }
  .packtable td.cell-version { display: none; }
  .version-mobile { display: inline; }
  .packtable td.statuscell { margin-top: 6px; }
  .packtable td.cell-actions { margin-top: 7px; }
  .rowactions { justify-content: flex-start; }
  .packmeta .desc { white-space: normal; }
}
@media (max-width: 480px) {
  .brand .badge { display: none; }
  .logo { width: 32px; height: 32px; }
  .logo svg { width: 18px; height: 18px; }
  h1 { font-size: 1rem; }
  body { font-size: 14.5px; }
  .cardhead { gap: 8px; }
  .btn { padding: 8px 10px; }
  .pending-item { align-items: flex-start; }
  .json-head { align-items: flex-start; }
  .json-tools { width: 100%; justify-content: space-between; }
  .json-tools .tabs { flex: 1 1 auto; }
  .rowactions { width: 100%; }
  .rowactions .btn { flex: 1 1 auto; }
  .savebar-info span { display: none; }
  .savebar-actions .btn { flex: 1 1 0; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { width: 100%; min-height: 44px; }
  .staged-note { font-size: 0.76rem; }
}
