:root {
  --bg: #f7fafc;
  --surface: #ffffff;
  --surface-soft: #eef5f7;
  --ink: #102029;
  --muted: #62717b;
  --border: #d9e5ea;
  --accent: #00c77b;
  --accent-strong: #03a96b;
  --blue: #246bfe;
  --warn: #f59f00;
  --danger: #e03131;
  --shadow: 0 22px 55px rgba(24, 44, 56, 0.12);
  --radius: 8px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #071216;
  --surface: #0e1c22;
  --surface-soft: #13272f;
  --ink: #f2fbff;
  --muted: #9eb1ba;
  --border: #24414b;
  --shadow: 0 24px 65px rgba(0, 0, 0, 0.34);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  max-width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 0%, rgba(36, 107, 254, 0.12), transparent 28rem),
    linear-gradient(180deg, var(--bg), var(--surface-soft));
  color: var(--ink);
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  max-width: 100%;
  margin: 0 auto;
  padding: 20px 0 54px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.05rem;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: var(--accent);
}

.brand-mark svg {
  width: 25px;
  fill: currentColor;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
}

.language-switcher {
  max-width: min(42vw, 210px);
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(18, 38, 48, 0.06);
  font-size: 0.9rem;
  font-weight: 850;
}

[data-theme="dark"] .language-switcher {
  background: rgba(14, 28, 34, 0.86);
}

.topbar-actions .unit-select {
  display: none;
}

.icon-button,
.unit-select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(18, 38, 48, 0.06);
}

[data-theme="dark"] .icon-button,
[data-theme="dark"] .unit-select {
  background: rgba(14, 28, 34, 0.86);
}

.icon-button {
  display: grid;
  width: 40px;
  place-items: center;
  padding: 0;
}

.icon-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.unit-select {
  padding: 0 34px 0 12px;
}

