/* ==========================================================================
   Internet Speed Test Design System
   Pixel-accurate reproduction of Google Speed Test UI.
   Colors sampled directly from Google reference:
   - Header: #3e4245
   - Body: #252629
   - Unreached Track: #ececec
   - Download Active Track: #673db6
   - Upload Active Track: #00bcd4
   - Dividers: #464948
   - Typography: Google Sans / Roboto
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Roboto:wght@400;500;700&display=swap');

:root, html.theme-dark, body.theme-dark {
  --bg-page: #171717;
  --bg-card: #252629;
  --bg-header: #3e4245;
  --bg-surface: #2b2c30;
  --bg-hover: rgba(255, 255, 255, 0.08);

  --text-primary: #ffffff;
  --text-secondary: #9aa0a6;
  --text-muted: #707173;
  --text-link: #8ab4f8;

  --border-subtle: #464948;
  --border-divider: #464948;
  --border-light: rgba(255, 255, 255, 0.1);

  --track-bg: #ececec;
  --track-download: #673db6;
  --track-upload: #00bcd4;
  --knob-bg: #ffffff;
  --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);

  --btn-cancel-border: #5f6368;
  --btn-cancel-text: #ffffff;
  --btn-cancel-hover-bg: rgba(255, 255, 255, 0.08);

  --blue-btn: #1a73e8;
  --blue-btn-hover: #1557b0;
  --blue-btn-active: #0d47a1;

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-number: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --radius-card: 8px;
  --radius-pill: 9999px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

html.theme-light, body.theme-light {
  --bg-page: #f1f3f4;
  --bg-card: #ffffff;
  --bg-header: #f8f9fa;
  --bg-surface: #f1f3f4;
  --bg-hover: rgba(0, 0, 0, 0.05);

  --text-primary: #202124;
  --text-secondary: #5f6368;
  --text-muted: #80868b;
  --text-link: #1a73e8;

  --border-subtle: #dadce0;
  --border-divider: #dadce0;
  --border-light: rgba(0, 0, 0, 0.08);

  --track-bg: #e8eaed;
  --track-download: #673db6;
  --track-upload: #1a73e8;
  --knob-bg: #ffffff;
  --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);

  --btn-cancel-border: #dadce0;
  --btn-cancel-text: #1a73e8;
  --btn-cancel-hover-bg: rgba(26, 115, 232, 0.08);

  --blue-btn: #1a73e8;
  --blue-btn-hover: #1557b0;
  --blue-btn-active: #0d47a1;

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-number: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  font-family: var(--font-family);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* --------------------------------------------------------------------------
   App Wrapper & Main Speed Test Card
   -------------------------------------------------------------------------- */
.app-wrapper {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.speed-card {
  width: 100%;
  min-height: 595px;
  background-color: var(--bg-card);
  border-radius: var(--radius-card);
  border: 1px solid var(--border-divider);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-normal);
}

/* --------------------------------------------------------------------------
   Card Header (Exact match to reference #3e4245)
   -------------------------------------------------------------------------- */
.card-header {
  background-color: var(--bg-header);
  height: 54px;
  padding: 0 16px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-divider);
}

.card-title {
  font-size: 16px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: #ffffff;
}

