:root {
  --red: #c81e2c;
  --red-dark: #96131e;
  --red-tint: #fbeaea;
  --ink: #211d1a;
  --page: #ece9e2;
  --card: #fbfaf7;
  --line: #e1dcd2;
  --muted: #6b6358;
  --green: #2e7d4f;
  --green-tint: #eff7ee;

  /* material accent colors — used only for the tab dots and quiet
     material-coded touches, never for the primary CTA/result accent */
  --brass: #a9842c;
  --copper: #b1552b;
  --bronze: #7c6a42;

  --mono:
    ui-monospace, SFMono-Regular, Menlo, Consolas, "Roboto Mono",
    "Droid Sans Mono", "Liberation Mono", monospace;

  /* elevation: a restrained two-layer shadow (a tight contact shadow +
     a soft ambient falloff) instead of one flat grey shadow everywhere —
     applied with different strength per module so the main calculator
     card reads as the primary surface and the rest sit a step below it */
  --shadow-sm:
    0 1px 2px rgba(33, 29, 26, 0.05), 0 6px 16px -10px rgba(33, 29, 26, 0.14);
  --shadow-md:
    0 1px 2px rgba(33, 29, 26, 0.05), 0 14px 32px -14px rgba(33, 29, 26, 0.22);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
[hidden] {
  display: none !important;
}
body {
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  position: relative;
}

/* Faint tiled logo watermark across the whole page — a quiet premium
   texture, not a loud repeated graphic. The logo's white background
   is blended away with multiply so only a whisper of the red mark
   shows through; opacity keeps it from competing with real content. */
.bg-logos {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("logo.jpg");
  background-size: 110px 110px;
  background-repeat: repeat;
  opacity: 0.05;
  filter: grayscale(1);
  mix-blend-mode: multiply;
}
.app-header,
.app-footer,
.wrap {
  position: relative;
  z-index: 1;
}

/* ---- main ---- */
.wrap {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 22px 18px 60px;
}

/* ---- tabs: their own module card, grouped rows inside ---- */
.tabs-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 20px 18px;
  margin-bottom: 16px;
}
.tabs {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.tab-group {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.tab-group:first-child {
  padding-top: 0;
  border-top: none;
}
.tab-group-label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--ink);
  margin: 0 0 12px 1px;
}
.tab-group-label::before {
  content: "";
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: var(--red);
  flex-shrink: 0;
}
.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  padding: 10px 15px;
  border: 1.5px solid var(--line);
  background: var(--page);
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}
.tab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  box-shadow: 0 4px 12px -4px rgba(33, 29, 26, 0.35);
}
.tab-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--dot-color, var(--muted));
}
.tab-dot-brass {
  background: var(--brass);
}
.tab-dot-copper {
  background: var(--copper);
}
.tab-dot-bronze {
  background: var(--bronze);
}
.tab-sq {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--muted);
}
.tab.active .tab-sq {
  background: #fff;
  opacity: 0.8;
}

/* ---- card ---- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 26px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}

.mode-switch {
  display: flex;
  gap: 4px;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 26px;
}
.mode {
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  padding: 11px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}
.mode.active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 3px 10px -4px rgba(33, 29, 26, 0.4);
}

/* ---- fields ---- */
.field {
  margin-bottom: 20px;
}
.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.field-label {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
}
.field-unit-static {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
}

input[type="number"],
select {
  width: 100%;
  font-size: 16px;
  font-family: var(--mono);
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--page);
  box-shadow: inset 0 1px 2px rgba(33, 29, 26, 0.04);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
input[type="number"]::placeholder {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #9a9287;
}
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow:
    inset 0 1px 2px rgba(33, 29, 26, 0.04),
    0 0 0 3px rgba(33, 29, 26, 0.1);
}

.unit-tog,
.mat-tog {
  display: flex;
  border-radius: 999px;
  overflow: hidden;
  border: 1.5px solid var(--line);
}
.unit-btn,
.mat-btn {
  font-size: 12.5px;
  font-weight: 700;
  font-family: var(--mono);
  padding: 6px 13px;
  border: none;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.unit-btn.active,
.mat-btn.active {
  background: var(--ink);
  color: #fff;
}
.mat-tog {
  width: fit-content;
  margin-bottom: 6px;
}
.mat-btn {
  padding: 10px 22px;
  font-size: 13.5px;
  font-family: inherit;
}

.thickness-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.gauge-label {
  font-size: 12.5px;
  color: var(--muted);
}
#gaugeSel {
  width: auto;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 600;
}
.mm-btn {
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  padding: 6px 12px;
}
.mm-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.formula {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  margin: 14px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

/* ---- result readout: styled like a digital gauge display ---- */
.result-box {
  margin-top: 22px;
  background: linear-gradient(165deg, #2a2520, var(--ink) 60%);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  box-shadow: 0 14px 28px -16px rgba(33, 29, 26, 0.5);
}
.result-box::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--red);
  box-shadow: 0 0 14px 1px rgba(200, 30, 44, 0.6);
}
.result-label {
  font-size: 13px;
  font-weight: 600;
  color: #b9b2a9;
  padding-left: 10px;
}
.result-value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  color: #fff;
}
.result-unit {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--mono);
  color: #b9b2a9;
}

