/* Base typography and color palette */
:root {
  --primary-color: #d32f2f;      /* brand red colour */
  --secondary-color: #222;       /* dark gray used for text */
  --background-color: #f7f7f7;   /* light background */
  --card-bg: #ffffff;            /* card background */
  --border-radius: 6px;
  --box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);

  /*
   * Header sizing variables
   *
   * These CSS custom properties centralise control of the logo height,
   * heading font-size and navigation button dimensions. Adjust them
   * here rather than editing multiple declarations throughout the
   * stylesheet. The values use `clamp()` so that they scale with
   * viewport width but remain within sensible bounds.
   */
  --logo-height: clamp(20px, 12vw, 30px);
  --header-title-font-size: clamp(18px, 4vw, 32px);
  --nav-btn-padding: 0.5rem 0.5rem;
  --nav-btn-font-size: 1rem;

  --header-padding-y: clamp(6px, 2vw, 16px);
  --header-padding-left: clamp(1px, 2vw, 32px);
  --header-padding-right: clamp(1px, 2vw, 32px);
  --header-gap: clamp(8px, 2vw, 16px);

  --brand-logo-height: 180px;
  --brand-logo-gap: clamp(12px, 12vw, 60px);
  --brand-strip-padding-y: 2px;
  --brand-strip-margin-y: 2px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--background-color);
  color: var(--secondary-color);
  line-height: 1.6;
}

header.site-header {
  /*
   * Use a three‑column grid for the header. The first column holds
   * the logo, the second holds the page title and the third holds
   * the navigation controls. Each column occupies one third of the
   * header width, ensuring consistent proportions across devices.
   */
  display: grid;
  grid-template-columns: max-content 1fr max-content;
  align-items: center;
  column-gap: var(--header-gap);
  padding-top: var(--header-padding-y);
  padding-bottom: var(--header-padding-y);
  padding-left: var(--header-padding-left);
  padding-right: var(--header-padding-right);
  background: #000;
  color: #fff;
}

header.site-header .logo {
  /* Position logo in the first grid column and let it scale via
   * the CSS variable defined on :root. `width: 100%` and
   * `object-fit: contain` keep the aspect ratio without overflowing
   * its cell. */
  grid-column: 1;
  height: var(--logo-height);
  object-fit: contain;
}

header.site-header h1 {
  /* Place the heading in the second grid column. Keep the text from
   * wrapping and use the CSS variable for responsive sizing. Set
   * `min-width: 0` so it shrinks within its column rather than
   * overflowing. */
  grid-column: 2;
  white-space: nowrap;
  word-break: keep-all;
  line-height: 1.2;
  font-size: var(--header-title-font-size);
  font-weight: 600;
  margin: 0;
  min-width: 0;
  overflow: visible;
  text-align: left;
}

header.site-header h1 .title-en {
  margin-right: 0.4rem;
}

@media (max-width: 450px) {
  /* Hide the English text on small screens; this avoids text
   * wrapping issues while still presenting the essential Chinese
   * branding. */
  header.site-header h1 .title-en {
    display: none;
  }
}

