:root {
  --bg: #f6f3ee;
  --bg-accent: #e8e2d8;
  --ink: #1c2430;
  --muted: #5c6672;
  --card: #fffcf8;
  --line: #d5cdc0;
  --accent: #0f6b5c;
  --accent-ink: #ffffff;
  --danger: #8b2e2e;
  --warn: #7a5a12;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --radius: 14px;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dff1ec 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #f0e6d4 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
}

.container { width: min(1120px, calc(100% - 2rem)); margin: 0 auto; }

.site-header {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 248, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0;
}
.brand {
  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.tagline { color: var(--muted); font-size: 0.85rem; }

.site-footer {
  margin-top: 3rem;
  padding: 1.5rem 0 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

.hero { padding: 2.5rem 0 1.25rem; text-align: center; }
.hero h1 {
  font-family: var(--font);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: 0.04em;
  margin: 0 0 0.75rem;
}
.lead { color: var(--muted); max-width: 40rem; margin: 0 auto; line-height: 1.5; }

.upload-card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.drop-zone {
  border: 2px dashed #b9c4bf;
  border-radius: calc(var(--radius) - 4px);
  background: linear-gradient(180deg, #f8faf8, #f3efe8);
  padding: 2.5rem 1rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: #e7f4f0;
}
.drop-title { font-family: var(--font); font-size: 1.35rem; margin: 0; }
.drop-or { color: var(--muted); margin: 0.75rem 0; }
.selected-file { margin: 1rem 0 0; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); width: 100%; margin-top: 1rem; }
.btn-secondary { background: #eef2f0; color: var(--ink); border-color: var(--line); }
.btn-small { padding: 0.35rem 0.8rem; font-size: 0.8rem; border-radius: 8px; }
.btn-small.active { background: var(--accent); color: white; }

.debug-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  margin: 1rem 0;
}
.alert-error { background: #f8e8e8; color: var(--danger); border: 1px solid #e2bcbc; }
.alert-warn { background: #fff6df; color: var(--warn); border: 1px solid #e8d59a; }

.result-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.75rem 0 1rem;
  flex-wrap: wrap;
}
.result-header h1 { font-family: var(--font); margin: 0 0 0.4rem; font-size: 1.7rem; }
.meta-line { display: flex; flex-wrap: wrap; gap: 0.75rem; color: var(--muted); font-size: 0.9rem; margin: 0; }
.meta-line span::before { content: "·"; margin-right: 0.75rem; color: #b0a89c; }
.meta-line span:first-child::before { content: none; margin: 0; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .result-grid { grid-template-columns: 1fr; }
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.panel-head h2 { margin: 0; font-family: var(--font); font-size: 1.15rem; }
.json-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; align-items: center; }
.copy-status { color: var(--accent); font-weight: 600; font-size: 0.9rem; }

.structure-tree, .json-tree {
  font-size: 0.92rem;
  line-height: 1.45;
  max-height: 70vh;
  overflow: auto;
  padding-right: 0.25rem;
}
.json-raw {
  margin: 0;
  max-height: 70vh;
  overflow: auto;
  background: #1c2430;
  color: #e8eef2;
  padding: 1rem;
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
}

.tree-node { margin: 0.15rem 0 0.15rem 0.1rem; }
.tree-toggle {
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: var(--muted);
  padding: 0 0.25rem 0 0;
}
.tree-key { font-weight: 700; color: var(--ink); }
.tree-value {
  color: var(--muted);
  margin-left: 1.25rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.tree-children { margin-left: 1rem; border-left: 1px solid var(--line); padding-left: 0.75rem; }
.tree-children.collapsed { display: none; }

.kv-row {
  display: grid;
  grid-template-columns: minmax(8rem, 34%) 1fr;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid #efe8dc;
}
.kv-row .k { font-weight: 700; }
.kv-row .v { color: var(--muted); white-space: pre-wrap; word-break: break-word; }

details.section {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  margin: 0.4rem 0;
  background: #fffcf8;
}
details.section > summary {
  cursor: pointer;
  font-weight: 700;
  font-family: var(--font);
}

.result-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 1rem; }
.tab-panel { margin-bottom: 1rem; }
.muted { color: var(--muted); }
.table-card { margin: 0.75rem 0 1.25rem; }
.table-card h3 { margin: 0 0 0.35rem; font-family: var(--font); }
.table-scroll { overflow: auto; max-height: 420px; border: 1px solid var(--line); border-radius: 8px; }
.table-scroll table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
.table-scroll th, .table-scroll td { border-bottom: 1px solid var(--line); padding: 0.4rem 0.5rem; text-align: left; vertical-align: top; }
.table-scroll th { background: #f3efe8; position: sticky; top: 0; }
.para-list { padding-left: 1.2rem; color: var(--muted); line-height: 1.5; }
.para-list li { margin: 0.55rem 0; }
.layout-fig { margin: 1rem 0; }
.layout-fig img { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: white; }
.legend { display: flex; flex-wrap: wrap; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.swatch { display: inline-block; width: 0.75rem; height: 0.75rem; border-radius: 2px; margin-right: 0.25rem; }
.swatch.line { background: #3474d9; }
.swatch.block { background: #8c59d9; }
.swatch.table { background: #d94033; }
.swatch.heading { background: #e67319; }
.swatch.header { background: #bf268c; }
.swatch.footer { background: #7326bf; }

.debug-panel { margin-top: 1rem; }
.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
.debug-panel h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.debug-panel ul { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.85rem; }
.debug-pre {
  background: #1c2430;
  color: #dce5eb;
  padding: 1rem;
  border-radius: 8px;
  overflow: auto;
  max-height: 280px;
  font-family: var(--mono);
  font-size: 0.75rem;
}
