:root {
  --bg-color: #ffffff;
  --text-color: #1e293b;
  --secondary-text-color: #475569;
  --border-color: #d1d5db;
  --shadow-color: rgba(0, 0, 0, 0.05);
  --card-bg: rgba(255, 255, 255, 0.2);
  --button-bg: rgba(59, 130, 246, 0.3);
  --button-hover-bg: rgba(37, 99, 235, 0.4);
  --error-color: #dc2626;
  --success-color: #1e293b;
  --blur-radius: 10px;
  --primary-font: Arial, sans-serif;
  --heading-color: #0f172a;
  --text-shadow-light: 0 1px 2px rgba(0, 0, 0, 0.1);
  --text-shadow-dark: 0 1px 2px rgba(0, 0, 0, 0.3);
  --glass-bg: rgba(255, 255, 255, 0.15);
  --glass-bg-fallback: rgba(255, 255, 255, 0.3);
  --button-text-color: #000000;
  /* Animation variables */
  --animation-duration: 150ms;
  --animation-duration-slow: 300ms;
  --animation-duration-load: 400ms;
  --animation-easing: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-color: #333333;
  --text-color: #f8fafc;
  --secondary-text-color: #94a3b8;
  --border-color: #475569;
  --shadow-color: rgba(0, 0, 0, 0.2);
  --card-bg: rgba(45, 55, 72, 0.2);
  --button-bg: rgba(96, 165, 250, 0.3);
  --button-hover-bg: rgba(59, 130, 246, 0.4);
  --error-color: #f87171;
  --success-color: #e2e8f0;
  --heading-color: #f1f5f9;
  --glass-bg: rgba(45, 55, 72, 0.15);
  --glass-bg-fallback: rgba(45, 55, 72, 0.3);
  --button-text-color: #ffffff;
}

body {
  font-family: var(--primary-font);
  margin: 0;
  padding: 24px;
  background: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  max-width: 1280px;
  margin: 0 auto;
  text-shadow: var(--text-shadow-light);
  position: relative;
  min-height: 100vh;
  z-index: 1;
  transition: background var(--animation-duration-slow) var(--animation-easing),
              color var(--animation-duration-slow) var(--animation-easing);
}

main {
  animation: fadeIn var(--animation-duration-load) var(--animation-easing);
}

#backgroundContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: -1;
  transition: background-image var(--animation-duration-slow) var(--animation-easing);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cardEntrance {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(20px); }
}

h1 {
  font-size: 2.25rem;
  font-weight: 700;
  color: #a61b29;
  text-align: center;
  margin: 1em 0;
  letter-spacing: -0.025em;
  font-family: var(--primary-font);
  text-shadow: var(--text-shadow-light);
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--heading-color);
  margin: 1.5rem 0 0.75rem;
  text-align: left;
  letter-spacing: 0.01em;
  line-height: 1.4;
  font-family: var(--primary-font);
  text-shadow: var(--text-shadow-light);
  position: relative;
  padding-bottom: 4px;
  transition: color var(--animation-duration) var(--animation-easing);
}

h2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 40px;
  height: 2px;
  background: var(--button-bg);
  opacity: 0.7;
  transition: width var(--animation-duration-slow) var(--animation-easing),
              opacity var(--animation-duration-slow) var(--animation-easing);
}

h2:hover::after {
  width: 80px;
  opacity: 1;
}

p {
  color: var(--secondary-text-color);
  font-size: 1rem;
  margin: 0 0 1.25rem;
  text-align: left;
  line-height: 1.7;
  letter-spacing: 0.005em;
  font-weight: 400;
  font-family: var(--primary-font);
  text-shadow: var(--text-shadow-light);
  transition: color var(--animation-duration) var(--animation-easing);
}

[data-theme="dark"] h2,
[data-theme="dark"] p,
[data-theme="dark"] h1,
[data-theme="dark"] body {
  text-shadow: var(--text-shadow-dark);
}

hr {
  border: none;
  height: 1px;
  background-color: var(--border-color);
  margin: 2rem 0;
  transition: background-color var(--animation-duration-slow) var(--animation-easing);
}

#themeToggle, .file-input-button, #removeBackground {
  padding: 10px 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius));
  -webkit-backdrop-filter: blur(var(--blur-radius));
  color: var(--button-text-color);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background-color var(--animation-duration) var(--animation-easing),
              transform var(--animation-duration) var(--animation-easing),
              box-shadow var(--animation-duration) var(--animation-easing);
  font-family: var(--primary-font);
  will-change: transform, box-shadow;
}