.speed-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.speed-copy h1 {
  margin: 0;
  max-width: none;
  font-size: clamp(1.55rem, 4vw, 2.2rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.speed-copy p {
  max-width: 520px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

.install-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  margin: 16px auto 0;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(18, 38, 48, 0.06);
  font-size: 0.92rem;
  font-weight: 850;
}

.install-button[hidden] {
  display: none;
}

.mode-selector {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  width: min(520px, 100%);
  max-width: 100%;
  margin: 16px auto 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.mode-button {
  overflow: hidden;
  min-height: 38px;
  min-width: 64px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 850;
}

.mode-button.is-active {
  background: var(--ink);
  color: var(--surface);
}

.speedometer {
  position: relative;
  overflow: hidden;
  width: min(760px, 100%);
  max-width: 100%;
  min-height: 500px;
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.72)),
    var(--surface);
  box-shadow: var(--shadow);
}

[data-theme="dark"] .speedometer {
  background:
    linear-gradient(145deg, rgba(14, 28, 34, 0.96), rgba(19, 39, 47, 0.7)),
    var(--surface);
}

.dial {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 1;
  margin: 0 auto;
}

.dial-track,
.dial-fill {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  mask: radial-gradient(circle, transparent 58%, #000 59%);
}

.dial-track {
  background: conic-gradient(from 225deg, var(--border) 0deg 270deg, transparent 270deg);
}

.dial-fill {
  background: conic-gradient(from 225deg, var(--accent) 0deg, var(--blue) var(--dial-deg, 0deg), transparent var(--dial-deg, 0deg));
  transition: background 240ms ease;
}

.needle {
  display: none;
}

.needle::after {
  content: none;
}

.speed-readout {
  position: absolute;
  inset: 108px 28px auto;
  display: grid;
  justify-items: center;
  pointer-events: none;
}

.speed-value {
  font-size: clamp(5.4rem, 12vw, 8.8rem);
  font-weight: 850;
  line-height: 0.86;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.speed-unit {
  margin-top: 12px;
  color: var(--muted);
  font-size: 1.08rem;
  font-weight: 750;
}

.unit-switch {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: min(320px, 92vw);
  max-width: 100%;
  margin-top: 14px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: 0 10px 22px rgba(18, 38, 48, 0.08);
  pointer-events: auto;
}

.unit-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.unit-button.is-active {
  background: var(--ink);
  color: var(--surface);
}

.status-line {
  min-height: 44px;
  margin: -18px auto 22px;
  max-width: 490px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.controls {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 48px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #031612;
}

.secondary-button {
  background: var(--ink);
  color: var(--surface);
}

.ghost-button {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}

.button-icon {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
}

.button-icon svg {
  width: 18px;
  fill: currentColor;
}

.button-icon path {
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.speedometer.is-alerting {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px rgba(224, 49, 49, 0.12), var(--shadow);
}

.modal-open {
  overflow: hidden;
}

.gps-modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 18, 22, 0.48);
  backdrop-filter: blur(7px);
}

.gps-modal[hidden] {
  display: none;
}

.gps-modal-card {
  width: min(520px, 100%);
  padding: clamp(22px, 4vw, 32px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 26px 80px rgba(7, 18, 22, 0.28);
}

.gps-modal-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  line-height: 1.15;
}

.gps-modal-copy {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.gps-modal-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.install-steps {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-inline-start: 20px;
  color: var(--muted);
}

.install-steps li {
  line-height: 1.45;
}

.gps-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.gps-modal-actions .ghost-button,
.gps-modal-actions .secondary-button {
  min-width: 104px;
  padding: 0 18px;
}

.gps-continue-button {
  outline: 3px solid color-mix(in srgb, var(--accent) 48%, transparent);
  outline-offset: 3px;
}

.speedometer.is-alerting .speed-value,
.status-line[data-tone="bad"],
.alert-state[data-tone="bad"] {
  color: var(--danger);
}

.status-line[data-tone="good"],
.alert-state[data-tone="good"] {
  color: var(--accent-strong);
}

.status-line[data-tone="warn"],
.alert-state[data-tone="warn"] {
  color: var(--warn);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
  margin-top: 18px;
}

.stat-card {
  min-width: 0;
  min-height: 106px;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.stat-label {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  font-size: clamp(1.28rem, 2vw, 1.8rem);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-card small {
  color: var(--muted);
  font-size: 0.85rem;
}

.privacy-strip {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 18px;
  padding: 20px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
}

.privacy-strip svg {
  flex: 0 0 auto;
  width: 34px;
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.privacy-strip h2,
.content-section h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

.privacy-strip p {
  margin: 6px 0 0;
  color: color-mix(in srgb, var(--surface) 74%, transparent);
  line-height: 1.55;
}

.tools-section {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
  min-width: 0;
  margin-top: 18px;
}

.tool-panel,
.history-section {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.panel-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 850;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.alert-controls {
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto;
  min-width: 0;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
}

.alert-controls label,
.alert-controls span,
.chart-scale {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 850;
}

.alert-controls input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 850;
}

.alert-state {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.chart-wrap {
  position: relative;
  min-width: 0;
  min-height: 236px;
}

.speed-chart {
  display: block;
  width: 100%;
  height: 220px;
  margin-top: 12px;
  overflow: visible;
  touch-action: none;
}

.chart-grid {
  fill: none;
  stroke: var(--border);
  stroke-width: 1;
}

.chart-area {
  fill: rgba(0, 199, 123, 0.12);
}

.chart-line {
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
}

.chart-axis {
  fill: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.chart-cursor {
  stroke: var(--ink);
  stroke-dasharray: 5 5;
  stroke-width: 1.5;
  opacity: 0.52;
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--blue);
  stroke-width: 4;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -100%);
  min-width: 112px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  padding: 8px 10px;
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  pointer-events: none;
}

.chart-empty {
  position: absolute;
  inset: 52% 22px auto;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.4;
  text-align: center;
}

.history-section {
  margin-top: 18px;
}

.compact-button {
  min-height: 38px;
  padding: 0 14px;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.history-empty {
  margin: 0;
  color: var(--muted);
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  min-width: 0;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.history-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  margin-bottom: 8px;
  font-weight: 900;
}

.history-title time {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.history-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 750;
}

.history-share {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 850;
}

.app-shell.is-fullscreen {
  min-height: 100vh;
  width: min(1280px, calc(100% - 28px));
}

.content-section {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 1.1fr);
  gap: 34px;
  min-width: 0;
  margin-top: 42px;
  padding-top: 34px;
  border-top: 1px solid var(--border);
}

.content-section p,
.faq-list p {
  color: var(--muted);
  line-height: 1.7;
}

.faq-list {
  display: grid;
  gap: 10px;
  min-width: 0;
}

details {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

summary {
  cursor: pointer;
  padding: 16px 18px;
  font-weight: 800;
}

details p {
  margin: 0;
  padding: 0 18px 18px;
}

.site-footer {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(3, minmax(150px, 0.8fr));
  gap: 24px;
  min-width: 0;
  margin-top: 42px;
  padding: 28px 0 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.site-footer nav {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.site-footer a {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.site-footer h2,
.site-footer h3 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.2;
}

.site-footer p {
  margin: 0;
}

.footer-brand {
  max-width: 330px;
}

.article-main {
  max-width: 860px;
  margin: 52px auto 0;
}

.article-main h1 {
  margin: 0;
  font-size: clamp(2.55rem, 7vw, 5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.article-main h2 {
  margin: 38px 0 10px;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.15;
}

.article-main p,
.article-main li {
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.75;
}

.article-main a {
  color: var(--blue);
  font-weight: 800;
}

[dir="rtl"] body {
  text-align: right;
}

[dir="rtl"] .brand,
[dir="rtl"] .topbar,
[dir="rtl"] .control-row,
[dir="rtl"] .mode-tabs,
[dir="rtl"] .stat-card,
[dir="rtl"] .history-title,
[dir="rtl"] .history-metrics,
[dir="rtl"] .site-footer,
[dir="rtl"] .content-section,
[dir="rtl"] .article-main {
  direction: rtl;
}

[dir="rtl"] .speed-readout,
[dir="rtl"] .unit-switcher,
[dir="rtl"] .gauge-wrap,
[dir="rtl"] .speed-chart {
  direction: ltr;
}

.article-panel {
  margin-top: 28px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.article-panel p {
  margin: 0;
}

@media (max-width: 880px) {
  .content-section,
  .tools-section {
    grid-template-columns: 1fr;
  }

  .site-footer {
    grid-template-columns: 1fr 1fr;
  }

  .speed-copy h1 {
    max-width: 100%;
    font-size: clamp(1.7rem, 8vw, 2.5rem);
  }

  .speedometer {
    min-height: 470px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 12px;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
  }

  .topbar .brand {
    flex: 1 1 auto;
  }

  .topbar .language-switcher {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
  }

  .topbar-actions {
    gap: 8px;
  }

  .brand span:last-child {
    font-size: 1rem;
  }

  .speed-section {
    gap: 18px;
  }

  .speed-copy p {
    margin-top: 12px;
    font-size: 0.98rem;
  }

  .speedometer {
    min-height: 500px;
    padding: 18px 14px;
  }

  .dial {
    width: min(100%, 420px);
  }

  .speed-readout {
    inset: 106px 14px auto;
  }

  .status-line {
    margin-top: -28px;
    font-size: 0.92rem;
  }

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

  .gps-modal {
    align-items: end;
    padding: 12px;
  }

  .gps-modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .mode-selector {
    width: 100%;
  }

  .mode-button {
    min-width: 0;
    padding: 0 4px;
    font-size: 0.78rem;
  }

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

  .stat-card {
    min-height: 96px;
    padding: 14px;
  }

  .privacy-strip {
    align-items: flex-start;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .site-footer {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
