:root {
  --bg-base: #f7f8ef;
  --bg-strong: #efe9d9;
  --ink: #1e2a27;
  --ink-muted: #5a6a64;
  --accent: #1f6f5f;
  --accent-soft: #d8f1ea;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(31, 111, 95, 0.24);
  --error: #a53030;
  --shadow: 0 12px 40px rgba(30, 42, 39, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at 10% 0%, #f2d7a2 0%, transparent 45%),
    radial-gradient(circle at 85% 10%, #bfded3 0%, transparent 48%),
    linear-gradient(165deg, var(--bg-base) 0%, var(--bg-strong) 100%);
  font-family: "Space Grotesk", "Avenir Next", "Gill Sans", sans-serif;
}

.aurora {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    -18deg,
    rgba(31, 111, 95, 0.02),
    rgba(31, 111, 95, 0.02) 20px,
    rgba(255, 255, 255, 0.12) 20px,
    rgba(255, 255, 255, 0.12) 40px
  );
}

.app-shell {
  position: relative;
  width: min(1200px, calc(100% - 32px));
  margin: 28px auto 36px;
  display: grid;
  gap: 18px;
  animation: rise 0.45s ease-out both;
}

.app-header {
  display: grid;
  gap: 8px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-muted);
  font-size: 0.72rem;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--ink-muted);
  max-width: 70ch;
}

.app-version {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
}

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

.auth-user {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.92rem;
}

.update-status {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.update-status.error {
  color: var(--error);
}

.auth-panel {
  padding: 16px;
}

#auth-form {
  display: grid;
  gap: 10px;
}

.auth-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.auth-subtitle {
  margin: 0;
  color: var(--ink-muted);
}

.auth-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

#auth-username,
#auth-password {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(30, 42, 39, 0.2);
  font: inherit;
  color: var(--ink);
  background: #fff;
}

#auth-username:focus,
#auth-password:focus {
  outline: 2px solid rgba(31, 111, 95, 0.45);
  outline-offset: 1px;
}

.auth-status {
  margin: 0;
  min-height: 1.3em;
  color: var(--ink-muted);
}

.auth-status.error {
  color: var(--error);
}

.app-content {
  display: grid;
  gap: 18px;
}

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

.controls {
  padding: 16px;
}

#load-form {
  display: grid;
  gap: 8px;
}

label {
  font-size: 0.85rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px auto 46px;
  gap: 10px;
  align-items: stretch;
}

.source-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 8px;
}

#source-url {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(30, 42, 39, 0.2);
  font: inherit;
  color: var(--ink);
  background: #fff;
}

#saved-searches-select {
  width: 100%;
  padding: 12px 10px;
  border-radius: 10px;
  border: 1px solid rgba(30, 42, 39, 0.2);
  font: inherit;
  color: var(--ink);
  background: #fff;
}

#max-releases {
  width: 100%;
  padding: 12px 10px;
  border-radius: 10px;
  border: 1px solid rgba(30, 42, 39, 0.2);
  font: inherit;
  color: var(--ink);
  background: #fff;
}

#max-releases:focus {
  outline: 2px solid rgba(31, 111, 95, 0.45);
  outline-offset: 1px;
}

#saved-searches-select:focus {
  outline: 2px solid rgba(31, 111, 95, 0.45);
  outline-offset: 1px;
}

#source-url:focus {
  outline: 2px solid rgba(31, 111, 95, 0.45);
  outline-offset: 1px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(31, 111, 95, 0.35);
}

button:disabled {
  opacity: 0.65;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.save-search-btn {
  width: 46px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.save-search-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.hidden {
  display: none !important;
}

.filters-toggle {
  margin-top: 12px;
  background: rgba(31, 111, 95, 0.12);
  color: var(--ink);
}

.filters-toggle:hover {
  box-shadow: 0 8px 20px rgba(31, 111, 95, 0.18);
}

.status-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
}

#status {
  margin: 0;
  font-weight: 600;
}

#status.error {
  color: var(--error);
}

#summary {
  margin: 0;
  color: var(--ink-muted);
}

#progress-counter {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
}

.category-filter-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(30, 42, 39, 0.12);
}

.quality-filter-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(30, 42, 39, 0.12);
}

.category-filter-title {
  margin: 0 0 8px;
  color: var(--ink-muted);
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(31, 111, 95, 0.28);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 0.9rem;
}

.category-chip input[type="checkbox"] {
  margin: 0;
  accent-color: var(--accent);
}

.quality-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(30, 42, 39, 0.25);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 0.9rem;
}

.quality-chip input[type="checkbox"] {
  margin: 0;
  accent-color: var(--accent);
}

.quality-chip--red {
  border-color: #e3a5a2;
  background: #ffe1df;
}

.quality-chip--yellow {
  border-color: #e4d08a;
  background: #fff4ce;
}

.quality-chip--green {
  border-color: #a9d9ae;
  background: #e3f8e1;
}

.quality-chip--blue {
  border-color: #9fc3eb;
  background: #e1efff;
}

