/* liftmath - "steel and chalk": cool graphite surfaces, chalk-white ink, a
   hot-iron accent. Dark is the default identity (a gym's ambient light is
   rarely bright white); light is available as an explicit override and is
   also honored automatically via prefers-color-scheme when no override has
   been chosen yet. See js/app.js's tiny theme toggle for how [data-theme]
   gets set - all the actual color values live here, keyed off that
   attribute, so the JS stays a thin "which block applies" switch. */

:root {
  --color-bg: #101216;
  --color-surface: #181b21;
  --color-surface-alt: #1f232b;
  --color-border: #2a2f39;
  --color-border-strong: #3a4150;
  --color-ink: #f4f5f7;
  --color-ink-dim: #c7cbd4;
  --color-faint: #9aa1ad;
  --color-accent: #e08347;
  --color-accent-ink: #1a1006;
  --color-danger: #ff8a80;
  --color-focus: #e08347;

  --plate-25: #d94f4f;
  --plate-20: #4f7fd9;
  --plate-15: #d9c34f;
  --plate-10: #4fae5a;
  --plate-5: #e8e8ea;
  --plate-2_5: #202329;
  --plate-1_25: #b7bdc7;
  --plate-other: #7d8797;
  --bar-steel: #7d8797;

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-surface-alt: #eceef1;
    --color-border: #d7dae0;
    --color-border-strong: #b7bdc7;
    --color-ink: #171a1f;
    --color-ink-dim: #3c4350;
    --color-faint: #565e6b;
    --color-accent: #c14b1f;
    --color-accent-ink: #fff7f2;
    --color-danger: #b3261e;
    --color-focus: #c14b1f;

    --plate-25: #c23b3b;
    --plate-20: #3b63b3;
    --plate-15: #b39c2f;
    --plate-10: #3b8a46;
    --plate-5: #e3e5e8;
    --plate-2_5: #23262c;
    --plate-1_25: #9aa1ad;
    --plate-other: #6b7480;
    --bar-steel: #6b7480;

    color-scheme: light;
  }
}

[data-theme="light"] {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-surface-alt: #eceef1;
  --color-border: #d7dae0;
  --color-border-strong: #b7bdc7;
  --color-ink: #171a1f;
  --color-ink-dim: #3c4350;
  --color-faint: #565e6b;
  --color-accent: #c14b1f;
  --color-accent-ink: #fff7f2;
  --color-danger: #b3261e;
  --color-focus: #c14b1f;

  --plate-25: #c23b3b;
  --plate-20: #3b63b3;
  --plate-15: #b39c2f;
  --plate-10: #3b8a46;
  --plate-5: #e3e5e8;
  --plate-2_5: #23262c;
  --plate-1_25: #9aa1ad;
  --plate-other: #6b7480;
  --bar-steel: #6b7480;

  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

a.visually-hidden:focus {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0.6rem 1rem;
  clip: auto;
  overflow: visible;
  background: var(--color-accent);
  color: var(--color-accent-ink);
  border-radius: 0.5rem;
  z-index: 1000;
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.app-title .accent {
  color: var(--color-accent);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.unit-toggle {
  display: flex;
  border: 1px solid var(--color-border-strong);
  border-radius: 0.6rem;
  overflow: hidden;
}

.unit-toggle button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.75rem;
  border: none;
  background: transparent;
  color: var(--color-ink-dim);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.unit-toggle button[aria-pressed="true"] {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

.icon-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.75rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 0.6rem;
  background: var(--color-surface-alt);
  color: var(--color-ink);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem;
  background: var(--color-bg);
  position: sticky;
  top: 64px;
  z-index: 9;
}

.tab {
  flex: 1 1 0;
  min-height: 48px;
  border: 1px solid var(--color-border);
  border-radius: 0.7rem;
  background: var(--color-surface);
  color: var(--color-ink-dim);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--color-surface-alt);
  border-color: var(--color-accent);
  color: var(--color-ink);
}

/* ---------- main / panels ---------- */

main {
  padding: 0.75rem 1rem 3rem;
  max-width: 640px;
  margin: 0 auto;
}

.tool-panel h2 {
  margin: 0.25rem 0 0.25rem;
  font-size: 1.15rem;
}

.disclaimer {
  margin: 0 0 1rem;
  color: var(--color-ink-dim);
  font-size: 0.9rem;
}

.hint {
  margin: 0.35rem 0 0;
  color: var(--color-ink-dim);
  font-size: 0.85rem;
}

/* ---------- fields ---------- */

.field {
  margin-bottom: 1rem;
}

.field > label,
.field > span {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-ink-dim);
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.75rem;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--color-border-strong);
  border-radius: 0.6rem;
  background: var(--color-surface);
  color: var(--color-ink);
}

select {
  font-variant-numeric: normal;
}

/* ---------- steppers ---------- */

.stepper-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.stepper-row input {
  text-align: center;
  flex: 1 1 auto;
  min-width: 0;
}

.stepper-btn {
  flex: 0 0 auto;
  width: 48px;
  min-height: 48px;
  font-size: 1.4rem;
  line-height: 1;
  border: 1px solid var(--color-border-strong);
  border-radius: 0.6rem;
  background: var(--color-surface-alt);
  color: var(--color-ink);
  cursor: pointer;
}

.stepper-btn:active {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

/* ---------- chips ---------- */

.chip-row,
.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  min-height: 44px;
  padding: 0 0.9rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-ink-dim);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-ink);
}

