/* LSW Scale — white base, standard blue primary (#2B6CB0) */
:root {
  --bg: #ffffff;
  --bg-muted: #f7fafc;
  --blue: #2b6cb0;
  --blue-dark: #1a4f8b;
  --blue-soft: #ebf4ff;
  --blue-line: rgba(43, 108, 176, 0.18);
  --text: #1a202c;
  --text-muted: #4a5568;
  --green: #2f855a;
  --red: #c53030;
  --border: #e2e8f0;
  --radius: 6px;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --header-h: auto;
  --ad-left-w: 160px;
  --sidebar-w: 280px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  min-height: 100vh;
}

a {
  color: var(--blue);
}

a:hover {
  color: var(--blue-dark);
}

/* —— Header —— */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--blue);
  color: #fff;
  position: relative;
  z-index: 20;
}

.brand {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  line-height: 1.2;
  position: relative;
  z-index: 1;
  flex: 0 1 auto;
  max-width: calc(50% - 8rem);
}

.tagline {
  margin: 0;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.95rem;
  max-width: min(34rem, calc(100% - 22rem));
  width: max-content;
  pointer-events: none;
}

.info-menu {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  margin-left: auto;
}

.info-btn {
  appearance: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font: inherit;
}

.info-btn:hover,
.info-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.18);
}

.info-btn-icon {
  font-size: 1rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.info-box {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: min(340px, calc(100vw - 2rem));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(26, 79, 139, 0.2);
  padding: 0.75rem 0.9rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  z-index: 30;
}

.info-box[hidden] {
  display: none;
}

.info-box .credit {
  margin: 0 0 0.4rem;
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
}

.info-box p {
  margin: 0 0 0.35rem;
}

.info-box p:last-child {
  margin-bottom: 0;
}

.info-box .disclaimer {
  color: var(--text-muted);
  font-size: 0.72rem;
  border-top: 1px solid var(--border);
  padding-top: 0.35rem;
  margin-top: 0.35rem;
}

/* —— Page layout —— */
.page {
  display: grid;
  grid-template-columns: var(--ad-left-w) minmax(0, 1fr) var(--sidebar-w);
  gap: 1rem;
  padding: 1rem 1.25rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

.ad-slot {
  background: var(--bg-muted);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 0.7rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}

.ad-slot .ad-label {
  padding: 0.5rem;
  line-height: 1.3;
}

.ad-vertical {
  min-height: 600px;
  width: 100%;
  position: sticky;
  top: 0.75rem;
}

.ad-horizontal {
  width: 100%;
  min-height: 90px;
  margin-top: 0.75rem;
}

.main-col {
  min-width: 0;
}

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.panel-title {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
  color: var(--blue-dark);
  font-weight: 700;
}

.panel-heading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.65rem;
}

.panel-heading-row .panel-title {
  margin: 0;
}

.heading-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
  margin-left: auto;
}

.heading-controls .chart-hint {
  margin: 0;
}

.unit-toggle {
  display: flex;
  width: auto;
  min-width: 140px;
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

.direction-toggle {
  display: flex;
  width: 100%;
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

.unit-btn,
.direction-btn {
  appearance: none;
  flex: 1;
  border: none;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  line-height: 1.2;
}

.unit-btn + .unit-btn,
.direction-btn + .direction-btn {
  border-left: 1px solid var(--blue);
}

.unit-btn.is-active,
.direction-btn.is-active {
  background: var(--blue);
  color: #fff;
}

.unit-btn:hover:not(.is-active),
.direction-btn:hover:not(.is-active) {
  background: var(--blue-soft);
}

.calc-field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.btn-block {
  width: 100%;
  margin-top: 0.75rem;
}

.calc-formula {
  margin: 0.5rem 0 0;
  font-size: 0.72rem;
  color: var(--blue);
  font-family: ui-monospace, monospace;
  word-break: break-word;
}

.calc-formula[hidden] {
  display: none;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.toggle-group .group-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
}

.toggle-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.toggle-item input {
  accent-color: var(--blue);
  margin: 0;
}

.toggle-item .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.toggle-item .swatch-cone {
  background: linear-gradient(
    135deg,
    rgba(43, 108, 176, 0.35),
    rgba(43, 108, 176, 0.12)
  );
  border: 1px solid rgba(45, 55, 72, 0.45);
}

.toolbar-actions {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.btn:hover {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.btn-ghost {
  background: var(--bg);
  color: var(--blue);
}

.btn-ghost:hover {
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.chart-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.chart-wrap {
  position: relative;
  height: min(58vh, 520px);
  min-height: 320px;
}

.chart-tooltip {
  position: absolute;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(26, 79, 139, 0.15);
  padding: 0.65rem 0.8rem;
  font-size: 0.8rem;
  min-width: 200px;
  max-width: 280px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.chart-tooltip strong {
  display: block;
  color: var(--blue-dark);
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
}

.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.15rem 0;
  color: var(--text-muted);
}

.tip-row span:last-child {
  color: var(--text);
  text-align: right;
}

.tip-link {
  margin-top: 0.45rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}

.link-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.75rem;
}

/* —— Calculator —— */
.calc-panel .calc-intro {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.calc-field {
  margin-bottom: 0.65rem;
}

.calc-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.calc-field input,
.calc-field select {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

.calc-field input:focus,
.calc-field select:focus {
  outline: 2px solid var(--blue-soft);
  border-color: var(--blue);
}

.calc-result {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.calc-result h3 {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.calc-dims {
  list-style: none;
  margin: 0;
  padding: 0;
}

.calc-dims li {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  font-size: 0.9rem;
}

.calc-dims li span {
  color: var(--text-muted);
}

.calc-error {
  margin: 0;
  color: var(--red);
  font-size: 0.85rem;
}

.calc-panel .btn {
  width: 100%;
  margin-top: 0.25rem;
}

/* —— Responsive —— */
@media (max-width: 960px) {
  .site-header {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand info"
      "tagline tagline";
    text-align: left;
    align-items: start;
  }

  .brand {
    grid-area: brand;
    max-width: none;
  }

  .tagline {
    grid-area: tagline;
    position: static;
    transform: none;
    text-align: left;
    max-width: none;
    width: auto;
    pointer-events: auto;
  }

  .info-menu {
    grid-area: info;
    justify-self: end;
    align-self: start;
    margin-left: 0;
  }

  .page {
    grid-template-columns: 1fr;
  }

  .ad-vertical {
    display: none;
  }

  .ad-horizontal {
    order: 3;
  }
}

@media (max-width: 640px) {
  .chart-wrap {
    height: 360px;
  }

  .toolbar-actions {
    margin-left: 0;
    align-items: flex-start;
    width: 100%;
  }
}
