:root {
  --bg: #f5f1e8;
  --panel: #fffdf9;
  --ink: #1b1b18;
  --muted: #696451;
  --accent: #1f6f5f;
  --accent-soft: #d9efe9;
  --line: #d8cfbf;
  --danger: #9f3a2d;
  --shadow: 0 18px 45px rgba(42, 32, 12, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(31, 111, 95, 0.12), transparent 28%),
    linear-gradient(180deg, #f8f4ec, #eee5d6);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 18px 48px;
}

main.wide {
  max-width: 1600px;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

nav a {
  text-decoration: none;
  color: var(--ink);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
}

.hero,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px;
  margin-bottom: 18px;
}

.hero h1,
.panel h2,
.panel h3 {
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  margin-top: 0;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.panel {
  padding: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

textarea,
input,
select,
button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
}

textarea {
  min-height: 180px;
  resize: vertical;
}

button {
  cursor: pointer;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

button.secondary {
  background: var(--accent-soft);
  color: var(--ink);
}

button.danger {
  background: var(--danger);
}

button.compact {
  width: auto;
  padding: 5px 9px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.2;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.alert {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  font-weight: 700;
}

.alert.hidden {
  display: none;
}

.alert.info {
  background: #eef4f1;
  border-color: #bfd8cf;
  color: var(--accent);
}

.alert.success {
  background: #e7f5eb;
  border-color: #afd4ba;
  color: #226234;
}

.alert.error {
  background: #f8e9e5;
  border-color: #deb2a8;
  color: var(--danger);
}

.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.inline > * {
  flex: 1 1 220px;
}

.list {
  display: grid;
  gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: white;
}

.card h3 {
  margin-bottom: 8px;
}

.candidate-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.candidate-list h4 {
  margin: 0;
}

.candidate-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: #fbf7ee;
}

.candidate-card h4 {
  margin: 8px 0 4px;
}

.candidate-card .inline > button.compact {
  flex: 0 0 auto;
  align-self: flex-start;
}

.sense-fields {
  display: grid;
  grid-template-columns: minmax(110px, 160px) 1fr;
  gap: 8px 12px;
  margin: 12px 0 0;
}

.sense-fields dt {
  color: var(--muted);
  font-weight: 700;
}

.sense-fields dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.code {
  font-family: "SFMono-Regular", "Consolas", monospace;
  white-space: pre-wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.result-ok {
  border-left: 6px solid var(--accent);
}

.result-bad {
  border-left: 6px solid var(--danger);
}

#graph-canvas {
  width: 100%;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(243,236,222,0.9));
}

#full-graph-canvas {
  width: 100%;
  min-height: 78vh;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(rgba(31, 111, 95, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 111, 95, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(243,236,222,0.9));
  background-size: 28px 28px, 28px 28px, auto;
}

.graph-toolbar {
  margin: 14px 0 8px;
}

.graph-toolbar > button.compact {
  flex: 0 0 auto;
}

@media (max-width: 700px) {
  .hero,
  .panel {
    padding: 18px;
    border-radius: 18px;
  }
}

.portal-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 460px);
}

.portal-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.portal-topbar-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--accent);
  color: white;
  text-decoration: none;
  font-weight: 700;
}

.danger-link {
  background: var(--danger);
  color: white;
}

.stats-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-bottom: 18px;
}

.stat-panel h2 {
  margin-bottom: 12px;
}

.key-value-list {
  margin: 0;
  display: grid;
  gap: 10px;
}

.key-value-list > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.key-value-list dt {
  color: var(--muted);
  font-weight: 700;
}

.key-value-list dd {
  margin: 0;
  font-weight: 700;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 13px;
}

.candidate-header > button.compact {
  flex: 0 0 auto;
}

.action-row > button {
  flex: 1 1 240px;
}
