@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-soft: #121932;
  --panel: rgba(17, 24, 39, 0.86);
  --panel-strong: rgba(20, 28, 47, 0.96);
  --border: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.38);
  --text: #eef2ff;
  --text-muted: #9aa8ca;
  --accent: #ffb84d;
  --accent-strong: #ff9a1f;
  --primary: #5ab0ff;
  --primary-soft: rgba(90, 176, 255, 0.16);
  --success: #49d19f;
  --success-soft: rgba(73, 209, 159, 0.16);
  --danger: #ff6f7d;
  --danger-soft: rgba(255, 111, 125, 0.16);
  --cell-pareto: #72f0b8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --sticky-top: 20px;
  --font: "IBM Plex Sans", "Segoe UI", "Tahoma", sans-serif;
  --font-display: "Manrope", "IBM Plex Sans", sans-serif;
  --matrix-cols: 2;
  --matrix-rows: 2;
  --matrix-cell-height: 94px;
  --matrix-input-height: 38px;
  --matrix-font-size: 18px;
  --matrix-entry-gap: 8px;
  --matrix-cell-padding: 9px;
  --matrix-index-width: 76px;
  --chart-height: clamp(360px, 45vh, 580px);
  --ring: rgba(90, 176, 255, 0.22);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-soft: #e9eef8;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #f59e0b;
  --accent-strong: #d97706;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.10);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.10);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.10);
  --cell-pareto: #10b981;
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
  --ring: rgba(37, 99, 235, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 8% -4%, rgba(90, 176, 255, 0.18), transparent 34%),
    radial-gradient(circle at 95% -10%, rgba(255, 184, 77, 0.14), transparent 36%),
    radial-gradient(circle at 70% 80%, rgba(114, 240, 184, 0.1), transparent 28%),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  border: none;
}

strong {
  font-weight: 700;
}

.app-shell {
  max-width: 1760px;
  margin: 0 auto;
  padding: 24px;
}

.hero,
.panel,
.metric-card {
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, var(--panel-strong), var(--panel));
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero__text {
  max-width: 900px;
}

