/* ════════════════════════════════════════════════════════════════════════════
   SOMA — BIG3 RECORD
   Direction: competition platform. Numerals are stamped, data is tabular,
   the three lifts keep their hue everywhere (competition order S→B→D).
   ════════════════════════════════════════════════════════════════════════════ */

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

:root {
  color-scheme: dark;

  /* surfaces — cold graphite, not pure black */
  --ink-0: #0B0D12;
  --ink-1: #11141B;
  --ink-2: #181C25;
  --ink-3: #1F2431;

  /* hairlines */
  --line:   #232833;
  --line-2: #2E3542;
  --grid:   #1C212B;

  /* ink */
  --t1: #F2F4F8;
  --t2: #A8B0BF;
  --t3: #7C8798;

  /* series — validated all-pairs on --ink-0 (CVD ΔE 9.4, normal 20.9) */
  --s1: #3987e5;  /* 01 SQUAT    */
  --s2: #d95926;  /* 02 BENCH    */
  --s3: #199e70;  /* 03 DEADLIFT */

  /* status */
  --good: #0ca30c;
  --crit: #d03b3b;

  /* IPF plate colors — literal depiction, always weight-labeled */
  --p25: #C8102E; --p20: #0057B8; --p15: #FFD100;
  --p10: #009639; --p5: #E9EBEF;  --p2: #14171D; --p1: #B9BEC6;

  --ja: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", sans-serif;
  --sans: "Archivo", system-ui, -apple-system, "Segoe UI", var(--ja), sans-serif;
  --mono: "Martian Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r: 10px;
  --pad: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  background: var(--ink-0);
  color: var(--t1);
  font-family: var(--sans);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

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

/* ─── SHELL ──────────────────────────────────────────────────────────────── */
#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.view { display: none; flex: 1; min-height: 0; }
.view.is-on { display: flex; flex-direction: column; }

.scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.wrap {
  width: 100%; max-width: 520px; margin: 0 auto;
  padding: 16px var(--pad) calc(28px + var(--safe-b));
  display: flex; flex-direction: column; gap: 14px;
}

/* ─── HEADER ─────────────────────────────────────────────────────────────── */
.hd {
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
  background: var(--ink-0);
  flex: none;
}
.hd-in {
  max-width: 520px; margin: 0 auto; padding: 12px var(--pad);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.wordmark { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.wordmark-s {
  font-weight: 900; font-size: 1.18rem; letter-spacing: -0.045em;
  font-stretch: 125%;
}
.wordmark-sub {
  font-family: var(--mono); font-size: 0.5rem; font-weight: 500;
  letter-spacing: 0.24em; color: var(--t3); white-space: nowrap;
}

.sync {
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: 1px solid var(--line); border-radius: 100px;
  padding: 5px 11px 5px 9px; color: var(--t2); cursor: pointer;
  font-family: var(--mono); font-size: 0.55rem; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}
.sync-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--t3); flex: none;
  transition: background 0.2s;
}
.sync[data-state="ok"]      .sync-dot { background: var(--good); }
.sync[data-state="pending"] .sync-dot { background: #fab219; animation: pulse 1.1s ease-in-out infinite; }
.sync[data-state="off"]     .sync-dot { background: var(--t3); }
.sync[data-state="err"]     .sync-dot { background: var(--crit); }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .sync-dot { animation: none !important; } }

/* ─── TABS ───────────────────────────────────────────────────────────────── */
.tabs {
  flex: none; display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line); background: var(--ink-0);
  padding-bottom: var(--safe-b);
  max-width: 520px; margin: 0 auto; width: 100%;
}
.tab {
  background: none; border: none; cursor: pointer; padding: 13px 4px 14px;
  color: var(--t3); position: relative; -webkit-tap-highlight-color: transparent;
}
.tab-t {
  font-family: var(--ja); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em;
}
.tab[aria-current="page"] { color: var(--t1); }
.tab[aria-current="page"]::before {
  content: ""; position: absolute; inset: -1px 22% auto; height: 2px; background: var(--t1);
}

