:root {
  --bg: #f6f3ef;
  --card: #ffffff;
  --text: #252525;
  --muted: #6b6b6b;
  --border: #e2ddd5;
  --accent: #7254ef;
  --accent-dark: #5337d1;
  --danger: #b00020;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

img,
canvas {
  max-width: 100%;
}

.page-header,
.page-main {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding-left: 32px;
  padding-right: 32px;
}

.page-header {
  padding-top: 28px;
  padding-bottom: 10px;
}

.page-header h1 {
  margin: 0 0 8px;
  font-size: 32px;
  line-height: 1.15;
}

.page-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.page-main {
  padding-top: 16px;
  padding-bottom: 60px;
}

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

.panel {
  padding: 22px;
  margin-bottom: 24px;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
}

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

input[type="file"],
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
  font-size: 14px;
}

.crop-stage {
  margin-top: 20px;
}

.crop-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 20px;
  align-items: start;
}

.canvas-shell {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #ebe8e3;
  overscroll-behavior: contain;
}

#cropCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: #ddd;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.preview-card {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
}

.preview-card h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

#modelPreviewCanvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #eee;
}

.help,
.small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

button {
  min-height: 44px;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

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

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(114, 84, 239, 0.25);
  outline-offset: 2px;
}

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

button.secondary {
  background: #ece7ff;
  color: var(--accent-dark);
}

button.secondary:hover {
  background: #ded5ff;
}

button.neutral {
  background: #efede9;
  color: #333;
}

button.neutral:hover {
  background: #e1ddd7;
}


.status {
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
}

.status.error {
  color: var(--danger);
  font-weight: 700;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0;
}

.results-header h2 {
  margin: 0;
}

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

.card {
  min-width: 0;
  min-height: 280px;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.card-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}

.result-image-wrap {
  position: relative;
  min-width: 0;
}

.card-images img {
  display: block;
  width: 100%;
  height: 125px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #eee;
}

.image-score {
  position: absolute;
  right: 5px;
  bottom: 7px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.card-body {
  min-width: 0;
  overflow-wrap: anywhere;
}

.score-badge {
  display: inline-block;
  margin-bottom: 8px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #f0edff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.card-title {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.25;
}

.card-title a {
  color: var(--text);
  text-decoration: none;
}

.card-title a:hover {
  text-decoration: underline;
}

.meta {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.description {
  max-height: 82px;
  overflow: hidden;
  margin: 10px 0 12px;
  color: #333;
  font-size: 14px;
  line-height: 1.45;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.link-button {
  display: inline-block;
  padding: 9px 11px;
  border-radius: 10px;
  background: #f3f1ed;
  color: #333;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.link-button.primary {
  background: var(--accent);
  color: #fff;
}

.empty {
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: 18px;
  background: var(--card);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1050px) {
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .crop-layout,
  .cards {
    grid-template-columns: 1fr;
  }

  .preview-card {
    width: min(100%, 420px);
    max-width: none;
  }
}

@media (max-width: 700px) {
  .page-header,
  .page-main {
    padding-left: 12px;
    padding-right: 12px;
  }

  .page-header {
    padding-top: 18px;
  }

  .page-header h1 {
    font-size: 25px;
  }

  .page-header p {
    font-size: 14px;
  }

  .page-main {
    padding-top: 10px;
    padding-bottom: 36px;
  }

  .panel {
    padding: 14px;
    border-radius: 16px;
  }

  .filter-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .crop-layout,
  .card {
    grid-template-columns: 1fr;
  }

  .crop-layout {
    gap: 14px;
  }

  .canvas-shell {
    min-height: 180px;
    padding: 6px;
    border-radius: 12px;
  }

  .preview-card {
    width: 100%;
    max-width: none;
    padding: 12px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .actions button {
    width: 100%;
    min-height: 48px;
  }

  .results-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .card {
    min-height: 0;
    padding: 13px;
    border-radius: 16px;
  }

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

  .card-images img {
    height: 130px;
  }

  .links {
    display: grid;
    grid-template-columns: 1fr;
  }

  .link-button {
    width: 100%;
    min-height: 44px;
    text-align: center;
  }
}

@media (max-width: 420px) {
  .card-images img {
    height: 110px;
  }

  .help,
  .small,
  .meta {
    font-size: 12px;
  }
}