html.theme-light .card-title {
  color: var(--text-primary);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: #9aa0a6;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.icon-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--blue-btn);
  outline-offset: 2px;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* --------------------------------------------------------------------------
   Testing View (Single Centered Speedometer Gauge)
   -------------------------------------------------------------------------- */
.testing-view {
  padding: 16px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  flex: 1;
}

.active-gauge-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

.xbPTxc {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.gauge-visual-wrap {
  width: 380px;
  height: 304px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.speed-gauge-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  display: block;
}

.gauge-track-bg {
  stroke: var(--track-bg);
  fill: none;
  stroke-linecap: round;
}

.gauge-track-active {
  fill: none;
  stroke-linecap: round;
}

.gauge-knob {
  fill: #ffffff;
}

.gauge-ticks text {
  font-family: var(--font-family);
  fill: var(--text-primary);
  font-size: 13px;
  font-weight: 400;
  user-select: none;
}

/* Central Numbers Display (Google's exact class Zz4rre) */
.Zz4rre {
  position: absolute;
  top: 62.5%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 75%;
  pointer-events: none;
}

.Fd0qyb {
  display: flex;
  align-items: baseline;
  justify-content: center;
  line-height: 1;
}

.NC4yhe {
  font-family: var(--font-number);
  font-size: 3.3rem; /* Scaled to match Google's larger reference slider */
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.Dto7td {
  font-family: var(--font-number);
  font-size: 2.35rem; /* Scaled to match Google's larger reference slider */
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  margin-left: 1px;
  line-height: 1;
}

.VdlJdf {
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 5px;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

/* Expected Network section positioned directly below MegaBytes per second */
.gauge-expected-net {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  line-height: 1.2;
}

.gauge-expected-net .exp-net-label {
  color: var(--text-secondary);
  opacity: 0.88;
}

.gauge-expected-net .exp-net-val {
  font-weight: 500;
  color: var(--text-primary);
}

/* Phase Indicators below gauge */
.gauge-phase-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 22px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 400;
}

.google-arrow-icon {
  width: 22px;
  height: 25px;
  color: var(--text-secondary);
  fill: currentColor;
}

/* --------------------------------------------------------------------------
   Live Metrics Row & Bottom Action Bar (During Test)
   -------------------------------------------------------------------------- */
.test-metrics-row {
  width: 100%;
  height: 80px;
  border-top: 1px solid var(--border-divider);
  border-bottom: 1px solid var(--border-divider);
  display: flex;
  align-items: center;
}

.metric-cell {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.cell-divider {
  width: 1px;
  height: 100%;
  background-color: var(--border-divider);
}

.live-metric-val {
  font-family: var(--font-number);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  min-height: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.live-metric-label {
  font-size: 13.5px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: 4px;
}

.test-action-bar {
  width: 100%;
  height: 84px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.btn-start-test-pill {
  background-color: var(--blue-btn);
  color: #ffffff;
  border: none;
  padding: 8px 22px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: all var(--transition-fast);
}

.btn-start-test-pill:hover {
  background-color: var(--blue-btn-hover);
}

.btn-start-test-pill:active {
  background-color: var(--blue-btn-active);
  transform: scale(0.98);
}

.btn-cancel {
  background: transparent;
  border: 1px solid var(--btn-cancel-border);
  color: var(--btn-cancel-text);
  padding: 7px 24px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-cancel:hover {
  background-color: var(--btn-cancel-hover-bg);
}

/* --------------------------------------------------------------------------
   Results View (Panel 3 - Final State)
   -------------------------------------------------------------------------- */
.results-view {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.results-metrics-box {
  display: flex;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-divider);
}

.results-metrics-box .metric-item {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.results-metrics-box .metric-value {
  font-family: var(--font-number);
  font-size: 2.35rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.results-metrics-box .metric-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: 2px;
}

.metrics-divider {
  width: 1px;
  height: 48px;
  background-color: var(--border-divider);
  margin: 0 16px;
}

.results-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
  line-height: 1.6;
}

.detail-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.detail-label {
  color: var(--text-secondary);
  font-weight: 400;
}

.detail-value {
  color: var(--text-primary);
  font-weight: 500;
}

.results-divider-space {
  height: 6px;
}

.connection-quality-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 6px;
}

.quality-summary {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-primary);
}

.quality-detail {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Results Action Buttons Row */
.results-action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 1px solid var(--border-divider);
}

.action-buttons-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-learn-more {
  background: transparent;
  border: none;
  color: var(--text-link);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.btn-learn-more:hover {
  background-color: var(--bg-hover);
}

.btn-test-again {
  background-color: var(--blue-btn);
  color: #ffffff;
  border: none;
  padding: 9px 24px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.btn-test-again:hover {
  background-color: var(--blue-btn-hover);
}

.btn-test-again:active {
  background-color: var(--blue-btn-active);
  transform: scale(0.98);
}

.feedback-link {
  color: var(--text-secondary);
  font-size: 13px;
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 4px;
  transition: color var(--transition-fast);
}

.feedback-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Modals (Learn More & Feedback)
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border-divider);
  border-radius: var(--radius-card);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-divider);
  background-color: var(--bg-header);
}

.modal-body {
  padding: 20px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.thresholds-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 13px;
}

.thresholds-table th, .thresholds-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-divider);
}

.thresholds-table th {
  color: var(--text-primary);
  font-weight: 500;
  background-color: var(--bg-surface);
}

.thresholds-table tr:hover {
  background-color: var(--bg-hover);
}

/* --------------------------------------------------------------------------
   Google AdSense Slot (Exact spot of the user's grey box)
   -------------------------------------------------------------------------- */
.results-ad-box {
  width: 100%;
  min-height: 105px;
  background-color: var(--bg-hover);
  border: 1px dashed var(--border-divider);
  border-radius: var(--radius-card, 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  transition: all var(--transition-fast);
}

.results-ad-box .adsbygoogle {
  width: 100%;
  min-height: 90px;
}

.ad-placeholder-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 14px 10px;
  pointer-events: none;
  user-select: none;
}

.ad-placeholder-label .ad-pill {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background-color: rgba(128, 128, 128, 0.18);
  padding: 3px 10px;
  border-radius: 4px;
}

.ad-placeholder-label .ad-slot-hint {
  font-size: 11.5px;
  color: var(--text-secondary);
  opacity: 0.85;
}

/* Once AdSense serves an ad or inserts an iframe */
.results-ad-box.ad-filled {
  border: none;
  background-color: transparent;
  min-height: auto;
}

.results-ad-box.ad-filled .ad-placeholder-label {
  display: none !important;
}
