/* Tool pages: the KDP cover calculator and the KDP royalty calculator.
   Loaded after v3.css and built only from its tokens, so the tools share the
   site's white ground, near-black ink, Instrument Sans for words and IBM Plex
   Mono for every number. No dark band is used on these pages. */

/* The tool sits right under the page opener. */
.tool-sec { padding-top: 0; }
.tool-jump { margin-top: 18px; font-size: var(--fs-small); color: var(--muted); }
.tool-jump a { color: var(--ink); font-weight: 600; }

.tool {
  border-top: 1px solid var(--ink);
  padding-top: 24px;
}
.tool__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 28px;
}
.tool__k {
  font-family: var(--mono);
  font-size: var(--fs-mono);
  color: var(--faint);
}
.tool__panel + .tool__panel { margin-top: clamp(48px, 6vw, 72px); }
.tool__panel[hidden] { display: none; }
.tool__panel:focus-visible { outline-offset: 6px; }
.tool__h {
  font-size: clamp(1.25rem, 1.05rem + 0.7vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 20px;
}

.tool__grid {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 7fr);
  gap: 40px clamp(32px, 5vw, 72px);
  align-items: start;
}

/* Inputs */
.tool__inputs {
  display: grid;
  gap: 20px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.tool__inputs > legend { padding: 0; margin-bottom: 4px; }
.tool__inputs[hidden] { display: none; }
.field { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > label,
.field > legend {
  padding: 0;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--ink);
}
.field > legend { margin-bottom: 8px; }
.field__hint { font-size: 0.875rem; line-height: 1.5; color: var(--faint); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-row[hidden] { display: none; }

.input,
.select {
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.2;
  transition: border-color 0.2s var(--ease-soft);
}
.input {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.input::-webkit-outer-spin-button,
.input::-webkit-inner-spin-button { margin: 0; }
.select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%235b5b61' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 15px center;
  background-size: 12px 8px;
  cursor: pointer;
}
.input:hover,
.select:hover { border-color: var(--soft); }
.input:focus-visible,
.select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--ink);
  border-radius: 10px;
}
.input[aria-invalid="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

/* A unit or currency sign set inside the field. */
.affix { position: relative; display: block; }
.affix > span {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 0.9375rem;
  color: var(--faint);
  pointer-events: none;
}
.affix--pre > span { left: 14px; }
.affix--pre .input { padding-left: 30px; }
.affix--post > span { right: 14px; }
.affix--post .input { padding-right: 44px; }

/* Segmented radio choice (Paperback or eBook). */
.choice {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  width: fit-content;
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(12, 12, 13, 0.04);
}
.choice label {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 9px;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.25s var(--ease-soft), color 0.25s var(--ease-soft);
}
.choice label:hover { color: var(--ink); }
.choice input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.choice label.is-on,
.choice label:has(input:checked) { background: var(--btn-bg); color: var(--btn-fg); }
.choice label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Results */
.tool__out { min-width: 0; }
.keys {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.9fr);
  border-top: 1px solid var(--line);
}
.keys--even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.keys[hidden],
.diagram-fig[hidden] { display: none; }
.key { min-width: 0; padding: 18px 20px 20px 0; border-bottom: 1px solid var(--line); }
.key + .key { padding-left: 20px; padding-right: 0; border-left: 1px solid var(--line); }
.key__k { font-family: var(--mono); font-size: var(--fs-mono); color: var(--faint); }
.key__v {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: clamp(1.5rem, 1.1rem + 1.2vw, 2.125rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.035em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.key__s {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: var(--fs-mono);
  line-height: 1.5;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tool__out .math { margin-top: 24px; border-top: 0; padding-top: 0; }
.tool__sub { margin-top: 28px; }
.tool__out .tool__sub + .files { margin-top: 10px; }
.tool__out .files { margin-top: 24px; }
.tool__out .files dd { font-variant-numeric: tabular-nums; }
.tool__out .files > div { grid-template-columns: 150px minmax(0, 1fr); }
.tool__out .files dt { white-space: normal; }

.tool__error {
  padding: 14px 0 14px 16px;
  border-left: 2px solid var(--ink);
  color: var(--ink);
  font-weight: 600;
}
.tool__error[hidden],
.tool__results[hidden] { display: none; }

.flags { display: grid; gap: 10px; margin-top: 20px; }
.flags:empty { display: none; }
.flag {
  padding: 10px 0 10px 16px;
  border-left: 2px solid var(--ink);
  font-size: var(--fs-small);
  line-height: 1.55;
  color: var(--ink-2);
}

.tool__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 24px; }
.tool__actions[hidden] { display: none; }
.tool__status { font-size: var(--fs-small); color: var(--muted); min-height: 1.5em; }

/* The flat wrap, drawn to scale. Labels sit in HTML so they stay readable at
   any width. */
.diagram { position: relative; margin-top: clamp(36px, 4.5vw, 56px); }
.diagram svg { display: block; width: 100%; height: auto; overflow: visible; }
.diagram__lbl {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--mono);
  font-size: var(--fs-mono);
  color: var(--faint);
  white-space: nowrap;
  pointer-events: none;
}
.d-bleed { fill: var(--paper-3); stroke: var(--line-strong); stroke-width: 1; }
.d-trim { fill: var(--paper); stroke: var(--ink); stroke-width: 1.25; }
.d-spine { fill: var(--paper-2); stroke: none; }
.d-fold { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 6 4; }
.d-safe { fill: none; stroke: var(--soft); stroke-width: 1; stroke-dasharray: 3 3; }
.d-spine-safe { fill: none; stroke: var(--soft); stroke-width: 1; stroke-dasharray: 3 3; }
.d-barcode { fill: var(--paper-3); stroke: var(--muted); stroke-width: 1; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
  color: var(--faint);
}
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.legend i { display: inline-block; width: 18px; height: 12px; border: 1px solid var(--line-strong); background: var(--paper); }
.legend .lg-bleed { background: var(--paper-3); }
.legend .lg-trim { border-color: var(--ink); }
.legend .lg-fold { height: 0; border: 0; border-top: 1px dashed var(--ink); }
.legend .lg-safe { border: 1px dashed var(--soft); }
.legend .lg-bar { background: var(--paper-3); border-color: var(--muted); }

/* Data tables inside a tool panel (the prose tables below use .prose). */
.tool-table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); line-height: 1.5; }
.tool-table caption {
  caption-side: top;
  text-align: left;
  padding-bottom: 10px;
  font-family: var(--mono);
  font-size: var(--fs-mono);
  color: var(--faint);
}
.tool-table th,
.tool-table td { text-align: left; vertical-align: top; padding: 11px 16px 11px 0; border-bottom: 1px solid var(--line); }
.tool-table thead th { font-family: var(--mono); font-size: var(--fs-mono); font-weight: 500; color: var(--faint); border-bottom-color: var(--ink); }
.tool-table tbody th { font-weight: 500; color: var(--muted); }
.tool-table td { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.tool-table tr.is-current th,
.tool-table tr.is-current td { color: var(--ink); font-weight: 600; }

.tool-more { margin-top: clamp(40px, 5vw, 56px); }
.tool-more .h3 { margin-bottom: 8px; }
.tool-more p { font-size: var(--fs-small); color: var(--muted); max-width: 64ch; }
.tool-more p + p { margin-top: 8px; }

/* Numbers inside long-form tables. */
.prose .num { font-family: var(--mono); font-size: 0.9375em; font-variant-numeric: tabular-nums; }
.prose .tc-sub {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: var(--fs-mono);
  font-weight: 400;
  color: var(--faint);
}
.prose .math { margin-top: 1.4em; }
.prose .tbox { margin-top: 1.6em; }
.prose .tbox ul { margin-top: 10px; padding-left: 1.2em; font-size: var(--fs-small); }

@media (max-width: 920px) {
  .tool__grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .keys,
  .keys--even { grid-template-columns: minmax(0, 1fr); }
  .key + .key { padding-left: 0; border-left: 0; }
  .tool__out .files > div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .field-row { gap: 10px; }
}
@media print {
  .tool__bar, .tool__actions { display: none !important; }
}
