/* Global reset-ish */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --bg-elevated: #111827;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.1);
  --accent-strong: #0ea5e9;
  --border-subtle: #1f2937;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --danger: #f97373;
  --radius-lg: 14px;
  --radius-md: 8px;
  --shadow-soft: 0 16px 40px rgba(0, 0, 0, 0.6);
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #1d2741 0, #020617 55%);
  color: var(--text-main);
}

/* Layout */
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1.5rem;
}

/* Header text */
h1 {
  margin: 0 0 0.25rem;
  font-weight: 700;
  font-size: clamp(1.8rem, 3vw, 2.2rem);
  letter-spacing: 0.03em;
}

p {
  margin: 0 0 1.5rem;
  max-width: 720px;
  text-align: center;
  color: var(--text-muted);
  line-height: 1.6;
}

p code {
  background: rgba(15, 23, 42, 0.8);
  padding: 0.15rem 0.35rem;
  border-radius: 0.35rem;
  font-size: 0.9em;
}

/* Card */
.card {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem 1.75rem;
  box-shadow: var(--shadow-soft);
  max-width: 1200px;
  width: 100%;
}

/* Top control bar */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

/* File input */
input[type="file"] {
  padding: 0.3rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  font-size: 0.9rem;
}

input[type="file"]::file-selector-button {
  padding: 0.35rem 0.8rem;
  margin-right: 0.5rem;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #0b1120;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

input[type="file"]::file-selector-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

/* Button */
button {
  padding: 0.5rem 1.05rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #0b1120;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: transform 0.06s ease, box-shadow 0.1s ease, filter 0.12s ease;
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.35);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  filter: grayscale(0.2);
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 25px rgba(56, 189, 248, 0.45);
  filter: brightness(1.05);
}

button:not(:disabled):active {
  transform: translateY(0);
  box-shadow: 0 5px 12px rgba(15, 23, 42, 0.7);
}

/* Status text */
.hint,
#status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Main content layout */
.canvas-wrapper {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 2rem;
  align-items: flex-start;
  justify-content: center;
}

/* Make the control strip span full width at top of wrapper */
.canvas-wrapper > .gap-label,
.canvas-wrapper > #gapRange,
.canvas-wrapper > .crop-controls {
  flex: 1 1 100%;
}

/* Gap slider + label */
.gap-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

#gapValue {
  color: var(--accent-strong);
  font-weight: 600;
}

#gapRange {
  width: 220px;
  max-width: 100%;
}

/* Slider styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: #111827;
  outline: none;
  border: 1px solid #1f2937;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-strong);
  border: 2px solid #0b1120;
  cursor: pointer;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-strong);
  border: 2px solid #0b1120;
  cursor: pointer;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

/* Crop controls block */
.crop-controls {
  margin-top: 0.25rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  font-size: 0.85rem;
}

.crop-controls label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Text inputs & selects */
input[type="number"],
select {
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: #020617;
  color: var(--text-main);
  font-size: 0.85rem;
  min-width: 80px;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

input[type="number"]:focus,
select:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 1px var(--accent-soft);
  background: #020617;
}

/* Canvas containers */
.canvas-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 360px;
  max-width: 600px;
}

.label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

/* Wrap label + slider in a clean horizontal row */
.gap-control {
  display: flex;
  align-items: center;       /* vertically centers the slider */
  gap: 0.5rem;
}

/* Nudge slider downward slightly to match label baseline */
.gap-control input[type="range"] {
  margin-top: 2px;           /* adjust 0–5px until perfectly centered in your theme */
}

/* Canvases */
canvas {
  border: 1px solid #1f2937;
  max-width: 100%;
  height: auto;
}

#originalCanvas {
  background: #020617;
  border-radius: 10px;
  cursor: crosshair;
}

#resultCanvas {
  background: #ffffff !important;
  border-radius: 0 !important;
}

.number-input {
  min-width: 60px;   /* or smaller */
  width: 60px;       /* hard cap width so it doesn’t stretch */
  text-align: right; /* optional: looks nice for numbers */
}

/* Responsive layout */
@media (max-width: 900px) {
  .card {
    padding: 1.25rem 1.25rem 1.5rem;
  }

  .canvas-wrapper {
    flex-direction: column;
    gap: 1.25rem;
  }

  .canvas-container {
    max-width: 100%;
  }

  .crop-controls {
    padding: 0.65rem 0.8rem;
  }
}

@media (max-width: 600px) {
  body {
    padding: 1.75rem 1rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  p {
    font-size: 0.9rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .controls > * {
    width: 100%;
  }

  input[type="file"] {
    width: 100%;
  }

  button {
    justify-content: center;
  }
}
