/* MARTIAN RAILS
 * The sheet is an areographic survey plate: drafting linen, plate ink,
 * quadrangle unit fills, and verdigris survey marking for the one thing that
 * matters most on this map -- the seam where the sheet wraps.
 */

:root {
  --sheet:      #ede2cc;
  --sheet-2:    #e4d7bc;
  --sheet-3:    #d9caa9;
  --ink:        #2b2620;
  --ink-soft:   #6b6153;
  --ink-faint:  #978b74;
  --rule:       #b9a67f;
  --seam:       #1f6f78;
  --seam-lift:  #2e8c94;
  --alert:      #8c3b2a;
  --gain:       #3f6b3a;

  --plate: 'Arial Narrow', 'Helvetica Neue', 'Liberation Sans Narrow',
           'Nimbus Sans Narrow', 'DejaVu Sans Condensed', sans-serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue',
          Arial, sans-serif;
  --data: ui-monospace, 'DejaVu Sans Mono', 'Liberation Mono', Menlo,
          Consolas, 'Courier New', monospace;

  --gap: 14px;
  --hair: 1px solid var(--rule);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #cdbf9f;
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* The plate itself sits on the desk with a printed edge. */
.plate {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  max-width: 1680px;
  margin: 0 auto;
  background: var(--sheet);
  box-shadow: 0 0 0 1px var(--rule), 0 8px 40px rgba(43, 38, 32, .28);
}

/* ------------------------------------------------------------- title block */
.plate-head {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-bottom: 2px solid var(--ink);
  background: var(--sheet-2);
}

.plate-mark {
  width: 74px;
  display: grid;
  place-items: center;
  border-right: var(--hair);
  font-family: var(--plate);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--seam);
}

.plate-title { padding: 10px 18px; flex: 1 1 auto; border-right: var(--hair); }

.plate-title h1 {
  margin: 0;
  font-family: var(--plate);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: .3em;
  text-transform: uppercase;
}

.plate-sub {
  margin: 3px 0 0;
  font-family: var(--data);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--ink-soft);
}

.plate-meta {
  display: flex;
  margin: 0;
  align-items: stretch;
}

.plate-meta div {
  padding: 10px 16px;
  border-left: var(--hair);
  min-width: 92px;
}

.plate-meta dt {
  font-family: var(--plate);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.plate-meta dd {
  margin: 2px 0 0;
  font-family: var(--data);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

.plate-meta dd.lead { color: var(--seam); }

/* ------------------------------------------------------------------ body */
.plate-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  min-height: 0;
}

.chart {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  border-right: 2px solid var(--ink);
}

.chart-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: var(--hair);
  background: var(--sheet-2);
  flex-wrap: wrap;
}

.chart-canvas { position: relative; min-height: 0; overflow: hidden; }
.chart-canvas canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

/* the signature: a longitude rule that shows the sheet wrapping */
.ribbon {
  position: relative;
  height: 34px;
  border-top: 2px solid var(--ink);
  background: var(--sheet-2);
}
.ribbon canvas { display: block; width: 100%; height: 100%; cursor: ew-resize; }

/* ------------------------------------------------------------- the office */
/* min-width:0 throughout, or a long waybill label sets the panel's min-content
 * width and pushes the whole plate wider than a phone screen. */
.office {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  background: var(--sheet);
}

.card { border-bottom: var(--hair); padding: 11px 14px; min-width: 0; }