.hero__text h1 {
  margin: 8px 0 12px;
  font-size: clamp(28px, 3vw, 44px);
  line-height: 1.05;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

.hero__text p,
.panel__header p,
.status-box p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hero__side {
  min-width: 220px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.hero-status {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  text-align: center;
  font-weight: 600;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  transition: 0.2s ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--primary-soft);
  border-color: var(--primary);
  outline: none;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.metric-card {
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card__label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.metric-card__value {
  font-size: clamp(22px, 2vw, 30px);
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.column {
  min-width: 0;
  display: grid;
  gap: 18px;
}

.column--left {
  position: sticky;
  top: var(--sticky-top);
  max-height: calc(100vh - (var(--sticky-top) * 2));
  overflow-y: auto;
  padding-right: 6px;
  align-content: start;
}

.column--left .panel--sticky {
  position: static;
}

.column--left::-webkit-scrollbar {
  width: 8px;
}

.column--left::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.34);
  border-radius: 999px;
}

.column--main {
  grid-template-columns: minmax(0, 1.62fr) minmax(300px, 1fr);
  align-items: start;
}

.main-stack {
  min-width: 0;
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel--process .process-log {
  min-height: 130px;
  align-content: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(170deg, color-mix(in srgb, var(--panel-strong) 82%, transparent), var(--panel));
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel--sticky,
.panel--sticky-right {
  position: sticky;
  top: var(--sticky-top);
}

.panel--matrix {
  overflow: hidden;
  border-color: color-mix(in srgb, var(--primary) 22%, var(--border));
}

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

.panel__header h2,
.result-block h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

.panel__header--matrix {
  align-items: center;
}

.panel__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.chip {
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.field-grid,
.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.action-grid--stack {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 8px;
}

.field--full {
  grid-column: 1 / -1;
}

.field__label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}

.control {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
  transition: 0.2s ease;
}

.control:focus,
.control:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.control option {
  color: #0f172a;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  font-weight: 700;
  transition: 0.18s ease;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.18;
  min-width: 0;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.btn:disabled {
  opacity: 0.45;
  transform: none;
  cursor: not-allowed;
}

.btn--primary {
  background: linear-gradient(180deg, var(--primary), color-mix(in srgb, var(--primary) 78%, black));
  color: white;
}

.btn--secondary {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(90, 176, 255, 0.24);
}

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

.btn--large {
  grid-column: 1 / -1;
  min-height: 54px;
  font-size: 16px;
}

.btn--small {
  min-height: 40px;
  padding-inline: 12px;
  font-size: 13px;
}

#autoBtn {
  font-size: clamp(12px, 1vw, 14px);
}

.upload-btn {
  position: relative;
  overflow: hidden;
}

.status-box {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.status-box__label {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.legend {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.legend__mark {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 2px solid transparent;
  display: inline-block;
}

.legend__mark--p1 { background: rgba(90, 176, 255, 0.20); }
.legend__mark--p2 { background: rgba(73, 209, 159, 0.20); }
.legend__mark--nash { border-color: var(--accent); }
.legend__mark--pareto { border-color: var(--cell-pareto); }

.matrix-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.matrix-toolbar__title {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.matrix-toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.matrix-wrap {
  overflow: hidden;
  padding: 14px;
  margin: 0 -10px -10px;
  border-radius: 20px;
  background:
    radial-gradient(circle at 4% 4%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 48%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012));
  border: 1px solid color-mix(in srgb, var(--border-strong) 68%, var(--primary-soft));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

#matrixContainer {
  width: 100%;
  min-width: 0;
}

.payoff-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: color-mix(in srgb, var(--panel-strong) 80%, transparent);
  border-radius: 14px;
  overflow: hidden;
}

.payoff-table th,
.payoff-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.payoff-table thead th,
.payoff-table tbody th {
  position: sticky;
  z-index: 2;
  background: color-mix(in srgb, var(--panel-strong) 92%, rgba(255, 255, 255, 0.04));
  color: var(--text);
  text-align: center;
  font-weight: 700;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.payoff-table thead th {
  top: 0;
}

.payoff-table tbody th {
  left: 0;
  z-index: 1;
  box-shadow: 6px 0 12px -12px rgba(15, 23, 42, 0.9);
}

.payoff-table th:first-child {
  left: 0;
  z-index: 3;
  box-shadow: 7px 7px 16px -13px rgba(15, 23, 42, 0.9);
}

.payoff-table tr:first-child th {
  border-top: 1px solid var(--border);
}

.payoff-table tr > *:first-child {
  border-left: 1px solid var(--border);
}

.payoff-table th {
  min-width: 0;
  padding: 10px;
  font-size: clamp(12px, 1.2vw, 14px);
}

.payoff-table thead th:first-child,
.payoff-table tbody th {
  width: var(--matrix-index-width);
  min-width: var(--matrix-index-width);
}

.payoff-table thead th:not(:first-child),
.payoff-cell {
  width: calc((100% - var(--matrix-index-width)) / var(--matrix-cols));
}

.payoff-cell {
  height: var(--matrix-cell-height);
  min-width: 0;
  padding: var(--matrix-cell-padding);
  background: color-mix(in srgb, var(--panel-strong) 80%, rgba(255, 255, 255, 0.02));
  transition: background 0.18s ease, box-shadow 0.18s ease;
  position: relative;
}

.payoff-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
  gap: var(--matrix-entry-gap);
  height: 100%;
}

.payoff-entry input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-align: center;
  font-weight: 700;
  font-size: var(--matrix-font-size);
  min-height: var(--matrix-input-height);
  padding: 6px 8px;
}

.payoff-entry .u1 {
  color: color-mix(in srgb, var(--primary) 82%, white);
}

.payoff-entry .u2 {
  color: color-mix(in srgb, var(--accent) 90%, white);
}

.payoff-entry input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.payoff-cell.best-p1 {
  background: color-mix(in srgb, var(--primary-soft) 86%, rgba(255, 255, 255, 0.025));
}

.payoff-cell.best-p2 {
  background: color-mix(in srgb, var(--success-soft) 90%, rgba(255, 255, 255, 0.025));
}

.payoff-cell.nash {
  box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 28px -17px color-mix(in srgb, var(--accent) 65%, transparent);
}

.payoff-cell.pareto {
  box-shadow: inset 0 0 0 2px var(--cell-pareto), inset 0 0 28px -17px color-mix(in srgb, var(--cell-pareto) 75%, transparent);
}

.payoff-cell.nash.pareto {
  box-shadow:
    inset 0 0 0 2px var(--accent),
    inset 0 0 0 6px rgba(0, 0, 0, 0),
    inset 0 0 0 8px rgba(114, 240, 184, 0.85);
}

.process-log {
  margin: 0;
  padding-left: 24px;
  display: grid;
  gap: 12px;
}

.process-log li {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  line-height: 1.45;
}

.process-log li.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--text);
}

.result-block + .result-block {
  margin-top: 16px;
}

.result-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  color: var(--text-muted);
}

.result-list li {
  line-height: 1.45;
}

.callout {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  line-height: 1.5;
}

.callout--success {
  border-color: rgba(73, 209, 159, 0.34);
  background: var(--success-soft);
}

.callout--warning {
  border-color: rgba(255, 184, 77, 0.34);
  background: rgba(255, 184, 77, 0.12);
}

.callout--danger {
  border-color: rgba(255, 111, 125, 0.34);
  background: var(--danger-soft);
}

.chart-frame {
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--border-strong) 72%, var(--primary-soft));
  background:
    radial-gradient(circle at 9% 14%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 46%),
    radial-gradient(circle at 93% 88%, color-mix(in srgb, var(--cell-pareto) 16%, transparent), transparent 44%),
    rgba(255, 255, 255, 0.03);
  min-height: var(--chart-height);
  height: var(--chart-height);
  padding: 8px;
}

#payoffChart {
  display: block;
  width: 100%;
  height: 100%;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.34);
  border-radius: 999px;
}

@media (max-width: 1400px) {
  .workspace {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .column--main {
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr);
  }

  :root {
    --chart-height: clamp(340px, 44vh, 520px);
  }
}

@media (max-width: 1024px) {
  .app-shell {
    padding: 16px;
  }

  .hero {
    flex-direction: column;
  }

  .hero__side {
    align-items: stretch;
  }

  .summary-strip,
  .workspace,
  .column--main {
    grid-template-columns: 1fr;
  }

  .panel--sticky {
    position: static;
  }

  .column--left {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  :root {
    --chart-height: clamp(320px, 44vh, 480px);
  }
}

@media (max-width: 720px) {
  .field-grid,
  .action-grid {
    grid-template-columns: 1fr;
  }

  .matrix-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .panel__header,
  .panel__header--matrix {
    flex-direction: column;
    align-items: flex-start;
  }

  .payoff-cell {
    height: max(76px, var(--matrix-cell-height));
  }

  .matrix-wrap {
    padding: 10px;
    margin: 0 -6px -8px;
  }

  .payoff-entry input {
    min-height: max(32px, var(--matrix-input-height));
    border-radius: 8px;
    font-size: clamp(12px, 3.2vw, var(--matrix-font-size));
  }

  .chart-frame {
    min-height: clamp(280px, 46vh, 420px);
    height: clamp(280px, 46vh, 420px);
  }
}
