/* The native [hidden] attribute would normally set display: none, but our
 * display: grid rules on .views-grid / .calc-grid have higher specificity
 * and override it. This explicit rule restores [hidden] behaviour. */
.calculator [hidden] {
  display: none !important;
}

.calculator .calc-grid {
  display: grid;
  gap: 0.4rem 1rem;
  align-items: end;
}

.calculator .calc-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Span every grid column — used so a single full-width row can sit between
 * two-up rows without leaving an empty cell next to it. */
.calculator .calc-grid .calc-grid-span {
  grid-column: 1 / -1;
}

.calculator .calc-grid p {
  margin: 0.3rem 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.calculator .calc-grid label {
  font-size: 0.82rem;
  line-height: 1.25;
  margin-bottom: 0.2rem;
}

.calculator input[type="number"],
.calculator input[type="range"] {
  width: 100%;
  font: inherit;
  box-sizing: border-box;
}

.calculator input[type="number"] {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--md-default-fg-color--lighter);
  border-radius: 0.2rem;
  background: var(--md-default-bg-color);
  color: var(--md-default-fg-color);
  font-size: 0.85rem;
}

.calculator .calc-hint {
  font-size: 0.78rem;
  color: var(--md-default-fg-color--light);
  margin: 0.3rem 0 0;
  line-height: 1.35;
}

/* Sliders: label above the range input so the range gets the full width. */
.calculator .slider-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.2rem;
  padding: 0.1rem 0;
}

.calculator .slider-grid label {
  font-size: 0.82rem;
  margin-top: 0.35rem;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.calculator .slider-grid output {
  font-family: var(--md-code-font-family, monospace);
  color: var(--md-default-fg-color--light);
  font-size: 0.78rem;
}

.calculator .calc-presets {
  margin: 0.8rem 0 0;
}

/* Pair two collapsible panels side by side on wide screens. */
@media (min-width: 720px) {
  .calculator .calc-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 1rem;
    align-items: start;
  }
}

/* Settings beside the drawing on wide screens: the controls column stays put
 * while the drawing sticks in view so geometry edits update it live. The
 * .calc-splitter between them is draggable (see CalcKit.initSplitter). */
.calculator .calc-splitter {
  display: none;
}

@media (min-width: 820px) {
  .calculator .calc-layout {
    display: grid;
    grid-template-columns: minmax(15rem, 0.4fr) 0.65rem minmax(0, 0.6fr);
    align-items: stretch;
  }

  .calculator .calc-controls {
    padding-right: 0.5rem;
  }

  .calculator .calc-stage {
    padding-left: 0.5rem;
    position: sticky;
    top: 4.2rem;
    align-self: start;
  }

  .calculator .calc-splitter {
    display: block;
    cursor: col-resize;
    border-radius: 3px;
    background: var(--md-default-fg-color--lightest);
    transition: background 0.12s ease;
  }

  .calculator .calc-splitter:hover {
    background: var(--md-accent-fg-color);
  }
}

.calculator .calc-controls > .tabbed-set,
.calculator .calc-controls > details {
  margin-top: 0.6rem;
}

.calculator .calc-controls > details {
  margin-bottom: 0;
}

.calculator .calc-stage > .tabbed-set,
.calculator .calc-stage > #g-axis-wrap {
  margin-top: 0.6rem;
}

.calculator .md-button {
  margin: 0.1rem 0.2rem 0.1rem 0;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
}

.calculator .calc-actions {
  margin-top: 0.8rem;
}

.calculator .calc-result {
  margin-top: 0.6rem;
}

.calculator .calc-warnings {
  margin-top: 0.4rem;
}

.calculator .calc-warning-list {
  margin: 0.3rem 0;
  padding: 0.4rem 0.8rem 0.4rem 1.6rem;
  background: rgba(200, 80, 80, 0.08);
  border-left: 3px solid #c44;
  border-radius: 0.2rem;
  font-size: 0.85rem;
  list-style: disc;
}

/* Comparison views are stacked one above the other so each stays large
 * enough to read. */
.calculator .views-grid {
  display: grid;
  gap: 1rem;
  margin-top: 0.6rem;
}

.calculator .calc-figure {
  margin: 0;
  width: 100%;
  text-align: left;
}

.calculator .calc-figure figcaption {
  font-size: 0.82rem;
  color: var(--md-default-fg-color--light);
  margin-bottom: 0.3rem;
}

