:root {
  /* Color palette */
  --color-primary: rgb(74, 85, 104);
  --color-accent: rgb(21, 128, 61);
  --color-accent-hover: rgb(34, 154, 77);
  --color-bg: rgb(247, 250, 252);
  --color-text: rgb(45, 55, 72);
  --color-border: rgb(226, 232, 240);
  --color-container-bg: rgb(255, 255, 255);
  --color-result-bg: rgb(241, 245, 249);
  --color-white: rgb(255, 255, 255);
  --color-black: rgb(0, 0, 0);

  /* Typography */
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --font-size-base: 1rem;
  --font-size-small: 0.875rem;
  --line-height: 1.5;

  /* Spacing scale (used throughout) */
  --spacing-2xs: 0.25rem;
  --spacing-xs: 0.375rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* Layout */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-round: 50%;
  --container-width: 90%;
  --container-max-width: 40rem;

  /* Effects */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-default: 0 0.25rem 0.375rem rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  --focus-ring-width: 0.1875rem;
  --focus-ring-default: 0 0 0 var(--focus-ring-width) rgba(21, 128, 61, 0.5);
  --transition-fast: 0.1s;
  --transition-medium: 0.2s;
}

/* Base styles with improved accessibility */
body {
  font-family: var(--font-family);
  background-color: var(--color-bg);
  color: var(--color-text);
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  line-height: var(--line-height);
  font-size: var(--font-size-base);
}

/* Container with responsive width */
.app-container {
  background-color: var(--color-container-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-default);
  padding: var(--spacing-xl);
  width: var(--container-width);
  max-width: var(--container-max-width);
  margin: var(--spacing-md);
  text-align: center;
}

.app-title {
  color: var(--color-primary);
  margin-top: 0;
  margin-bottom: var(--spacing-lg);
  font-size: calc(var(--font-size-base) * 1.5);
  line-height: 1.2;
}

/* Form controls with improved accessibility */
.number-input {
  width: 100%;
  padding: calc(var(--spacing-md) * 0.75) var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  border: 0.125rem solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  box-sizing: border-box;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.number-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring-default);
}

.result-container {
  overflow-wrap: break-word;
  width: 100%;
}

.range-inputs {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  width: 100%;
}

/* Responsive layout for larger screens */
@media (min-width: 40em) {
  .range-inputs {
    flex-direction: row;
  }
}

/* Accessible buttons with appropriate contrast */
button {
  background-color: transparent;
  color: var(--color-accent);
  border: 0.1875rem solid var(--color-accent);
  border-radius: var(--radius-sm);
  padding: calc(var(--spacing-md) * 0.75) var(--spacing-lg);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), transform 0.1s, box-shadow var(--transition-fast);
  margin-bottom: var(--spacing-lg);
}

button:hover {
  background-color: var(--color-accent);
  color: var(--color-white);
}

button:focus {
  outline: none;
  box-shadow: var(--focus-ring-default);
}

/* Results display with better readability */
.result-line {
  background-color: var(--color-result-bg);
  padding: var(--spacing-md);
  border-radius: var(--radius-sm);
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--font-size-small);
  line-height: 1.6;
  overflow: auto;
  max-height: 40vh;
  white-space: pre-wrap;
  margin-top: var(--spacing-md);
}

/* Toggle component with improved accessibility */
.mode-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  margin: 0 auto var(--spacing-lg);
  width: 100%;
  max-width: 14rem;
}

.toggle-label {
  width: 4rem;
  text-align: center;
  font-weight: 500;
}

.toggle-button {
  position: relative;
  width: 3.5rem;
  height: 1.75rem;
  background-color: var(--color-border);
  border-radius: calc(var(--radius-lg) * 1.5);
  padding: 0;
  margin: 0;
  cursor: pointer;
  transition: background-color var(--transition-medium);
  display: flex;
  align-items: center;
  border: none;
}

.toggle-button:focus {
  outline: none;
  box-shadow: var(--focus-ring-default);
}

.toggle-thumb {
  position: absolute;
  width: 1.4rem;
  height: 1.4rem;
  background-color: var(--color-container-bg);
  border-radius: var(--radius-round);
  transition: transform var(--transition-medium);
  box-shadow: var(--shadow-sm);
}

.toggle-thumb-left {
  transform: translateX(0.2rem);
}

.toggle-thumb-right {
  transform: translateX(1.9rem);
}

.toggle-active {
  color: var(--color-accent);
  font-weight: 600;
  width: 4rem;
  text-align: center;
}

/* GitHub link button */
.github-link {
  position: fixed;
  top: var(--spacing-lg);
  right: var(--spacing-lg);
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-round);
  background-color: var(--color-accent);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-default);
  transition: transform var(--transition-fast), background-color var(--transition-fast);
  z-index: 100;
  font-size: 1.5rem;
}

.github-link:hover,
.github-link:focus {
  background-color: var(--color-accent-hover);
  color: var(--color-white);
  outline: none;
}

.github-link:focus {
  box-shadow: var(--focus-ring-default);
}

/* Print styles for better output */
@media print {
  body {
    background-color: var(--color-container-bg);
  }

  .app-container {
    box-shadow: none;
    width: 100%;
    max-width: 100%;
    padding: 0;
    margin: 0;
  }

  button,
  .mode-toggle,
  .github-link {
    display: none;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: white) {
  :root {
    /* Dark theme colors */
    --color-bg: rgb(26, 32, 44);
    --color-text: rgb(226, 232, 240);
    --color-border: rgb(74, 85, 104);
    --color-primary: rgb(226, 232, 240);
    --color-container-bg: rgb(45, 55, 72);
    --color-result-bg: rgb(26, 32, 44);
    --shadow-default: 0 0.25rem 0.375rem rgba(0, 0, 0, 0.3);
  }
}