/* ─── TYPE ───────────────────────────────────────────────────────────────── */
.eyebrow {
  font-family: var(--mono); font-size: 0.53rem; font-weight: 500;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--t3);
  display: inline-flex; align-items: baseline; gap: 4px;
}
.eyebrow i { font-style: normal; opacity: 0.65; letter-spacing: 0.1em; }
.note {
  font-family: var(--ja); font-size: 0.7rem; line-height: 1.65; color: var(--t3);
}
.lede { font-family: var(--ja); font-size: 0.8rem; line-height: 1.7; color: var(--t2); }

/* ─── BUTTONS ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: var(--r); cursor: pointer; border: 1px solid transparent;
  font-family: var(--ja); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em;
  padding: 13px 18px; min-height: 44px; transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent; background: none; color: var(--t1);
}
.btn-solid { background: var(--t1); color: var(--ink-0); font-weight: 700; }
.btn-solid:active { background: #c9ced8; }
.btn-line { border-color: var(--line-2); }
.btn-line:active { background: var(--ink-2); }
.btn-quiet {
  color: var(--t2); font-size: 0.72rem; padding: 10px 12px; min-height: 38px;
  font-family: var(--mono); font-weight: 500; letter-spacing: 0.1em;
}
.btn-quiet:active { color: var(--t1); }
.btn-full { width: 100%; }

/* ─── DATE BAR ───────────────────────────────────────────────────────────── */
.datebar {
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: stretch;
  border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  background: var(--ink-1);
}
.datebar-nav {
  background: none; border: none; color: var(--t2); font-size: 1.3rem; cursor: pointer;
  line-height: 1; -webkit-tap-highlight-color: transparent;
}
.datebar-nav:active { background: var(--ink-2); }
.datebar-field {
  display: flex; flex-direction: column; gap: 3px; align-items: center;
  padding: 9px 0 10px; border-inline: 1px solid var(--line);
}
.datebar-field input[type="date"] {
  background: none; border: none; color: var(--t1); font-family: var(--mono);
  font-size: 0.86rem; font-weight: 500; text-align: center; padding: 0;
  letter-spacing: 0.02em; width: 100%;
}

