:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1a1f36;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-soft: #eef2ff;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

.topbar {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: white;
  padding: 36px 0 28px;
  margin-bottom: 32px;
}
.topbar h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
}
.topbar .muted {
  color: rgba(255,255,255,0.7);
  font-weight: 400;
}
.topbar .subtitle {
  margin: 8px 0 0;
  color: rgba(255,255,255,0.85);
  font-size: 15px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 600;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.card.hidden { display: none; }

.hint {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 16px;
}

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

button {
  font-family: inherit;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
button:active { transform: translateY(1px); }

button.primary {
  background: var(--accent);
  color: white;
}
button.primary:hover { background: var(--accent-dark); }
button.primary.big {
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 500;
}

button.secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: #f9fafb; }

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border);
  padding: 7px 14px;
}
button.ghost:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

button.icon {
  background: transparent;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 14px;
}
button.icon:hover { color: var(--bad); }

.field {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.field span {
  min-width: 100px;
  color: var(--muted);
  font-size: 14px;
}

input[type="text"] {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 1;
  outline: none;
  transition: border 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-top: 16px;
}
@media (max-width: 700px) {
  .two-col { grid-template-columns: 1fr; }
}

.entity-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.entity-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.entity-list input {
  flex: 1;
}

.matrix-wrap {
  overflow-x: auto;
}

table.pairwise-matrix {
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 13px;
}
table.pairwise-matrix th,
table.pairwise-matrix td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
  min-width: 90px;
}
table.pairwise-matrix th {
  background: #fafbfc;
  font-weight: 600;
  font-size: 12px;
}
table.pairwise-matrix td.diagonal {
  background: #f3f4f6;
  color: var(--muted);
  font-weight: 600;
}
table.pairwise-matrix td.mirror {
  background: #fafbfc;
  color: var(--muted);
  font-style: italic;
}
table.pairwise-matrix select {
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  background: white;
  width: 100%;
  cursor: pointer;
}
table.pairwise-matrix select:hover { border-color: var(--accent); }
table.pairwise-matrix select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.alt-matrix-block {
  margin-bottom: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.alt-matrix-block:first-child {
  border-top: none;
  padding-top: 0;
}
.alt-matrix-block h3 {
  color: var(--accent);
  font-size: 14px;
  margin-bottom: 8px;
}

.compute-bar {
  text-align: center;
  margin: 32px 0;
}

/* Results */
.result-banner {
  padding: 16px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-weight: 500;
}
.result-banner.success {
  background: var(--good-soft);
  color: #14532d;
  border: 1px solid #86efac;
}
.result-banner.error {
  background: var(--bad-soft);
  color: #7f1d1d;
  border: 1px solid #fca5a5;
}

.ranking {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
}
.ranking li {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.ranking li.first {
  background: linear-gradient(90deg, #fef3c7 0%, #fffbeb 100%);
  border-color: #fcd34d;
}
.ranking .rank {
  font-weight: 700;
  font-size: 18px;
  color: var(--muted);
  min-width: 32px;
}
.ranking .first .rank { color: #b45309; }
.ranking .name {
  font-weight: 500;
  flex: 1;
}
.ranking .bar {
  flex: 2;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.ranking .bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}
.ranking .first .bar-fill { background: linear-gradient(90deg, #f59e0b, #d97706); }
.ranking .score {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  min-width: 60px;
  text-align: right;
}

.consistency-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 16px 0;
}
.consistency-table th,
.consistency-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.consistency-table th {
  background: #fafbfc;
  font-weight: 600;
}
.consistency-table .ok { color: var(--good); font-weight: 600; }
.consistency-table .ko { color: var(--bad); font-weight: 600; }

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 12px 0;
}
.detail-table th,
.detail-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: right;
}
.detail-table th:first-child,
.detail-table td:first-child {
  text-align: left;
}
.detail-table th {
  background: #fafbfc;
  font-weight: 600;
}
.detail-table tr.total {
  background: #f9fafb;
  font-weight: 600;
}

.inconsistency-card {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 16px 20px;
  margin: 16px 0;
}
.inconsistency-card strong { color: #92400e; }

details summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--accent);
  margin: 12px 0 8px;
}

.footnote {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 0 48px;
}

/* ========== Saaty legend ========== */

.saaty-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  background: var(--accent-soft);
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  padding: 12px 16px;
  margin: 4px 0 18px;
  font-size: 13px;
}
.saaty-legend strong {
  color: var(--accent-dark);
  font-weight: 600;
  margin-right: 4px;
}
.saaty-legend .item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}
.saaty-legend .item b {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: white;
  border: 1px solid #c7d2fe;
  border-radius: 4px;
  padding: 1px 7px;
  font-weight: 700;
  color: var(--accent-dark);
  font-size: 12px;
}
.saaty-legend .note {
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
  flex-basis: auto;
}

