:root {
  color-scheme: light;
  --background: #fafafa;
  --foreground: #0f172a;
  --muted: #f1f5f9;
  --muted-foreground: #64748b;
  --accent: #0052ff;
  --accent-secondary: #4d7cff;
  --accent-foreground: #ffffff;
  --border: #e2e8f0;
  --card: #ffffff;
  --ring: #0052ff;
  --warning: #a14900;
  --gradient: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 20px rgba(15, 23, 42, 0.07);
  --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.1);
  --shadow-accent: 0 10px 24px rgba(0, 82, 255, 0.24);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(0, 82, 255, 0.04), transparent 320px),
    var(--background);
  color: var(--foreground);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  gap: 18px;
  width: min(1160px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 34px 22px;
}

.tool-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) 300px;
  gap: 24px;
  align-items: end;
  padding: 20px 0 8px;
}

.hero-copy {
  display: grid;
  gap: 18px;
}

.section-label {
  display: inline-flex;
  width: max-content;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(0, 82, 255, 0.3);
  border-radius: 999px;
  background: rgba(0, 82, 255, 0.05);
  color: var(--accent);
  padding: 8px 14px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

.section-label.compact {
  margin-bottom: 10px;
  padding: 6px 12px;
  font-size: 11px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(0, 82, 255, 0.1);
  animation: pulse-dot 2s ease-in-out infinite;
}

h1 {
  max-width: 760px;
  margin: 0;
  font-family: "Calistoga", Georgia, "Noto Serif TC", serif;
  font-size: 64px;
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 span {
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.signal-card {
  position: relative;
  min-height: 156px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.16) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--foreground);
  box-shadow: var(--shadow-xl);
  color: white;
}

.signal-card::after {
  content: "";
  position: absolute;
  inset: auto -20px -70px auto;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 34px solid rgba(77, 124, 255, 0.12);
}

.signal-ring {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 84px;
  height: 84px;
  border: 1px dashed rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  animation: rotate-ring 60s linear infinite;
}

.signal-content {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 8px;
  padding: 26px;
}

.signal-content > span {
  color: rgba(255, 255, 255, 0.58);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  letter-spacing: 0;
}

.signal-status {
  width: max-content;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  padding: 8px 12px;
  color: white;
  font-size: 18px;
  font-weight: 800;
}

.signal-status.ready {
  background: rgba(0, 82, 255, 0.22);
  color: #dbe7ff;
}

.signal-status.error {
  background: rgba(161, 73, 0, 0.25);
  color: #ffe8d1;
}

.panel,
.output-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-md);
}

.convert-panel {
  position: relative;
  overflow: hidden;
  padding: 22px;
}

.convert-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(0, 82, 255, 0.06), transparent 34%);
}

.convert-form {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
}

.field-row {
  display: grid;
  gap: 10px;
}

label {
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 800;
}

.url-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 142px;
  gap: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(241, 245, 249, 0.35);
  color: var(--foreground);
  outline: none;
}

input {
  min-height: 56px;
  padding: 0 16px;
}

textarea {
  min-height: 420px;
  height: clamp(420px, calc(100vh - 392px), 760px);
  resize: vertical;
  padding: 18px;
  background: #fbfdff;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.65;
}

input::placeholder,
textarea::placeholder {
  color: rgba(100, 116, 139, 0.58);
}

input:focus,
textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(0, 82, 255, 0.14);
}

button {
  min-height: 52px;
  border-radius: 12px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 800;
  transition:
    transform 200ms ease,
    box-shadow 200ms ease,
    filter 200ms ease,
    color 200ms ease,
    border-color 200ms ease;
  white-space: nowrap;
}

button[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: var(--gradient);
  color: var(--accent-foreground);
  box-shadow: var(--shadow-sm);
}

button[type="submit"]:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-accent);
  filter: brightness(1.05);
}

button[type="submit"]:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.button-arrow {
  transition: transform 200ms ease;
}

button[type="submit"]:hover .button-arrow {
  transform: translateX(3px);
}

button[type="button"] {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--foreground);
}

button[type="button"]:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(0, 82, 255, 0.35);
  color: var(--accent);
  box-shadow: var(--shadow-md);
}

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

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status {
  min-height: 20px;
  margin: 0;
  color: var(--muted-foreground);
  font-size: 13px;
}

.status.error,
.status.warn {
  color: var(--warning);
}

#htmlStats {
  color: var(--muted-foreground);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  white-space: nowrap;
}

.output-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  transition:
    box-shadow 220ms ease,
    border-color 220ms ease;
}

.output-panel.has-output {
  border-color: rgba(0, 82, 255, 0.22);
  box-shadow:
    var(--shadow-md),
    0 0 0 1px rgba(0, 82, 255, 0.05);
}

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

.section-header p {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-size: 13px;
}

.copy-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-panel {
  overflow: hidden;
}

.image-panel[hidden] {
  display: none;
}

summary {
  display: flex;
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  padding: 0 18px;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  font-weight: 900;
}

.summary-main {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.summary-main span:last-child {
  color: var(--muted-foreground);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

summary .download-all-button {
  min-height: 40px;
  border: 1px solid rgba(0, 82, 255, 0.28);
  background: rgba(0, 82, 255, 0.06);
  color: var(--accent);
  padding: 0 14px;
}

.image-settings {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--border);
  padding: 18px;
}

.image-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.image-list:empty::before {
  content: "尚未擷取圖片";
  color: var(--muted-foreground);
  font-size: 14px;
}

.image-item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 96px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--muted);
  padding: 10px;
}

.image-preview {
  width: 88px;
  overflow: hidden;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #e8eef7;
}

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

.image-fields {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.image-fields input {
  min-width: 0;
  min-height: 46px;
}

.image-meta {
  color: var(--muted-foreground);
  font-size: 12px;
}

.image-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.download-image-link,
.saved-image-link {
  width: max-content;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.download-image-link {
  border-radius: 999px;
  background: rgba(0, 82, 255, 0.08);
  padding: 5px 9px;
}

.download-image-link:hover,
.saved-image-link:hover {
  text-decoration: underline;
}

.saved-image-path {
  overflow-wrap: anywhere;
  color: var(--muted-foreground);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
}

@keyframes pulse-dot {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.28);
    opacity: 0.72;
  }
}

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

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

@media (max-width: 860px) {
  .tool-hero {
    grid-template-columns: 1fr;
  }

  .signal-card {
    min-height: 126px;
  }

  h1 {
    font-size: 46px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 18px 12px;
  }

  h1 {
    font-size: 38px;
  }

  .url-action-row {
    grid-template-columns: 1fr;
  }

  .status-line,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  summary {
    align-items: stretch;
    flex-direction: column;
    padding: 14px 18px;
  }

  .summary-main {
    justify-content: space-between;
  }

  .download-all-button {
    width: 100%;
  }

  .copy-actions,
  .copy-actions button {
    width: 100%;
  }

  textarea {
    height: 56vh;
  }
}
