* { box-sizing: border-box; }

:root {
  /* Center correction derived from rosa.png (~+2px,+1.5px on a 1641px image) */
  --e6b-ring-x: -0.122%;
  --e6b-ring-y: -0.091%;
  /* Clockwise rotation to align rosa with arrow center */
  --e6b-ring-rot: 1deg;
  --e6b-face-x: 0px;
  --e6b-face-y: 0px;
}

body {
  font-family: system-ui, sans-serif;
  background: #f6f7f8;
  margin: 0;
  padding: clamp(8px, 1.2vw, 14px);
  color: #1f2d3d;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.report-note {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #e1e6ee;
  border-radius: 8px;
  background: #fafbfc;
  color: #5b6775;
  font-size: 12px;
}

.report-note a {
  color: inherit;
  text-decoration: underline;
}

.report-note--inside {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f6f8fb;
}

.page {
  width: 100%;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: start;
  height: 100%;
}

.stack > .card {
  width: 100%;
}

.e6b-mini {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card {
  width: 100%;
  background: #fff;
  margin: 0;
  padding: 16px;
  border-radius: 6px;
  border: 1px solid #dcdcdc;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.logo-link {
  display: inline-flex;
  line-height: 0;
  text-decoration: none;
}

.titles h1,
.titles h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.1;
  color: #1f2d3d;
}

.subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: #56606a;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
}

/* Prevent overflow on tablet/mobile widths (e.g. 768px) where the 720px breakpoint
   doesn't apply but the fixed label widths + long inline labels can push content out. */
@media (max-width: 920px) {
  .row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  label {
    width: auto;
  }

  /* Keep radio + text together and allow wrapping */
  .row label.inline {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: normal;
  }

  /* The calculated temperature line should not rely on a desktop left margin */
  .temp-display {
    margin-left: 0;
  }

  .row input:not([type="radio"]):not([type="checkbox"]),
  .row select {
    width: 100%;
    max-width: 100%;
  }

  .row input[type="radio"],
  .row input[type="checkbox"] {
    width: auto;
  }
}

label {
  width: 190px;
}

label.inline {
  width: auto;
  white-space: nowrap;
}

.abbr {
  display: inline-block;
  margin-left: 6px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #355c9d;
}

input, select {
  padding: 7px 8px;
  border-radius: 4px;
  border: 1px solid #cfd4da;
  background: #f1f3f5;
  font-size: 14px;
}

/* Darker background for calculated data */
input[readonly] {
  background: #e2e7ee;
}

input:disabled {
  background: #e9ecef;
}

.unit {
  width: 90px;
}

.temp-display {
  margin-left: 190px;
  font-weight: 600;
}

hr {
  margin: 14px 0;
  border-top: 1px solid #ddd;
}

.theory {
  margin-top: 18px;
  padding-top: 8px;
}

.theory summary {
  cursor: pointer;
  font-weight: 700;
  color: #1f2d3d;
}

.theory p {
  margin: 10px 0;
  line-height: 1.45;
  color: #2b2b2b;
}

.theory .muted {
  color: #56606a;
  font-size: 13px;
}

.equations {
  margin: 10px 0 12px;
  padding: 10px 12px;
  background: #f7f9fc;
  border: 1px solid #e3e8f0;
  border-radius: 6px;
  overflow-x: auto;
}

/* Toggle */
.toggle {
  position: relative;
  width: 46px;
  height: 24px;
}
.toggle input { display: none; }

.slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 24px;
}
.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
}

.toggle input:checked + .slider {
  background: #355c9d;
}
.toggle input:checked + .slider::before {
  transform: translateX(22px);
}

button {
  margin-top: 18px;
  padding: 8px 18px;
  border-radius: 4px;
  border: 1px solid #355c9d;
  background: white;
  color: #355c9d;
  cursor: pointer;
}

/* E6B styles (kept visually consistent with the card above) */
.e6b .card-header {
  border-bottom: 1px solid #eee;
}

.section-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 800;
  color: #1f2d3d;
}

.e6b-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.e6b-form {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.e6b-mini-form {
  gap: 6px;
  margin: 0;
}

.e6b-mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.mini-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mini-toggle {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #cfd4da;
  background: #f1f3f5;
  color: #1f2d3d;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.mini-toggle:hover {
  background: #e7ebf0;
}

.mini-toggle:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.e6b-mini .mini-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: #1f2d3d;
}

.e6b-mini .field {
  grid-template-columns: 160px 1fr;
  gap: 10px;
}

/* Mini card mode toggles */
.e6b-mini[data-mode="windTriangle"] .only-windSolve {
  display: none;
}

.e6b-mini[data-mode="windSolve"] .only-windTriangle {
  display: none;
}

@media (max-width: 1060px) {
  .e6b-mini-grid {
    grid-template-columns: 1fr;
  }

  .stack {
    height: auto;
  }

  .e6b-mini {
    flex: 0 0 auto;
  }
}

.field {
  display: grid;
  grid-template-columns: 200px 1fr;
  align-items: center;
  gap: 14px;
}

.control {
  position: relative;
  display: flex;
  align-items: center;
}

.control.split {
  gap: 10px;
}

.mini-control {
  position: relative;
  flex: 1 1 0;
  display: flex;
  align-items: center;
}