/* Force SVGs to fill the figure. Material's base CSS sets max-width: 100%
 * on .md-typeset svg but not width: 100%, so without this the SVG falls
 * back to its viewBox-derived intrinsic width and leaves empty space. */
.calculator .calc-figure svg,
.calculator svg {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0;
  background: var(--md-default-bg-color);
}

/* The shop card and its info-page sibling are screen-hidden; they exist
 * only to be printed. */
.calculator .shop-card,
.calculator .shop-card-info {
  display: none;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  /* Material's chrome reserves screen space (header, sidebars, footer,
   * .md-main__inner margin, .md-content__inner ::before spacer); leaving
   * any of it in place pushes the shop card down so it lands on page 2,
   * leaving page 1 blank. Reset everything down to the article. */
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  .md-container,
  .md-main,
  .md-main__inner,
  .md-content,
  .md-content__inner {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    box-shadow: none !important;
  }
  .md-content__inner::before,
  .md-content__inner::after {
    display: none !important;
    height: 0 !important;
  }

  /* Strip the page chrome and *everything* in .md-typeset that isn't the
   * interactive tool — the intro prose, the formula admonition, the
   * worked-example, even the intro <ul> whose round bullets would otherwise
   * appear as "Forward/Reverse dots" above the shop card. */
  .md-header,
  .md-tabs,
  .md-footer,
  .md-sidebar,
  .md-content__button {
    display: none !important;
  }
  .md-typeset > *:not(.calculator) {
    display: none !important;
  }
  /* Inside the calculator the shop card prints on page 1 and the info
   * block on page 2 — everything else (controls, sliders, buttons) is
   * hidden so nothing leaks onto the paper. */
  .calculator > *:not(.shop-card):not(.shop-card-info) {
    display: none !important;
  }

  .calculator {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .calculator .shop-card {
    display: block;
    border: 1.2pt solid #333;
    padding: 12pt;
    border-radius: 3pt;
    background: #fff;
    color: #000;
    font-family: var(--md-text-font-family, sans-serif);
    page-break-inside: avoid;
    /* Force the info block onto page 2. Many will only print page 1. */
    page-break-after: always;
  }
  .calculator .shop-card h2 {
    margin: 0 0 6pt;
    font-size: 13pt;
  }
  /* Procedural note — the workshop reminder, like the on-screen hints. */
  .calculator .shop-card-note {
    margin: 0 0 9pt;
    font-size: 9.5pt;
    line-height: 1.45;
    color: #222;
  }
  /* Two dt/dd pairs per row keeps the spec table short, leaving the page
   * height for the drawings below. */
  .calculator .shop-card dl {
    display: grid;
    grid-template-columns: max-content 1fr max-content 1fr;
    gap: 3pt 14pt;
    margin: 0 0 10pt;
    font-size: 10pt;
  }
  .calculator .shop-card dt {
    font-weight: 600;
  }
  .calculator .shop-card dd {
    margin: 0;
  }

  /* Both routed views, stacked so each one prints large. */
  .calculator .shop-card-views {
    display: flex;
    flex-direction: column;
    gap: 8pt;
    page-break-inside: avoid;
  }
  .calculator .shop-card-views .calc-figure {
    margin: 0;
    page-break-inside: avoid;
  }
  .calculator .shop-card-views figcaption {
    font-size: 8.5pt;
    color: #333;
    margin-bottom: 2pt;
  }
  .calculator .shop-card-views svg {
    display: block;
    height: 82mm;
    width: auto;
    max-width: 100%;
    margin: 0 auto;
    background: #fff;
  }

  /* The optional info page (page 2). Many will only print page 1; this
   * is the reference detail for what each derived dimension means. */
  .calculator .shop-card-info {
    display: block;
    page-break-before: always;
    page-break-inside: avoid;
    font-family: var(--md-text-font-family, sans-serif);
    color: #222;
    font-size: 10.5pt;
    line-height: 1.5;
  }
  .calculator .shop-card-info h2 {
    margin: 0 0 8pt;
    font-size: 13pt;
  }
  .calculator .shop-card-info p {
    margin: 0 0 8pt;
  }
  .calculator .shop-card-info ul {
    margin: 0 0 8pt;
    padding-left: 18pt;
  }
  .calculator .shop-card-info li {
    margin: 0 0 5pt;
  }
  .calculator .shop-card-info code {
    background: #f1eee5;
    border-radius: 2pt;
    padding: 0 3pt;
    font-size: 9.5pt;
  }
}
