/* =========================================================
   LP Solver — styles
   Palette: navy, blue, light blue, grey, a little red.
   Layout: input panel beside the results; stacks on phones.
   ========================================================= */

:root {
  /* Colors and fonts. Everything below uses these tokens. */
  --navy: #14284b;
  --blue: #2c6bb3;
  --sky: #e4eef9;
  --sky2: #c4d8ef;
  --ink: #1c2535;
  --gray: #667284;
  --line: #d7dde6;
  --paper: #f4f6f9;
  --card: #ffffff;
  --red: #c42f3a;
  --font-d: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-b: "IBM Plex Sans", "Segoe UI", sans-serif;
  color-scheme: light;
}

html[lang="ar"] {
  --font-d: "Noto Kufi Arabic", "IBM Plex Sans Arabic", Tahoma, sans-serif;
  --font-b: "IBM Plex Sans Arabic", "IBM Plex Sans", Tahoma, sans-serif;
}

html[lang="ar"] .en,
html[lang="en"] .ar {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-b);
  font-size: 16px;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--blue);
}

h1,
h2,
h3 {
  font-family: var(--font-d);
  color: var(--navy);
  text-wrap: balance;
  line-height: 1.35;
  margin: 0;
}

p {
  margin: 0;
}

sub {
  font-size: .7em;
}


/* ---------- header ---------- */
.top {
  background: var(--navy);
  color: #fff;
}

.top-in {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: grid;
  gap: 4px;
}

.brand h1 {
  color: #fff;
  font-size: 1.3rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 .logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  box-shadow: 0 0 0 1.5px #3a5079;
  flex: none;
}

.brand p {
  color: #b6c4da;
  font-size: .88rem;
}

.lang {
  display: inline-flex;
  border: 1px solid #3a5079;
  border-radius: 7px;
  overflow: hidden;
}

.lang button {
  font: inherit;
  font-size: .88rem;
  border: 0;
  background: transparent;
  color: #b6c4da;
  padding: 5px 14px;
  cursor: pointer;
  font-family: "IBM Plex Sans", "IBM Plex Sans Arabic", sans-serif;
}

.lang button[aria-pressed="true"] {
  background: #fff;
  color: var(--navy);
  font-weight: 600;
}

nav.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.tabs-in {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  gap: 2px;
  overflow-x: auto;
}

.tabs a {
  display: block;
  padding: 12px 16px;
  color: var(--gray);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  font-weight: 500;
  font-size: .95rem;
}

.tabs a:hover {
  color: var(--navy);
}

.tabs a[aria-current="page"] {
  color: var(--navy);
  border-bottom-color: var(--blue);
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

section.view {
  display: none;
}

section.view.on {
  display: grid;
  gap: 18px;
}

.head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
}

.head h2 {
  font-size: 1.3rem;
}

.head p {
  color: var(--gray);
  font-size: .92rem;
}

.explain-btn {
  font: inherit;
  font-size: .92rem;
  font-weight: 600;
  border: 1.5px solid var(--navy);
  background: var(--card);
  color: var(--navy);
  border-radius: 7px;
  padding: 6px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.explain-btn:hover {
  background: var(--sky);
}

.explain-btn[aria-pressed="true"] {
  background: var(--navy);
  color: #fff;
}

.explain-btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}


/* ---------- explanation visibility ----------
   Anything with .explain is hidden until the Explain button
   adds .explaining to <body>. */
.explain {
  display: none !important;
}

body.explaining .explain {
  display: grid !important;
}

body.explaining p.explain {
  display: block !important;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  display: grid;
  gap: 12px;
}

.guide {
  border-color: var(--sky2);
  background: #f8fbfe;
}

.guide h3 {
  font-size: 1rem;
}

ol.steps,
ul.plain {
  margin: 0;
  padding-inline-start: 22px;
  display: grid;
  gap: 5px;
}

ol.steps li::marker {
  color: var(--blue);
  font-weight: 600;
}

.term {
  color: var(--gray);
  font-size: .88em;
}

.rule {
  border-inline-start: 3px solid var(--blue);
  background: var(--sky);
  padding: 9px 14px;
  border-radius: 6px;
}

.warn {
  border-inline-start: 3px solid var(--red);
  background: #fbeeee;
  padding: 10px 14px;
  border-radius: 6px;
}

.model {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-grid;
  gap: 2px;
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 1rem;
  justify-self: start;
  min-width: 210px;
  font-family: "IBM Plex Sans", sans-serif;
}

.model .st {
  color: var(--gray);
  font-size: .88rem;
}

