:root {
  --bg: #0b0f14;
  --panel: #0f1622;
  --ink: #e8eef9;
  --muted: #9fb3c8;
  --accent: #7ae0ff;
  --accent-2: #ff8ab0;
  --grid: #203047;
  --axis: #6ea8ff;
  --good: #84f7a9;
  --bad: #ff6b6b;
  --grey-curve: #b8c3d333;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(
    1200px 800px at 20% -10%,
    #142033 0%,
    #0b0f14 60%
  );
  color: var(--ink);
  font-family: "Nunito", system-ui, -apple-system, Segoe UI, Roboto, Arial,
    sans-serif;
}

.app-header {
  padding: 16px 20px;
  border-bottom: 1px solid #1f2a3a;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02),
    rgba(255, 255, 255, 0)
  );
  position: sticky;
  top: 0;
  z-index: 10;
}

.title-wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  font-family: "Space Grotesk", monospace;
}
.title-left {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 0 0 12px #7ae0ff44;
}
.title-right {
  font-size: 32px;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 12px;
}
.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  padding: 16px;
  height: calc(100% - 86px);
}
.left-panel {
  background: var(--panel);
  .actions button.primary.disabled,
  .actions button.primary:disabled {
    background: #3a4b63 !important;
    opacity: 0.55;
    cursor: not-allowed;
  }
  border: 1px solid #1f2a3a;
  border-radius: 14px;
  padding: 12px;
  position: relative;
  overflow: hidden;
}

#graphCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  background: radial-gradient(
    1200px 800px at 60% -10%,
    #10203a 0%,
    #0c1628 60%
  );
}
.axes-overlay {
  position: absolute;
  inset: 12px;
  pointer-events: none;
}

.right-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scoreboard {
  background: var(--panel);
  border: 1px solid #1f2a3a;
  border-radius: 14px;
  padding: 12px;
}
.score-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #101a28;
  margin-bottom: 8px;
}
.score-row .swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
}
.score-row .name {
  font-weight: 700;
}
.score-row .score {
  font-family: "Space Grotesk";
  font-size: 18px;
}