#themeToggle {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 8px 16px;
}

#themeToggle:hover, .file-input-button:hover, #removeBackground:hover {
  background: var(--button-bg);
  transform: scale(1.05);
  box-shadow: 0 2px 4px var(--shadow-color);
}

#themeToggle:active, .file-input-button:active, #removeBackground:active {
  transform: scale(0.95);
}

.file-input-container, .background-input-container {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  width: 100%;
  position: relative;
}

#fontInput, #backgroundInput {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 1;
}

.file-input-button {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-input-button::before {
  content: '📁';
  font-size: 1rem;
  transition: transform var(--animation-duration) var(--animation-easing);
}

.file-input-button:hover::before {
  transform: scale(1.2);
}

.file-input-name, .background-input-name {
  flex: 1;
  font-size: 0.875rem;
  color: var(--secondary-text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--primary-font);
  transition: color var(--animation-duration) var(--animation-easing);
}

.file-input-name.success, .background-input-name.success {
  color: var(--success-color);
}

.file-input-name.error, .background-input-name.error {
  color: var(--error-color);
}

#preview {
  border: 1px solid var(--border-color);
  padding: 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius));
  -webkit-backdrop-filter: blur(var(--blur-radius));
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--shadow-color);
  min-height: 120px;
  font-size: 1.25rem;
  white-space: pre-wrap;
  font-feature-settings: "kern" 1;
  transition: box-shadow var(--animation-duration) var(--animation-easing),
              transform var(--animation-duration) var(--animation-easing),
              background var(--animation-duration-slow) var(--animation-easing);
  font-family: var(--primary-font);
  will-change: transform, box-shadow;
}

#preview:hover {
  box-shadow: 0 4px 12px var(--shadow-color);
  transform: translateY(-2px);
}

.font-size-control, .font-weight-control, .font-axis-control, .blur-control {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.font-size-control p, .font-weight-control p, .font-axis-control p, .blur-control p {
  margin: 0;
  font-weight: 500;
  color: var(--text-color);
  font-family: var(--primary-font);
  text-shadow: var(--text-shadow-light);
  transition: color var(--animation-duration) var(--animation-easing);
}

[data-theme="dark"] .font-size-control p,
[data-theme="dark"] .font-weight-control p,
[data-theme="dark"] .font-axis-control p,
[data-theme="dark"] .blur-control p {
  text-shadow: var(--text-shadow-dark);
}

input[type="range"] {
  width: 200px;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  accent-color: var(--button-bg);
  cursor: pointer;
  -webkit-appearance: none;
  position: relative;
  transition: background var(--animation-duration) var(--animation-easing);
}

input[type="range"]:hover {
  background: var(--secondary-text-color);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--button-bg);
  border-radius: 50%;
  cursor: pointer;
  transition: background var(--animation-duration) var(--animation-easing),
              transform var(--animation-duration) var(--animation-easing);
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--button-hover-bg);
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--button-bg);
  border-radius: 50%;
  cursor: pointer;
  transition: background var(--animation-duration) var(--animation-easing),
              transform var(--animation-duration) var(--animation-easing);
}

input[type="range"]::-moz-range-thumb:hover {
  background: var(--button-hover-bg);
  transform: scale(1.2);
}

input[type="range"]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
  font-family: var(--primary-font);
  opacity: 0;
  transition: opacity var(--animation-duration) var(--animation-easing);
}

input[type="range"]:hover::after {
  opacity: 1;
}

#fontSizeInput, #fontWeightInput {
  width: 200px;
}

#fontSizeInput:focus, #fontWeightInput:focus {
  outline: none;
}

.preset-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.preset-container p {
  margin: 0;
  font-weight: 500;
  color: var(--text-color);
  font-family: var(--primary-font);
  text-shadow: var(--text-shadow-light);
  transition: color var(--animation-duration) var(--animation-easing);
}

[data-theme="dark"] .preset-container p {
  text-shadow: var(--text-shadow-dark);
}

#presetSelect {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius));
  -webkit-backdrop-filter: blur(var(--blur-radius));
  max-width: 200px;
  width: 100%;
  color: var(--text-color);
  transition: border-color var(--animation-duration) var(--animation-easing),
              background var(--animation-duration-slow) var(--animation-easing),
              transform var(--animation-duration) var(--animation-easing);
  font-family: var(--primary-font);
  will-change: transform;
}

