@import url("https://fonts.googleapis.com/css2?family=PT+Mono&family=Roboto:ital,wght@0,400;0,700;0,900;1,400;1,700;1,900&display=swap");

:root {
  --primary-color: #007bff;
  --dark-accent: #0056b3;
  --hover-color: #bde2ff;
  --active-color: #2196f3;
  --link-hover-color: #84caff;
  --soft-white: #f7f7f7;
  --soft-black: #333;
  --app-max-width: 800px;
  --width-limit: 540px;
  --toggle-color: #e9ecef;
  --slider-width: 54px;
  --slider-height: 30px;
  --uncertainty-color: #64748b;

  /* Fluid dial sizing: scale continuously so 4 dials + colon fit 360px
       and stay comfortably large at desktop widths. */
  --dial-digit-fs: clamp(1.5rem, 7vw, 3rem);
  --dial-btn-fs: clamp(1.1rem, 6vw, 2.25rem);
}

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

body,
html {
  font-family: "Roboto", sans-serif;
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  background-color: var(--soft-white);
}

button {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

a {
  color: var(--primary-color);
  text-decoration: none;
}

h1 {
  text-align: center;
  font-size: 1.5em;
}

h2,
h3,
h4,
h5,
h6 {
  color: var(--soft-black);
  padding: 0.75em 0 0.25em 0;
}

p {
  padding: 0.5em 0;
}

/* ---------- Header ---------- */

header {
  width: 100%;
  background-color: var(--soft-black);
  color: var(--soft-white);
  padding: 10px;
}

.header-content {
  max-width: var(--app-max-width);
  width: 100%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5em;
}

header .brand {
  display: flex;
  align-items: center;
  gap: 0.5em;
  color: var(--soft-white);
}

header img.logo {
  height: 42px;
  width: auto;
}

header .home-link {
  white-space: nowrap;
  text-decoration: none;
  font-size: 1.4em;
  font-weight: bold;
  color: var(--soft-white);
}

/* ---------- Main ---------- */

main {
  max-width: var(--app-max-width);
  background-color: white;
  margin: 0 auto;
  padding: 0.5em 1em;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.app-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- Input label + dials ---------- */

.input-label {
  font-size: 1.1em;
  font-weight: bold;
  padding: 0.5em 0 0.25em 0;
}

.pace-box {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 0.25em 0;
}

.clock {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.digitbox {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.digitbox.colon {
  justify-content: center;
  margin: 0 0.15em;
}

.digit {
  font-family: "PT Mono", monospace;
  font-weight: bold;
  font-size: var(--dial-digit-fs);
  line-height: 1.1;
  min-width: 0.8em;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

.svg-arrow {
  font-family: "Material Icons", sans-serif;
  font-size: var(--dial-btn-fs);
  color: var(--primary-color);
  background-color: white;
  cursor: pointer;
  border: solid var(--dark-accent) 2px;
  border-radius: 10px;
  margin: 4px 3px;
  padding: 0;
  min-width: 1.6em;
  min-height: 1.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 5k pace row ---------- */

.race-pace-text-box {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5em;
  padding: 0.35em 0;
}

.race-pace-prefix {
  font-size: 1.1em;
  font-weight: bold;
}

.race-pace {
  font-family: "PT Mono", monospace;
  font-weight: bold;
  font-size: 1.2em;
}

.unit-suffix {
  font-size: 0.85em;
  color: var(--soft-black);
}

/* ---------- Warnings ---------- */

.alert-box {
  width: 100%;
  max-width: var(--width-limit);
  margin: 0.5em auto;
}

.alert-inner {
  width: 100%;
  display: flex;
  align-items: center;
  background-color: #a5f3fc;
  border-radius: 10px;
  padding: 0.4em 0.6em;
  box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.05);
}

.alert-text {
  text-align: center;
  color: var(--soft-black);
  padding: 0 0.5em;
  line-height: 1.4;
}

/* "Enter a time" message (0:00) — informational, distinct from warnings */
.alert-inner.error {
  background-color: #fef3c7;
}

/* ---------- Results ---------- */

.spacer {
  font-size: 1.5em;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0.25em;
}

.results-div {
  padding: 0;
}

.result-table {
  flex: 1;
  max-width: 440px;
  margin: 0 auto;
  border-collapse: collapse;
}

.result-label {
  font-size: 0.75em;
  font-weight: bold;
  text-align: right;
  padding: 0.5em 0.6em 0.5em 0;
  white-space: nowrap;
}

.result-label.z2-label {
  font-size: 0.6em;
  line-height: 1.3;
}

.result-value {
  text-align: left;
  padding: 0.5em 0;
  white-space: nowrap;
}

.output-pace {
  font-family: "PT Mono", monospace;
  font-weight: bold;
  font-size: 2.2em;
  line-height: 1;
}

.output-pace.z2-pace {
  font-size: 1.6em;
}

.result-units {
  font-size: 0.7em;
  color: var(--uncertainty-color);
  margin-left: 0.25em;
}

.result-separator {
  border: none;
  border-top: 2px solid var(--toggle-color);
  margin: 0.1em 0;
}

/* ---------- Unit toggles / confidence ---------- */

.unit-stack-horiz {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3em;
  margin: 0.4em 0;
  width: 100%;
}

.unit-toggle {
  background-color: var(--toggle-color);
  border: none;
  border-radius: 5px;
  font-size: 1.1em;
  height: 1.6em;
  padding: 0.25em 0.5em;
  margin: 0.2em 0em;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.confidence-div {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5em;
  padding: 0.35em 0;
}

.conf-pre {
  font-size: 1.1em;
  color: var(--soft-black);
}

.conf-toggle-group {
  display: flex;
  gap: 0.3em;
}

/* ---------- Disclaimer ---------- */

.disclaimer {
  max-width: var(--width-limit);
  text-align: center;
  font-size: 0.85em;
  color: var(--uncertainty-color);
  padding: 0.5em 0.5em;
}

/* ---------- Controls (history / restore / remember) ---------- */

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.8em;
  padding: 0.5em 0 0.25em 0;
  max-width: var(--width-limit);
}

.ctrl-button {
  background-color: var(--toggle-color);
  border: none;
  border-radius: 5px;
  font-size: 1em;
  padding: 0.35em 0.6em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  white-space: nowrap;
}

.ctrl-button .material-icons {
  font-size: 1.2em;
  color: var(--primary-color);
}

.remember-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  cursor: pointer;
  font-size: 0.95em;
  white-space: nowrap;
}

.remember-text {
  font-weight: bold;
  color: var(--soft-black);
}

/* ---------- "?" info note ---------- */

.i-note {
  outline: none;
  cursor: pointer;
  border: solid var(--primary-color) 2px;
  background-color: white;
  font-size: 1.05rem;
  font-weight: bold;
  color: #2196f3;
  width: 1.6em;
  height: 1.6em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  flex: 0 0 auto;
}

/* ---------- Tooltip ---------- */

.tooltip-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  max-width: 80vw;
  background-color: var(--soft-black);
  color: var(--soft-white);
  font-size: 0.85em;
  line-height: 1.4;
  padding: 0.7em;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--soft-black);
}

.tooltip.open {
  display: block;
}

/* ---------- History panel ---------- */

.history-panel {
  width: 100%;
  max-width: var(--width-limit);
  margin: 0.25em auto 0.5em auto;
  background-color: var(--soft-white);
  border: 1px solid var(--toggle-color);
  border-radius: 8px;
  padding: 0.75em;
  text-align: center;
  font-size: 0.9em;
  color: var(--uncertainty-color);
}

/* ---------- Toggle switch ---------- */

.switch {
  position: relative;
  display: inline-block;
  width: var(--slider-width, 60px);
  height: var(--slider-height, 34px);
  vertical-align: middle;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: background-color 0.3s;
  border-radius: calc(var(--slider-height, 34px) / 2);
}

.slider:before {
  position: absolute;
  content: "";
  height: calc(var(--slider-height, 34px) - 8px);
  width: calc(var(--slider-height, 34px) - 8px);
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: transform 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #2196f3;
}

input:checked + .slider:before {
  transform: translateX(calc(var(--slider-width, 60px) - var(--slider-height, 34px)));
}

/* ---------- Active / hover / focus ---------- */

.active {
  background-color: var(--active-color);
  color: white;
}

.unit-toggle:active,
.conf-toggle:active {
  background-color: var(--active-color);
}

.svg-arrow:active {
  background-color: var(--link-hover-color);
}

.i-note:active {
  color: white;
  border-color: var(--link-hover-color);
}

@media (hover: hover) {
  .svg-arrow:hover,
  .unit-toggle:hover,
  .ctrl-button:hover {
    background-color: var(--hover-color);
    box-shadow: 0px 6px 8px rgba(0, 0, 0, 0.12);
  }
  .unit-toggle:hover {
    color: black;
  }
  .svg-arrow:hover {
    color: var(--dark-accent);
  }
  .i-note:hover {
    background-color: var(--hover-color);
    cursor: pointer;
  }
}

/* Visible focus (accessibility requirement — the reference app removes outlines; we do not copy that gap) */
:focus-visible {
  outline: 3px solid var(--link-hover-color);
  outline-offset: 2px;
}

/* ---------- Theory footer ---------- */

.theory-footer {
  max-width: var(--app-max-width);
  background-color: white;
  margin: 0 auto;
  padding: 0.5em 1em 2.5em 1em;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.theory-footer h2 {
  font-size: 1.15em;
  border-bottom: 2px solid var(--toggle-color);
  padding-bottom: 0.25em;
  margin-top: 1em;
}

.theory-footer p {
  font-size: 0.95em;
  line-height: 1.5;
  color: var(--soft-black);
}

/* ---------- Hidden ---------- */

.hidden {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 500px) {
  h1 {
    font-size: 1.33em;
  }
  main {
    padding: 0.25em 0.25em;
  }
  .theory-footer {
    padding: 0.25em 0.25em 1.5em 0.25em;
  }
  .svg-arrow {
    margin: 3px 2px;
    border-radius: 8px;
  }
  .race-pace-prefix {
    font-size: 1em;
  }
  .race-pace {
    font-size: 1.05em;
  }
  .result-label {
    font-size: 0.65em;
  }
  .result-label.z2-label {
    font-size: 0.55em;
  }
  .output-pace {
    font-size: 1.9em;
  }
  .output-pace.z2-pace {
    font-size: 1.4em;
  }
  .spacer {
    font-size: 1.25em;
  }
  .unit-toggle {
    font-size: 0.95em;
  }
  .conf-pre {
    font-size: 1em;
  }
}

@media (max-width: 400px) {
  h1 {
    font-size: 1.1em;
  }
  header img.logo {
    height: 32px;
  }
  header .home-link {
    font-size: 1.1em;
  }
  .input-label {
    font-size: 1em;
  }
  .digitbox.colon {
    margin: 0 0.05em;
  }
  .svg-arrow {
    border-width: 1.5px;
  }
  .race-pace-holder {
    white-space: nowrap;
  }
  .controls-row {
    gap: 0.5em;
  }
  .remember-text {
    font-size: 0.9em;
  }
  .switch {
    transform: scale(0.85);
    transform-origin: right center;
  }
}

/* ---- Embed variant (iframe on wielkikrzych.pl): hide chrome, keep tool ---- */
body.embed header {
  display: none;
}
body.embed main h1 {
  display: none;
}
body.embed .theory-footer {
  display: none;
}
