/* ============================================
   HEIC to PNG Converter — Dark Theme
   Mobile-first responsive styles
   ============================================ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #252838;
  --bg-hover: #2e3245;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-muted: #6b7280;
  --accent: #6c9cff;
  --accent-hover: #8bb3ff;
  --accent-glow: rgba(108, 156, 255, 0.15);
  --danger: #ff6b6b;
  --danger-bg: rgba(255, 107, 107, 0.1);
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.1);
  --border: #2e3245;
  --border-dashed: #3a3f54;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 0.2s ease;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ---- Header / Nav ---- */
header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

nav {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.logo span { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 1rem;
}

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.nav-links a:hover,
.nav-links a:focus-visible {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}
.nav-links a.active {
  color: var(--accent);
  background: var(--accent-glow);
}

/* ---- Main Content ---- */
main {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.25rem;
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* ---- Drop Zone ---- */
.drop-zone {
  border: 2px dashed var(--border-dashed);
  border-radius: var(--radius);
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  background: var(--bg-secondary);
  outline: none;
  position: relative;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.drop-zone:focus-visible {
  border-color: var(--accent);
}

.upload-icon {
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.drop-text {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.drop-sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.drop-limit {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 0.75rem;
}

/* ---- File List ---- */
.file-list {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  transition: border-color var(--transition);
}

.file-item:hover {
  border-color: var(--bg-hover);
}

.file-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg-tertiary);
  flex-shrink: 0;
  /* Checkerboard pattern for transparency */
  background-image: 
    linear-gradient(45deg, #1a1d27 25%, transparent 25%),
    linear-gradient(-45deg, #1a1d27 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1d27 75%),
    linear-gradient(-45deg, transparent 75%, #1a1d27 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
}
.file-remove:hover,
.file-remove:focus-visible {
  color: var(--danger);
  background: var(--danger-bg);
}

/* ---- Actions ---- */
.actions {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.btn {
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s, box-shadow var(--transition);
  outline: none;
}
.btn:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: var(--bg-hover);
}

/* ---- Progress ---- */
.progress {
  margin-top: 1.5rem;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* ---- Results ---- */
.results {
  margin-top: 2rem;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.result-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--transition);
}

.result-card:hover {
  border-color: var(--accent);
}

.result-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
  /* Checkerboard for transparent PNGs */
  background-image: 
    linear-gradient(45deg, #1a1d27 25%, transparent 25%),
    linear-gradient(-45deg, #1a1d27 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1d27 75%),
    linear-gradient(-45deg, transparent 75%, #1a1d27 75%);
  background-size: 12px 12px;
  background-color: var(--bg-tertiary);
}

.result-card-body {
  padding: 0.6rem 0.75rem;
}

.result-card-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-card-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.result-card .btn-download {
  display: block;
  width: 100%;
  padding: 0.5rem;
  background: var(--bg-tertiary);
  border: none;
  border-top: 1px solid var(--border);
  color: var(--accent);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.result-card .btn-download:hover {
  background: var(--bg-hover);
}

.download-all {
  margin-top: 1.25rem;
  text-align: center;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 100;
  animation: slideUp 0.3s ease;
}

.toast.success {
  border-color: var(--success);
  color: var(--success);
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ---- Footer ---- */
footer {
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.footer-links {
  margin-top: 0.5rem;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}
.footer-links a:hover { color: var(--accent); }

/* ---- Responsive ---- */
@media (max-width: 480px) {
  main { padding: 1.25rem 1rem; }
  h1 { font-size: 1.4rem; }
  .drop-zone { padding: 2rem 1rem; }
  .result-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; }
  .result-card img { height: 110px; }
  .nav-links { gap: 0.5rem; }
  .nav-links a { font-size: 0.78rem; padding: 0.25rem 0.5rem; }
}

/* ---- Focus States ---- */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Screenreader only ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