.card h2 {
  margin: 0 0 8px;
  font-family: var(--plate);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.card h2 span { font-family: var(--data); letter-spacing: 0; color: var(--ink); }

/* ------------------------------------------------------------- waybills */
.bill {
  border: 1px solid var(--rule);
  background: var(--sheet-2);
  margin-bottom: 8px;
  padding: 0;
}
.bill-head {
  font-family: var(--plate);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 4px 8px 3px;
  border-bottom: 1px dashed var(--rule);
}
.demand {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 5px 8px;
  border: 0;
  border-top: 1px solid rgba(185, 166, 127, .5);
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.demand:first-of-type { border-top: 0; }
.demand:hover, .demand:focus-visible { background: rgba(31, 111, 120, .12); }
.demand .swatch {
  width: 12px; height: 12px;
  border: 1px solid var(--ink);
  border-radius: 2px;
}
.demand .where { font-size: 13px; line-height: 1.2; min-width: 0;
                 overflow-wrap: anywhere; }
.demand .where em { font-style: normal; color: var(--ink-soft); display: block; font-size: 11px; }
.demand .fee { font-family: var(--data); font-variant-numeric: tabular-nums; font-size: 14px; }
.demand.picked { background: rgba(31, 111, 120, .2);
                 box-shadow: inset 3px 0 0 var(--seam); }
.demand.ready { background: rgba(63, 107, 58, .16); }
.demand.ready .fee { color: var(--gain); font-weight: 700; }

/* the where-to-load caption under the waybills */
.loadhint {
  border: 1px solid var(--seam);
  background: rgba(31, 111, 120, .09);
  padding: 7px 9px;
  margin-top: 2px;
}
.loadhint[hidden] { display: none; }
.load-line { display: flex; align-items: center; gap: 7px; }
.load-line strong { font-size: 13px; }
.load-note { margin: 5px 0 0; font-size: 12.5px; line-height: 1.45; }
.load-note.faint { color: var(--ink-soft); font-size: 11.5px; }
.placelink {
  font-family: var(--data);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  padding: 0 3px;
  border: 0;
  border-bottom: 1px dashed var(--seam);
  background: none;
  color: var(--seam);
}
.placelink:hover:not(:disabled) { background: var(--seam); color: var(--sheet); }
.placelink.near { font-weight: 700; }

/* ---------------------------------------------------------------- train */
.cars { display: flex; gap: 5px; margin-bottom: 8px; }
.car {
  flex: 1 1 0;
  height: 34px;
  border: 1px solid var(--rule);
  background: var(--sheet-2);
  display: grid;
  place-items: center;
  font-family: var(--data);
  font-size: 10px;
  text-align: center;
  line-height: 1.1;
  padding: 2px;
  overflow: hidden;
}
.car.full { border-color: var(--ink); }
.car.empty { color: var(--ink-faint); border-style: dashed; }

.gauge {
  height: 7px;
  border: 1px solid var(--rule);
  background: var(--sheet-2);
  margin: 6px 0 10px;
  position: relative;
  overflow: hidden;
}
.gauge i { display: block; height: 100%; background: var(--seam); }

/* --------------------------------------------------------------- buttons */
button {
  font-family: var(--plate);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--sheet-2);
  border: 1px solid var(--ink);
  padding: 7px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--seam); color: var(--sheet); border-color: var(--seam); }
button:focus-visible { outline: 2px solid var(--seam-lift); outline-offset: 2px; }
button:disabled { opacity: .38; cursor: not-allowed; }

.doclink {
  flex: 1 1 auto;
  text-align: center;
  font-family: var(--plate);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--sheet-2);
  border: 1px solid var(--ink);
  padding: 7px 12px;
  text-decoration: none;
}
.doclink:hover { background: var(--seam); color: var(--sheet); border-color: var(--seam); }
.doclink:focus-visible { outline: 2px solid var(--seam-lift); outline-offset: 2px; }

button.key { background: var(--ink); color: var(--sheet); }
button.key:hover:not(:disabled) { background: var(--seam); border-color: var(--seam); }

.modes { display: inline-flex; border: 1px solid var(--ink); }
.modes button { border: 0; border-right: 1px solid var(--ink); }
.modes button:last-child { border-right: 0; }
.modes button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); }
.modes button[aria-pressed="true"]:hover { background: var(--seam); }