/* Navigation link container positioned on the right side of the header */
header.site-header .nav-links {
  /* Place navigation controls in the third grid column. Push them to
   * the far right of their cell via `justify-self: end`. Use flex
   * layout to align the buttons horizontally with spacing. */
  grid-column: 3;
  margin-left: 0;
  justify-self: end;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Styles for navigation buttons */
header.site-header .nav-btn {
  color: #fff;
  background: transparent;
  border: 1px solid #fff;
  border-radius: var(--border-radius);
  /* Use CSS variables for sizing so the user can easily adjust
   * navigation button dimensions. */
  padding: var(--nav-btn-padding);
  font-size: var(--nav-btn-font-size);
  line-height: 1.2;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;
  text-align: center;
  /* Prevent text wrapping inside the buttons. */
  white-space: nowrap;
  word-break: keep-all;
  overflow: hidden;
}

header.site-header .nav-btn:hover {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

header.site-header .nav-btn.active {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

@media (max-width: 340px) {
  /* On very small devices reduce the size of the header elements via
   * the CSS variables. This keeps the header compact without
   * introducing separate height/font-size declarations. */
  :root {
    --logo-height: clamp(28px, 9vw, 48px);
    --header-title-font-size: clamp(11px, 5.2vw, 18px);
    --nav-btn-font-size: 0.8rem;
    --nav-btn-padding: 0.3rem 0.6rem;
  }
}

/* Main container: adjust for dual-column layout */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

/* Two-column layout container */
.layout-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

@media (min-width: 992px) {
  .layout-container {
    display: flex;
    gap: 1.5rem;
    /* Update */
    min-height: 0;
    align-items: flex-start;
  }
  .left-column {
    flex: 2;
  }
  /* Fix the right-hand info panel relative to the viewport */
  .layout-container .card.info {
    flex: 1;
    /* Use CSS sticky positioning with max-height and overflow-y so the content follows the scroll on wide screens */
    position: sticky;
    /* Top offset for the card relative to the viewport; adjust to match header height if needed */
    top: 0;
    align-self: flex-start;
    /* Limit visible height to viewport height minus the offset so the content scrolls within the card */
    max-height: calc(100vh - 0px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

section.card {
  background-color: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

section.card h2 {
  margin-top: 0;
  color: var(--primary-color);
  font-size: 1.3rem;
  margin-bottom: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
}

.form-group label {
  font-weight: 500;
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: var(--border-radius);
  font-size: 1rem;
}

button.primary-btn {
  background-color: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: var(--border-radius);
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
  margin-top: 0.5rem;
}

button.primary-btn:hover {
  background-color: #b71c1c;
}

/* Secondary buttons: used for bonus options on the street page */
button.secondary-btn {
  background-color: #ffffff;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
  border-radius: var(--border-radius);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
  margin-right: 0.5rem;
  margin-top: 0.3rem;
}
button.secondary-btn:hover {
  background-color: var(--primary-color);
  color: #fff;
}

.results {
  margin-top: 1rem;
  padding: 0.75rem;
  background-color: #f1f1f1;
  border-radius: var(--border-radius);
  border-left: 4px solid var(--primary-color);
}

.results p {
  margin: 0 0 0.5rem;
}

/* Group for cold/hot pressure inputs in Bonus section */
.pressure-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.5rem;
}

.pressure-group {
  flex: 1 1 200px;
  padding: 0.75rem;
  border: 2px solid #ccc;
  border-radius: var(--border-radius);
}

/* Blue border for cold tyre pressures */
.pressure-group.cold {
  border-color: #1976d2;
}

/* Red border for hot tyre pressures */
.pressure-group.hot {
  border-color: var(--primary-color);
}

/* Styles for appendix image containers */
.appendix-container {
  margin-top: 1rem;
}
.appendix-img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border: 1px solid #ddd;
  /* border-radius: var(--border-radius); */
}
.appendix-container figure {
  margin: 0 0 1rem;
  text-align: center;
}
.appendix-container figcaption {
  font-size: 0.85rem;
  color: #555;
  margin-top: 0.3rem;
}

/* Responsive sizing for appendix images on narrower screens.
 * On smaller devices the appendix tables can become overwhelming or force
 * horizontal scrolling. Reduce their maximum width gradually as the
 * viewport narrows so the tables remain legible without overflowing the
 * layout. The images remain centred via auto margins. */
@media (max-width: 992px) {
.appendix-container .appendix-img {
width: 80vw; /* 80% 的 viewport 寬度 */
max-width: 80vw; /* 保險起見，避免被其它 max-width 蓋掉 */
}
}

p.hint {
  font-size: 0.9rem;
  color: #666;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
}

section.info ul {
  padding-left: 1.2rem;
}

section.info li {
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.brand-strip {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  align-items: center;
  column-gap: var(--brand-logo-gap);
  padding: var(--brand-strip-padding-y) 0;
  margin: var(--brand-strip-margin-y) auto;
}

.brand-strip .brand-logo:first-child { grid-column: 2; justify-self: end; }
.brand-strip .brand-logo:last-child  { grid-column: 3; justify-self: start; }

.brand-strip .brand-logo {
  height: var(--brand-logo-height);
  width: auto
}

@media (max-width: 480px) {
  :root {
    --brand-logo-height: 120px;
    --brand-logo-gap: clamp(16px, 8vw, 80px);
  }
}

footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: #555;
}

/* ==========================================
 * Page-specific background images
 *
 * To visually distinguish between the track and street
 * guides, apply different photographic backgrounds
 * to each page. The images are placed behind a semi-
 * transparent white overlay via a CSS linear-gradient
 * so that text and UI elements remain clearly legible.
 *
 * The assets live in the `assets/` folder alongside
 * the HTML files. Adjust the opacity values below to
 * fine‑tune the visibility of the background photo.
 */
body.track-page {
  /* Top overlay (70% white) then the racetrack image */
  background-image: linear-gradient(rgba(255, 200, 200, 0.7), rgba(255, 255, 255, 0.9)),
    url('assets/race-track.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  /* Keep background fixed so it doesn’t scroll with content */
  background-attachment: fixed;
}

body.street-page {
  /* Top overlay (70% white) then the mountain road image */
  background-image: linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7)),
    url('assets/mountain-road.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
}

/*
 * Sub-card styles: used in the bonus pressure adjustment section to group
 * previous session data and next session inputs. Provides a subtle
 * background and border separation so users can more easily distinguish
 * the input fields.
 */
.sub-card {
  background-color: #f9f9f9;
  border: 1px solid #e5e5e5;
  border-radius: var(--border-radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.sub-card h3 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: var(--primary-color);
}