:root {
  --canvas: #f5f5f7;
  --surface: #ffffff;
  --surface-muted: #eceef1;
  --ink: #0c0c0d;
  --muted: #6e6e73;
  --line: #d9d9de;
  --blue: #006edb;
  --green: #24734f;
  --red: #ba3c36;
  --bronze: #9a7048;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.09);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: #0b0b0c; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #0b0b0c;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button, input { -webkit-appearance: none; appearance: none; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.login-page {
  min-height: 100svh;
  display: grid;
  place-items: center;
  background: #050506;
}

.login-stage {
  width: min(100%, 460px);
  height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow-x: hidden;
  overflow-y: auto;
  color: #fff;
  background: #09090a;
}

.login-header {
  padding: calc(22px + env(safe-area-inset-top)) 24px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-monogram,
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid currentColor;
  font-size: 10px;
  font-weight: 750;
}

.brand-name { color: #a4a4aa; font-size: 9px; font-weight: 650; }

.login-title {
  align-self: end;
  padding: 28px 24px 38px;
}

.login-title > span { color: #88888f; font-size: 9px; font-weight: 700; }
.login-title h1 { margin: 10px 0 0; max-width: 280px; font-size: 42px; line-height: 1.06; font-weight: 650; }
.login-title p { margin: 12px 0 0; color: #b5b5bb; font-size: 14px; }

.login-panel {
  padding: 27px 24px calc(24px + env(safe-area-inset-bottom));
  display: grid;
  gap: 16px;
  color: var(--ink);
  background: #fff;
  border-top: 1px solid #242427;
}

.field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 560;
}

.field input {
  width: 100%;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  padding: 0 14px;
  color: var(--ink);
  background: #f8f8fa;
  font-size: 15px;
  transition: border-color .2s, background .2s;
}

.field input:focus { border-color: #79797f; background: #fff; }
.field input::placeholder { color: #a1a1a6; }

.login-note {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}

.login-note strong { color: var(--bronze); font-weight: 650; }

.login-button,
.primary-button {
  min-height: 52px;
  border: 0;
  border-radius: 6px;
  padding: 0 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: #111113;
  font-size: 14px;
  font-weight: 650;
  transition: transform .18s, opacity .18s;
}

.login-button:active,
.primary-button:active:not(:disabled) { transform: scale(.985); }
.login-button b,
.primary-button .arrow { color: #8ab8ff; font-size: 20px; font-weight: 400; }
.login-button:disabled { background: #77777d; cursor: wait; }
#loginMessage { min-height: 16px; margin: -5px 0 0; color: var(--red); font-size: 11px; }

#appShell {
  width: min(100%, 540px);
  min-height: 100svh;
  margin: 0 auto;
  position: relative;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--canvas);
  box-shadow: 0 0 70px rgba(0, 0, 0, .45);
}

.topbar {
  min-height: 67px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(0, 0, 0, .07);
  background: rgba(255, 255, 255, .88);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
}

.brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 32px; height: 32px; color: #fff; background: var(--ink); border-color: var(--ink); }
.brand-lockup strong,
.brand-lockup small { display: block; }
.brand-lockup strong { font-size: 14px; line-height: 1.15; font-weight: 670; }
.brand-lockup small { margin-top: 4px; color: #8a8a90; font-size: 7px; font-weight: 700; }

.account-area { margin-left: 12px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-area span { color: var(--muted); font-size: 9px; white-space: nowrap; }
.account-area button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #5f5f64;
  background: rgba(255, 255, 255, .8);
  font-size: 14px;
}

main { padding: 22px 16px calc(102px + env(safe-area-inset-bottom)); }
.app-page { display: none; }
.app-page.active { display: block; }

.page-title { padding: 7px 2px 20px; }
.page-title span,
.works-heading > div > span,
.eyebrow { color: #88888e; font-size: 8px; font-weight: 720; }
.page-title h1,
.works-heading h1 { margin: 7px 0 0; font-size: 29px; line-height: 1.1; font-weight: 640; }

.mode-switch {
  height: 74px;
  margin-bottom: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  background: #fff;
}

.mode-button {
  min-width: 0;
  border: 0;
  border-left: 1px solid #e2e2e6;
  padding: 11px 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: left;
  color: var(--ink);
  background: #fff;
  transition: color .2s, background .2s;
}

.mode-button:first-child { border-left: 0; }
.mode-button.active { color: #fff; background: #111113; }
.mode-index { color: #96969c; font-size: 9px; font-weight: 650; }
.mode-button.active .mode-index { color: #8ab8ff; }
.mode-button strong,
.mode-button small { display: block; white-space: nowrap; }
.mode-button strong { font-size: 12px; font-weight: 650; }
.mode-button small { margin-top: 4px; color: #96969c; font-size: 7px; }
.mode-button.active small { color: #a8a8ae; }

.workspace {
  padding: 20px;
  border: 1px solid #dfdfe3;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.section-heading {
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.section-heading h2 { margin: 6px 0 0; font-size: 20px; line-height: 1.2; font-weight: 630; }
.eyebrow { color: var(--blue); }

.count-badge {
  width: 48px;
  height: 42px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #f8f8fa;
}
.count-badge b { font-size: 17px; font-weight: 630; }
.count-badge i { color: #96969c; font-size: 9px; font-style: normal; }

.upload-grid { width: 100%; margin-bottom: 17px; }
.upload-tile,
.image-tile {
  width: 100%;
  aspect-ratio: 4 / 3;
  position: relative;
  overflow: hidden;
  border: 1px solid #d5d5da;
  border-radius: 8px;
  background: var(--surface-muted);
}

.upload-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.upload-tile:active { background: #e4e6e9; }
.upload-icon {
  width: 44px;
  height: 44px;
  margin-bottom: 13px;
  display: grid;
  place-items: center;
  border: 1px solid #bfc0c5;
  border-radius: 50%;
  color: #272729;
  background: #fff;
  font-size: 24px;
  font-weight: 300;
}
.upload-tile strong { font-size: 13px; font-weight: 620; }
.upload-tile small { margin-top: 7px; color: #89898f; font-size: 8px; }
.image-tile img { width: 100%; height: 100%; display: block; object-fit: cover; }
.image-number {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border-radius: 4px;
  color: #fff;
  background: rgba(0, 0, 0, .68);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 9px;
}
.remove-image {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(0, 0, 0, .68);
  font-size: 20px;
}

.result-count-field {
  min-height: 70px;
  padding: 13px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid #e4e4e7;
}
.result-count-field strong,
.result-count-field small { display: block; }
.result-count-field strong { font-size: 12px; font-weight: 630; }
.result-count-field small { margin-top: 5px; color: #99999f; font-size: 7px; font-weight: 650; }
.result-count-control {
  width: 156px;
  height: 36px;
  padding: 3px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-radius: 6px;
  background: #e9e9ed;
}
.result-count-control button { border: 0; border-radius: 4px; color: #747479; background: transparent; font-size: 11px; }
.result-count-control button.active { color: #111; background: #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .12); }

.primary-button { width: 100%; }
.primary-button:disabled { color: #98989e; background: #e4e4e7; cursor: not-allowed; }
.primary-button:disabled .arrow { color: #ababaf; }
.form-message { min-height: 16px; margin: 9px 2px -4px; color: var(--red); font-size: 10px; }

.works-heading {
  min-height: 69px;
  padding: 6px 2px 20px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}
.works-heading button {
  width: 38px;
  height: 38px;
  border: 1px solid #d6d6da;
  border-radius: 50%;
  color: #55555a;
  background: #fff;
  font-size: 20px;
}

.task-list { display: grid; gap: 12px; }
.task-card {
  min-width: 0;
  padding: 16px;
  overflow: hidden;
  border: 1px solid #dfdfe3;
  border-radius: 8px;
  background: #fff;
}
.task-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.task-title { margin: 0; font-size: 14px; font-weight: 640; }
.task-meta { margin: 6px 0 0; color: var(--muted); font-size: 9px; line-height: 1.5; }
.status { padding: 5px 7px; border-radius: 4px; white-space: nowrap; color: #66666b; background: #eeeeF1; font-size: 8px; font-weight: 650; }
.status.success { color: var(--green); background: #e8f2ec; }
.status.failed { color: var(--red); background: #f8e9e7; }
.status.processing,
.status.queued { color: #7b5a28; background: #f4ecdf; }
.task-results { margin-top: 14px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.task-results.count-1 { grid-template-columns: 1fr; }
.task-results.count-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.task-result { aspect-ratio: 1; position: relative; overflow: hidden; border-radius: 6px; background: #eceef1; }
.task-result img { width: 100%; height: 100%; display: block; object-fit: cover; cursor: zoom-in; }
.task-result.placeholder { display: grid; place-items: center; color: #8b8b90; }
.task-result.placeholder b { font-size: 23px; font-weight: 350; }
.task-result > span { position: absolute; left: 6px; bottom: 6px; min-width: 20px; height: 20px; display: grid; place-items: center; border-radius: 3px; color: #fff; background: rgba(0, 0, 0, .66); font-size: 8px; }
.failed-result { color: var(--red); background: #f6e9e7; }
.spinner { width: 23px; height: 23px; border: 2px solid #d1d1d6; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
.video-result { width: 100%; aspect-ratio: 3 / 4; margin-top: 14px; overflow: hidden; border-radius: 6px; background: #080809; }
.video-result video { width: 100%; height: 100%; display: block; object-fit: contain; }
.video-pending { position: relative; background-size: cover; background-position: center; }
.video-pending::before { content: ''; position: absolute; inset: 0; background: rgba(0, 0, 0, .62); }
.video-overlay { position: relative; z-index: 1; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #fff; }
.video-overlay span { font-size: 11px; }
.video-overlay b { font-size: 27px; font-weight: 350; }
.task-error { margin: 10px 0 0; padding: 9px 10px; border-radius: 4px; color: var(--red); background: #fbefee; font-size: 9px; line-height: 1.5; overflow-wrap: anywhere; }
.task-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.task-actions button,
.task-actions a { min-height: 32px; border: 1px solid #d8d8dc; border-radius: 5px; padding: 0 10px; display: inline-flex; align-items: center; color: #3f3f43; background: #fff; text-decoration: none; font-size: 9px; }

.empty-state { min-height: 310px; display: grid; place-items: center; align-content: center; color: #aaaab0; }
.empty-state span { font-size: 26px; font-weight: 300; }
.empty-state p { margin: 10px 0 0; font-size: 11px; }

.bottom-nav {
  width: min(100%, 540px);
  height: calc(69px + env(safe-area-inset-bottom));
  padding: 0 70px env(safe-area-inset-bottom);
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 12;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border-top: 1px solid rgba(0, 0, 0, .08);
  background: rgba(250, 250, 252, .9);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
}
.bottom-nav button { position: relative; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: #8a8a90; background: transparent; }
.bottom-nav button.active { color: #111113; }
.bottom-nav strong { font-size: 9px; font-weight: 610; }
.nav-symbol { height: 20px; font-size: 20px; line-height: 20px; }
.bottom-nav i { position: absolute; top: 12px; left: calc(50% + 10px); width: 6px; height: 6px; border-radius: 50%; background: var(--blue); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  padding: calc(58px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .94);
}
.modal img,
.modal video { max-width: min(100%, 700px); max-height: calc(100svh - 160px); object-fit: contain; }
.modal video { background: #000; }
.modal-close { position: absolute; top: calc(13px + env(safe-area-inset-top)); right: 16px; width: 38px; height: 38px; border: 1px solid #4f4f53; border-radius: 50%; color: #fff; background: #161618; font-size: 24px; }
.save-button { margin-top: 17px; min-width: 100px; min-height: 40px; border: 1px solid #5c5c61; border-radius: 6px; display: grid; place-items: center; color: #fff; background: #161618; text-decoration: none; font-size: 11px; }

.toast {
  max-width: calc(100% - 40px);
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translate(-50%, 12px);
  overflow: hidden;
  border-radius: 6px;
  padding: 10px 14px;
  color: #fff;
  background: rgba(20, 20, 22, .92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 10px;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes spin { to { transform: rotate(360deg); } }
@media (min-width: 541px) {
  .login-stage { height: min(860px, 100dvh); min-height: min(860px, 100svh); border-left: 1px solid #202024; border-right: 1px solid #202024; box-shadow: 0 0 80px rgba(0, 0, 0, .6); }
  #appShell { border-left: 1px solid #202024; border-right: 1px solid #202024; }
}

@media (max-width: 390px) {
  main { padding-left: 12px; padding-right: 12px; }
  .workspace { padding: 16px; }
  .mode-button { gap: 5px; padding-left: 5px; padding-right: 5px; }
  .mode-index { display: none; }
  .account-area span { font-size: 8px; }
  .bottom-nav { padding-left: 52px; padding-right: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
