/* Logo font: Poppins (SIL Open Font License), served from our own site so it looks the same
   on PC, tablet and phone. Latin subset (ASCII). License in fonts/OFL.txt */
@font-face {
  font-family: 'Poppins';
  font-style: italic;
  font-weight: 700;
  font-display: block;
  src: url('fonts/Poppins-BoldItalic-latin.woff') format('woff');
}

@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 500;
  font-display: block;
  src: url('fonts/Poppins-Medium-latin.woff') format('woff');
}

:root {
  --gradient-bg: linear-gradient(135deg, #e62840 0%, #7b126d 50%, #120963 100%);
  --card-bg: rgba(18, 11, 48, 0.75);
  --card-border: rgba(255, 255, 255, 0.12);
  --box-bg: rgba(0, 0, 0, 0.25);
  --text-main: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.7);
  --text-footer: rgba(255, 255, 255, 0.55);
  --brand-blue: #1b1cdb;
  --speed-coral: #ff453a;
  --btn-gradient: linear-gradient(90deg, #ff453a 0%, #1b1cdb 100%);
  --btn-hover: linear-gradient(90deg, #ff5e54 0%, #3233f2 100%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gradient-bg);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.container {
  width: 100%;
  max-width: 480px;
}

.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 1.25rem 2rem 1.75rem 2rem;
  border-radius: 1.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--card-border);
  text-align: center;
}

.logo-wrapper {
  margin-bottom: 2rem;
}

