*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #0c0e14;
  --bg-elevated: #12151d;
  --surface: #181c26;
  --surface-hover: #1f2430;
  --border: #2a3040;
  --border-focus: #4d6aff;
  --text: #f0f2f7;
  --text-secondary: #a8b0c2;
  --text-muted: #6b7385;
  --accent: #4d6aff;
  --accent-hover: #3d58e0;
  --accent-soft: rgba(77, 106, 255, 0.12);
  --danger: #f06565;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

html {
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(77, 106, 255, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(77, 106, 255, 0.06), transparent);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.25rem 2.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.site-header {
  margin-bottom: 1.75rem;
}

.auth-field {
  margin-top: 1rem;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.auth-field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.auth-input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
}

.auth-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-hint {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--danger);
}

.dropzone--locked {
  opacity: 0.55;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid rgba(77, 106, 255, 0.25);
  display: grid;
  place-items: center;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 26px;
  height: 26px;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.2rem;
}

/* Mode tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.3rem;
  margin-bottom: 1rem;
  padding: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.6rem 0.3rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  line-height: 1.2;
  text-align: center;
}

.mode-tab svg {
  width: 20px;
  height: 20px;
}

.mode-tab:hover:not(:disabled):not(.active) {
  color: var(--text-secondary);
  background: var(--surface-hover);
}

.mode-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(77, 106, 255, 0.35);
}

.mode-tab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Layout */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Dropzone */
.dropzone {
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--border-focus);
  background: var(--surface-hover);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dropzone-inner {
  padding: 2.25rem 1.5rem;
  text-align: center;
}

.drop-icon-wrap {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--accent);
}

.drop-icon {
  width: 28px;
  height: 28px;
}

.drop-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.drop-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 0.35rem;
  margin-bottom: 1rem;
}

/* Settings panels */
.settings-panel {
  padding: 1.15rem 1.25rem;
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.field-value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.field-note {
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.45;
  margin-top: 0.15rem;
}

select {
  appearance: none;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 2rem 0.6rem 0.8rem;
  font-size: 0.9rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7385' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

select:focus,
input[type="range"]:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 1px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Option card (background removal) */
.option-card {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin-top: 0.15rem;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-copy {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.checkbox-copy strong {
  font-size: 0.9rem;
  font-weight: 500;
}

.checkbox-copy small {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.nested-options {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

/* File queue */
.file-queue {
  padding: 1rem 1.25rem;
}

.queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.reorder-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: -0.35rem 0 0.75rem;
}

.queue-header .panel-title {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 240px;
  overflow-y: auto;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
}

.file-item-sortable {
  cursor: grab;
}

.file-item-sortable.dragging {
  opacity: 0.55;
  cursor: grabbing;
}

.file-item-sortable.drag-over {
  border-color: var(--border-focus);
  background: var(--accent-soft);
}

.drag-handle {
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: -0.12em;
  user-select: none;
  flex-shrink: 0;
  line-height: 1;
}

.file-order {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.file-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin-left: auto;
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1;
  font-family: inherit;
}

.btn-icon:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-hover);
}

.btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.file-item img,
.file-thumb {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  flex-shrink: 0;
}

.file-item img {
  object-fit: cover;
}

.file-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.file-size {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.file-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  line-height: 1;
  font-size: 1.15rem;
  transition: color 0.15s, background 0.15s;
}

.file-remove:hover {
  color: var(--danger);
  background: rgba(240, 101, 101, 0.1);
}

/* Convert bar */
.convert-bar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.progress-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 35%;
  background: var(--accent);
  border-radius: 999px;
}

.progress-panel.is-active .progress-fill {
  animation: progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.progress-text {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(77, 106, 255, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px rgba(77, 106, 255, 0.4);
}

.btn-convert {
  width: 100%;
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(77, 106, 255, 0.35);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn-ghost:hover {
  background: var(--accent-soft);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-family: inherit;
}

.btn-text:hover {
  color: var(--danger);
  background: rgba(240, 101, 101, 0.08);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Footer */
.site-footer {
  margin-top: 2rem;
  text-align: center;
}

.site-footer p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  z-index: 100;
  max-width: min(90vw, 400px);
}

.toast.error {
  border-color: rgba(240, 101, 101, 0.5);
  color: var(--danger);
}

/* Responsive */
@media (max-width: 640px) {
  .mode-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .mode-tab {
    font-size: 0.68rem;
    padding: 0.55rem 0.2rem;
  }
}

@media (max-width: 520px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .mode-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .mode-tab svg {
    width: 18px;
    height: 18px;
  }
}

@media (min-width: 640px) {
  .app {
    padding-top: 3rem;
  }
}
