:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --violet: #a78bfa;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

header {
  margin-bottom: 1.5rem;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 650;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.hint code {
  background: var(--surface2);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------------ upload */

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.upload-area.dragover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.upload-area input {
  display: none;
}

.upload-area label {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
}

.upload-icon {
  font-size: 2rem;
  color: var(--accent);
}

#upload-section.collapsed .upload-area,
#upload-section.collapsed .hint {
  display: none;
}

#upload-section.collapsed {
  padding: 0.75rem 1.5rem;
}

#upload-section.collapsed h2 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

.error {
  margin: 0.75rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

/* --------------------------------------------------------------- statusbar */

.statusbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  padding: 0.9rem 1.5rem;
}

.status-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.status-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.status-value {
  font-family: var(--mono);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.status-value.ok {
  color: var(--success);
}

.status-value.bad {
  color: var(--danger);
}

.status-value.changed {
  color: var(--warning);
}

.alerts:empty {
  display: none;
}

.alert {
  margin: 0 0 0.75rem;
  padding: 0.7rem 0.95rem;
  border: 1px solid rgba(239, 68, 68, 0.42);
  background: rgba(239, 68, 68, 0.09);
  border-radius: 8px;
  font-size: 0.88rem;
}

/* ------------------------------------------------------------------ groups */

.group {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  background: rgba(0, 0, 0, 0.12);
}

.group > summary {
  cursor: pointer;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  list-style-position: inside;
}

.group-count {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface2);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-weight: 500;
}

.group-desc {
  margin: 0 1rem 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ------------------------------------------------------------------ fields */

.field {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
  transition: background 0.4s;
}

.field.flash {
  background: rgba(59, 130, 246, 0.18);
}

.field-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.field-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.field-offset {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.42rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  cursor: help;
}

.badge-safe {
  color: var(--success);
}

.badge-risky {
  color: var(--warning);
}

.badge-expert {
  color: var(--violet);
}

.badge-read-only {
  color: var(--muted);
}

.conf-confirmed {
  color: var(--success);
  border-style: dashed;
}

.conf-likely {
  color: var(--accent);
  border-style: dashed;
}

.conf-unverified {
  color: var(--danger);
  border-style: dashed;
}

.field-desc {
  margin: 0 0 0.4rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.field-warning {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  color: var(--warning);
}

.field-control {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.field-control select,
.field-control input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.92rem;
  font-family: var(--mono);
}

.field-control input:focus,
.field-control select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.access-expert .field-control input,
.access-expert .field-control select {
  border-color: rgba(167, 139, 250, 0.5);
}

.readonly-value {
  flex: 1 1 auto;
  font-family: var(--mono);
  font-size: 0.92rem;
  padding: 0.45rem 0.7rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.unit {
  color: var(--muted);
  font-size: 0.85rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.2rem;
  font-family: inherit;
}

.link-btn:hover {
  color: var(--text);
}

.field-meta {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin: 0.35rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
  font-family: var(--mono);
}

/* ------------------------------------------------------------------- diff */

.diff {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.diff th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.diff td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid rgba(45, 63, 86, 0.5);
}

.mono {
  font-family: var(--mono);
}

.diff td.changed {
  color: var(--warning);
  font-weight: 600;
}

.muted-note {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0 0 1rem;
}

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

.btn {
  padding: 0.6rem 1.15rem;
  border: none;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  background: var(--border);
}

/* ----------------------------------------------------------------- compare */

.compare-input {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.compare-input input[type="file"] {
  flex: 1 1 16rem;
  min-width: 0;
  padding: 0.45rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-family: inherit;
}

h3.sub {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

/* ---------------------------------------------------------------- hex view */

.hexwrap {
  overflow: auto;
  max-height: 26rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.hex {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.5;
  padding: 0.6rem 0.8rem;
  width: max-content;
  min-width: 100%;
}

.hex-row {
  display: flex;
  gap: 0.9rem;
  white-space: nowrap;
}

.hex-addr {
  color: var(--muted);
  user-select: none;
}

.hex-byte {
  padding: 0 0.12rem;
  border-radius: 2px;
  color: #6b7f99;
}

.hex-bytes .hex-byte:nth-child(8n) {
  margin-right: 0.45rem;
}

.hb-safe {
  color: var(--success);
  background: rgba(34, 197, 94, 0.12);
}

.hb-risky {
  color: var(--warning);
  background: rgba(245, 158, 11, 0.12);
}

.hb-expert {
  color: var(--violet);
  background: rgba(167, 139, 250, 0.13);
}

.hb-read-only {
  color: #9fb2c9;
  background: rgba(159, 178, 201, 0.12);
}

.hb-changed {
  outline: 1px solid var(--warning);
  color: #fff;
  background: rgba(245, 158, 11, 0.4);
}

.hex-byte:hover {
  outline: 1px solid var(--accent);
  cursor: pointer;
}

.hex-ascii {
  color: #5d708a;
  user-select: none;
}

.hex-inspect {
  margin: 0.6rem 0 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
}

#hex-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
}

.swatch::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  display: inline-block;
}

.sw-safe::before {
  background: rgba(34, 197, 94, 0.5);
}

.sw-risky::before {
  background: rgba(245, 158, 11, 0.5);
}

.sw-expert::before {
  background: rgba(167, 139, 250, 0.5);
}

.sw-readonly::before {
  background: rgba(159, 178, 201, 0.4);
}

.sw-changed::before {
  background: rgba(245, 158, 11, 0.9);
}

/* ---------------------------------------------------------------- warnings */

.warning {
  font-size: 0.85rem;
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.38);
  padding: 0.7rem 0.95rem;
  background: rgba(245, 158, 11, 0.08);
  border-radius: 8px;
  margin: 0;
}

@media (max-width: 640px) {
  .statusbar {
    gap: 1rem;
  }

  .field-offset {
    margin-left: 0;
  }
}

/* ---------------------------------------------------------------- insights */

.insight {
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(45, 63, 86, 0.6);
}

.insight:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.insight-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.2rem;
}

.insight-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.insight-value {
  font-family: var(--mono);
  font-size: 1.15rem;
  color: var(--text);
  overflow-wrap: anywhere;
}

.insight-detail {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 68ch;
}