.mini-control input {
  width: 100%;
}

.mini-control .suffix {
  position: absolute;
  right: 10px;
}

.control.has-toggle input {
  padding-right: 12px;
}

.control.has-toggle {
  gap: 10px;
}

.control.has-toggle .suffix {
  position: static;
  right: auto;
  pointer-events: none;
}

.unit-switch {
  position: relative;
  width: 42px;
  height: 24px;
  display: inline-block;
  flex: 0 0 auto;
}

.unit-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.unit-switch .track {
  position: absolute;
  inset: 0;
  background: #cfcfcf;
  border-radius: 999px;
}

.unit-switch .thumb {
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform .18s ease;
}

.unit-switch input:checked ~ .track {
  background: #355c9d;
}

.unit-switch input:checked ~ .thumb {
  transform: translateX(18px);
}

.unit-switch input:focus-visible ~ .track {
  outline: 3px solid rgba(53, 92, 157, 0.25);
  outline-offset: 2px;
}

.e6b input {
  width: 100%;
  padding: 8px 38px 8px 12px;
  border-radius: 4px;
  border: 1px solid #cfd4da;
  background: #f1f3f5;
  font-size: 14px;
  outline: none;
}

.e6b input[readonly] {
  background: #e9ecef;
}

.e6b input.invalid {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
}

.suffix {
  position: absolute;
  right: 10px;
  font-size: 12px;
  color: #56606a;
  pointer-events: none;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.e6b-warning {
  margin: 8px 0 14px;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.12);
  color: #7a4b00;
  font-size: 12px;
  font-weight: 650;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  margin-bottom: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #1f2d3d;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.1);
}

.swatch.wind { background: #1976d2; }
.swatch.wca  { background: #f9a825; }
.swatch.course { background: #d32f2f; }
.swatch.heading { background: #111; }
.swatch.gs { background: #d32f2f; }
.swatch.tas { background: #111827; }

.svg-wrap {
  display: grid;
  place-items: center;
  border-top: 1px solid #eee;
  padding-top: 10px;
}

#e6b_compass {
  width: 100%;
  max-width: 520px;
  height: auto;
}

/* Compact mode for shorter viewports (avoid scrolling on typical laptops) */
@media (max-height: 820px) {
  body { padding: 8px; }
  .grid { gap: 10px; }
  .stack { gap: 10px; height: auto; }
  .card { padding: 14px; }
  .logo { width: 46px; height: 46px; }
  .titles h1 { font-size: 18px; }
  .subtitle { font-size: 12px; }
  .row { margin: 6px 0; }
  hr { margin: 12px 0; }
  .section-title { font-size: 14px; margin-bottom: 8px; }
  .e6b-form { gap: 6px; margin-bottom: 10px; }
  .field { grid-template-columns: 180px 1fr; gap: 10px; }
  .e6b input { padding: 7px 34px 7px 10px; }
  #e6b_compass { max-width: 470px; }
  button { margin-top: 12px; }

  .e6b-mini .mini-title { margin-bottom: 6px; }
  .e6b-mini-grid { gap: 10px; }
  .e6b-mini .field { grid-template-columns: 150px 1fr; }
  .e6b-mini { flex: 0 0 auto; }
}

#e6b_ring {
  pointer-events: none;
  transform: translate(var(--e6b-ring-x), var(--e6b-ring-y)) rotate(var(--e6b-ring-rot));
  transform-origin: center;
  transform-box: fill-box;
}

#e6b_face {
  transform: translate(var(--e6b-face-x), var(--e6b-face-y));
  transform-origin: center;
  transform-box: fill-box;
}

/* When using the ring image, the big N/E/S/W letters are redundant */
.cardinal {
  opacity: 0;
  font-size: 26px;
  font-weight: 900;
  fill: #2563eb;
}

#e6b_windBarbs {
  opacity: 0.95;
}

#e6b_wcaGuide1,
#e6b_wcaGuide2 {
  stroke: rgba(249, 168, 37, 0.95);
  stroke-width: 2;
  stroke-dasharray: 6 6;
}

#e6b_wcaArc {
  stroke: rgba(249, 168, 37, 0.95);
  stroke-width: 4;
  stroke-linecap: round;
}

.wca-label {
  font-size: 14px;
  font-weight: 800;
  fill: #b26c00;
  paint-order: stroke;
  stroke: rgba(247, 249, 252, 0.9);
  stroke-width: 4px;
}

.invalid-text {
  font-size: 18px;
  font-weight: 850;
  fill: #111827;
  paint-order: stroke;
  stroke: rgba(247, 249, 252, 0.95);
  stroke-width: 6px;
}

@media (max-width: 1180px) {
  body { padding: 12px; }
  .grid { grid-template-columns: 1fr; }
  #e6b_compass { max-width: 520px; }
}

@media (max-width: 720px) {
  .card { padding: 16px; }

  .row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  label { width: auto; }

  input, select { width: 100%; }
  .unit { width: 100%; }
  .temp-display { margin-left: 0; }
  button { width: 100%; }

  .e6b-grid { grid-template-columns: 1fr; }
  .field { grid-template-columns: 1fr; gap: 6px; }
  .legend { grid-template-columns: 1fr; }
}