.logo-link {
  text-decoration: none;
  display: inline-block;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.logo-link:hover {
  transform: scale(1.02);
  opacity: 0.95;
}

.logo-text {
  font-family: 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-synthesis: none;
  font-size: min(3.5rem, 11.4vw); /* "calculatest" is wide: smaller on narrow screens so it fits the card */
  font-weight: 700;
  font-style: italic;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Logo: one word, blue -> red gradient from the "c" to the "t" */
.logo-text .brand {
  background: linear-gradient(90deg, #1b1cdb 0%, #ff453a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  padding: 0 0.12em 0.1em 0.02em; /* room for the italic slant so the last "t" is not clipped */
  filter: drop-shadow(0 0 14px rgba(140, 50, 160, 0.55));
}

.tagline {
  font-family: 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-synthesis: none;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  margin-top: 0.4rem;
  opacity: 0.9;
}

/* Slogan under the descriptor: smaller, italic and muted */
.slogan {
  margin-top: 0.3rem;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); /* two columns, always the same width */
  gap: 1rem;
  margin-bottom: 2rem;
}

.metric-box {
  background: var(--box-bg);
  padding: 1.25rem;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.metric-box.full {
  grid-column: span 2;
}

.label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.value {
  font-size: 2rem;
  font-weight: 800;
  color: #ffffff;
  margin-top: 0.25rem;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.unit {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

.btn {
  width: 100%;
  background: var(--btn-gradient);
  color: #ffffff;
  border: none;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 1rem 1.5rem;
  border-radius: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 10px 25px -5px rgba(255, 69, 58, 0.4);
}

.btn:hover {
  background: var(--btn-hover);
  transform: translateY(-2px);
  box-shadow: 0 15px 30px -5px rgba(27, 28, 219, 0.5);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.footer-note {
  margin-top: 1.75rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.72rem;
  color: var(--text-footer);
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.info {
  margin-top: 1.25rem;
  text-align: left;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.info summary {
  cursor: pointer;
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.info ul {
  margin-top: 0.75rem;
  padding-left: 1.1rem;
  line-height: 1.45;
}

.info li {
  margin-bottom: 0.5rem;
}

.info strong {
  color: var(--text-main);
}

.last-test {
  margin-top: 0.9rem;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.conn-info {
  margin-top: 2.15rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.conn-info:not([hidden]) + .conn-info {
  margin-top: 0.3rem;
}

.conn-info strong {
  color: var(--text-main);
  font-weight: 700;
}

.last-test .elapsed {
  color: var(--text-main);
}

.note {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-muted);
  text-shadow: none;
}

.note.ok {
  color: #4ade80; /* green */
}

.note.ok-soft {
  color: #b7efc5; /* pastel green */
}

.note.caution {
  color: #ffe8a3; /* pastel yellow */
}

.note.warn {
  color: #ffbc8c; /* pastel orange */
}

.note.bad {
  color: #ff9eaa; /* pastel red */
}

.note.fail {
  color: #ff5c5c; /* red */
}

.last-test .running-phase {
  color: var(--text-main);
  font-weight: 700;
}

/* Notes table in the "How does this test work?" section */
.notes-table {
  width: 100%;
  margin-top: 0.5rem;
  border-collapse: collapse;
  font-size: 0.75rem;
  line-height: 1.35;
  background: var(--box-bg);
  border-radius: 0.6rem;
  overflow: hidden;
}

.notes-table th,
.notes-table td {
  padding: 0.4rem 0.55rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.notes-table tbody tr:last-child td {
  border-bottom: none;
}

.notes-table th {
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.06);
}

.notes-table td:first-child {
  white-space: nowrap;
}

.notes-table .note {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Colour dot, the same as the note text */
.notes-table .note::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Narrow screens (phone): each note in its own row, with the explanation below */
@media (max-width: 420px) {
  .notes-table thead {
    display: none;
  }

  .notes-table tr {
    display: block;
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .notes-table tbody tr:last-child {
    border-bottom: none;
  }

  .notes-table td {
    display: block;
    padding: 0;
    border-bottom: none;
  }

  .notes-table td + td {
    margin-top: 0.15rem;
    padding-left: 0.9rem; /* aligned with the text, after the colour dot */
  }
}

/* Data usage note above the button (since V040, so it is seen before starting a test).
   The negative top margin brings it closer to the button than to the result boxes. */
.data-note {
  margin: -1rem 0 0.75rem;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--text-footer);
}

/* Mobile data detected: pastel yellow, the same as "limited data" */
.data-note.warn {
  color: #ffe8a3;
  font-weight: 600;
}

/* Footer: each piece stays whole; if it does not fit, the line breaks between pieces */
.footer-note .seg {
  white-space: nowrap;
}

/* Narrow screens (phone): in DOWNLOAD and UPLOAD the "Mbps" unit always goes on the line below
   (with real results it already did; this way "--" and results look the same). Less side padding
   in the boxes and slightly smaller numbers below ~410 px, so that 1000.0 fits. */
@media (max-width: 520px) {
  .metric-box:not(.full) {
    padding: 1.25rem 0.5rem;
  }

  .value {
    font-size: min(2rem, 7.8vw);
  }

  .metric-box:not(.full) .value .unit {
    display: block;
  }
}

/* "Debug mode" switch in "How does this test work?": small, pastel red (OFF) / pastel green (ON).
   The real checkbox is visually hidden but still usable with the keyboard and screen readers. */
.debug-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
}

.debug-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.debug-toggle .switch {
  position: relative;
  flex-shrink: 0;
  width: 20px;
  height: 11px;
  border-radius: 6px;
  background: #ff9eaa; /* pastel red */
  transition: background 0.2s ease;
}

.debug-toggle .switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2a1640;
  transition: left 0.2s ease;
}

.debug-toggle .state {
  font-size: 0.7rem;
  font-weight: 700;
  color: #ff9eaa;
}

.debug-toggle input:checked + .switch {
  background: #b7efc5; /* pastel green */
}

.debug-toggle input:checked + .switch::after {
  left: 11px;
}

.debug-toggle input:checked ~ .state {
  color: #b7efc5;
}

.debug-toggle input:focus-visible + .switch {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* Disabled while a test is running (switching would reload the page) */
.debug-toggle:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

/* "Debug Mode" label under the button text, only with ?debug=1 (pastel red, as the switch OFF).
   A pseudo-element is used so it stays when the script changes the button text. */
.btn.debug-on::after {
  content: "Debug Mode";
  display: block;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #ff9eaa; /* pastel red */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