/* ---- pieces box ---- */
.pieces-box {
  margin-top: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}
.pieces-left {
  flex: 1;
}
.pieces-right {
  text-align: right;
}
.pieces-label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}
.pieces-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--page);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
}
.pieces-input-wrap input {
  border: none;
  padding: 8px 0;
  background: transparent;
  flex: 1;
  min-width: 0;
}
.pieces-input-wrap input:focus {
  outline: none;
}
.pieces-unit {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
}
.pieces-divider {
  font-size: 18px;
  color: var(--muted);
}
.pieces-value {
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 700;
  color: var(--green);
}

/* ---- PF thickness section: a nested inset module ---- */
.pf-section {
  margin-top: 16px;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px 6px;
}
.pf-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 12px;
}
.pf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}
.pf-cell {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.pf-cell:nth-last-child(-n + 2) {
  border-bottom: none;
}
.pf-code {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.pf-pct {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.pf-val {
  font-family: var(--mono);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
}
.pf-unit {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

/* ---- quote button + dialog ---- */
.quote-btn {
  width: 100%;
  margin-top: 22px;
  font-size: 14.5px;
  font-weight: 700;
  font-family: inherit;
  padding: 15px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 12px 24px -10px rgba(200, 30, 44, 0.55);
  transition:
    background 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}
.quote-btn:hover:not(:disabled) {
  background: var(--red-dark);
  box-shadow: 0 14px 28px -10px rgba(200, 30, 44, 0.6);
}
.quote-btn:active:not(:disabled) {
  transform: translateY(1px);
}
.quote-btn:disabled {
  background: var(--line);
  color: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(33, 29, 26, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
@media (min-width: 560px) {
  .overlay {
    align-items: center;
  }
}
.dialog {
  background: var(--card);
  width: 100%;
  max-width: 440px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 26px 22px 30px;
  position: relative;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 40px -12px rgba(33, 29, 26, 0.3);
}
@media (min-width: 560px) {
  .dialog {
    border-radius: var(--radius-lg);
  }
}
.dialog h2 {
  margin: 0 0 4px;
  font-size: 20px;
}
.dialog-sub {
  font-size: 13.5px;
  color: var(--muted);
  margin: 0 0 18px;
}
.dialog-close {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 22px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.dialog-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.dialog-label input,
.dialog-label textarea {
  font-size: 16px;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--page);
  font-family: inherit;
}
.dialog-label input:focus,
.dialog-label textarea:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  border-color: var(--ink);
}
.spec-preview {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
  white-space: pre-line;
}
.dialog-submit {
  width: 100%;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  padding: 13px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 10px 22px -10px rgba(200, 30, 44, 0.5);
}
.dialog-submit:hover {
  background: var(--red-dark);
}
.dialog-status {
  font-size: 13px;
  text-align: center;
  margin: 12px 0 0;
  color: var(--muted);
}

@media (max-width: 480px) {
  .pf-grid {
    grid-template-columns: 1fr;
  }
  .pf-cell:nth-last-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
  .pf-cell:last-child {
    border-bottom: none;
  }
}

/* Thickness row (label + Gauge select + mm toggle) was a single
   non-wrapping flex row, so it forced a ~360px minimum page width
   and caused horizontal scrolling on narrower phones. Let it wrap
   onto its own line below ~400px instead. */
@media (max-width: 400px) {
  .group-thickness .field-header {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .thickness-controls {
    width: 100%;
    flex-wrap: wrap;
  }
  #gaugeSel {
    flex: 1;
    min-width: 0;
  }
}

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

/* Circle views: Thickness (or Weight) comes first, then Diameter - same order as reference */
#calcForm {
  display: flex;
  flex-direction: column;
}
#calcForm .formula {
  order: 10;
}
#calcForm.is-circle .group-thickness,
#calcForm.is-circle .group-weight {
  order: -1;
}

.coil-hint {
  color: var(--red);
  order: 11;
  margin-top: -6px;
}

/* Coil tabs: title + short descriptor, stacked inside the same pill look */
.tab-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  line-height: 1.25;
  min-width: 0;
}
.tab-text small {
  font-size: 11.5px;
  font-weight: 500;
  opacity: 0.75;
  white-space: normal;
}
.tab:has(.tab-text) {
  border-radius: 18px;
  max-width: 100%;
}
@supports not selector(:has(*)) {
  .tab-text {
    display: block;
  }
}
