:root {
  color-scheme: light;
  --page: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #16201b;
  --muted: #69766f;
  --line: #d8e0da;
  --line-strong: #b9c7bf;
  --accent: #165a4a;
  --accent-dark: #0e4639;
  --blue: #285fbc;
  --red: #b42318;
  --amber: #9a5b13;
  --shadow: 0 18px 42px rgba(22, 32, 27, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 247, 245, 0.94)),
    var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 66px;
  padding: 12px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid rgba(216, 224, 218, 0.9);
  background: rgba(250, 252, 250, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: max-content;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 19px;
  line-height: 1;
}

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

.brand-name strong {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

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

.nav span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #46524c;
  font-size: 13px;
  font-weight: 650;
}

main {
  padding: clamp(22px, 5vw, 52px) clamp(14px, 4vw, 48px) 56px;
}

.workspace {
  display: grid;
  gap: 18px;
  width: min(1080px, 100%);
  margin: 0 auto;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  align-items: stretch;
}

.search-panel,
.result,
.account-panel,
.history-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.search-panel {
  display: grid;
  gap: 20px;
  padding: clamp(20px, 4vw, 34px);
}

.account-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 18px;
}

.account-top,
.usage-row,
.upgrade-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.plan-badge {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 8px;
  padding: 5px 8px;
  border: 1px solid #c9ddd4;
  border-radius: 999px;
  background: #eef8f3;
  color: var(--accent);
  font-size: 12px;
  font-weight: 820;
}

.account-top h2 {
  font-size: 20px;
}

.ghost-button,
.upgrade-button,
.secondary-button,
.icon-button {
  width: auto;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #24312b;
}

.ghost-button::after,
.upgrade-button::after,
.secondary-button::after,
.icon-button::after {
  content: "";
}

.usage-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.usage-row span,
.upgrade-box span,
.policy-note {
  color: var(--muted);
  font-size: 13px;
}

.usage-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #dde7e1;
}

.usage-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.upgrade-box {
  padding: 13px;
  border: 1px solid #cddfd7;
  border-radius: 8px;
  background: #f2faf6;
}

.upgrade-box div {
  display: grid;
  gap: 3px;
}

.upgrade-button {
  min-height: 36px;
  padding: 0 12px;
  background: var(--accent);
  color: #fff;
}

.upgrade-button:disabled {
  background: #dce8e2;
  color: var(--muted);
}

.policy-note {
  line-height: 1.5;
}

.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  max-width: 620px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.12;
  letter-spacing: 0;
}

.resolver {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 10px;
}

.url-field {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 58px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.url-field:focus-within {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(22, 90, 74, 0.13);
}

.url-prefix {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
}

input::placeholder {
  color: #8a958f;
}

button,
.primary-action,
.secondary-action,
.format-card a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 780;
}

button {
  gap: 8px;
  width: 100%;
  border: 0;
  background: var(--accent);
  color: #fff;
}

button::after {
  content: ">";
  font-weight: 900;
}

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

button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.status {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 620;
}

.status:empty {
  display: none;
}

.status[data-state="loading"] {
  color: var(--amber);
}

.status[data-state="success"] {
  color: var(--accent);
}

.status[data-state="error"] {
  color: var(--red);
}

.result {
  display: grid;
  gap: 18px;
  padding: clamp(16px, 3vw, 24px);
}

