:root {
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --secondary-color: #6c757d;
  --secondary-hover: #5a6268;
  --success-color: #28a745;
  --success-hover: #218838;
  --light-color: #f8f9fa;
  --dark-color: #343a40;
  --background-color: #eef2f7;
  --card-background: #ffffff;
  --text-color: #333;
  --border-color: #dee2e6;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --border-radius: 8px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Poppins", sans-serif;
  line-height: 1.6;
  background-color: var(--background-color);
  color: var(--text-color);
  padding: 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  color: var(--primary-color);
  font-weight: 800;
  font-size: 2.25rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  display: inline-block;
  transform: skew(-18deg, -3deg);
  background: linear-gradient(
    90deg,
    var(--primary-color) 60%,
    var(--secondary-color) 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  margin-bottom: 0.2rem;
  padding: 0.1em 0.4em;
  box-shadow: 0 2px 12px 0 rgba(0, 123, 255, 0.08);
}

h2 {
  color: var(--dark-color);
  font-weight: 500;
  font-size: 1.1rem;
  letter-spacing: -0.05em;
}

.instructions {
  max-width: 480px;
  margin: 0.5rem auto -1rem auto;
  background: var(--card-background);
  border: 1.5px dashed var(--border-color);
  border-radius: 12px;
  box-shadow: none;
  color: var(--secondary-color);
  padding: 0.5rem 0.8rem;
  font-size: 0.91rem;
  line-height: 1.5;
  text-align: left;
  position: relative;
}

.instructions ol {
  padding-left: 1.3em;
  margin: 0.2em 0 0.2em 0;
}

.instructions ol li {
  margin-bottom: 0.3em;
  position: relative;
  padding-left: 0.5em;
  list-style: none;
  counter-increment: step;
}

.instructions ol li::before {
  content: counter(step) ". ";
  counter-reset: none;
  display: inline-block;
  min-width: 1.2em;
  color: var(--primary-color);
  font-weight: 600;
  background: none;
  border-radius: 3px;
  margin-right: 0.2em;
  font-size: 0.97em;
}

.instructions ol {
  counter-reset: step;
}

.instructions h3,
.instructions::before {
  display: none;
}

main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  background-color: var(--card-background);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.file-input-wrapper input[type="file"] {
  display: none;
}

button,
a {
  padding: 10px 20px;
  font-size: 1em;
  font-family: "Poppins", sans-serif;
  cursor: pointer;
  border: none;
  border-radius: 5px;
  transition: background-color 0.3s ease, transform 0.1s ease;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

button:active,
a:active {
  transform: scale(0.98);
}

button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
  color: #888;
}

.btn-upload {
  background-color: var(--secondary-color);
  color: white;
}
.btn-upload:hover {
  background-color: var(--secondary-hover);
}

.action-container {
  text-align: center;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  font-size: 1.1rem;
  font-weight: 500;
}

.btn-primary:not(:disabled):hover {
  background-color: var(--primary-hover);
}

.canvas-container {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f0f0f0;
  border-radius: var(--border-radius);
  min-height: 190px; /* Ensure container has a min height */
  margin-bottom: 1rem;
}

#preview-canvas-container {
  background-color: #e9e9e9;
}

canvas {
  border: 2px dashed var(--border-color);
  max-width: 100%;
  height: auto;
  display: block;
}

#imageCanvas {
  cursor: crosshair;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.toolbar button {
  padding: 5px 10px;
  font-size: 1.5em;
  min-width: 50px;
  line-height: 1;
  background-color: var(--light-color);
  color: var(--dark-color);
  border: 1px solid var(--border-color);
}

.toolbar button:not(:disabled):hover {
  background-color: #e2e6ea;
}

.download-container {
  margin-top: 1rem;
  text-align: center;
}

#downloadLink {
  background-color: var(--success-color);
  color: white;
  padding: 12px 24px;
  font-size: 1.1rem;
  font-weight: 500;
}

#downloadLink:hover {
  background-color: var(--success-hover);
}

.hidden {
  display: none !important;
}

.btn-upload.hidden,
#downloadLink.hidden {
  visibility: hidden !important;
  display: inline-block !important;
}

/* Loader Overlay */
#loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.8);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.spinner {
  border: 6px solid var(--light-color);
  border-top: 6px solid var(--primary-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

#loader-overlay p {
  font-size: 1.2rem;
  color: var(--dark-color);
  font-weight: 500;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Desktop Layout */
@media (min-width: 992px) {
  main {
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
  }
  .action-container {
    padding: 0 1rem;
    margin-top: 10rem;
  }
}