.row { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.row button, .row .doclink { min-width: 0; overflow-wrap: anywhere; }
.row button { flex: 1 1 auto; }

.pick {
  display: flex; flex-wrap: wrap; gap: 5px;
}
.pick button {
  font-family: var(--data);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  padding: 4px 7px;
}

/* --------------------------------------------------------------- rivals */
.rival {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 3px 0;
  font-size: 13px;
}
.rival b { width: 10px; height: 10px; border: 1px solid var(--ink); border-radius: 50%; }
.rival .cash, .rival .maj {
  font-family: var(--data);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.rival .maj { color: var(--ink-soft); }
.rival.you { font-weight: 700; }

/* ------------------------------------------------------------------ log */
.plate-foot {
  border-top: 2px solid var(--ink);
  background: var(--sheet-2);
  padding: 6px 14px;
  height: 62px;
  overflow-y: auto;
  font-family: var(--data);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}
.plate-foot p { margin: 0; }
.plate-foot p b { color: var(--ink); font-weight: 400; }
.plate-foot p.event { color: var(--alert); }

.notice {
  padding: 6px 10px;
  border: 1px solid var(--alert);
  background: rgba(140, 59, 42, .1);
  color: var(--alert);
  font-size: 13px;
  margin-bottom: 9px;
}

.hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 6px 0 0;
  line-height: 1.4;
}

/* ---------------------------------------------------------------- veils */
.veil {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(43, 38, 32, .82);
  z-index: 40;
  padding: 20px;
  overflow-y: auto;
}
/* An element carrying [hidden] must actually be hidden: .veil sets a display
 * that would otherwise win.  Deleting this line is a visible bug, so the
 * validator checks for it. */
.veil[hidden] { display: none; }

.sheet-dialog {
  background: var(--sheet);
  border: 2px solid var(--ink);
  max-width: 640px;
  width: 100%;
  padding: 26px 30px 24px;
  box-shadow: 0 12px 60px rgba(0, 0, 0, .5);
}

.sheet-dialog h2 {
  margin: 0 0 4px;
  font-family: var(--plate);
  font-size: 24px;
  letter-spacing: .26em;
  text-transform: uppercase;
}
.sheet-dialog .plate-sub { margin-bottom: 18px; }
.sheet-dialog h3 {
  margin: 18px 0 7px;
  font-family: var(--plate);
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.sheet-dialog p { line-height: 1.55; margin: 0 0 10px; }

.field { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.field button { flex: 0 0 auto; min-width: 54px; }
.field button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); }

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 6px 14px;
  font-family: var(--data);
  font-size: 12px;
}
.legend-grid div { display: flex; align-items: center; gap: 7px; }
.legend-grid i {
  width: 15px; height: 15px;
  border: 1px solid var(--ink);
  flex: 0 0 auto;
  display: block;
}
.legend-grid i.line { height: 4px; border-width: 0; }

table.tariff {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--data);
  font-size: 12px;
}
table.tariff th, table.tariff td {
  text-align: left;
  padding: 3px 8px 3px 0;
  border-bottom: 1px dotted var(--rule);
}
table.tariff td.n { text-align: right; font-variant-numeric: tabular-nums; }

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--sheet);
  font-family: var(--data);
  font-size: 11.5px;
  padding: 5px 8px;
  line-height: 1.4;
  white-space: nowrap;
  z-index: 5;
}
.tip[hidden] { display: none; }

/* --------------------------------------------------------------- mobile */
@media (max-width: 900px) {
  .plate { height: auto; min-height: 100vh; }
  .plate-body { grid-template-columns: minmax(0, 1fr); }
  .chart { border-right: 0; border-bottom: 2px solid var(--ink); }
  .chart-canvas { height: 62vh; }
  .office { max-height: none; overflow: visible; min-width: 0; }
  .rival { grid-template-columns: 10px minmax(0, 1fr) auto auto; }
  .rival span { overflow-wrap: anywhere; }
  .plate-head { flex-wrap: wrap; }
  .plate-title { border-right: 0; }
  /* Five tabular readouts will not fit one phone row; the monospaced value
   * cannot wrap, so the row wraps instead. */
  .plate-meta { width: 100%; border-top: var(--hair); flex-wrap: wrap; }
  .plate-meta div { flex: 1 1 33%; min-width: 0; padding: 7px 10px;
                    border-top: var(--hair); }
  .plate-meta dd { font-size: 15px; }
  .plate-meta dt { font-size: 9px; }
  .plate-title h1 { font-size: 21px; letter-spacing: .2em; }
}

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