#presetSelect:hover, #presetSelect:focus {
  border-color: var(--button-bg);
  transform: scale(1.02);
  outline: none;
}

#fontMetadata {
  margin-top: 2rem;
}

.metadata-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius));
  -webkit-backdrop-filter: blur(var(--blur-radius));
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px var(--shadow-color);
  transition: box-shadow var(--animation-duration) var(--animation-easing),
              transform var(--animation-duration) var(--animation-easing),
              background var(--animation-duration-slow) var(--animation-easing);
  cursor: pointer;
  animation: cardEntrance var(--animation-duration-slow) var(--animation-easing);
  will-change: transform, box-shadow;
}

.metadata-card:hover {
  box-shadow: 0 4px 12px var(--shadow-color);
  transform: translateY(-2px);
}

.metadata-card h4 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-color);
  font-family: var(--primary-font);
  text-shadow: var(--text-shadow-light);
  transition: color var(--animation-duration) var(--animation-easing);
}

[data-theme="dark"] .metadata-card h4 {
  text-shadow: var(--text-shadow-dark);
}

.metadata-card-content {
  font-size: 0.875rem;
  color: var(--text-color);
  font-family: var(--primary-font);
  transition: color var(--animation-duration) var(--animation-easing);
}

.metadata-item {
  margin: 0.5rem 0;
}

.metadata-lang-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 12px;
  margin-left: 1.5rem;
  font-size: 0.875rem;
  font-family: var(--primary-font);
}

#credits {
  margin-top: 2rem;
  font-size: 0.875rem;
  color: var(--secondary-text-color);
  text-align: center;
  font-family: var(--primary-font);
  transition: color var(--animation-duration) var(--animation-easing);
}

#credits a {
  color: var(--button-bg);
  text-decoration: none;
  transition: color var(--animation-duration) var(--animation-easing);
}

#credits a:hover {
  color: var(--button-hover-bg);
  text-decoration: underline;
}

#credits a:visited {
  color: var(--button-bg);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur-radius));
  -webkit-backdrop-filter: blur(var(--blur-radius));
  color: #fff;
  padding: 12px 20px;
  border-radius: 6px;
  box-shadow: 0 4px 12px var(--shadow-color);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--animation-duration-slow) var(--animation-easing),
              transform var(--animation-duration-slow) var(--animation-easing);
  z-index: 1000;
  font-family: var(--primary-font);
}

.toast.show {
  animation: slideIn var(--animation-duration-slow) var(--animation-easing) forwards;
}

.toast:not(.show) {
  animation: slideOut var(--animation-duration-slow) var(--animation-easing) forwards;
}

@supports not (backdrop-filter: blur(var(--blur-radius))) {
  .metadata-card,
  #preview,
  #presetSelect,
  .file-input-button,
  #themeToggle,
  .toast,
  #removeBackground {
    background: var(--glass-bg-fallback);
    opacity: 1;
  }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  main,
  .metadata-card,
  .toast,
  #themeToggle,
  .file-input-button,
  #removeBackground,
  #presetSelect,
  #preview,
  h2::after,
  input[type="range"]::-webkit-slider-thumb,
  input[type="range"]::-moz-range-thumb,
  .file-input-button::before {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 768px) {
  body {
    padding: 16px;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.25rem;
    margin: 1.25rem 0 0.5rem;
  }

  h2::after {
    width: 30px;
  }

  h2:hover::after {
    width: 50px;
  }

  p {
    font-size: 0.875rem;
    margin-bottom: 1rem;
    line-height: 1.6;
  }

  #themeToggle {
    top: 10px;
    right: 10px;
    font-size: 0.75rem;
    padding: 6px 12px;
  }

  .file-input-container, .background-input-container {
    max-width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .file-input-button, #removeBackground {
    padding: 8px 12px;
    font-size: 0.75rem;
    justify-content: center;
  }

  .file-input-name, .background-input-name {
    font-size: 0.75rem;
    text-align: center;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }

  .font-size-control, .font-weight-control, .font-axis-control, .blur-control, .preset-container {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  input[type="range"] {
    width: 100%;
  }

  #presetSelect {
    max-width: none;
    width: 100%;
  }

  .toast {
    bottom: 10px;
    right: 10px;
    font-size: 0.75rem;
    padding: 8px 16px;
  }
}