:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--tg-theme-text-color, #163047);
  background: var(--tg-theme-bg-color, #f2f7fb);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(45, 189, 232, 0.18), transparent 34%),
    var(--tg-theme-bg-color, #f2f7fb);
}

.app-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 28px 18px calc(34px + env(safe-area-inset-bottom));
}

header {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--tg-theme-link-color, #149dcc);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 8vw, 48px);
  line-height: 1;
}

.subtitle {
  margin: 12px 0 0;
  color: var(--tg-theme-hint-color, #6f7f8c);
  line-height: 1.55;
}

.card {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid rgba(48, 108, 145, 0.12);
  border-radius: 20px;
  background: var(--tg-theme-secondary-bg-color, rgba(255, 255, 255, 0.9));
  box-shadow: 0 12px 32px rgba(38, 85, 114, 0.09);
}

#imageInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-zone {
  display: grid;
  place-items: center;
  min-height: 190px;
  border: 2px dashed var(--tg-theme-link-color, #25afe0);
  border-radius: 16px;
  cursor: pointer;
  text-align: center;
}

.upload-zone span:last-child {
  color: var(--tg-theme-hint-color, #71808e);
  font-size: 13px;
}

.upload-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--tg-theme-button-color, #28afe0);
  font-size: 34px;
  line-height: 1;
}

.selected-panel {
  display: grid;
  gap: 14px;
}

.input-preview-shell {
  position: relative;
  display: grid;
  min-height: 190px;
  max-height: 240px;
  place-items: center;
  overflow: hidden;
  border-radius: 16px;
  background: repeating-conic-gradient(#eef2f5 0 25%, #dfe7ec 0 50%) 50% / 18px 18px;
}

.input-preview-shell::after {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(37, 175, 224, 0.34);
  border-radius: inherit;
  content: "";
  pointer-events: none;
}

#inputPreview {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: contain;
}

.selected-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.selected-heading > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.selected-check {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: #20aa6b;
  font-size: 22px;
  font-weight: 900;
}

.large-file-badge {
  padding: 5px 9px;
  border-radius: 999px;
  color: #08769d;
  background: rgba(37, 175, 224, 0.14);
  font-size: 12px;
  font-weight: 800;
}

.selected-details {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border-radius: 13px;
  background: rgba(37, 175, 224, 0.1);
  overflow-wrap: anywhere;
}

.selected-details span {
  color: var(--tg-theme-hint-color, #71808e);
  font-size: 13px;
}

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

.secondary-button,
.danger-button {
  display: grid;
  min-height: 46px;
  place-items: center;
  border-radius: 13px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.secondary-button {
  border: 1px solid var(--tg-theme-button-color, #24afe0);
  color: var(--tg-theme-link-color, #149dcc);
  background: transparent;
}

.danger-button {
  border: 1px solid rgba(208, 67, 67, 0.22);
  color: #bd3333;
  background: rgba(208, 67, 67, 0.08);
}

.controls label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 18px;
  font-weight: 700;
}

.controls label:last-child {
  margin-bottom: 0;
}

.controls input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--tg-theme-button-color, #24afe0);
}

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

.select-grid label {
  display: grid;
  grid-template-columns: 1fr;
  margin: 0;
}

select {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(48, 108, 145, 0.2);
  border-radius: 12px;
  color: inherit;
  background: var(--tg-theme-bg-color, white);
  font: inherit;
}

.primary-button,
.download-button {
  display: grid;
  width: 100%;
  min-height: 58px;
  place-items: center;
  border: 0;
  border-radius: 18px;
  color: var(--tg-theme-button-text-color, white);
  background: var(--tg-theme-button-color, #24afe0);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

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

.status-card {
  margin-top: 16px;
}

progress {
  width: 100%;
  height: 10px;
  margin-top: 12px;
  accent-color: var(--tg-theme-button-color, #24afe0);
}

.result-card img {
  display: block;
  width: 100%;
  max-height: 380px;
  object-fit: contain;
  border-radius: 14px;
  background: repeating-conic-gradient(#eef2f5 0 25%, #dfe7ec 0 50%) 50% / 18px 18px;
}

.result-stats {
  margin: 14px 0;
  line-height: 1.65;
}

.privacy-note {
  color: var(--tg-theme-hint-color, #71808e);
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}

@media (max-width: 440px) {
  .select-grid {
    grid-template-columns: 1fr;
  }
}
