:root {
  color: #17201b;
  background: #f5f7f6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  --green: #168a53;
  --green-dark: #0f6e41;
  --surface: #ffffff;
  --line: #dfe5e1;
  --muted: #68756d;
  --danger: #b42318;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { overflow-x: hidden; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
img { display: block; max-width: 100%; }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 20px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { color: #26322b; background: #fff; border-color: var(--line); }
.button:focus-visible, .icon-button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(22, 138, 83, .22);
  outline-offset: 2px;
}

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-panel { width: min(100%, 380px); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 32px; }
.brand-mark { width: 48px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 8px; color: #fff; background: var(--green); font-size: 24px; font-weight: 800; }
.auth-panel h1 { margin: 24px 0 6px; font-size: 24px; }
.auth-panel p { margin: 0 0 24px; color: var(--muted); }
.stack-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; color: #35423a; font-size: 14px; font-weight: 650; }
input, textarea { width: 100%; border: 1px solid #cfd8d2; border-radius: 6px; background: #fff; color: #17201b; padding: 11px 12px; }
textarea { resize: vertical; line-height: 1.55; }
.alert { margin-bottom: 18px; border-radius: 6px; padding: 12px 14px; font-size: 14px; }
.alert.error { color: #8b1e17; background: #fff1f0; border: 1px solid #f3c4bf; }

.admin-header, .public-header { min-height: 64px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 max(20px, calc((100vw - 1120px) / 2)); }
.admin-header div { display: flex; align-items: baseline; gap: 12px; }
.admin-header strong, .public-header strong { font-size: 18px; }
.admin-header span { color: var(--muted); font-size: 13px; }
.admin-header form, .row-actions form { margin: 0; }
.admin-main { width: min(100% - 40px, 1120px); margin: 0 auto; }
.admin-section { padding: 34px 0; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-heading h1, .section-heading h2 { margin: 0; font-size: 20px; }
.section-heading p, .section-heading span { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.upload-grid .wide { grid-column: 1 / -1; }
.file-field { border: 1px dashed #b8c7be; border-radius: 6px; background: #fff; padding: 14px; }
.file-field { position: relative; cursor: pointer; }
.file-field input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.file-picker { display: flex; align-items: center; gap: 12px; min-width: 0; }
.file-trigger { min-height: 36px; display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 0 12px; background: #f5f7f6; color: #26322b; }
.file-name { min-width: 0; color: var(--muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-progress { display: grid; gap: 9px; }
.upload-progress[hidden] { display: none; }
.progress-track { height: 8px; overflow: hidden; border-radius: 4px; background: #dfe7e2; }
.progress-bar { display: block; width: 100%; height: 100%; background: var(--green); transform: scaleX(0); transform-origin: left center; transition: transform 160ms linear; }
.progress-stats { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 13px; }
.upload-percent { color: #26322b; font-size: 14px; }
.upload-progress.failed .progress-bar { background: var(--danger); }
.checkbox { display: flex; align-items: center; grid-template-columns: 20px auto; gap: 8px; min-height: 44px; }
.checkbox input { width: 18px; height: 18px; margin: 0; accent-color: var(--green); }

.app-table { border-top: 1px solid var(--line); }
.app-row { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto auto; align-items: center; gap: 16px; min-height: 84px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.app-row > img, .catalog-row img { width: 52px; aspect-ratio: 1; border-radius: 8px; }
.app-main { min-width: 0; display: grid; gap: 4px; }
.app-main strong { overflow-wrap: anywhere; }
.app-main span { color: var(--muted); font-size: 13px; }
.status { border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status.live { color: #0a6b3c; background: #e6f5ed; }
.status.offline { color: #5f6963; background: #e9edeb; }
.row-actions { display: flex; align-items: center; gap: 6px; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: #344139; text-decoration: none; cursor: pointer; font-size: 20px; }
.icon-button:hover { background: #e9efeb; }
.icon-button.danger { color: var(--danger); }
details { position: relative; }
summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
.edit-form { position: absolute; z-index: 5; right: 0; top: 46px; width: min(340px, calc(100vw - 40px)); display: grid; gap: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 16px 40px rgba(24, 39, 30, .14); }
.empty-state { padding: 36px 0; color: var(--muted); text-align: center; }

.catalog { width: min(100% - 40px, 720px); margin: 0 auto; padding: 36px 0 64px; }
.catalog h1 { margin: 0 0 24px; font-size: 24px; }
.catalog-list { border-top: 1px solid var(--line); }
.catalog-row { display: grid; grid-template-columns: 52px 1fr 24px; align-items: center; gap: 16px; min-height: 84px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.catalog-row span { min-width: 0; display: grid; gap: 4px; }
.catalog-row strong { overflow-wrap: anywhere; }
.catalog-row small { color: var(--muted); }
.catalog-row b { color: var(--muted); font-size: 26px; }

.download-shell { min-height: 100vh; background: #fff; }
.app-identity { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 56px 24px 40px; text-align: center; }
.app-identity > img { width: 104px; aspect-ratio: 1; border-radius: 8px; box-shadow: 0 10px 30px rgba(18, 38, 26, .12); }
.app-identity h1 { margin: 24px 0 8px; max-width: 680px; font-size: 30px; overflow-wrap: anywhere; }
.app-identity p { margin: 0 0 26px; color: var(--muted); }
.download-button { min-width: 220px; }
.safety-note { margin-top: 12px; color: var(--muted); font-size: 12px; }
.release-section { width: min(100% - 40px, 680px); margin: 0 auto; padding: 34px 0 64px; border-top: 1px solid var(--line); }
.release-section h2 { margin: 0 0 14px; font-size: 18px; }
.release-section p { margin: 0 0 18px; white-space: pre-wrap; line-height: 1.7; color: #3f4b44; overflow-wrap: anywhere; }
.release-section time { color: var(--muted); font-size: 13px; }

.handoff { min-height: 100vh; position: relative; display: grid; place-items: center; padding: 30px 24px; background: #15231b; color: #fff; }
.handoff section { width: min(100%, 420px); text-align: center; }
.handoff img { width: 82px; aspect-ratio: 1; margin: 0 auto; border-radius: 8px; }
.handoff h1 { margin: 24px 0 12px; font-size: 26px; }
.handoff p { margin: 0 0 28px; color: #cdd8d1; line-height: 1.7; }
.handoff .button { width: 100%; margin-top: 10px; }
.handoff .secondary { color: #fff; border-color: #587064; background: transparent; }
.browser-menu { position: absolute; top: max(18px, env(safe-area-inset-top)); right: 22px; font-size: 28px; }

@media (max-width: 640px) {
  .admin-header { padding: 0 16px; }
  .admin-header span { display: none; }
  .admin-main { width: min(100% - 32px, 1120px); }
  .upload-grid { grid-template-columns: 1fr; }
  .upload-grid .wide { grid-column: auto; }
  .progress-stats { align-items: flex-start; flex-direction: column; gap: 4px; }
  .upload-grid .button { width: 100%; }
  .app-row { grid-template-columns: 46px minmax(0, 1fr) auto; gap: 11px; }
  .app-row > img { width: 46px; }
  .status { grid-column: 2; justify-self: start; }
  .row-actions { grid-column: 1 / -1; justify-content: flex-end; border-top: 1px solid #edf1ee; padding-top: 10px; }
  .edit-form { position: fixed; top: 50%; right: 16px; left: 16px; width: auto; transform: translateY(-50%); }
  .app-identity { min-height: 68vh; }
  .app-identity h1 { font-size: 26px; }
  .download-button { width: min(100%, 320px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
