:root {
  color-scheme: light;
  --ink: #17201c;
  --muted: #68716c;
  --line: #dfe4e1;
  --surface: #ffffff;
  --canvas: #f4f6f4;
  --green: #176b4d;
  --green-dark: #0f513a;
  --green-soft: #e9f3ee;
  --amber: #b97919;
  --danger: #a23a31;
  --shadow: 0 8px 24px rgba(24, 40, 32, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible + span,
.template-option:has(input:focus-visible) {
  outline: 3px solid rgba(23, 107, 77, 0.25);
  outline-offset: 2px;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1080px, 100%);
  min-height: 58px;
  margin: 0 auto;
  padding: 8px 20px;
}

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

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  color: #fff;
  background: var(--ink);
  border-radius: 5px;
  font-size: 18px;
  font-weight: 800;
}

.brand-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.privacy-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-entry {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--muted);
  border-radius: 5px;
  font-size: 18px;
  text-decoration: none;
}

.admin-entry:hover {
  color: var(--green-dark);
  background: var(--green-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.app-main {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.tool-shell {
  width: 100%;
}

.page-heading,
.section-heading,
.result-heading,
.result-heading > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-heading {
  margin-bottom: 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.3;
}

h2 {
  font-size: 17px;
  line-height: 1.4;
}

.page-heading p,
.section-heading span,
.upload-zone p,
.process-status {
  color: var(--muted);
  font-size: 13px;
}

.page-heading p {
  margin-top: 5px;
}

.icon-text-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 38px;
  padding: 6px 11px;
  color: var(--danger);
  background: transparent;
  border-radius: 5px;
}

.icon-text-button:hover {
  background: #f9ecea;
}

.template-picker {
  min-width: 0;
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

.template-picker legend {
  margin-bottom: 10px;
  padding: 0;
  font-size: 14px;
  font-weight: 700;
}

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

.template-option {
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 14px;
  min-height: 88px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(24, 40, 32, 0.03);
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.template-option:hover {
  border-color: #9eb9ac;
}

.template-option:has(input:checked) {
  border-color: var(--green);
  background: #fbfefc;
  box-shadow: 0 0 0 2px rgba(23, 107, 77, 0.1);
}

.template-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.template-visual {
  position: relative;
  display: block;
  width: 62px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid #dadfdd;
  background: #fff;
}

.template-preview-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.template-loading,
.template-error {
  grid-column: 1 / -1;
  padding: 22px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 7px;
  background: var(--surface);
  font-size: 13px;
  text-align: center;
}

.template-error {
  color: var(--danger);
}

.visual-logo {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 6px;
  font-weight: 900;
}

.visual-footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 13px;
  background: #e9e9eb;
}

.template-visual-34 {
  background: #e9e9eb;
}

.template-visual-34 .visual-frame {
  position: absolute;
  top: 14px;
  right: 14px;
  bottom: 10px;
  left: 14px;
  background: #fff;
}

.template-visual-34 .visual-logo {
  z-index: 1;
}

.template-copy {
  min-width: 0;
}

.template-copy strong,
.template-copy small {
  display: block;
}

.template-copy strong {
  font-size: 15px;
}

.template-copy small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.radio-mark {
  width: 19px;
  height: 19px;
  border: 2px solid #aeb6b2;
  border-radius: 50%;
}

.template-option:has(input:checked) .radio-mark {
  border: 6px solid var(--green);
}

.upload-zone {
  display: grid;
  min-height: 170px;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 26px;
  border: 1px dashed #9aaba2;
  border-radius: 7px;
  background: var(--surface);
  transition: border-color 160ms ease, background 160ms ease;
}

.upload-zone.is-dragging {
  border-color: var(--green);
  background: var(--green-soft);
}

.select-button,
.primary-button,
.secondary-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  font-weight: 700;
}

.select-button {
  min-height: 46px;
  padding: 10px 20px;
  color: #fff;
  background: var(--ink);
}

.select-button:hover {
  background: #2b3530;
}

.button-symbol {
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
}

.selected-section,
.results-section {
  margin-top: 28px;
}

.section-heading {
  margin-bottom: 12px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.image-item {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.image-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #eef0ef;
}

.image-meta {
  min-width: 0;
  padding: 9px 10px 10px;
}

.image-name {
  display: block;
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-size {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.remove-button {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: #fff;
  background: rgba(20, 26, 23, 0.78);
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.remove-button:hover {
  background: var(--danger);
}

.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px -8px 0;
  padding: 12px 8px calc(12px + env(safe-area-inset-bottom));
  background: rgba(244, 246, 244, 0.94);
  backdrop-filter: blur(12px);
}

.primary-button {
  min-width: 150px;
  min-height: 48px;
  padding: 10px 22px;
  color: #fff;
  background: var(--green);
  box-shadow: var(--shadow);
}

.primary-button:hover {
  background: var(--green-dark);
}

.process-status {
  min-width: 0;
  overflow-wrap: anywhere;
}

.results-section {
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.result-heading > div {
  justify-content: flex-start;
}

.secondary-button,
.download-button {
  min-height: 40px;
  padding: 8px 14px;
  color: var(--green-dark);
  background: var(--green-soft);
}

.secondary-button:hover,
.download-button:hover {
  background: #dcece4;
}

.download-button {
  width: 100%;
  margin-top: 9px;
}

.result-grid .image-meta {
  padding-bottom: 10px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(360px, calc(100vw - 36px));
  padding: 11px 14px;
  color: #fff;
  background: #202824;
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

noscript {
  display: block;
  padding: 20px;
  color: var(--danger);
  text-align: center;
}

@media (max-width: 720px) {
  .header-inner {
    min-height: 54px;
    padding-inline: 14px;
  }

  .brand-name {
    font-size: 13px;
  }

  .app-main {
    padding: 20px 14px 44px;
  }

  h1 {
    font-size: 23px;
  }

  .template-options {
    grid-template-columns: 1fr;
  }

  .template-option {
    min-height: 82px;
  }

  .upload-zone {
    min-height: 150px;
  }

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

  .action-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
  }

  .primary-button {
    width: 100%;
  }

  .process-status {
    min-height: 18px;
    text-align: center;
  }

  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-button {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .privacy-state {
    font-size: 11px;
  }

  .brand-name {
    max-width: 130px;
  }

  .template-option {
    grid-template-columns: 56px minmax(0, 1fr) 20px;
    gap: 10px;
    padding-inline: 10px;
  }

  .template-visual {
    width: 54px;
  }
}

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