:root {
  --bg: #fafafa;
  --bg-secondary: #f4f4f5;
  --bg-tertiary: #e4e4e7;
  --border: #d4d4d8;
  --text: #18181b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-subtle: #eff6ff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --tag-bg: #ecfdf5;
  --tag-fg: #047857;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --bg-secondary: #18181b;
    --bg-tertiary: #27272a;
    --border: #3f3f46;
    --text: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-subtle: #1e3a5f;
    --danger: #f87171;
    --danger-bg: #3f1f1f;
    --tag-bg: #052e2b;
    --tag-fg: #6ee7b7;
  }
}

[hidden] {
  display: none !important;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: 1rem;
  line-height: 1.5;
}

.container {
  width: 100%;
  max-width: 56rem;
  margin-inline: auto;
}

h1 {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;

  & code {
    font-family: var(--mono);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.85em;
  }
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;

  &:hover, &.drag-over {
    border-color: var(--accent);
    background: var(--accent-subtle);
  }
}

.upload-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;

  & p { color: var(--text-secondary); font-size: 0.9rem; }
  & strong { color: var(--text); }
}

.upload-icon {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.file-label {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  pointer-events: all;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Tool panel */
.tool-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.preview {
  width: 4rem;
  height: 4rem;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

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

.file-name {
  font-weight: 600;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.error-box {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

/* Sections */
.sections {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;

  & h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  & .count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.05rem 0.5rem;
  }
}

.section-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  transform: rotate(0deg);

  & svg {
    width: 1rem;
    height: 1rem;
  }
}

.section[data-collapsed="true"] .section-toggle {
  transform: rotate(-90deg);
}

.section[data-collapsed="true"] .section-body {
  display: none;
}

.section-body {
  padding: 0.5rem 0;
}

.section-empty {
  padding: 0.875rem 1rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-style: italic;
}

/* Tag rows */
.kv-list {
  display: flex;
  flex-direction: column;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.15rem;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;

  &:nth-child(even) {
    background: color-mix(in srgb, var(--bg) 50%, transparent);
  }

  & .kv-key {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
  }

  & .kv-tag {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--tag-fg);
    background: var(--tag-bg);
    border-radius: 3px;
    padding: 0.05rem 0.35rem;
  }

  & .kv-value {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--text);
    word-break: break-word;
    white-space: pre-wrap;
  }

  & .kv-value.is-muted {
    color: var(--text-muted);
    font-style: italic;
  }
}

@media (min-width: 640px) {
  body { padding: 2rem; }

  .kv-row {
    grid-template-columns: 14rem minmax(0, 1fr);
    gap: 1rem;
    align-items: baseline;
  }
}

/* Raw blocks (XMP, hex dumps) */
.raw-block {
  padding: 0.5rem 1rem 0.75rem;
}

.raw-block pre {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  max-height: 24rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;

  &:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
  }

  &:active {
    transform: scale(0.97);
  }
}

.btn-sm {
  padding: 0.3rem 0.625rem;
  font-size: 0.78rem;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);

  &:hover {
    color: var(--text);
    background: var(--bg-tertiary);
    border-color: var(--border);
  }
}

/* GPS link */
.gps-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
}