/* ========== Winner card ========== */

.winner-card {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid #fcd34d;
  border-radius: 14px;
  padding: 22px 28px;
  margin-bottom: 22px;
  box-shadow: 0 4px 20px rgba(251, 191, 36, 0.18);
  animation: fadeUp 0.5s ease-out;
}
.winner-card .winner-label {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #92400e;
  font-weight: 700;
}
.winner-card .winner-name {
  font-size: 30px;
  font-weight: 700;
  color: #78350f;
  margin: 0;
  line-height: 1.1;
}
.winner-card .winner-meta {
  margin: 10px 0 0;
  font-size: 14px;
  color: #92400e;
}
.winner-card .winner-meta strong {
  font-variant-numeric: tabular-nums;
  color: #78350f;
}

/* ========== Animations ========== */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes growBar {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.ranking li {
  animation: fadeUp 0.4s ease-out backwards;
}
.ranking li:nth-child(1) { animation-delay: 0.10s; }
.ranking li:nth-child(2) { animation-delay: 0.18s; }
.ranking li:nth-child(3) { animation-delay: 0.26s; }
.ranking li:nth-child(4) { animation-delay: 0.34s; }
.ranking li:nth-child(5) { animation-delay: 0.42s; }
.ranking li:nth-child(6) { animation-delay: 0.50s; }

.ranking .bar-fill {
  transform-origin: left;
  animation: growBar 0.7s 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.result-banner {
  animation: fadeUp 0.4s ease-out;
}

button.primary,
button.secondary,
button.ghost {
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s, box-shadow 0.15s;
}
button.primary:hover {
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}
button.primary.big:hover {
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.3);
}

.card {
  transition: box-shadow 0.2s;
}

table.pairwise-matrix select {
  transition: border-color 0.15s, background 0.15s;
}
table.pairwise-matrix td:has(select):hover {
  background: var(--accent-soft);
}

/* ========== Table wrap (for overflow on small screens) ========== */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 12px 0;
}

/* ========== Responsive ========== */

@media (max-width: 768px) {
  .container { padding: 0 20px; }
  .topbar { padding: 28px 0 22px; margin-bottom: 24px; }
  .topbar h1 { font-size: 24px; }
  .topbar .subtitle { font-size: 14px; }
  .card { padding: 20px 22px; }
  .card h2 { font-size: 17px; }
  .winner-card .winner-name { font-size: 26px; }
  .saaty-legend .note { margin-left: 0; flex-basis: 100%; }
  .compute-bar { margin: 24px 0; }
}

@media (max-width: 480px) {
  .container { padding: 0 14px; }

  .topbar { padding: 22px 0 18px; margin-bottom: 18px; }
  .topbar h1 { font-size: 20px; line-height: 1.25; }
  .topbar h1 .muted { display: block; font-size: 13px; margin-top: 2px; font-weight: 400; }
  .topbar .subtitle { font-size: 13px; margin-top: 6px; }

  .card { padding: 16px 18px; margin-bottom: 16px; border-radius: 10px; }
  .card h2 { font-size: 16px; margin-bottom: 10px; }
  .card h3 { font-size: 13px; }

  .field { flex-direction: column; align-items: stretch; gap: 6px; margin-bottom: 14px; }
  .field span { min-width: 0; }

  .actions { flex-direction: column; }
  .actions button { width: 100%; }

  button.primary.big { padding: 13px 20px; font-size: 15px; width: 100%; }

  .two-col { gap: 24px; }

  table.pairwise-matrix { font-size: 11px; }
  table.pairwise-matrix th,
  table.pairwise-matrix td {
    min-width: 64px;
    padding: 4px 5px;
  }
  table.pairwise-matrix select {
    font-size: 11px;
    padding: 3px 4px;
  }

  table.consistency-table,
  table.detail-table { font-size: 12px; }
  table.consistency-table th,
  table.consistency-table td,
  table.detail-table th,
  table.detail-table td { padding: 6px 8px; }

  .ranking li {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 6px 10px;
  }
  .ranking .name { flex: 1 1 auto; }
  .ranking .score { min-width: auto; text-align: right; }
  .ranking .bar { flex: 1 1 100%; order: 5; height: 6px; }

  .winner-card { padding: 18px 20px; border-radius: 12px; }
  .winner-card .winner-name { font-size: 22px; }
  .winner-card .winner-meta { font-size: 13px; }

  .saaty-legend {
    font-size: 12px;
    padding: 10px 12px;
    gap: 6px 10px;
  }
  .saaty-legend strong { flex-basis: 100%; margin-bottom: 4px; }

  .alt-matrix-block h3 { font-size: 13px; }

  .inconsistency-card { padding: 14px 16px; font-size: 13px; }
}