.math {
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
  font-family: "IBM Plex Sans", "IBM Plex Sans Arabic", sans-serif;
}

.pair {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 28px;
  align-items: start;
}

.pair > div {
  display: grid;
  gap: 6px;
}

.cap {
  font-size: .82rem;
  color: var(--gray);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .03em;
}

html[lang="ar"] .cap {
  text-transform: none;
  letter-spacing: 0;
}


/* ---------- editor ---------- */
.editor {
  display: grid;
  gap: 14px;
}

.ed-top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
}

.ed-top label.full {
  flex: 1 1 100%;
}

.ed-top label.full select {
  flex: 1;
  min-width: 0;
}

.ed-top label {
  font-size: .88rem;
  color: var(--gray);
  display: flex;
  align-items: center;
  gap: 8px;
}

select {
  font: inherit;
  font-size: .9rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  background: #fff;
  color: var(--ink);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  direction: ltr;
}

.seg button {
  font: inherit;
  font-size: .88rem;
  border: 0;
  background: #fff;
  padding: 4px 14px;
  cursor: pointer;
  color: var(--gray);
}

.seg button[aria-pressed="true"] {
  background: var(--navy);
  color: #fff;
}

.ed-grid {
  direction: ltr;
  display: grid;
  gap: 8px;
  justify-items: start;
  overflow-x: auto;
  padding: 12px 14px;
  background: var(--paper);
  border-radius: 8px;
  font-family: "IBM Plex Sans", sans-serif;
}