.preview {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.preview > img {
  width: 100%;
  min-height: 210px;
  max-height: 360px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #edf2ef;
}

.media-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.media-gallery[data-count="3"] .media-tile:first-child {
  grid-row: span 2;
}

.media-tile {
  position: relative;
  overflow: hidden;
  min-height: 154px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2ef;
}

.media-tile img {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 0;
  object-fit: contain;
}

.media-tile span {
  position: absolute;
  right: 7px;
  bottom: 7px;
  max-width: calc(100% - 14px);
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(22, 32, 27, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-meta {
  min-width: 0;
  padding-top: 2px;
}

.platform {
  width: fit-content;
  margin-bottom: 10px;
  padding: 6px 9px;
  border: 1px solid #c9ddd4;
  border-radius: 999px;
  background: #eef8f3;
  color: var(--accent);
  font-size: 12px;
  font-weight: 820;
}

h2 {
  overflow-wrap: anywhere;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.24;
  letter-spacing: 0;
}

#subMeta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

#description {
  margin-top: 13px;
  color: #4a5850;
  line-height: 1.65;
}

.download-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 2px;
}

.primary-action,
.secondary-action {
  padding: 0 16px;
}

.primary-action {
  border: 0;
  background: var(--accent);
  color: #fff;
}

.secondary-action {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #24312b;
}

.secondary-action:hover,
.format-card a:hover {
  border-color: #7fa092;
  background: #f4faf7;
}

.download-progress {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.download-progress[data-state="success"] {
  border-color: #b8d7ca;
  background: #f0faf5;
}

.download-progress[data-state="error"] {
  border-color: #e3b6b0;
  background: #fff6f4;
}

.progress-head,
.progress-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-head span {
  min-width: 0;
  overflow: hidden;
  color: #26342d;
  font-size: 14px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-head strong {
  color: var(--accent);
  font-size: 14px;
}

.download-progress[data-state="error"] .progress-head strong {
  color: var(--red);
}

.progress-track {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: #dde7e1;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

.progress-track span[data-indeterminate="true"] {
  width: 28%;
  animation: progress-slide 1.1s ease-in-out infinite;
}

.progress-foot {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.cancel-download {
  width: auto;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #3e4a44;
  font-size: 13px;
}

.cancel-download::after {
  content: "";
}

.cancel-download:hover {
  border-color: #a7b8af;
  background: #f7faf8;
}

@keyframes progress-slide {
  0% {
    transform: translateX(-110%);
  }

  50% {
    transform: translateX(110%);
  }

  100% {
    transform: translateX(360%);
  }
}

.formats-wrap {
  display: grid;
  gap: 12px;
  padding-top: 2px;
}

.formats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

h3 {
  font-size: 16px;
  letter-spacing: 0;
}

#formatCount {
  color: var(--muted);
  font-size: 14px;
  font-weight: 680;
}

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

.format-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.format-main {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.format-main strong,
.format-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.format-main strong {
  font-size: 14px;
}

.format-main span {
  color: var(--muted);
  font-size: 13px;
}

.format-card a {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--accent-dark);
  font-size: 14px;
}

.empty {
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
}

.history-panel {
  display: grid;
  gap: 12px;
  padding: clamp(16px, 3vw, 22px);
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.history-item div {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.history-item strong,
.history-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item strong {
  font-size: 14px;
}

.history-item span {
  color: var(--muted);
  font-size: 13px;
}

.history-status {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 999px;
  background: #eef8f3;
  color: var(--accent) !important;
  font-weight: 780;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 32, 27, 0.38);
}

.modal-card {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(22, 32, 27, 0.18);
}

.modal-head,
.auth-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-button {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.auth-form {
  display: grid;
  gap: 13px;
  margin-top: 16px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: #3a4740;
  font-size: 13px;
  font-weight: 720;
}

.auth-form input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
}

.auth-message {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

.auth-actions button {
  flex: 1 1 0;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav {
    justify-content: flex-start;
  }

  .panel-head {
    display: grid;
  }

  .resolver,
  .preview,
  .formats,
  .hero-grid {
    grid-template-columns: 1fr;
  }

  .media-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .download-actions a {
    flex: 1 1 180px;
  }
}

@media (max-width: 520px) {
  main {
    padding-inline: 12px;
  }

  .search-panel,
  .result {
    padding: 16px;
  }

  .url-field {
    min-height: 54px;
    padding-inline: 10px;
  }

  .url-prefix {
    display: none;
  }

  .media-gallery {
    grid-template-columns: 1fr;
  }

  .media-tile {
    min-height: 230px;
  }
}
