/* KDP royalty calculator: this page only, on top of /style.css and /tools/tools.css. */

:root {
  --kdp-royalty: #b8862f;  /* gold: what the author earns */
  --kdp-cost: #36599f;     /* ink blue: printing or delivery */
  --kdp-tax: #c46f55;      /* terracotta: tax inside an eBook price */
  --kdp-amazon: #9aa3b8;   /* quiet grey-blue: the rest, Amazon's share */
  --kdp-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* the light that crosses the glass sits under the text, not over it (it washed out the top-left labels) */
.tool-card.glass::before, .tool-card .glass::before { z-index: -1; }

/* ---------- form ---------- */
.seg-2 label, .seg-3 label { flex: 1 1 0; min-width: 0; }
/* no spin arrows: they sat on top of the unit (USD, MB); the arrow keys still step the value */
.tool-form input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.tool-form input[type="number"]::-webkit-inner-spin-button,
.tool-form input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.seg-3 span { padding: 0 10px; }
.seg-paper label { flex: 1 1 auto; }
.seg label.is-off span { opacity: 0.4; cursor: not-allowed; }

.kdp-pair { align-items: end; }
.kdp-hints { margin-top: -14px; }
.kdp-hints .f-hint { margin-top: 0; }
.kdp-hints .f-hint + .f-hint { margin-top: 4px; }

.unit-field { position: relative; }
.tool-form .unit-field input { padding-right: 62px; }
.unit-field .unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--gold-deep);
  pointer-events: none;
}

.trim-hint { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.trim-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--hairline);
  white-space: nowrap;
}
.trim-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.trim-chip.is-large::before { background: var(--gold-line); }

