/* Bluetoothサイクルメーター Pro v1.2.2 */
:root {
  --bg-a: #07111f;
  --bg-b: #0d2342;
  --panel: rgba(11, 20, 35, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.07);
  --panel-line: rgba(148, 163, 184, 0.22);
  --text: #f8fafc;
  --muted: #aebbd0;
  --blue: #2f8cff;
  --blue-dark: #1565c0;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #facc15;
  --heart: #fb7185;
  --power: #facc15;
  --cadence: #60a5fa;
  --footer-blue: #1d4ed8;
  --footer-bg: transparent;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, #173b68 0%, var(--bg-a) 55%, #030712 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 10px calc(10px + var(--safe-bottom));
  touch-action: manipulation;
}

button, select, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; }

.app-shell {
  width: min(100%, 430px);
  margin: 0 auto;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

.app-screen {
  width: 100%;
  min-height: calc(100svh - 88px - var(--safe-bottom));
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(8, 18, 33, 0.99), rgba(4, 9, 18, 0.99));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
  position: relative;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
}

.app-title { min-width: 0; text-align: center; }

.app-title h1 {
  margin: 0;
  font-size: 1.04rem;
  line-height: 1.25;
  letter-spacing: 0.04em;
}

.status-line {
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.12);
}

.status-dot.live {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.14), 0 0 18px rgba(34, 197, 94, 0.45);
}

.status-dot.warn {
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.12);
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.12);
}

.page {
  display: none;
  min-height: calc(100svh - 148px - var(--safe-bottom));
  padding: 12px 14px 78px;
}

#pageSpeed.is-active,
#pageStats.is-active,
#pageSettings.is-active {
  display: flex;
  flex-direction: column;
}

.sensor-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.sensor-chip {
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 13px;
  background: rgba(255,255,255,0.045);
  padding: 7px 4px;
  text-align: center;
}

.sensor-chip span {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1.1;
  white-space: nowrap;
}

.sensor-chip b {
  display: block;
  margin-top: 4px;
  color: #94a3b8;
  font-size: 0.58rem;
  line-height: 1.1;
  white-space: nowrap;
}

.sensor-chip.is-on {
  border-color: rgba(34,197,94,0.42);
  background: rgba(34,197,94,0.10);
}

.sensor-chip.is-on b { color: #86efac; }

.speed-panel {
  margin-top: 0;
  min-height: 0;
  flex: 1 1 auto;
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  background: radial-gradient(circle at 50% 24%, rgba(47, 140, 255, 0.25), rgba(12, 30, 56, 0.76) 50%, rgba(5, 11, 22, 0.94) 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 14px 12px;
  text-align: center;
}

.readout-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.83rem;
  letter-spacing: 0.06em;
}

.speed-ring {
  width: min(72vw, 300px);
  aspect-ratio: 1 / 0.72;
  margin: 0 auto;
  border-radius: 999px 999px 44px 44px;
  border: 6px solid rgba(47, 140, 255, 0.34);
  border-bottom: 1px solid rgba(47, 140, 255, 0.12);
  box-shadow: 0 0 36px rgba(47, 140, 255, 0.28), inset 0 0 30px rgba(47, 140, 255, 0.16);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.speed-value {
  font-size: clamp(4.4rem, 20vw, 6.2rem);
  line-height: 0.92;
  font-weight: 950;
  letter-spacing: -0.06em;
  color: #ffffff;
  text-shadow: 0 0 30px rgba(47, 140, 255, 0.72);
  font-variant-numeric: tabular-nums;
}

.speed-unit {
  margin-top: 8px;
  font-size: 1.2rem;
  font-weight: 850;
  color: #b9e6ff;
  letter-spacing: 0.03em;
}

.sub-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 16px;
}

.metric-chip {
  min-height: 76px;
  border: 1px solid rgba(96, 165, 250, 0.30);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.45);
  padding: 8px 4px;
  text-align: center;
}

.metric-chip .label {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.2;
}