/* ─── INPUTS ─────────────────────────────────────────────────────────────── */
.nfield { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.nfield input {
  width: 100%; background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 8px; color: var(--t1); padding: 12px 10px;
  font-family: var(--mono); font-size: 1.02rem; font-weight: 500;
  text-align: center; letter-spacing: -0.01em; -moz-appearance: textfield;
}
.nfield input::-webkit-outer-spin-button,
.nfield input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.nfield input::placeholder { color: #39404C; font-weight: 400; }
.nfield input:focus { border-color: var(--t2); outline: none; }

/* ─── BLOCKS ─────────────────────────────────────────────────────────────── */
.block {
  background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--r);
  padding: 15px; display: flex; flex-direction: column; gap: 13px;
}
.block-hd { display: flex; align-items: center; gap: 10px; }
.block-no {
  font-family: var(--mono); font-size: 0.6rem; font-weight: 700; color: var(--t3);
  letter-spacing: 0.05em; padding-top: 1px;
}
.block-name {
  font-size: 0.95rem; font-weight: 800; letter-spacing: 0.13em; font-stretch: 112%;
  text-transform: uppercase;
}
.block-meta {
  margin-left: auto; font-family: var(--mono); font-size: 0.58rem; font-weight: 500;
  color: var(--t3); letter-spacing: 0.06em; text-align: right;
}
.block-meta b { color: var(--t1); font-weight: 700; }

.block-ja {
  margin-left: auto; font-family: var(--ja); font-size: 0.68rem; color: var(--t3);
}
/* the day's numbers get their own line — three short facts read better than one long one */
.block-stats {
  display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: -5px;
  font-family: var(--mono); font-size: 0.6rem; font-weight: 500; color: var(--t3);
  letter-spacing: 0.04em;
}
.block-stats:empty { display: none; }
.block-stats b { color: var(--t1); font-weight: 700; font-size: 0.72rem; letter-spacing: -0.01em; }

/* per-lift accent — set inline via --a */
.block-lift { border-left: 2px solid var(--a, var(--line)); }
.block-lift .block-no { color: var(--a); }

/* set entry — weight / reps-per-set / how many sets, then a full-width 追加 */
.setrow { display: grid; grid-template-columns: 1.15fr 1fr 0.8fr; gap: 8px; align-items: end; }
.nudge { display: flex; gap: 6px; }
.nudge button {
  flex: 1; background: var(--ink-2); border: 1px solid var(--line); border-radius: 7px;
  color: var(--t2); font-family: var(--mono); font-size: 0.62rem; font-weight: 500;
  padding: 8px 0; cursor: pointer; letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
}
.nudge button:active { background: var(--ink-3); color: var(--t1); }

/* logged sets */
.sets { display: flex; flex-direction: column; gap: 1px; }
.set {
  display: grid; grid-template-columns: 22px auto 1fr auto 34px; align-items: center;
  gap: 9px; padding: 9px 2px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 0.8rem;
}
.set-i { color: var(--t3); font-size: 0.62rem; font-weight: 500; }
.set-w { font-weight: 600; letter-spacing: -0.01em; }
.set-w em { font-style: normal; color: var(--t3); font-size: 0.7rem; font-weight: 400; }
.set-r { color: var(--t2); }
.set-o { font-size: 0.62rem; color: var(--t3); text-align: right; }
.set-del {
  background: none; border: none; color: var(--t3); cursor: pointer; font-size: 0.95rem;
  padding: 6px; line-height: 1; -webkit-tap-highlight-color: transparent;
}
.set-del:active { color: var(--crit); }
.empty {
  font-family: var(--ja); font-size: 0.72rem; color: var(--t3);
  padding: 10px 0 2px; border-top: 1px solid var(--line);
}

/* ─── PLATE STRIP (signature) ────────────────────────────────────────────── */
.plates { display: flex; flex-direction: column; gap: 6px; }
.plates-hd {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.plates-hd .eyebrow { letter-spacing: 0.16em; }
.plates-sum {
  font-family: var(--mono); font-size: 0.6rem; color: var(--t2); font-weight: 500;
}
.plates-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 11px; min-height: 50px;
}
.plates-bar { display: flex; align-items: center; gap: 3px; height: 36px; flex: none; }
.plates-sleeve { width: 13px; height: 5px; background: #4A5261; border-radius: 2px; flex: none; }
.plate { flex: none; width: 9px; border-radius: 2px; }
/* the 2.5kg disc is near-black; it needs an edge to be seen against the surface */
.plate-dark { box-shadow: inset 0 0 0 1px #454C59; }
.plates-list {
  font-family: var(--mono); font-size: 0.68rem; font-weight: 600; color: var(--t1);
  letter-spacing: 0.02em; line-height: 1.4;
}
.plates-list:only-child { color: var(--t3); font-weight: 500; }

/* ─── SETTINGS ───────────────────────────────────────────────────────────── */
.block-settings { padding: 0; gap: 0; }
.block-settings > summary {
  padding: 15px; display: flex; align-items: baseline; gap: 10px; cursor: pointer;
  list-style: none;
}
.block-settings > summary::-webkit-details-marker { display: none; }
.block-settings > summary::after {
  content: "＋"; margin-left: auto; color: var(--t3); font-size: 0.8rem;
}
.block-settings[open] > summary::after { content: "−"; }
.block-settings > summary .block-meta { margin-left: 0; }
.settings-in {
  padding: 0 15px 15px; display: flex; flex-direction: column; gap: 12px;
  border-top: 1px solid var(--line); padding-top: 14px;
}
.settings-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.settings-row .btn { border: 1px solid var(--line-2); border-radius: var(--r); }
.body-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.body-grid-2 { grid-template-columns: repeat(2, 1fr); }

/* ─── HERO ───────────────────────────────────────────────────────────────── */
.hero {
  border: 1px solid var(--line); border-radius: var(--r); background: var(--ink-1);
  padding: 16px 16px 18px; display: flex; flex-direction: column; gap: 2px;
}
.hero-fig { display: flex; align-items: baseline; gap: 7px; margin-top: 6px; }
.hero-num {
  font-size: clamp(3.1rem, 17vw, 4.6rem); font-weight: 900; line-height: 0.82;
  letter-spacing: -0.05em; font-stretch: 118%;
}
.hero-unit {
  font-family: var(--mono); font-size: 0.78rem; font-weight: 500; color: var(--t2);
}
.hero-delta {
  font-family: var(--mono); font-size: 0.68rem; font-weight: 500; margin-top: 9px;
  display: flex; align-items: center; gap: 6px; color: var(--t3);
}
.hero-delta b { font-weight: 700; letter-spacing: 0.01em; }
.hero-delta.is-up b { color: var(--good); }
.hero-delta.is-down b { color: var(--crit); }
.hero-goal { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.hero-goal-txt {
  font-family: var(--mono); font-size: 0.58rem; color: var(--t3); letter-spacing: 0.08em;
  display: flex; justify-content: space-between;
}
.hero-goal-txt b { color: var(--t2); font-weight: 600; }
.meter { height: 3px; background: var(--ink-3); border-radius: 2px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--t1); border-radius: 2px; }

/* ─── FILTERS ────────────────────────────────────────────────────────────── */
.filters { display: flex; flex-direction: column; gap: 8px; }
.seg {
  display: flex; gap: 2px; padding: 2px; background: var(--ink-1);
  border: 1px solid var(--line); border-radius: 9px;
}
.seg button {
  flex: 1; background: none; border: none; border-radius: 7px; cursor: pointer;
  color: var(--t3); padding: 9px 4px; font-family: var(--ja); font-size: 0.74rem;
  font-weight: 600; letter-spacing: 0.04em; -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.seg button[aria-selected="true"] { background: var(--ink-3); color: var(--t1); }
.seg-sm button { font-size: 0.68rem; padding: 7px 4px; }

/* ─── FIGURES ────────────────────────────────────────────────────────────── */
.fig {
  border: 1px solid var(--line); border-radius: var(--r); background: var(--ink-1);
  padding: 15px 12px 11px; display: flex; flex-direction: column; gap: 11px;
}
.fig-cap {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 0 3px;
}
.fig-title {
  font-family: var(--ja); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.03em;
  color: var(--t1);
}
.fig-unit { font-family: var(--mono); font-size: 0.55rem; color: var(--t3); letter-spacing: 0.1em; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0 3px; }
.lg { display: inline-flex; align-items: center; gap: 6px; background: none; border: none;
      padding: 2px 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.lg-swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.lg-t {
  font-family: var(--mono); font-size: 0.56rem; font-weight: 500; letter-spacing: 0.11em;
  color: var(--t2); text-transform: uppercase;
}
.lg[aria-pressed="false"] { opacity: 0.35; }

.plot { width: 100%; }
.plot svg, .sm svg { display: block; width: 100%; height: auto; overflow: visible; }
.sm { display: flex; flex-direction: column; gap: 4px; }

/* chart internals */
.ax-line { stroke: var(--line-2); stroke-width: 1; }
.ax-grid { stroke: var(--grid); stroke-width: 1; }
.ax-t {
  font-family: var(--mono); font-size: 9px; font-weight: 500; fill: var(--t3);
  letter-spacing: 0.04em;
}
.ax-t.is-y { text-anchor: end; }
.ln { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dot { stroke: var(--ink-1); stroke-width: 2; }
.tip-line { stroke: var(--t3); stroke-width: 1; }
.dlabel {
  font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: -0.01em;
  /* halo, so a label sitting mid-plot survives a line or dot crossing it */
  paint-order: stroke fill; stroke: var(--ink-1); stroke-width: 3px; stroke-linejoin: round;
}
.sm-title {
  font-family: var(--mono); font-size: 0.53rem; font-weight: 500; letter-spacing: 0.16em;
  fill: var(--t3); text-transform: uppercase;
}
.sm-val { font-family: var(--mono); font-size: 11px; font-weight: 700; fill: var(--t1); }
.hit { fill: transparent; cursor: crosshair; }

.tip {
  position: absolute; pointer-events: none; z-index: 30; min-width: 132px;
  background: var(--ink-3); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 9px 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  transform: translate(-50%, -100%); opacity: 0; transition: opacity 0.1s;
}
.tip.is-on { opacity: 1; }
.tip-d {
  font-family: var(--mono); font-size: 0.55rem; color: var(--t3); letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.tip-r { display: flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 0.63rem; }
.tip-r + .tip-r { margin-top: 3px; }
.tip-r span:first-child { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tip-r .tip-n { color: var(--t2); flex: 1; letter-spacing: 0.06em; }
.tip-r .tip-v { color: var(--t1); font-weight: 700; font-variant-numeric: tabular-nums; }

.plotbox { position: relative; }

/* table view */
.btn-table { align-self: flex-start; }
.tableview { overflow-x: auto; border-top: 1px solid var(--line); padding-top: 8px; }
.tableview table { border-collapse: collapse; width: 100%; font-family: var(--mono); font-size: 0.62rem; }
.tableview th, .tableview td {
  padding: 6px 8px; text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--line);
}
.tableview th { color: var(--t3); font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; }
.tableview td { color: var(--t2); }
.tableview th:first-child, .tableview td:first-child { text-align: left; }

/* ─── PR ROWS ────────────────────────────────────────────────────────────── */
.prs { display: flex; flex-direction: column; gap: 8px; }
.prs-hd { padding: 4px 2px 0; letter-spacing: 0.16em; }
.pr {
  border: 1px solid var(--line); border-left: 2px solid var(--a); border-radius: var(--r);
  background: var(--ink-1); padding: 13px 14px; display: flex; flex-direction: column; gap: 9px;
}
.pr-top { display: flex; align-items: baseline; gap: 9px; }
.pr-no { font-family: var(--mono); font-size: 0.58rem; font-weight: 700; color: var(--a); }
.pr-name {
  font-size: 0.86rem; font-weight: 800; letter-spacing: 0.13em; font-stretch: 112%;
}
.pr-fig { margin-left: auto; display: flex; align-items: baseline; gap: 4px; }
.pr-num { font-size: 1.5rem; font-weight: 900; letter-spacing: -0.035em; line-height: 1; }
.pr-unit { font-family: var(--mono); font-size: 0.55rem; color: var(--t3); }
.pr-sub {
  display: flex; gap: 14px; font-family: var(--mono); font-size: 0.56rem; color: var(--t3);
  letter-spacing: 0.06em; flex-wrap: wrap;
}
.pr-sub b { color: var(--t2); font-weight: 600; }
.pr-sub .up { color: var(--good); }

/* ─── SHARE CARD ─────────────────────────────────────────────────────────── */
.cardstage {
  border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  background: var(--ink-0);
}
.cardstage canvas { display: block; width: 100%; height: auto; }
.cardactions { display: flex; flex-direction: column; gap: 8px; }

/* ─── GATE ───────────────────────────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 60; background: var(--ink-0);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate[hidden] { display: none; }
.gate-box { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.gate-mark { font-size: 1.7rem; }
.gate-lede { font-family: var(--ja); font-size: 0.78rem; line-height: 1.7; color: var(--t2); }
.gate-box input {
  width: 100%; background: var(--ink-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--t1); padding: 14px; font-family: var(--mono); font-size: 0.9rem;
}
.gate-box input:focus { border-color: var(--t2); outline: none; }

/* ─── TOAST ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translate(-50%, 8px);
  z-index: 50; background: var(--t1); color: var(--ink-0); border-radius: 100px;
  padding: 9px 18px; font-family: var(--ja); font-size: 0.74rem; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
  max-width: calc(100% - 40px); text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