/* ---------- the big figure ---------- */
.result-main { position: relative; }
.result-main .result-label { padding-right: 96px; }
.result-main .result-big { font-variant-numeric: lining-nums tabular-nums; white-space: nowrap; transition: opacity 0.3s var(--kdp-ease); }
.result-big.is-empty { opacity: 0.45; }
.result-big .cur, .peek-value .cur { font-size: 0.5em; font-weight: 500; color: #e2c47e; vertical-align: 0.62em; margin-right: 0.06em; }
.result-big .cur-after, .peek-value .cur-after { margin: 0 0 0 0.22em; vertical-align: 0.1em; }
.result-big.is-neg, .peek-value.is-neg { color: #f2b8ab; }
.result-big.is-neg .cur, .peek-value.is-neg .cur { color: #f2b8ab; }
.result-sub { line-height: 1.5; }

/* copy, on the card it copies: the label turns to "Copied" for a moment */
.card-copy {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 15px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 0.2s, border-color 0.2s, opacity 0.3s var(--kdp-ease), transform 0.2s var(--kdp-ease);
}
.card-copy:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.28); }
.card-copy:active { transform: scale(0.96); }
.card-copy:focus-visible { outline: 2px solid #e2c47e; outline-offset: 2px; }
.card-copy:disabled { opacity: 0; pointer-events: none; }
.card-copy svg { flex: none; }
.card-copy .cc-done { display: none; color: #e2c47e; }
.card-copy.is-done .cc-copy { display: none; }
.card-copy.is-done .cc-done { display: block; }
.anim .card-copy.is-done .cc-done { animation: cc-pop 0.36s var(--kdp-ease); }
@keyframes cc-pop { from { transform: scale(0.4); opacity: 0; } }

/* ---------- where the price goes ---------- */
.split { border-radius: 22px; padding: 16px 20px 15px; }
.split-title { font-family: var(--serif); font-size: 20px; font-weight: 600; line-height: 1.2; color: var(--ink); }
.split-bar { display: flex; height: 12px; margin-top: 12px; border-radius: 4px; overflow: hidden; }
.split-bar i { display: block; flex: 0 0 0; min-width: 0; margin-left: 2px; transition: flex-grow 0.45s var(--kdp-ease), margin 0.45s var(--kdp-ease); }
.split-bar i:first-child { margin-left: 0; }
.split-bar i.is-zero { margin-left: 0; }
.split-bar [data-k="royalty"], .split-legend [data-k="royalty"] i { background: var(--kdp-royalty); }
.split-bar [data-k="cost"], .split-legend [data-k="cost"] i { background: var(--kdp-cost); }
.split-bar [data-k="tax"], .split-legend [data-k="tax"] i { background: var(--kdp-tax); }
.split-bar [data-k="amazon"], .split-legend [data-k="amazon"] i { background: var(--kdp-amazon); }
.split-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 11px; font-size: 13.5px; color: var(--ink-soft); }
.split-legend li { display: inline-flex; align-items: center; gap: 7px; }
.split-legend i { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.split-legend b { font-weight: 600; color: var(--ink); font-variant-numeric: lining-nums tabular-nums; }

/* ---------- rows: label and its explanation on the left, the figure on the right ---------- */
.result-list .row { align-items: start; padding: 12px 0; }
.result-list dt { color: var(--ink); }
.result-list dt small { display: block; margin-top: 2px; font-size: 12.5px; line-height: 1.45; color: var(--ink-mute); }
.result-list dd { font-size: 16px; white-space: nowrap; }
.result-list dd .muted { font-weight: 500; color: var(--ink-mute); }

/* no lone word on the last line of a hint or a note */
.tool-card .f-hint, .tool-card .status, .est-note, .result-list dt small { text-wrap: pretty; }

/* ---------- notes: one quiet list, not a pile of cards ---------- */
.results .notes:not(:empty) {
  gap: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 10px 28px -20px rgba(29, 42, 69, 0.35);
}
.results .notes .status { gap: 10px; padding: 11px 15px; border: 0; border-radius: 0; background: none; font-size: 13.5px; line-height: 1.5; }
.results .notes .status + .status { border-top: 1px solid var(--hairline); }
.results .notes .status .dot { width: 20px; height: 20px; margin-top: 0; font-size: 11px; }

/* reference tables: tighter on a phone, so four columns fit without sideways scrolling */
@media (max-width: 559px) {
  .prose .ref-table { font-size: 13.5px; }
  .prose .ref-table th, .prose .ref-table td { padding: 10px 7px; }
  .prose .ref-table thead th { font-size: 11px; letter-spacing: 0.08em; }
}

/* ---------- how it is worked out: folded under the rows, opens softly ---------- */
.how { border-top: 1px solid var(--hairline); }
.how-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 48px;
  padding: 0 2px 0 0;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-align: left;
  color: var(--gold-deep);
  transition: color 0.2s;
}
.how-toggle:hover { color: var(--ink); }
.how-toggle:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 2px; }
.how-toggle i {
  flex: none;
  width: 12px;
  height: 12px;
  background:
    linear-gradient(var(--gold-deep), var(--gold-deep)) center / 12px 1.5px no-repeat,
    linear-gradient(var(--gold-deep), var(--gold-deep)) center / 1.5px 12px no-repeat;
  transition: transform 0.42s var(--kdp-ease);
}
.how.is-open .how-toggle i { transform: rotate(45deg); }
.how-body { display: grid; grid-template-rows: 0fr; visibility: hidden; transition: grid-template-rows 0.42s var(--kdp-ease), visibility 0s linear 0.42s; }
.how.is-open .how-body { grid-template-rows: 1fr; visibility: visible; transition-delay: 0s; }
.how-in { min-height: 0; overflow: hidden; }
.how-lines { display: grid; grid-template-columns: 1fr; gap: 8px; padding: 2px 0 16px; opacity: 0; transform: translateY(-4px); transition: opacity 0.28s var(--kdp-ease), transform 0.42s var(--kdp-ease); }
.how.is-open .how-lines { opacity: 1; transform: none; transition-delay: 0.06s; }
.how-line { display: flex; flex-direction: column; gap: 1px; }
.how-k { font-size: 12.5px; color: var(--ink-mute); }
.how-v { font-family: var(--serif); font-size: 18px; font-weight: 500; line-height: 1.35; color: var(--ink); font-variant-numeric: lining-nums tabular-nums; overflow-wrap: anywhere; }
.how-v em { font-style: italic; color: var(--gold-deep); }

.est-note { padding: 0 4px; font-size: 12.5px; line-height: 1.55; color: var(--ink-mute); }

/* ---------- phones: the royalty follows the form in a small bar at the foot ---------- */
.peek {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 44;
  display: flex;
  justify-content: center;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transform: translateY(calc(100% + 18px));
  transition: transform 0.46s var(--kdp-ease), opacity 0.3s var(--kdp-ease), visibility 0s linear 0.46s;
}
.peek.is-on { visibility: visible; opacity: 1; transform: none; transition-delay: 0s; }
.peek-in {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 30rem;
  min-height: 64px;
  padding: 8px 8px 8px 18px;
  border-radius: 22px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 20px 44px -14px rgba(29, 42, 69, 0.62), 0 4px 12px -4px rgba(29, 42, 69, 0.3);
}
.peek-text { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; margin: 0; }
.peek-value { flex: none; font-family: var(--serif); font-size: 30px; font-weight: 500; line-height: 1; white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }
.peek-value.is-empty { opacity: 0.5; }
.peek-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.peek-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.72; }
.peek-sub { font-size: 13px; line-height: 1.3; opacity: 0.92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peek-go {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 14px 0 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: var(--cream);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.2s, transform 0.2s var(--kdp-ease);
}
.peek-in:hover .peek-go { background: rgba(255, 255, 255, 0.18); }
.peek-in:active .peek-go { transform: scale(0.96); }
html:not(.anim) .peek { transform: none; transition: opacity 0.2s, visibility 0s linear 0.2s; }
html:not(.anim) .peek.is-on { transition-delay: 0s; }
@media (max-width: 899px) {
  /* a field the browser scrolls to stays clear of the bar */
  html { scroll-padding-bottom: 92px; }
}
@media (max-width: 479px) {
  /* on a phone the copy pill is a round button, so the label above the figure keeps one line */
  .result-main .result-label { padding-right: 52px; }
  .card-copy { top: 10px; right: 10px; width: 44px; padding: 0; justify-content: center; }
  .card-copy .cc-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (min-width: 900px) {
  .peek { display: none; }
}

/* ---------- call to action ---------- */
.kdp-cta { padding-top: 24px; }
.cta-card { border-radius: 32px; padding: 40px 22px 36px; text-align: center; }
.cta-card svg { margin: 0 auto; }
.cta-card h2 { margin-top: 18px; font-size: clamp(2.1rem, 5vw, 3.2rem); }
.cta-card p { max-width: 36rem; margin: 16px auto 0; color: var(--ink-soft); font-size: 16.5px; line-height: 1.7; }
.cta-card .cta-meta { margin-top: 12px; font-size: 13.5px; color: var(--ink-mute); letter-spacing: 0.02em; }
.cta-card .cta-row { margin-top: 26px; }
.tm-note { margin-top: 26px; text-align: center; font-size: 12.5px; line-height: 1.6; color: var(--ink-mute); }

/* the results run longer than the form: on wide screens the form stays in view beside them */
@media (min-width: 900px) {
  #kdp-form { position: sticky; top: 100px; }
}
@media (min-width: 520px) {
  .how-line { display: grid; grid-template-columns: 9.5rem 1fr; align-items: baseline; gap: 12px; }
}
@media (min-width: 640px) {
  .cta-card { padding: 52px 48px 46px; }
}
@media (max-width: 380px) {
  .seg-3 span { font-size: 13px; padding: 0 8px; }
}
