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

:root {
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --warn-bg: #fffbeb;
  --warn-border: #fbbf24;
  --busy-bg: #fef2f2;
  --busy-border: #fca5a5;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Layout */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.logo { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px; }
.logo span { color: var(--accent); }

.lang-switch {
  display: flex;
  gap: 0.25rem;
  font-size: 0.875rem;
}
.lang-btn {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  background: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.875rem;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

main { max-width: 640px; margin: 2rem auto; padding: 0 1rem 4rem; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }

/* Dropzone */
#dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--muted);
  margin-bottom: 1.25rem;
  user-select: none;
}
#dropzone:hover, #dropzone.drag-over { border-color: var(--accent); background: #eff6ff; }
#dropzone.disabled { opacity: 0.5; cursor: not-allowed; }
#dropzone.has-file { border-color: var(--accent); color: var(--text); }
#file-input { display: none; }
.dropzone-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.dropzone-hint { font-size: 0.8rem; margin-top: 0.25rem; }
#selected-file { font-weight: 600; color: var(--text); margin-top: 0.5rem; font-size: 0.9rem; }

#upload-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  width: 100%;
}
#upload-progress[hidden] { display: none; }
.upload-bar-wrap {
  flex: 1;
  background: var(--border);
  border-radius: 99px;
  height: 4px;
  overflow: hidden;
}
.upload-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.2s ease;
  width: 0%;
}
.upload-pct { font-size: 0.75rem; color: var(--muted); min-width: 2.5rem; text-align: right; }

/* Options */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 480px) { .options-grid { grid-template-columns: 1fr; } }

.option-group label.group-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.radio-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.radio-group input[type=radio] { display: none; }
.radio-group label {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.1s;
  min-height: 36px; display: flex; align-items: center;
}
.radio-group input[type=radio]:checked + label {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Mode toggle */
.mode-toggle { display: flex; gap: 0.5rem; }
.mode-toggle button {
  flex: 1; padding: 0.4rem 0.5rem; border: 1px solid var(--border);
  background: none; border-radius: 6px; cursor: pointer; font-size: 0.875rem;
  transition: all 0.1s; min-height: 36px;
}
.mode-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Sub-options */
.sub-options { margin-top: 0.75rem; }
.sub-options[hidden] { display: none; }

/* Letterbox */
.letterbox-row { margin-top: 0.75rem; }

/* Warnings */
.warn-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
.warn-banner[hidden] { display: none; }

/* Busy banner */
#busy-banner {
  background: var(--busy-bg);
  border: 1px solid var(--busy-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
}
#busy-banner[hidden] { display: none; }

/* Convert button */
#convert-btn {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 44px;
}
#convert-btn:hover:not(:disabled) { background: var(--accent-hover); }
#convert-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Progress */
#progress-section[hidden] { display: none; }

.progress-label {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.progress-bar-wrap {
  background: var(--border);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
  width: 0%;
}
.progress-eta { font-size: 0.8rem; color: var(--muted); }

/* Truncated banner */
#truncated-banner[hidden] { display: none; }
#truncated-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

/* Result section */
#result-section[hidden] { display: none; }
#result-section { display: flex; flex-direction: column; gap: 0.75rem; }

.result-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.btn-primary {
  flex: 1;
  padding: 0.75rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  flex: 1;
  padding: 0.75rem 1.25rem;
  background: none;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.15s;
}
.btn-secondary:hover { background: #eff6ff; }

.btn-cancel {
  margin-top: 1rem;
  padding: 0.6rem 1.25rem;
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-cancel:hover { background: #fef2f2; }

/* Error */
#error-section[hidden] { display: none; }
.error-box {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 1rem;
}
.error-box p { color: var(--danger); margin-bottom: 0.75rem; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
.modal-actions button { flex: 1; padding: 0.6rem; border-radius: 8px; cursor: pointer; font-size: 0.95rem; min-height: 44px; }
#modal-yes { background: var(--danger); color: #fff; border: none; }
#modal-no { background: none; border: 1px solid var(--border); color: var(--text); }

/* Toast */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}
.toast {
  background: #1e293b;
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  animation: fadeInUp 0.2s ease;
  max-width: 280px;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Share page */
#share-valid[hidden] { display: none; }
#share-expired[hidden] { display: none; }
#share-loading[hidden] { display: none; }

.share-meta { margin-bottom: 1.5rem; }
.share-meta table { width: 100%; border-collapse: collapse; }
.share-meta td { padding: 0.4rem 0; font-size: 0.95rem; }
.share-meta td:first-child { color: var(--muted); width: 40%; }

.countdown {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  margin-bottom: 1.5rem;
}
.countdown-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }

.expired-block { text-align: center; padding: 1rem 0; }
.expired-block .expired-cs { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; }
.expired-block .expired-en { font-size: 1rem; color: var(--muted); margin-bottom: 0.5rem; }
.expired-block .expired-sub-cs, .expired-block .expired-sub-en { font-size: 0.9rem; color: var(--muted); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 1.25rem; height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
