:root {
  color-scheme: light dark;
  --bg: #f5f4f9;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --text: #16151b;
  --muted: #6c6977;
  --line: #e5e2ec;
  --accent: #635bff;
  --accent-strong: #4a42e8;
  --accent-soft: #eeecff;
  --success: #087f5b;
  --danger: #c92a2a;
  --danger-soft: #fff0f0;
  --shadow: 0 18px 50px rgba(37, 31, 63, 0.08);
  --radius: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101014;
    --surface: rgba(28, 27, 34, 0.94);
    --surface-strong: #211f28;
    --text: #f7f5fb;
    --muted: #aaa6b4;
    --line: #393640;
    --accent: #8c85ff;
    --accent-strong: #a39eff;
    --accent-soft: #292545;
    --success: #63d6ac;
    --danger: #ff8787;
    --danger-soft: #3a2023;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 85% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", sans-serif;
  line-height: 1.55;
}

button,
textarea,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--accent);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 0 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 750;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1.1rem;
}

.privacy-label,
.badge {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.app-shell {
  width: min(100% - 32px, 760px);
  margin: 0 auto;
}

.step-label {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.panel,
.tool-panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel {
  padding: 22px;
}

.tool-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading h2,
.tool-panel h2 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.035em;
}

.input-panel .step-label {
  align-self: center;
  margin-bottom: 0;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 750;
}

.text-button.clear-action {
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 1.45rem;
  line-height: 1;
}

.text-button:focus-visible,
.primary-button:focus-visible,
.video-secondary-button:focus-visible,
textarea:focus-visible,
.media-card:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

textarea {
  display: block;
  width: 100%;
  min-height: 104px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 15px 16px;
  font-size: 1rem;
  line-height: 1.45;
  transition: border-color 150ms ease;
}

textarea:focus {
  border-color: var(--accent);
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 54px;
  margin-top: 14px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 0 19px;
  font-weight: 800;
  transition: transform 120ms ease, background 120ms ease;
}

.primary-button:active {
  transform: scale(0.985);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.recent-area {
  margin-top: 20px;
}

.recent-area > p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.recent-list {
  display: grid;
  gap: 8px;
}

.recent-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-strong);
  color: var(--muted);
  cursor: pointer;
  padding: 9px 11px;
  overflow-wrap: anywhere;
  text-align: left;
  font-size: 0.75rem;
  line-height: 1.4;
}

.status-card,
.error-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  border-radius: 18px;
  padding: 16px 18px;
}

.status-card {
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  background: var(--accent-soft);
}

.error-card {
  display: block;
  border: 1px solid color-mix(in srgb, var(--danger) 25%, var(--line));
  background: var(--danger-soft);
  color: var(--danger);
}

.status-card strong,
.error-card strong {
  display: block;
}

.status-card p,
.error-card p {
    margin: 2px 0 0;
    font-size: 0.85rem;
}

.error-card .error-detail {
  margin-top: 10px;
  color: color-mix(in srgb, var(--danger) 78%, var(--text));
  line-height: 1.55;
}

.error-card .error-action {
  margin-top: 10px;
  border-radius: 12px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  color: var(--text);
  line-height: 1.55;
}

.error-reference {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.68rem;
  overflow-wrap: anywhere;
}

.spinner {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 3px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.post-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.post-summary img {
  width: 76px;
  height: 76px;
  flex: 0 0 auto;
  border-radius: 14px;
  background: var(--bg);
  object-fit: cover;
}

.post-summary h3 {
  display: -webkit-box;
  overflow: hidden;
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.post-summary a {
  font-size: 0.78rem;
  font-weight: 700;
}

.selection-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.8rem;
}

.media-list {
  display: grid;
  gap: 20px;
}

.download-results {
  display: grid;
  gap: 10px;
}

.media-group-label {
  margin: 0 0 -8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.image-gallery,
.video-list {
  display: grid;
  gap: 14px;
}

.image-result {
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-strong);
}

.image-result img {
  display: block;
  width: 100%;
  height: auto;
  min-height: 120px;
  background: var(--bg);
  object-fit: contain;
  -webkit-touch-callout: default;
  user-select: auto;
}

.image-result figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px 12px;
}

.image-result figcaption strong {
  flex: 0 0 auto;
  font-size: 0.82rem;
}

.image-result figcaption span {
  color: var(--muted);
  font-size: 0.68rem;
  text-align: right;
}

.video-result {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-strong);
}

.video-thumbnail,
.video-preview-placeholder {
  display: grid;
  width: 100%;
  min-height: 220px;
  max-height: 520px;
  place-items: center;
  background: #09090b;
  object-fit: contain;
}

.video-preview-placeholder {
  color: var(--accent);
  font-size: 3rem;
}

.video-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.video-actions .primary-button {
  justify-content: center;
  margin: 0;
}

.video-secondary-button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 0 14px;
  font-weight: 800;
}

.video-secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.video-secondary-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.video-action-status {
  margin: 0;
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.download-status {
  margin-top: 2px;
}

.download-result {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-strong);
}

.download-result img,
.download-result video {
  display: block;
  width: 100%;
  max-height: 360px;
  background: #09090b;
  object-fit: contain;
}

.download-details {
  padding: 16px;
}

.download-details h3 {
  overflow-wrap: anywhere;
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.download-details .media-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.download-details .media-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 750;
  line-height: 1.2;
}

.download-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.download-actions a {
  flex: 1;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  padding: 10px 12px;
  text-align: center;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 800;
}

.download-actions a.secondary {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

.failure-item {
  border-radius: 14px;
  background: var(--danger-soft);
  color: var(--danger);
  padding: 13px;
  font-size: 0.82rem;
}

.tool-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.tool-chip {
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
}

.tool-chip.missing {
  background: var(--danger-soft);
  color: var(--danger);
}

.tool-chip.pending {
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

@media (min-width: 640px) {
  .app-header {
    padding-top: 26px;
  }

  .panel {
    padding: 28px;
  }

  .image-result figcaption {
    padding-right: 16px;
    padding-left: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