.turn-box {
  background: var(--panel);
  border: 1px solid #1f2a3a;
  border-radius: 14px;
  padding: 12px;
}
.turn-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.turn-header .timer {
  font-family: "Space Grotesk";
  font-size: 20px;
  color: var(--accent-2);
}
.equation-display {
  text-align: center;
  font-family: "Space Grotesk", monospace;
  font-size: 14px;
  color: var(--muted);
  background: #0b1422;
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid #1f2a3a;
}
.conic-types {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  padding: 8px 0;
  background: #0b1422;
  border-radius: 8px;
  border: 1px solid #1f2a3a;
}
.coeff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.coeff-grid label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #0f1a2a;
  border: 1px solid #1f2a3a;
  padding: 8px 10px;
  border-radius: 8px;
}
.coeff-grid input {
  width: 60px;
  background: #0b1422;
  color: var(--ink);
  border: 1px solid #273650;
  border-radius: 6px;
  padding: 6px 8px;
}
.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.primary {
  background: linear-gradient(180deg, #7ae0ff, #6bc9ff);
  border: none;
  color: #001220;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
}
.ghost {
  background: transparent;
  border: 1px solid #2b3d57;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.explain {
  background: var(--panel);
  border: 1px solid #1f2a3a;
  border-radius: 14px;
  padding: 12px;
  min-height: 120px;
}
.explain h3 {
  margin: 0 0 8px;
}
.explain .note {
  color: var(--muted);
  font-size: 14px;
}

/* Curve history panel (stacked in right panel, non-blocking) */
.curve-history {
  width: 100%;
  background: linear-gradient(160deg, #102034, #0d1522 70%);
  border: 1px solid #203047;
  border-radius: 16px;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px -4px #000a, 0 0 0 1px #152130;
  backdrop-filter: blur(4px) saturate(140%);
  margin-top: auto; /* push to bottom if space available */
}
.history-header {
  font-family: "Space Grotesk";
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
  margin: 0 0 8px;
  color: var(--accent);
  text-shadow: 0 0 6px #7ae0ff33;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.history-body {
  display: flex;
  flex-direction: column;
}
.history-list {
  font-family: "Space Grotesk", monospace;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Height for exactly two items (approx). Each ~52px inc gap */
  max-height: 112px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: #2a3d55 #0f1622;
}
.history-list::-webkit-scrollbar {
  width: 10px;
}
.history-list::-webkit-scrollbar-track {
  background: #0f1622;
  border-radius: 10px;
}
.history-list::-webkit-scrollbar-thumb {
  background: #27405a;
  border-radius: 10px;
  border: 2px solid #0f1622;
}
.history-list::-webkit-scrollbar-thumb:hover {
  background: #325574;
}
.history-item {
  background: #101a28;
  border: 1px solid #1c2a3a;
  border-radius: 10px;
  padding: 8px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  min-height: 48px;
}
.history-item .eq {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item .std {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item .badge {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 10px;
  background: #192b3d;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-2);
}

/* Remove now-unused pagination bar & dots styles if present */
.history-bar,
.history-dot {
  display: none !important;
}

/* Ensure right-panel is relative for absolute positioning of floating window */
.right-panel {
  position: relative;
}

.curve-history::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 16px;
  padding: 1px;
  background: linear-gradient(140deg, #244463, #0e1b2b 40%, #1e324b);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* Slight glow when hovering over the panel */
.curve-history:hover {
  box-shadow: 0 6px 32px -6px #000c, 0 0 0 1px #264058;
}

.history-empty {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 10px 0;
}

.history-list:empty::after {
  content: "No curves yet";
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.history-list::-webkit-scrollbar-corner {
  background: transparent;
}

/* Responsive placement: stack under scoreboard on narrow widths */
@media (max-width: 1100px) {
  .curve-history {
    position: static;
    width: auto;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  background: #0b0f14cc;
  z-index: 20;
}
.mini-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b0f1488;
  backdrop-filter: blur(4px);
  z-index: 40;
}
.mini-overlay[aria-hidden="true"] {
  display: none;
}
.mini-card {
  background: #0f1826;
  border: 1px solid #223449;
  border-radius: 14px;
  padding: 20px 22px 18px;
  width: 320px;
  box-shadow: 0 8px 34px -6px #000c, 0 0 0 1px #142233;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mini-card h3 {
  margin: 0;
  font-family: "Space Grotesk";
  font-size: 18px;
}
.mini-text {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.4;
}
.mini-check {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
}
.mini-check input {
  accent-color: var(--accent);
}
.mini-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.mini-actions .small {
  padding: 6px 10px;
  font-size: 13px;
}
.overlay[aria-hidden="false"] {
  display: flex;
}
.card {
  background: #0e1726;
  border: 1px solid #203047;
  border-radius: 16px;
  padding: 20px;
  width: min(720px, 92vw);
  box-shadow: 0 10px 40px #0008;
}
.card h2 {
  margin-top: 0;
}
.instructions ol {
  padding-left: 18px;
  line-height: 1.65;
}
.countdown {
  margin-top: 12px;
  color: var(--muted);
  font-family: "Space Grotesk";
}

.setup form {
  display: grid;
  gap: 10px;
}
.setup label {
  display: grid;
  gap: 6px;
}
.setup input {
  background: #0b1422;
  color: var(--ink);
  border: 1px solid #273650;
  border-radius: 8px;
  padding: 8px 10px;
}
#playerNames > .row {
  display: grid;
  grid-template-columns: 1fr;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }
}
:root {
  --bg-0: #0b1020;
  --bg-1: #0f1730;
  --bg-2: #121a3a;
  --text: #e8eefc;
  --muted: #b5c2e8;
  --accent: #7aa2ff;
  --accent-2: #ff7ad9;
  --good: #6fe3a2;
  --warn: #ffd36f;
  --bad: #ff6f6f;
  --panel: #151b34cc;
  --grid-major: #2a335f;
  --grid-minor: #1c2344;
  --axis: #dbe5ff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(
    1200px 800px at 20% 10%,
    var(--bg-2),
    var(--bg-1) 40%,
    var(--bg-0) 100%
  );
  color: var(--text);
  font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Ubuntu,
    Cantarell, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 28px);
  background: linear-gradient(90deg, #0d1530cc, #0b1020cc);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #2a3560b3;
}

.brand-left {
  font-weight: 800;
  font-size: clamp(20px, 4vw, 28px);
  letter-spacing: 1px;
  color: var(--accent-2);
  text-shadow: 0 0 16px #ff7ad944, 0 0 2px #ff7ad999;
}
.brand-left .arrow {
  padding: 0 6px;
}

.brand-right {
  font-weight: 800;
  font-size: clamp(22px, 5vw, 34px);
  color: var(--accent);
  text-shadow: 0 0 16px #7aa2ff55, 0 0 2px #7aa2ff99;
}

.app-main {
  padding: 16px clamp(12px, 4vw, 28px) 28px;
}

.top-row {
  display: flex;
  gap: 16px;
  align-items: stretch;
}

.scoreboard {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.score-card {
  background: var(--panel);
  border: 1px solid #2a3560b3;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #00000022 inset, 0 0 10px currentColor;
}

.player-name {
  font-weight: 700;
  letter-spacing: 0.2px;
}
.player-score {
  font-weight: 800;
  font-size: 22px;
}

.graph-section {
  margin-top: 16px;
  background: linear-gradient(180deg, #0e1633 0%, #0b1020 100%);
  border: 1px solid #2a3560b3;
  border-radius: 16px;
  box-shadow: var(--shadow);
  position: relative;
}

#graphCanvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 16px;
}

.explanation {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid #2a3560b3;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 15px;
}

.mono {
  font-family: "Fira Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: radial-gradient(800px 600px at 50% 20%, #0f1730ee, #0b1020ee);
  z-index: 50;
}
.overlay.visible {
  display: grid;
}

.overlay-card {
  width: min(960px, 92vw);
  background: #12193acc;
  border: 1px solid #2a3560b3;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: clamp(16px, 4vw, 28px);
}
.overlay-card h2 {
  margin: 0 0 8px;
  font-size: clamp(22px, 3.8vw, 34px);
}
.overlay-card .subtitle {
  color: var(--muted);
  margin: 0 0 12px;
}

.instructions ul {
  margin: 0 0 12px 18px;
  line-height: 1.6;
}
.countdown {
  margin-top: 10px;
  font-weight: 700;
  color: var(--warn);
}

.form-row {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}
.form-row label {
  font-weight: 600;
}
.form-row input,
.form-row select {
  background: #0c1330;
  border: 1px solid #2d3766;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
}

.player-names {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.player-names .name-item {
  background: #0c1330;
  border: 1px solid #2d3766;
  padding: 10px 12px;
  border-radius: 10px;
}
.player-names .name-item label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}
.player-names .name-item input {
  width: 100%;
  background: transparent;
  border: 1px solid #394582;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}
.primary {
  background: linear-gradient(90deg, #7aa2ff, #8ad0ff);
  color: #0b1020;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 20px #7aa2ff44;
}
.primary:hover {
  filter: brightness(1.05);
}

.coeff-form .coeff-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}
.coeff-form label {
  font-weight: 700;
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 8px;
}
.coeff-form input {
  background: #0c1330;
  border: 1px solid #2d3766;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
}

.help-btn {
  position: static;
  background: linear-gradient(135deg, #2d3f66, #1a2740);
  color: var(--ink);
  border: 1px solid #3a4e72;
  border-radius: 8px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 14px #0008;
  transition: background 0.25s, transform 0.2s;
  font-size: 14px;
  line-height: 1;
}

#helpOverlay.overlay[aria-hidden="false"] {
  display: flex;
}
#helpOverlay {
  backdrop-filter: blur(10px) brightness(0.9);
}
.help-card {
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.help-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.close-help {
  background: #1d2b44;
  border: 1px solid #2f4468;
  color: #b9c7e4;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s;
}
.close-help:hover {
  background: #274064;
}
.help-content {
  overflow-y: auto;
  padding-right: 4px;
  margin-top: 4px;
  line-height: 1.5;
  font-size: 14px;
}
.help-content pre {
  background: #0b1422;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #1f2a3a;
  overflow-x: auto;
}
.help-content hr {
  border: none;
  border-top: 1px solid #1f2a3a;
  margin: 14px 0;
}
.help-content ul {
  margin: 6px 0 12px 20px;
  padding: 0;
}
.help-content li {
  margin-bottom: 4px;
}
.help-content .note {
  color: var(--muted);
  font-style: italic;
  margin-top: 4px;
}

.help-section {
  margin: 14px 0 18px;
  padding: 12px 14px;
  background: #0b1422;
  border: 1px solid #1f2a3a;
  border-radius: 10px;
}
.help-section h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.help-section pre {
  margin: 0 0 8px;
}
.help-section .meaning {
  margin: 0 0 0 18px;
  padding: 0;
  list-style: disc;
}
.help-section .meaning li {
  margin-bottom: 4px;
}

@media (max-width: 680px) {
  .help-card {
    width: 92vw;
  }
  .help-content {
    font-size: 13px;
  }
}

.gameover-card {
  max-width: 560px;
  width: min(560px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.final-summary {
  margin: 0 0 4px;
  font-size: 15px;
  color: var(--muted);
}
.final-scoreboard {
  display: grid;
  gap: 8px;
  margin-bottom: 4px;
}
.final-scoreboard .final-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  background: #0f1d33;
  border: 1px solid #203047;
  padding: 8px 10px;
  border-radius: 10px;
}
.final-scoreboard .swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #0008 inset, 0 0 6px currentColor;
}
.final-scoreboard .name {
  font-weight: 600;
}
.final-scoreboard .score {
  font-family: "Space Grotesk";
  font-weight: 700;
  font-size: 18px;
}
.gameover-actions {
  justify-content: flex-end;
}
