/*
 * Copyright 2018 Kenichi Ishibashi (Original Work)
 * Modifications Copyright 2026 MeLi (Li Junjie)
 *
 * Kombu — OpenType/WOFF/WOFF2 Converter
 * Fork: https://github.com/MeLi-55S/kombu
 * Original: https://github.com/bashi/kombu
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* ============================================
   Theme & Variables
   ============================================ */
:root {
  /* Light theme — WCAG AA compliant contrast ratios */
  --color-bg: #f8f9fb;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-secondary: #5b6370;       /* ~4.7:1 on white */
  --color-text-muted: #7a8291;           /* ~4.5:1 on white (for small/decorative text) */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #bfdbfe;
  --color-primary-bg: #eff6ff;
  --color-border: #d1d5db;
  --color-border-hover: #9ca3af;
  --color-success: #059669;
  --color-success-bg: #d1fae5;
  --color-success-text: #065f46;
  --color-danger: #dc2626;
  --color-danger-bg: #fee2e2;
  --color-danger-text: #991b1b;
  --color-warning: #d97706;
  --color-warning-bg: #fef3c7;
  --color-warning-text: #92400e;
  --color-header-bg: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #1d4ed8 100%);
  --color-header-text: #ffffff;
  --color-dropzone-bg: #f0f4ff;
  --color-dropzone-border: #93c5fd;
  --color-dropzone-hover-bg: #dbeafe;
  --color-dropzone-hover-border: #3b82f6;
  --color-spinner: #2563eb;
  --color-shadow: rgba(0, 0, 0, 0.08);
  --color-shadow-hover: rgba(0, 0, 0, 0.12);
  --color-overlay: rgba(0, 0, 0, 0.3);

  /* Spacing */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Shadows */
  --shadow-sm: 0 1px 2px var(--color-shadow);
  --shadow-md: 0 4px 12px var(--color-shadow);
  --shadow-lg: 0 8px 30px var(--color-shadow);

  /* Layout */
  --max-width: 720px;
}

/* Dark theme — WCAG AA compliant */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #f1f5f9;
    --color-text-secondary: #b0c4de;     /* ~7.0:1 on #0f172a */
    --color-text-muted: #8899b0;         /* ~5.4:1 on #0f172a */
    --color-primary: #60a5fa;
    --color-primary-hover: #93c5fd;
    --color-primary-light: #1e3a5f;
    --color-primary-bg: #0f2647;
    --color-border: #475569;
    --color-border-hover: #64748b;
    --color-success: #34d399;
    --color-success-bg: #064e3b;
    --color-success-text: #a7f3d0;
    --color-danger: #f87171;
    --color-danger-bg: #7f1d1d;
    --color-danger-text: #fca5a5;
    --color-warning: #fbbf24;
    --color-warning-bg: #78350f;
    --color-warning-text: #fde68a;
    --color-header-bg: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1e293b 100%);
    --color-header-text: #f1f5f9;
    --color-dropzone-bg: #0f2647;
    --color-dropzone-border: #1e3a5f;
    --color-dropzone-hover-bg: #1e3a5f;
    --color-dropzone-hover-border: #60a5fa;
    --color-spinner: #60a5fa;
    --color-shadow: rgba(0, 0, 0, 0.4);
    --color-shadow-hover: rgba(0, 0, 0, 0.6);
    --color-overlay: rgba(0, 0, 0, 0.6);
  }
}


/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}


/* ============================================
   Header
   ============================================ */
header {
  background: var(--color-header-bg);
  color: var(--color-header-text);
  padding: 1.5rem 2rem 2.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
}

.header-top-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

header h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header h1 a {
  color: inherit;
  text-decoration: none;
  transition: opacity 0.2s;
}

header h1 a:hover {
  opacity: 0.85;
  text-decoration: none;
}

header .subtitle {
  font-size: 1rem;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.5;
  /* Remove opacity for better contrast on dark background */
}

/* Language toggle select */
.lang-toggle {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.4;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(255,255,255,0.7)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.5rem;
  min-width: 70px;
  text-align: center;
  text-align-last: center;
}

.lang-toggle:hover {
  background-color: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
}

.lang-toggle option {
  color: #1a1a2e;
  background: #ffffff;
  text-align: left;
}


/* ============================================
   Main Container
   ============================================ */
main.container {
  padding: 2rem 1rem 3rem;
  max-width: var(--max-width);
  margin: 0 auto;
}


/* ============================================
   Drop Zone (File Selection)
   ============================================ */
#input-select-zone {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

#input-select-zone > div {
  width: 100%;
}

#select-file-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 180px;
  padding: 2rem;
  background: var(--color-dropzone-bg);
  border: 2px dashed var(--color-dropzone-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  font-family: var(--font-sans);
}

