:root,
html[data-theme="dark"] {
  --bg: #0d0d10;
  --surface: #141418;
  --surface-hover: #19191e;
  --surface-input: #101014;
  --surface-control: #111115;
  --border: #29292f;
  --border-strong: #36363d;
  --text: #f3f3f5;
  --muted: #97979f;
  --accent: #ff4f8b;
  --accent-hover: #ff669b;
  --accent-soft: rgba(255, 79, 139, 0.12);
  --accent-text: #1a080e;
  --success: #68d391;
  --warning: #f0bf64;
  --radius: 12px;
}

html[data-theme="light"] {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-hover: #f1f1f3;
  --surface-input: #fbfbfc;
  --surface-control: #f3f3f5;
  --border: #dedee3;
  --border-strong: #c9c9d0;
  --text: #17171a;
  --muted: #73737c;
  --accent: #ff4f8b;
  --accent-hover: #eb3f7b;
  --accent-soft: rgba(255, 79, 139, 0.1);
  --accent-text: #2a0b15;
  --success: #2e9b58;
  --warning: #b57a19;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  transition: background 160ms ease, color 160ms ease;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 72px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.segmented-control {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-control);
}

.control-button {
  padding: 7px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.control-button:hover {
  color: var(--text);
}

.control-button.is-active {
  background: var(--surface-hover);
  color: var(--text);
}

.intro {
  max-width: 680px;
  margin-bottom: 28px;
}

.intro h1 {
  margin: 0 0 10px;
  font-size: clamp(32px, 5vw, 50px);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

.intro p {
  max-width: 600px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel {
  min-width: 0;
  padding: 22px;
}

.input-panel {
  border-right: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.results-header > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.result-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

textarea {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  background: var(--surface-input);
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  transition: border-color 150ms ease, background 160ms ease, color 160ms ease;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

textarea:focus {
  border-color: var(--border-strong);
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
}

.hint {
  color: var(--muted);
  font-size: 11px;
}

.primary-button,
.secondary-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: background 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.primary-button {
  min-height: 40px;
  padding: 0 15px;
  background: var(--accent);
  color: var(--accent-text);
}

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

.secondary-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text);
  font-size: 12px;
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--border-strong);
}

.primary-button:disabled,
.secondary-button:disabled,
.download-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
}

.status-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

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

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

.status.running .status-dot {
  background: var(--accent);
}

.results {
  min-height: 416px;
  max-height: 520px;
  overflow: auto;
}

.empty-state {
  display: flex;
  min-height: 380px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.empty-state strong {
  margin-bottom: 5px;
  font-size: 14px;
}

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

#linkList {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.link-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-input);
}

.link-row.is-downloaded {
  opacity: 0.5;
}

.link-index {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.link-info {
  min-width: 0;
}

.link-name,
.link-url {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-name {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

.link-url {
  margin-top: 2px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
}

.download-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(255, 79, 139, 0.28);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
}

.download-button:hover:not(:disabled) {
  background: rgba(255, 79, 139, 0.17);
}

.progress {
  margin-top: 14px;
}

.progress-track {
  overflow: hidden;
  height: 3px;
  border-radius: 999px;
  background: var(--border);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
}

@media (max-width: 820px) {
  .app {
    width: min(100% - 20px, 720px);
  }

  .header {
    margin-bottom: 48px;
  }

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

  .input-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 620px) {
  .header {
    flex-direction: column;
  }

  .header-controls {
    width: 100%;
    justify-content: flex-start;
  }

  .segmented-control {
    flex: 1;
  }

  .control-button {
    flex: 1;
  }

  .intro h1 {
    font-size: 36px;
  }

  .panel {
    padding: 16px;
  }

  .panel-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button {
    width: 100%;
  }

  .link-row {
    grid-template-columns: 26px minmax(0, 1fr);
  }

  .download-button {
    grid-column: 2;
    width: fit-content;
  }
}