.quality-chip--na {
  border-color: #b7bdc4;
  background: #eceff3;
}

.category-empty {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.save-search-dialog {
  width: min(520px, calc(100% - 24px));
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 18px 40px rgba(30, 42, 39, 0.28);
}

.save-search-dialog::backdrop {
  background: rgba(30, 42, 39, 0.45);
}

#save-search-form {
  margin: 0;
  padding: 18px;
  display: grid;
  gap: 10px;
}

#save-search-form label {
  text-transform: none;
  letter-spacing: 0;
}

#save-search-form h2 {
  margin: 0;
  font-size: 1.25rem;
}

.save-search-url {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f4f7f6;
  color: var(--ink-muted);
  font-size: 0.9rem;
  word-break: break-all;
}

#save-search-name {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(30, 42, 39, 0.2);
  font: inherit;
  color: var(--ink);
  background: #fff;
}

#save-search-name:focus {
  outline: 2px solid rgba(31, 111, 95, 0.45);
  outline-offset: 1px;
}

.dialog-actions {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.secondary-btn {
  background: rgba(31, 111, 95, 0.13);
  color: var(--ink);
}

.table-panel {
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 0.82rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: #f0f5f2;
}

thead th.sortable-header {
  cursor: pointer;
  user-select: none;
}

thead th.sortable-header:focus-visible {
  outline: 2px solid rgba(31, 111, 95, 0.55);
  outline-offset: -2px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid rgba(30, 42, 39, 0.11);
  vertical-align: top;
}

tbody tr.release-row-downloaded td {
  background: linear-gradient(180deg, rgba(241, 243, 245, 0.95), rgba(234, 237, 240, 0.9));
}

.poster-cell {
  width: 28%;
}

thead th:nth-child(3),
tbody td:nth-child(3) {
  width: 14%;
}

thead th:nth-child(4),
tbody td:nth-child(4) {
  width: 12%;
}

.description-cell {
  width: auto;
  min-width: 0;
}

.poster {
  display: block;
  width: min(264px, 100%);
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(30, 42, 39, 0.2);
  background: linear-gradient(135deg, #eef2ef, #d7e2dd);
  cursor: zoom-in;
}

.poster-fallback {
  width: min(264px, 100%);
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  border: 1px dashed rgba(30, 42, 39, 0.35);
  display: grid;
  place-items: center;
  color: var(--ink-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.poster-hover-panel {
  position: fixed;
  z-index: 1000;
  border: 1px solid rgba(30, 42, 39, 0.3);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  background: #ffffff;
  padding: 6px;
  pointer-events: none;
  display: none;
}

.poster-hover-panel img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.title-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.title-link:hover {
  text-decoration: underline;
}

.size-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.size-link:hover {
  text-decoration: underline;
}

.server-download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(30, 42, 39, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: #2a4f47;
  cursor: pointer;
}

.server-download-btn svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.server-download-btn:hover {
  background: #eef6f2;
}

.server-download-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.server-download-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.server-download-toast {
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 150ms ease, transform 150ms ease;
  font-size: 0.72rem;
  line-height: 1.1;
  padding: 3px 7px;
  border-radius: 999px;
  color: #195d24;
  background: #daf4d8;
  pointer-events: none;
  white-space: nowrap;
}

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

.size-cell-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.size-value {
  color: var(--ink);
}

.size-cell .quality-badge {
  display: block;
  margin: 0;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.2;
  text-transform: uppercase;
}

.size-cell .quality-badge--red {
  color: #6d1f1b;
  background: #ffd8d6;
}

.size-cell .quality-badge--yellow {
  color: #6b5102;
  background: #fff1bf;
}

.size-cell .quality-badge--green {
  color: #195d24;
  background: #daf4d8;
}

.size-cell .quality-badge--blue {
  color: #154a90;
  background: #d8eaff;
}

.size-cell .quality-badge--na {
  color: #4a5560;
  background: #e5e9ee;
}

.category-line {
  margin: 6px 0 8px;
  color: #3f5f56;
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.desc {
  margin: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.screenshots-wrap {
  margin-top: 12px;
  width: min(500px, 100%);
}

.screenshots-title {
  margin: 0 0 6px;
  color: var(--ink-muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.screenshots-grid {
  width: min(500px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  grid-auto-rows: 72px;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(30, 42, 39, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.screenshot-link {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(30, 42, 39, 0.14);
  background: linear-gradient(135deg, #eef2ef, #d7e2dd);
}

.screenshot-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
}

.meta {
  margin-top: 8px;
  color: var(--ink-muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.date-cell .date-value {
  font-weight: 600;
}

.date-cell .seeds-line {
  margin-top: 6px;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.placeholder {
  text-align: center;
  color: var(--ink-muted);
  padding: 28px;
}

.error-row td {
  color: var(--error);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: calc(100% - 20px);
    margin-top: 18px;
  }

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

  .auth-actions {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .source-input-wrap {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  .save-search-btn {
    width: 100%;
    min-height: 46px;
  }

  .dialog-actions {
    flex-direction: column;
  }
}