#select-file-button:hover {
  background: var(--color-dropzone-hover-bg);
  border-color: var(--color-dropzone-hover-border);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

#select-file-button:active {
  transform: translateY(0);
}

.dropzone-icon {
  width: 48px;
  height: 48px;
  fill: var(--color-primary);
  opacity: 0.7;
  transition: opacity 0.2s, transform 0.2s;
}

#select-file-button:hover .dropzone-icon {
  opacity: 1;
  transform: scale(1.1);
}

.dropzone-label {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-primary);
}

.dropzone-hint {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}


/* ============================================
   Selected Font Info & Format Detection
   ============================================ */
#selected-font-info {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.file-info-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  padding: 0.65rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}

.file-info-item::before {
  content: '📄';
  font-size: 1rem;
  flex-shrink: 0;
}

.file-info-name {
  font-weight: 600;
  color: var(--color-text);
  word-break: break-all;
}

.file-info-meta {
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.file-info-badge {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.badge-ok {
  color: var(--color-success-text);
  background: var(--color-success-bg);
  border: 1px solid transparent;
}

.badge-err {
  color: var(--color-danger-text);
  background: var(--color-danger-bg);
  border: 1px solid transparent;
}


/* ============================================
   Format Radio Buttons
   ============================================ */
#format-select-container {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 1.5rem 0;
}

.input-radio {
  display: none;
}

.input-radio + label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 100px;
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.input-radio + label:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.input-radio:checked + label {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}


/* ============================================
   Convert Button
   ============================================ */
#convert-button-container {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0;
}

#convert-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 2.5rem;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-sans);
  color: #ffffff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
  position: relative;
  overflow: hidden;
}

#convert-button::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  pointer-events: none;
}

#convert-button:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}

#convert-button:active:not(:disabled) {
  transform: translateY(0);
}

#convert-button:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
  box-shadow: none;
}


/* ============================================
   Spinner
   ============================================ */
#spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem;
  margin: 1rem 0;
}

#spinner.spinner-off {
  display: none;
}

#spinner > div:first-child {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-primary);
}

#spinner > div:last-child {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  text-align: center;
}

#spinner-icon rect {
  fill: var(--color-spinner);
}


/* ============================================
   Convert Results
   ============================================ */
#convert-result-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

#convert-result-container > a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--color-primary-bg);
  color: var(--color-primary);
  border: 1px solid var(--color-primary-light);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.2s ease;
}

#convert-result-container > a:hover {
  background: var(--color-primary-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

#convert-result-container > a::before {
  content: '⬇';
  font-size: 1.1rem;
}

/* Convert summary card */
.convert-summary {
  padding: 1rem 1.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.convert-summary > div {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.convert-summary > div:first-child {
  font-size: 1rem;
  color: var(--color-text);
  font-weight: 600;
}


#download-all-container {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

#download-all-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font-sans);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}

#download-all-button:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

#download-all-button.download-all-off {
  display: none;
}

/* ============================================
   Error Message
   ============================================ */
#error-message-container {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-md);
  color: var(--color-danger-text);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}

#error-message-container.error-message-off {
  display: none;
}


/* ============================================
   Footer
   ============================================ */
footer.container {
  padding: 2rem 1rem;
  max-width: var(--max-width);
  margin: 0 auto;
  text-align: center;
  border-top: 1px solid var(--color-border);
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.footer-links a {
  color: var(--color-text-secondary);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.footer-links .separator {
  color: var(--color-text-muted);
}

.footer-copyright {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.footer-blog {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-blog:hover {
  color: var(--color-primary-hover);
  text-decoration: none;
}

#version {
  color: var(--color-text-muted);
}


/* ============================================
   Utility & Responsive
   ============================================ */
@media (max-width: 480px) {
  header {
    padding: 1rem 1rem 1.5rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  header .subtitle {
    font-size: 0.9rem;
  }

  .header-top-bar {
    margin-bottom: 0.5rem;
  }

  main.container {
    padding: 1.5rem 0.75rem;
  }

  #select-file-button {
    min-height: 140px;
    padding: 1.5rem;
  }

  .dropzone-icon {
    width: 36px;
    height: 36px;
  }

  .input-radio + label {
    min-width: 80px;
    padding: 0.5rem 0.9rem;
    font-size: 0.8rem;
  }

  #convert-button {
    width: 100%;
    padding: 0.8rem 1.5rem;
    justify-content: center;
  }

  .footer-links {
    flex-direction: column;
    gap: 0.4rem;
  }

  .footer-links .separator {
    display: none;
  }

  .file-info-item {
    font-size: 0.8rem;
    padding: 0.5rem 0.75rem;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  header {
    padding: 1.25rem 1.5rem 2rem;
  }
}