.metric-chip .num {
  display: block;
  margin-top: 4px;
  font-size: 1.28rem;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.metric-chip .unit {
  display: block;
  color: var(--muted);
  font-size: 0.65rem;
}

.metric-chip.heart .num { color: var(--heart); }
.metric-chip.power .num { color: var(--power); }
.metric-chip.cadence .num { color: var(--cadence); }
.metric-chip.distance .num { color: #bfdbfe; }

.action-row {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 0;
  padding-top: 8px;
  padding-bottom: 8px;
}

.primary-action,
.outline-action,
.connect-tile {
  border: 0;
  min-height: 54px;
  border-radius: 18px;
  font-weight: 900;
  color: #fff;
}

.primary-action {
  background: linear-gradient(180deg, #2488ff, #155bd6);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.32), 0 0 24px rgba(47,140,255,0.22);
  font-size: 1.08rem;
  letter-spacing: 0.03em;
}

.primary-action.is-connected {
  background: linear-gradient(180deg, #22c55e, #15803d);
}

.primary-action.is-error {
  background: linear-gradient(180deg, #ef4444, #b91c1c);
}

.stat-header {
  margin: 2px 0 8px;
  text-align: center;
}

.stat-header h2,
.settings-card h2 {
  margin: 0;
  font-size: 1.12rem;
}

.stats-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin-top: 4px;
}

.grid-stat-card {
  min-height: 86px;
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  background: radial-gradient(circle at 50% 18%, rgba(47, 140, 255, 0.14), rgba(15, 23, 42, 0.90) 66%, rgba(2, 6, 23, 0.96) 100%);
  padding: 8px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.grid-stat-card h3 {
  margin: 0 0 6px;
  color: #dbeafe;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.grid-stat-number {
  font-size: clamp(1.8rem, 8.2vw, 2.45rem);
  line-height: 1;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.grid-stat-time {
  font-size: clamp(1.25rem, 5.5vw, 1.7rem);
  line-height: 1.05;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.grid-stat-unit {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.grid-stat-card.avg .grid-stat-number { color: #4ade80; }
.grid-stat-card.max .grid-stat-number { color: #fde047; }
.grid-stat-card.elapsed .grid-stat-time { color: #c4b5fd; }
.grid-stat-card.distance .grid-stat-number { color: #60a5fa; }
.grid-stat-card.heart .grid-stat-number { color: var(--heart); }
.grid-stat-card.power .grid-stat-number { color: var(--power); }
.grid-stat-card.cadence .grid-stat-number { color: var(--cadence); }

.record-actions {
  margin-top: auto;
  padding-top: 10px;
  padding-bottom: 14px;
}

.record-actions .outline-action {
  margin-top: 0;
  min-height: 48px;
  width: 100%;
  background: transparent;
  color: #93c5fd;
  border: 1px solid rgba(96, 165, 250, 0.54);
}

.settings-card {
  border: 1px solid var(--panel-line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.06);
  padding: 15px;
}

.settings-card p,
.note-text {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.6;
}

.connect-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.connect-tile {
  min-height: 48px;
  border: 1px solid rgba(96, 165, 250, 0.34);
  background: rgba(47, 140, 255, 0.14);
  color: #dbeafe;
  font-size: 0.78rem;
}

.connect-tile.is-connected {
  border-color: rgba(34, 197, 94, 0.46);
  background: rgba(34, 197, 94, 0.16);
  color: #bbf7d0;
}

.connect-tile.danger {
  border-color: rgba(239, 68, 68, 0.34);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.setting-row {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
}

.setting-row label {
  display: block;
  color: #dbeafe;
  font-size: 0.86rem;
  font-weight: 850;
  margin-bottom: 7px;
}

.setting-row select,
.setting-row input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.72);
  color: #f8fafc;
  padding: 0 12px;
}

.setting-row input[type="number"] { margin-top: 8px; }
.setting-row input[type="checkbox"] { accent-color: var(--blue); }

.check-label {
  display: flex !important;
  align-items: flex-start;
  gap: 9px;
  line-height: 1.45;
}

.setting-hint {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.message-box {
  margin-top: 10px;
  border: 1px solid rgba(250, 204, 21, 0.28);
  border-radius: 16px;
  background: rgba(250, 204, 21, 0.08);
  color: #fef3c7;
  padding: 10px 12px;
  font-size: 0.76rem;
  line-height: 1.5;
}

.message-box[hidden] { display: none; }

.bottom-nav {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(7px + var(--safe-bottom));
  height: 58px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
}

.bottom-nav button {
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  font-size: 0.70rem;
  font-weight: 850;
  line-height: 1.1;
}

.bottom-nav button span {
  display: block;
  font-size: 1.08rem;
  line-height: 1;
  margin-bottom: 1px;
}

.bottom-nav button.is-active {
  color: #ffffff;
  background: rgba(47, 140, 255, 0.17);
}

.help-sheet {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: none;
  align-items: flex-end;
  z-index: 50;
}

.help-sheet.is-open { display: flex; }

.help-card {
  width: 100%;
  border-radius: 28px 28px 0 0;
  background: #0b1423;
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 20px 18px calc(22px + var(--safe-bottom));
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.35);
}

.help-card h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.help-card ul {
  margin: 0;
  padding-left: 1.2em;
  color: #dbeafe;
  line-height: 1.72;
  font-size: 0.86rem;
}

.help-card button {
  width: 100%;
  margin-top: 16px;
  min-height: 46px;
  border: 0;
  border-radius: 16px;
  background: var(--blue-dark);
  color: #fff;
  font-weight: 900;
}

.app-footer {
  width: min(100%, 430px);
  flex: 0 0 auto;
  margin: 8px auto 0;
  min-height: 30px;
  border-top: 0;
  border-radius: 12px;
  background: var(--footer-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-footer p {
  margin: 0;
  padding: 6px 10px;
  font-size: 0.78rem;
  line-height: 1.2;
  text-align: center;
  color: var(--footer-blue);
}

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

.app-footer a:hover { text-decoration: underline; }

.ad-panel {
  width: min(100%, 430px);
  margin: 8px auto 0;
  border: 1px solid #d7e6f8;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;
  color: #1f2937;
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 29px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: #4f6f91;
  line-height: 1;
}

.ad-notice {
  flex: 1 1 auto;
  text-align: right;
  font-size: 0.70rem;
  color: #64748b;
  line-height: 1.2;
}

.ad-close-btn {
  flex: 0 0 auto;
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border: none;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 800;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.ad-body {
  padding: 8px;
  min-height: 64px;
  background: #ffffff;
}

@media (max-width: 360px) {
  body { padding-left: 6px; padding-right: 6px; }
  .page { padding-left: 10px; padding-right: 10px; padding-bottom: 66px; }
  .speed-value { font-size: clamp(3.8rem, 18vw, 5.3rem); }
  .sub-metrics { gap: 5px; }
  .metric-chip { min-height: 68px; }
  .metric-chip .num { font-size: 1.05rem; }
  .stats-grid { gap: 7px; }
  .grid-stat-card { min-height: 78px; }
}


/* v1.1.4 start-stop and settings connection refinement */
.connect-grid.single{grid-template-columns:1fr;}
.primary-action.is-running{background:linear-gradient(180deg,#ff5b5b,#dc2626);box-shadow:0 12px 26px rgba(239,68,68,.28);}
.primary-action:disabled,.connect-tile:disabled{opacity:.48;cursor:not-allowed;}


/* v1.1.4 sensor-type guidance */
.setting-hint strong {
  color: #dbeafe;
}
.connect-tile.cadence {
  border-color: rgba(96, 165, 250, 0.34);
  background: rgba(96, 165, 250, 0.12);
  color: #dbeafe;
}
.connect-tile.cadence.is-connected {
  border-color: rgba(34, 197, 94, 0.46);
  background: rgba(34, 197, 94, 0.16);
  color: #bbf7d0;
}

/* v1.2.0：端末保存・再接続・走行履歴 */
#pageStats.is-active,
#pageSettings.is-active {
  overflow-y: auto;
  max-height: calc(100svh - 64px - var(--safe-bottom));
  scrollbar-width: thin;
}

.setting-reset-btn,
.history-clear-btn {
  width: 100%;
  min-height: 40px;
  margin-top: 9px;
  border: 1px solid rgba(96, 165, 250, 0.45);
  border-radius: 13px;
  background: rgba(47, 140, 255, 0.12);
  color: #bfdbfe;
  font-weight: 800;
}

.history-panel {
  margin: 2px 0 18px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.20);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.045);
}

.history-head,
.history-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-head h3 {
  margin: 0;
  font-size: 1rem;
}

.history-head span {
  color: var(--muted);
  font-size: 0.72rem;
}

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

.history-empty {
  margin: 8px 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.history-item {
  padding: 10px;
  border: 1px solid rgba(96, 165, 250, 0.22);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.42);
}

.history-item-head strong {
  font-size: 0.78rem;
}

.history-item-head span {
  color: #bfdbfe;
  font-size: 0.82rem;
  font-weight: 900;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 8px;
}

.history-metrics div {
  min-width: 0;
  padding: 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.history-metrics span,
.history-metrics b {
  display: block;
}

.history-metrics span {
  color: var(--muted);
  font-size: 0.64rem;
}

.history-metrics b {
  margin-top: 2px;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.history-clear-btn {
  border-color: rgba(239, 68, 68, 0.38);
  background: rgba(239, 68, 68, 0.10);
  color: #fecaca;
}
