:root {
  --primary: #1c1c1c;
  --primary-soft: rgba(28, 28, 28, 0.07);
  --canvas: #f7f4ed;
  --paper: #fcfbf8;
  --surface: rgba(252, 251, 248, 0.82);
  --hairline: #e8e2d8;
  --hairline-strong: rgba(28, 28, 28, 0.34);
  --ink: #1a1a1a;
  --body: rgba(28, 28, 28, 0.78);
  --muted: rgba(28, 28, 28, 0.5);
  --success: #2f7d50;
  --error: #d63b2f;
  --shadow: rgba(31, 26, 18, 0.08) 0 12px 30px;
  --focus: rgba(0, 0, 0, 0.1) 0 4px 12px;
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--canvas);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--body);
  background:
    radial-gradient(circle at 8% -6%, rgba(255, 190, 145, 0.2), transparent 220px),
    radial-gradient(circle at 100% 0%, rgba(160, 205, 255, 0.16), transparent 190px),
    var(--canvas);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 12px 116px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -12px -12px 12px;
  padding: calc(12px + env(safe-area-inset-top)) 12px 12px;
  background: rgba(247, 244, 237, 0.94);
  border-bottom: 1px solid var(--hairline);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--paper);
  background: var(--primary);
  border-radius: 999px;
  font-weight: 700;
}

h1 {
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.brand p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.mode-badge {
  flex: 0 0 auto;
  color: var(--muted);
  background: rgba(252, 251, 248, 0.72);
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
}

.panel {
  margin-bottom: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: rgba(31, 26, 18, 0.03) 0 1px 2px;
}

.search-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent 120px),
    rgba(252, 251, 248, 0.76);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  height: 44px;
  color: var(--ink);
  background: rgba(247, 244, 237, 0.92);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  outline: none;
  padding: 0 12px;
}

input::placeholder {
  color: rgba(28, 28, 28, 0.36);
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--hairline-strong);
  outline: none;
  box-shadow: var(--focus);
}

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

.button-row {
  display: flex;
  gap: 8px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 600;
  transition: opacity 150ms ease, transform 150ms ease, background 150ms ease;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button.primary {
  flex: 1;
  color: var(--paper);
  background: var(--primary);
  border: 1px solid var(--primary);
}

.button.secondary {
  color: var(--ink);
  background: rgba(252, 251, 248, 0.72);
  border: 1px solid var(--hairline-strong);
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--ink);
  background: rgba(252, 251, 248, 0.72);
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
}

.status-panel {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 9px;
  background: rgba(28, 28, 28, 0.03);
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  background: rgba(28, 28, 28, 0.68);
  border-radius: 999px;
}

.status-panel p {
  color: var(--body);
  font-size: 13px;
}

.status-panel.success {
  background: rgba(47, 125, 80, 0.08);
}

.status-panel.success .status-dot {
  background: var(--success);
}

.status-panel.error {
  background: rgba(214, 59, 47, 0.08);
}

.status-panel.error .status-dot {
  background: var(--error);
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 2px 10px;
}

.results-head h2 {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.2;
}

.results-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pager span {
  min-width: 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

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

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 6px;
  color: var(--muted);
  background: rgba(252, 251, 248, 0.58);
  border: 1px dashed var(--hairline);
  border-radius: 14px;
}

.empty-state strong {
  color: var(--ink);
  font-size: 15px;
}

.photo-card {
  position: relative;
  overflow: hidden;
  min-width: 0;
  background: rgba(252, 251, 248, 0.82);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: rgba(31, 26, 18, 0.04) 0 2px 8px;
}

.photo-card.selected {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.photo-select {
  display: block;
  width: 100%;
  padding: 0;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
}

.photo-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: rgba(28, 28, 28, 0.05);
}

.photo-card.portrait .photo-thumb {
  aspect-ratio: 3 / 4;
}

.photo-body {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.photo-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.photo-actions {
  display: flex;
  gap: 8px;
  padding: 0 10px 10px;
}

.photo-actions .button {
  width: 100%;
  min-height: 38px;
  font-size: 13px;
}

.check-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-grid;
  width: 26px;
  height: 26px;
  place-items: center;
  color: var(--paper);
  background: rgba(28, 28, 28, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.photo-card.selected .check-pill {
  background: var(--primary);
}

.download-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(247, 244, 237, 0.96);
  border-top: 1px solid var(--hairline-strong);
  backdrop-filter: blur(18px);
}

.download-bar strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
}

.download-bar p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.download-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.download-actions .button {
  min-height: 40px;
  padding: 0 12px;
}

.loading .button,
.loading .photo-select {
  pointer-events: none;
}

@media (min-width: 680px) {
  .photo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .form-grid,
  .photo-grid {
    grid-template-columns: 1fr;
  }

  .download-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .download-actions {
    width: 100%;
  }
}
