/*
 * Basic styling for the Image Grid Splitter web application.
 *
 * The layout is kept intentionally simple and responsive. The container is
 * centered on the page with a maximum width, and form controls are spaced
 * evenly. The results section displays the generated image slices in a
 * flexible grid, ensuring they adapt nicely to various screen sizes.
 */

/*
 * Colour variables
 * Using CSS custom properties allows easy toggling between light and dark
 * themes. The default definitions live in the :root selector and are
 * overridden in the .dark-mode body.
 */

:root {
  --bg-color: #f9f9f9;
  --text-color: #333333;
  --container-bg: #ffffff;
  --border-color: #e0e0e0;
  --primary-color: #007bff;
  --primary-hover-color: #0056b3;
  --secondary-color: #f2f2f2;
}

body.dark-mode {
  --bg-color: #121212;
  --text-color: #f5f5f5;
  --container-bg: #1e1e1e;
  --border-color: #333333;
  --primary-color: #0d6efd;
  --primary-hover-color: #195ec8;
  --secondary-color: #2a2a2a;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Poppins', Arial, Helvetica, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  transition: background 0.3s ease, color 0.3s ease;
}

/* Container for all content */
.container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 1.5rem;
  background: var(--container-bg);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: background 0.3s ease;
}

/* Title */
h1 {
  text-align: center;
  margin-top: 0;
}

/* Descriptive paragraph */
.description {
  text-align: center;
  color: var(--text-color);
  opacity: 0.8;
  margin-bottom: 2rem;
}

/* Controls section for mode buttons and theme toggle */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

/* Mode buttons */
.mode-buttons {
  display: flex;
  gap: 0.5rem;
}

.mode-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--secondary-color);
  color: var(--text-color);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease;
}

.mode-btn.active {
  background: var(--primary-color);
  color: #fff;
  border-color: var(--primary-color);
}

.mode-btn:hover:not(.active) {
  background: var(--border-color);
}

/* Theme toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: #fff;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Adjust overall form layout */
form {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-end;
  background: var(--secondary-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
}

form {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-end;
}

/* Form group spacing */
.form-group {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
}

/* Input labels */
.form-group label {
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
}

/* File input styling */
.form-group input[type="file"] {
  padding: 0.25rem;
  color: var(--text-color);
}

/* Text and number inputs */
.form-group input[type="number"],
.form-group input[type="text"],
.form-group select {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 1rem;
  background: var(--secondary-color);
  color: var(--text-color);
  transition: background 0.3s ease, color 0.3s ease;
}

.form-group select {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
}

/* Primary button */
button.primary {
  padding: 0.8rem 1.6rem;
  border: none;
  border-radius: 4px;
  background-color: var(--primary-color);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 100%;
  transition: background-color 0.2s ease;
}

button.primary:hover {
  background-color: var(--primary-hover-color);
}

/* Horizontal rule */
hr {
  margin: 2rem 0;
  border: none;
  border-top: 1px solid var(--border-color);
}

/* Results container */
.results {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

/* Slice container for image pieces */
.slice {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.5rem;
  background: var(--secondary-color);
}

/* Group width, height and preset on one line */
.size-group .size-options {
  display: flex;
  gap: 0.5rem;
}

.size-group .size-options input[type="number"] {
  flex: 1 1 30%;
}

.size-group .size-options select {
  flex: 1 1 40%;
}

/* Sound toggle alignment */
.sound-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Ensure label inside sound group doesn't take full width */
.sound-group label:not(.switch) {
  margin-bottom: 0;
}

.slice img {
  max-width: 100%;
  height: auto;
  display: block;
  margin-bottom: 0.5rem;
  border-radius: 4px;
}

.slice a.download-link {
  text-decoration: none;
  color: var(--primary-color);
  font-size: 0.9rem;
}

.slice a.download-link:hover {
  text-decoration: underline;
}

/* Instructions text */
.instructions {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.7;
}