:root {
  --bg: #f4f7f2;
  --card: #fff;
  --ink: #152018;
  --muted: #66716a;
  --line: #dce4dc;
  --green: #147a4a;
  --soft: #e8f4ec;
  --red: #b42318;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  font: 16px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  overflow-x: hidden;
  max-width: 100%;
}

.wrap {
  max-width: 640px;
  width: 100%;
  margin: auto;
  padding: 20px 18px 70px;
  overflow-x: hidden;
}

.top {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
}

.top a {
  color: var(--muted);
  text-decoration: none;
}

.top a:hover { color: var(--ink); }

h1 {
  font-size: clamp(32px, 6vw, 44px);
  letter-spacing: -0.04em;
  margin: 28px 0 8px;
}

.sub {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  overflow: hidden;
  min-width: 0;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 10px;
  margin-top: 10px;
  min-width: 0;
}

.row > * { min-width: 0; width: 100%; }

input,
select,
button {
  font: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  background: white;
  max-width: 100%;
}

select {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  cursor: pointer;
  font-weight: 650;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--green);
  color: white;
  border-color: var(--green);
  width: 100%;
  margin-top: 10px;
}

.primary:disabled {
  opacity: 0.85;
  cursor: wait;
}

.primary.is-wait::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}

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

.photo {
  position: relative;
  display: block;
  width: 100%;
  border: 1px dashed #aebdb1;
  border-radius: 15px;
  padding: 22px 16px;
  text-align: center;
  background: #fbfcfb;
  font-weight: 650;
  cursor: pointer;
}

.filename {
  display: block;
  margin-top: 6px;
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.dragging .photo {
  border-color: var(--green);
  background: var(--soft);
}

.photo input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.scan {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.scan[data-state="wait"] {
  border-color: var(--green);
  background: var(--soft);
  color: var(--ink);
  font-weight: 650;
}

.scan[data-state="wait"]::before {
  content: "";
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
  border: 2px solid #c5d7cb;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.scan[data-state="ok"] {
  border-color: var(--green);
  background: var(--soft);
  color: var(--green);
  font-weight: 700;
}

.scan[data-state="fail"] {
  border-color: var(--red);
  background: #fef3f2;
  color: var(--red);
  font-weight: 700;
}

.scan[data-state="typed"] {
  border-color: #244b9b;
  background: #eef3fb;
  color: #244b9b;
  font-weight: 700;
}

.result { margin-top: 8px; min-width: 0; }

.answer {
  font-size: clamp(26px, 7vw, 32px);
  font-weight: 800;
  margin: 12px 0 4px;
  overflow-wrap: anywhere;
}

.bin { font-size: 17px; margin: 0; }

.swap {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--green);
  background: var(--soft);
}

.swap-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 4px;
}

.eco {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--soft);
}

.eco-score {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 4px;
}

.maker {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbfcfb;
}

.maker-score {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}

.maker-buy {
  font-size: 15px;
  font-weight: 650;
  margin: 0 0 8px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.meta,
.small,
.bin,
.eco,
.swap,
.maker,
.note,
.sources {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

.note {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 22px;
}

.sources {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.sources h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.sources ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sources li {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 8px;
}

a { color: var(--green); }

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