:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0d1117;
  color: #e5e7eb;
  margin: 0;
  padding: 16px;
  direction: rtl;
}

h1 {
  text-align: center;
  margin: 0 0 16px;
  font-size: 20px;
  color: #f9fafb;
}

.layout {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
}

.controls {
  min-width: 260px;
  max-width: 340px;
  background: #111827;
  padding: 12px;
  border-radius: 8px;
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.6);
  border: 1px solid #1f2937;
  color: #e5e7eb;
}

.controls label {
  display: block;
  margin: 8px 0 4px;
  font-size: 13px;
  color: #e5e7eb;
}

.controls input[type="text"],
.controls input[type="number"],
.controls textarea,
.controls select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid #374151;
  background: #020617;
  color: #e5e7eb;
  font-size: 13px;
}

.controls textarea {
  resize: vertical;
  min-height: 40px;
  max-height: 100px;
}

.controls select {
  background: #020617;
}

.controls input[type="text"]::placeholder,
.controls input[type="number"]::placeholder,
.controls textarea::placeholder {
  color: #6b7280;
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.color-row label {
  flex: 1 1 auto;
  margin: 0;
  font-size: 13px;
}

.color-row input[type="color"] {
  width: 46px;
  min-width: 46px;
  height: 26px;
  padding: 0;
  border: none;
  background: transparent;
}

button {
  width: 100%;
  padding: 8px;
  font-size: 14px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid #10a37f;
  outline-offset: 2px;
}

#generateBtn {
  margin-top: 10px;
  background: #10a37f;
  color: #fff;
}

#generateBtn:hover {
  background: #0e8c6c;
}

.section-title {
  margin-top: 10px;
  font-weight: 700;
  font-size: 13px;
  color: #f9fafb;
}

.scan-section {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #1f2937;
}

#scanFromImageBtn {
  margin-top: 6px;
  background: #10a37f;
  color: #fff;
}

#scanFromImageBtn:hover,
#openCameraBtn:hover,
.download-btn:hover {
  filter: brightness(1.05);
}

#openCameraBtn {
  margin-top: 6px;
  background: #15803d;
  color: #fff;
}

#qrVideo {
  display: none;
  width: 100%;
  max-height: 240px;
  margin-top: 6px;
  border-radius: 4px;
  background: #000;
}

.scan-result {
  margin-top: 6px;
  font-size: 12px;
  background: #020617;
  border-radius: 4px;
  padding: 6px;
  min-height: 24px;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid #1f2937;
  color: #e5e7eb;
}

.card-wrapper {
  background: #020617;
  padding: 8px;
  border-radius: 8px;
  max-width: 100%;
  border: 1px solid #1f2937;
}

.card {
  width: 100%;
  max-width: 10cm;
  aspect-ratio: 10 / 13;
  border: 4px solid #10a37f;
  padding: 0.5cm;
  background: #0b1120;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  color: #f9fafb;
}

.top-text,
.bottom-text {
  width: 100%;
  text-align: center;
  word-wrap: break-word;
  overflow-wrap: break-word;
  color: #f9fafb;
  min-height: 1.2em;
}

.top-text {
  margin-bottom: 6px;
}

.bottom-text {
  margin-top: 6px;
}

.qr-container {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: #ffffff;
  border-radius: 8px;
  padding: 4px;
}

#qrcode {
  width: 100%;
  height: 100%;
  max-width: 320px;
  max-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#qrcode canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.download-buttons {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.download-btn {
  background: #10a37f;
  color: #fff;
  flex: 1 1 150px;
}

.download-btn.secondary {
  background: #374151;
}

.site-footer {
  text-align: center;
  margin-top: 16px;
  font-size: 12px;
  color: #9ca3af;
}

.hidden-file-input,
.hidden-canvas {
  display: none;
}

.help-text {
  margin-top: 8px;
  font-size: 11px;
  color: #9ca3af;
  line-height: 1.5;
}

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

  .controls {
    max-width: 100%;
  }

  .card {
    max-width: min(10cm, 100vw - 56px);
  }
}
