:root {
  color-scheme: light;
  --ink: #1a1a1a;
  --muted: #5b6472;
  --border: #d8dbe0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --bg-soft: #f5f7fa;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --focus: #bfdbfe;
  --header-bg: rgba(255, 255, 255, 0.92);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg-soft);
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  z-index: 40;
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.top-bar {
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
}

.brand:hover .brand-name {
  color: var(--accent);
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: none;
  display: block;
  border-radius: 8px;
}

.brand-name {
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand--login {
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.brand--login h1 {
  margin: 0;
}

.brand-mark--lg {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.logout-form {
  margin: 0;
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 10px;
  min-height: 40px;
  text-decoration: none;
  border-radius: 8px;
}

.text-btn:hover {
  color: var(--accent-hover);
  background: var(--accent-soft);
}

.page {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

h1 {
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 8px;
}

.subtitle {
  color: var(--muted);
  margin-top: 0;
  margin-bottom: 28px;
  line-height: 1.55;
}

.subtitle code {
  background: #eef0f3;
  padding: 1px 5px;
  border-radius: 4px;
}

.subtitle.hint {
  font-size: 0.85rem;
  margin-top: -12px;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 168px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  background: white;
  color: var(--muted);
  text-align: center;
  padding: 28px 24px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.dropzone-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
}

.dropzone-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dropzone-copy strong {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
}

.dropzone-hint {
  font-size: 0.85rem;
}

.dropzone:hover,
.dropzone.dragover,
.dropzone:focus-within {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.dropzone.dragover .dropzone-copy strong,
.dropzone:hover .dropzone-copy strong {
  color: var(--accent);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

button,
.login-form button,
#submit-btn,
#download-all-btn,
#update-preview-btn,
.secondary-btn,
.tab-btn,
.tab-remove,
.text-btn {
  font-family: inherit;
}

#submit-btn,
#download-all-btn,
.login-form button {
  align-self: flex-start;
  background: var(--accent);
  color: white;
  border: none;
  padding: 11px 20px;
  min-height: 44px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

#submit-btn:hover,
#download-all-btn:hover,
.login-form button:hover {
  background: var(--accent-hover);
}

.login-body {
  background:
    radial-gradient(circle at top, #dbeafe 0%, transparent 42%),
    var(--bg-soft);
}

.login-page {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.login-form button {
  width: 100%;
  align-self: stretch;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-field input {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 44px;
}

.login-wake-hint {
  margin: 16px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.login-test-creds {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--focus);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.45;
}

.login-test-creds code {
  color: var(--ink);
  font-size: 0.95em;
}

.quota-banner {
  margin: 0 0 20px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  font-size: 0.95rem;
  line-height: 1.4;
}

#submit-btn:disabled {
  background: #c5cbd3;
  cursor: not-allowed;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.file-queue {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.queue-heading {
  font-size: 0.95rem;
  margin: 0 0 10px;
}

.queue-heading span {
  color: var(--muted);
  font-weight: 500;
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
}

.queue-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.queue-name {
  font-size: 0.9rem;
  word-break: break-word;
}

.queue-size {
  font-size: 0.78rem;
  color: var(--muted);
}

.file-tabs {
  margin-top: 28px;
}

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  display: flex;
  align-items: center;
  max-width: 100%;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tab.tab-error {
  border-color: #fecaca;
  background: var(--danger-bg);
}

.tab.tab-loading {
  opacity: 0.7;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.tab-remove {
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  padding: 10px 12px;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}

.tab-remove:hover {
  color: var(--danger);
}

.results-actions {
  display: flex;
  gap: 8px;
}

.status {
  margin-top: 20px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.spinner[hidden] {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status.error {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  padding: 12px 16px;
  border-radius: 8px;
  white-space: pre-wrap;
}

.status.info {
  color: var(--muted);
}

.edit-section {
  margin-top: 36px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.edit-section h2 {
  font-size: 1.1rem;
  margin: 0 0 4px;
}

.edit-section .subtitle {
  margin-bottom: 20px;
}

#edit-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.edit-group {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.edit-group legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0;
  margin-bottom: 4px;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

.edit-field-caption {
  word-break: break-word;
}

.edit-field textarea {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  resize: none;
  overflow: hidden;
  min-height: 32px;
  line-height: 1.35;
}

.edit-field textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--accent);
}

.edit-geo {
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

.edit-geo summary {
  font-size: 0.78rem;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.edit-geo summary::-webkit-details-marker {
  display: none;
}

.edit-geo summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}

.edit-geo[open] summary::before {
  transform: rotate(90deg);
}

.edit-geo summary:hover {
  text-decoration: underline;
}

.edit-geo-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.edit-geo-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  flex: 1;
  min-width: 80px;
}

.edit-geo-field input[type="number"] {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 6px;
  width: 100%;
}

.edit-geo-field input[type="number"]:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--accent);
}

.edit-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: linear-gradient(to top, var(--bg-soft) 70%, transparent);
  padding: 12px 0 4px;
  margin-top: -4px;
}

#update-preview-btn {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  padding: 11px 18px;
  min-height: 44px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

#update-preview-btn:hover {
  background: var(--accent-hover);
}

#update-preview-btn:disabled {
  border-color: #9ca3af;
  background: #9ca3af;
  cursor: not-allowed;
}

.secondary-btn {
  background: white;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 11px 18px;
  min-height: 44px;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.secondary-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.secondary-btn:disabled {
  color: #9ca3af;
  border-color: var(--border);
  background: #f3f4f6;
  cursor: not-allowed;
}

.results {
  margin-top: 32px;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.results-header h2 {
  font-size: 1.1rem;
  margin: 0;
}

.gallery {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
}

.card img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: repeating-conic-gradient(#f0f0f0 0% 25%, white 0% 50%) 50% / 16px 16px;
}

.card-title {
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-word;
}

.card a.download-link {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  background: var(--accent);
  border-radius: 8px;
  text-decoration: none;
}

.card a.download-link:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.card.card-error {
  border-color: #fecaca;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.9rem;
}

.site-footer {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 32px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.site-footer p {
  margin: 8px 0;
}

.site-footer a {
  color: var(--muted);
  text-decoration: underline;
}

.site-footer a:hover {
  color: var(--accent);
}

.legal-page h2 {
  font-size: 1.05rem;
  margin-top: 28px;
  margin-bottom: 8px;
}

.legal-page p,
.legal-page li {
  color: var(--ink);
  line-height: 1.6;
}

.legal-page ul {
  padding-left: 20px;
}

.legal-page code {
  background: #eef0f3;
  padding: 1px 5px;
  border-radius: 4px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.login-field input:focus,
.edit-field textarea:focus,
.edit-geo-field input[type="number"]:focus {
  outline: 2px solid var(--focus);
  border-color: var(--accent);
}

@media (max-width: 480px) {
  .page {
    padding: 24px 16px 64px;
  }

  .top-bar {
    padding: 10px 16px;
  }

  .site-footer {
    padding: 20px 16px 28px;
  }

  .edit-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .edit-actions button {
    width: 100%;
  }

  .edit-geo-row {
    flex-direction: column;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions button {
    width: 100%;
  }

  .tab-btn {
    max-width: 140px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .spinner,
  .dropzone,
  .text-btn,
  .brand-name {
    animation: none;
    transition: none;
  }
}