/* ---------- results ---------- */

.results {
  margin-top: 0.5rem;
}

.result-hero {
  padding: 1rem;
  border-radius: 0.8rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  margin-bottom: 0.75rem;
}

.result-hero .result-label {
  margin: 0 0 0.15rem;
  color: var(--color-ink-dim);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-hero .result-value {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-accent);
}

.result-hero .result-sub {
  margin: 0.35rem 0 0;
  color: var(--color-ink-dim);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.notice {
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border-strong);
  color: var(--color-ink-dim);
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
}

.notice.notice-warn {
  color: var(--color-danger);
  border-color: var(--color-danger);
}

table.result-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.75rem;
}

table.result-table th,
table.result-table td {
  padding: 0.5rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.95rem;
}

table.result-table th {
  color: var(--color-faint);
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.result-table td.num {
  text-align: right;
  font-weight: 600;
}

.onerm-percent-row {
  cursor: pointer;
}

.onerm-percent-row:hover,
.onerm-percent-row:focus-visible {
  background: var(--color-surface-alt);
}

.onerm-percent-row:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: -2px;
}

/* ---------- barbell ---------- */

.barbell-wrap {
  overflow-x: auto;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
}

.barbell-svg {
  width: 100%;
  height: auto;
  min-width: 320px;
  display: block;
}

.barbell-svg .bar {
  fill: var(--bar-steel);
}

.barbell-svg .plate text {
  font-size: 11px;
  font-weight: 700;
  fill: var(--color-bg);
  font-variant-numeric: tabular-nums;
}

.barbell-svg .plate text[data-plate-color="--plate-2_5"] {
  fill: var(--color-ink);
}

.plate-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-ink-dim);
}

.plate-legend .swatch {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border-radius: 0.2em;
  margin-right: 0.35em;
  vertical-align: -0.1em;
  border: 1px solid var(--color-border-strong);
}

.plate-legend .swatch[data-plate-color="--plate-25"] { background: var(--plate-25); }
.plate-legend .swatch[data-plate-color="--plate-20"] { background: var(--plate-20); }
.plate-legend .swatch[data-plate-color="--plate-15"] { background: var(--plate-15); }
.plate-legend .swatch[data-plate-color="--plate-10"] { background: var(--plate-10); }
.plate-legend .swatch[data-plate-color="--plate-5"] { background: var(--plate-5); }
.plate-legend .swatch[data-plate-color="--plate-2_5"] { background: var(--plate-2_5); }
.plate-legend .swatch[data-plate-color="--plate-1_25"] { background: var(--plate-1_25); }
.plate-legend .swatch[data-plate-color="--plate-other"] { background: var(--plate-other); }

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

.app-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
  color: var(--color-faint);
  font-size: 0.82rem;
  text-align: center;
}

.app-footer p {
  margin: 0 0 0.35rem;
}

.footer-links a {
  color: var(--color-accent);
}

/* ---------- world records ---------- */

.record-scope {
  display: block;
  margin-top: 0.1rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 600;
  color: var(--color-faint);
}

.record-meter {
  margin-top: 0.6rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.record-meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--color-accent);
}

.record-card a,
.results .hint a {
  color: var(--color-accent);
}

/* Six tabs now share the bar - shrink the labels a notch on narrow phones
   so "Records" and "Convert" don't overflow their pills. */
@media (max-width: 480px) {
  .tab {
    font-size: 0.82rem;
    padding-left: 0.1rem;
    padding-right: 0.1rem;
  }
}

/* ---------- rest timer ---------- */

/* [hidden] has to win over the flex display below - an author rule beats the
   UA stylesheet's [hidden] { display: none } at equal specificity, so
   without this the sheet would render even while hidden was set. */
.timer-sheet[hidden] {
  display: none;
}

.timer-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
  display: flex;
  align-items: flex-end;
}

.timer-sheet-inner {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-radius: 1rem 1rem 0 0;
  text-align: center;
}

#timer-close-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 1.4rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--color-ink-dim);
}

.timer-label {
  font-weight: 600;
  margin: 0 0 0.75rem;
}

.timer-ring {
  --pct: 0;
  width: 200px;
  height: 200px;
  margin: 0.5rem auto 1.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--color-accent) calc(var(--pct) * 1%), var(--color-border) 0);
}

.timer-ring span {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#timer-preset-group {
  justify-content: center;
}

#timer-picker .field {
  margin-top: 1.25rem;
  text-align: left;
}

#timer-custom-start-btn {
  flex: 0 0 auto;
  min-height: 48px;
  padding: 0 1.25rem;
  border: 1px solid var(--color-accent);
  border-radius: 0.6rem;
  background: var(--color-accent);
  color: var(--color-accent-ink);
  font-weight: 600;
  cursor: pointer;
}

#timer-stop-btn {
  min-height: 44px;
  padding: 0 1.5rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 0.6rem;
  background: var(--color-surface-alt);
  color: var(--color-ink);
  font-weight: 600;
  cursor: pointer;
}

/* Share added a third icon button to a header that only had room for two on
   a narrow phone - shrink the padding/gap rather than let it scroll sideways. */
@media (max-width: 400px) {
  .header-controls {
    gap: 0.3rem;
  }

  .icon-btn {
    padding: 0 0.5rem;
    font-size: 0.82rem;
  }
}