.ed-row {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.ed-row .lbl {
  min-width: 58px;
  color: var(--navy);
  font-weight: 600;
}

.ed-row .st {
  min-width: 34px;
  color: var(--gray);
  font-size: .86rem;
}

.ed-row input {
  width: 52px;
  font: inherit;
  font-size: .95rem;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 4px;
  background: #fff;
  color: var(--ink);
}

.ed-row input.bad {
  border-color: var(--red);
  background: #fdf1f1;
}

.ed-row select {
  padding: 3px 4px;
}

.ed-row .v {
  min-width: 24px;
}

.remove {
  font: inherit;
  border: 0;
  background: transparent;
  color: var(--gray);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.remove:hover {
  background: #fbeeee;
  color: var(--red);
}

.add {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  border: 1.5px dashed var(--sky2);
  background: transparent;
  color: var(--navy);
  border-radius: 7px;
  padding: 6px 14px;
  cursor: pointer;
  justify-self: start;
}

.add:hover {
  border-color: var(--blue);
  background: var(--sky);
}

.ed-act {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 7px;
  padding: 8px 26px;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
}

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

.hint {
  font-size: .84rem;
  color: var(--gray);
}

.err {
  color: var(--red);
  font-size: .9rem;
}


/* ---------- output ---------- */
.out {
  display: grid;
  gap: 16px;
}

.out:empty {
  display: none;
}

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

.stepbox h4 {
  margin: 0;
  font-family: var(--font-d);
  font-size: .95rem;
  color: var(--navy);
}

.answer {
  background: var(--card);
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--red);
  border-radius: 8px;
  padding: 14px 18px;
  display: grid;
  gap: 6px;
}

.answer .label {
  font-size: .82rem;
  color: var(--gray);
}

.answer .big {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--navy);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

.answer .z {
  color: var(--red);
}

.answer.no-solution {
  border-inline-start-color: var(--gray);
}

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

table.t {
  border-collapse: collapse;
  direction: ltr;
  font-size: .94rem;
  font-family: "IBM Plex Sans", "IBM Plex Sans Arabic", sans-serif;
}

table.t th,
table.t td {
  border: 1px solid var(--line);
  padding: 6px 12px;
  text-align: center;
  white-space: nowrap;
}

table.t thead th {
  background: var(--navy);
  color: #fff;
  font-weight: 500;
}

table.t tbody th {
  background: var(--paper);
  color: var(--navy);
  font-weight: 600;
}

table.t tr.zrow td,
table.t tr.zrow th {
  border-top: 2px solid var(--navy);
}

table.t td.pc,
table.t tbody th.pc {
  background: var(--sky);
}

table.t thead th.pc {
  background: var(--blue);
}

table.t tr.pr td,
table.t tr.pr th {
  background: var(--sky);
}

table.t td.pv {
  background: var(--sky2);
  color: var(--red);
  font-weight: 700;
  box-shadow: inset 0 0 0 2px var(--red);
}

table.t td.neg {
  color: var(--red);
  font-weight: 600;
}

table.t td.ratio {
  color: var(--gray);
  font-size: .86rem;
  background: #fff;
}

table.t td.ratio.min {
  color: var(--red);
  font-weight: 600;
}

table.t tr.best td,
table.t tr.best th {
  color: var(--red);
  font-weight: 600;
}

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

.tables .tname {
  font-size: .88rem;
  font-weight: 600;
  color: var(--navy);
}

.result-stack {
  display: grid;
  gap: 18px;
}

.work {
  display: grid;
  grid-template-columns: minmax(360px,450px) minmax(0,1fr);
  gap: 22px;
  align-items: start;
}

.work > .card {
  position: sticky;
  top: 62px;
  max-height: calc(100vh - 78px);
  overflow: auto;
}

.results {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.results > .placeholder {
  color: var(--gray);
}

@media (max-width:900px) {
  .work {
    grid-template-columns: 1fr;
  }
  .work > .card {
    position: static;
    max-height: none;
  }
}

.graph {
  display: grid;
  gap: 10px;
}

.graph svg {
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  direction: ltr;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: .86rem;
}

.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-block;
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.legend i.fill {
  height: 12px;
  background: var(--sky);
  border: 1px solid var(--sky2);
}

footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 28px;
  color: var(--gray);
  font-size: .84rem;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  justify-content: space-between;
}

@media (max-width:560px) {
  main {
    padding: 18px 16px 48px;
  }
  .card {
    padding: 14px;
  }
}

@media (prefers-reduced-motion:reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- small helpers ---------- */
.red {
  color: var(--red);
}

h4.cap {
  margin: 0;
}

.legend i.dash {
  background: repeating-linear-gradient(90deg, var(--red) 0 6px, transparent 6px 10px);
}

/* ---------- counts and sign toggles ---------- */
.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.counts label {
  font-size: .88rem;
  color: var(--gray);
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  width: 64px;
  font: inherit;
  font-size: .95rem;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 4px;
  background: #fff;
  color: var(--ink);
}

.count:disabled {
  background: var(--paper);
  color: var(--gray);
}

.ed-row.signs {
  flex-wrap: wrap;
  white-space: normal;
  padding-top: 4px;
}

.sign {
  font: inherit;
  font-size: .88rem;
  border: 1px solid var(--navy);
  border-radius: 999px;
  padding: 2px 12px;
  cursor: pointer;
  background: var(--navy);
  color: #fff;
  white-space: nowrap;
}

.sign[aria-pressed="false"] {
  background: #fff;
  color: var(--navy);
  border-style: dashed;
}

.sign:hover {
  border-color: var(--blue);
}

.add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* With 3+ variables the input panel goes full width above the results */
.work.wide {
  grid-template-columns: minmax(0, 1fr);
}

.work.wide > .card {
  position: static;
  max-height: none;
}

.var-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* Phones and narrow windows: one column that never grows wider than the screen */
@media (max-width: 900px) {
  .work {
    grid-template-columns: minmax(0, 1fr);
  }
  .work > .card {
    overflow: visible;
  }
}

.editor,
.card {
  grid-template-columns: minmax(0, 1fr);
}

.ed-top label.full select {
  max-width: 100%;
}

.ed-top label.full {
  min-width: 0;
}

.ed-top label.full select {
  width: 100%;
}

@media (max-width: 560px) {
  .ed-grid {
    padding: 10px;
  }
  .ed-row {
    gap: 3px;
  }
  .ed-row input {
    width: 42px;
  }
  .ed-row .lbl {
    min-width: 0;
  }
  .ed-row .st {
    min-width: 24px;
  }
}

@media (max-width: 400px) {
  .card {
    padding: 12px;
  }
  .ed-row input {
    width: 38px;
  }
  .remove {
    width: 20px;
  }
}

/* ---------- copy / print / explain buttons ---------- */
.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-btn {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--navy);
  border-radius: 7px;
  padding: 6px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.tool-btn:hover {
  background: var(--sky);
}

.tool-btn svg {
  width: 17px;
  height: 17px;
  flex: none;
}

.tool-btn[hidden] {
  display: none;
}

/* ---------- printing: the problem and its solution only ---------- */
@media print {
  body {
    background: #fff;
  }
  .top,
  nav.tabs,
  .head-actions,
  footer,
  .add-row,
  .ed-act,
  .remove,
  .hint,
  .ed-top label.full {
    display: none !important;
  }
  .work,
  .work.wide {
    grid-template-columns: minmax(0, 1fr);
  }
  .work > .card {
    position: static;
    max-height: none;
    overflow: visible;
  }
  .card,
  .answer,
  .stepbox {
    break-inside: avoid;
  }
}
